Skip to content

Commit

Permalink
Updating iree_status_t usage and adding tons of error messages.
Browse files Browse the repository at this point in the history
Progress on #265.

# Conflicts:
#	iree/vm/bytecode_dispatch.c
  • Loading branch information
benvanik committed Aug 7, 2020
1 parent ead5ce8 commit a03076f
Show file tree
Hide file tree
Showing 30 changed files with 510 additions and 492 deletions.
8 changes: 4 additions & 4 deletions bindings/java/com/google/iree/native/instance_wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ void SetupVm() {
int argc = 1;
InitializeEnvironment(&argc, &aargv);

CHECK_EQ(IREE_STATUS_OK, iree_vm_register_builtin_types());
CHECK_EQ(IREE_STATUS_OK, iree_hal_module_register_types());
CHECK_EQ(IREE_STATUS_OK, iree_tensorlist_module_register_types());
CHECK_EQ(IREE_STATUS_OK, iree_strings_module_register_types());
IREE_CHECK_OK(iree_vm_register_builtin_types());
IREE_CHECK_OK(iree_hal_module_register_types());
IREE_CHECK_OK(iree_tensorlist_module_register_types());
IREE_CHECK_OK(iree_strings_module_register_types());
}

} // namespace
Expand Down
6 changes: 4 additions & 2 deletions bindings/python/pyiree/common/status_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ pybind11::error_already_set StatusToPyExc(const Status& status) {

pybind11::error_already_set ApiStatusToPyExc(iree_status_t status,
const char* message) {
assert(status != IREE_STATUS_OK);
auto full_message = absl::StrCat(message, ": ", static_cast<int>(status));
assert(!iree_status_is_ok(status));
auto full_message = absl::StrCat(
message, ": ", iree_status_code_string(iree_status_code(status)));
PyErr_SetString(ApiStatusToPyExcClass(status), full_message.c_str());
iree_status_ignore(status);
return pybind11::error_already_set();
}

Expand Down
2 changes: 1 addition & 1 deletion bindings/python/pyiree/common/status_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pybind11::error_already_set ApiStatusToPyExc(iree_status_t status,
const char* message);

inline void CheckApiStatus(iree_status_t status, const char* message) {
if (status == IREE_STATUS_OK) {
if (iree_status_is_ok(status)) {
return;
}
throw ApiStatusToPyExc(status, message);
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/pyiree/rt/hal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class HalMappedMemory {
~HalMappedMemory() {
if (bv_) {
iree_hal_buffer_t* buffer = iree_hal_buffer_view_buffer(bv_);
CHECK_EQ(iree_hal_buffer_unmap(buffer, &mapped_memory_), IREE_STATUS_OK);
IREE_CHECK_OK(iree_hal_buffer_unmap(buffer, &mapped_memory_));
iree_hal_buffer_view_release(bv_);
}
}
Expand Down
16 changes: 9 additions & 7 deletions bindings/python/pyiree/rt/vm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ std::unique_ptr<FunctionAbi> VmContext::CreateFunctionAbi(
attrs.push_back({});
auto status = iree_vm_get_function_reflection_attr(
f, i, &attrs.back().first, &attrs.back().second);
if (status == IREE_STATUS_NOT_FOUND) {
if (iree_status_is_not_found(status) {
iree_status_ignore(status);
attrs.pop_back();
break;
}
Expand Down Expand Up @@ -165,7 +166,7 @@ VmModule VmModule::FromFlatbufferBlob(py::buffer flatbuffer_blob) {
{static_cast<const uint8_t*>(buffer_info.ptr),
static_cast<iree_host_size_t>(buffer_info.size)},
deallocator, IREE_ALLOCATOR_SYSTEM, &module);
if (status != IREE_STATUS_OK) {
if (!iree_status_is_ok(status)) {
deallocator.free(raw_ptr, nullptr);
}

Expand All @@ -178,7 +179,8 @@ absl::optional<iree_vm_function_t> VmModule::LookupFunction(
iree_vm_function_t f;
auto status = iree_vm_module_lookup_function_by_name(
raw_ptr(), linkage, {name.data(), name.size()}, &f);
if (status == IREE_STATUS_NOT_FOUND) {
if (iree_status_is_not_found(status)) {
iree_status_ignore(status);
return absl::nullopt;
}
CheckApiStatus(status, "Error looking up function");
Expand Down Expand Up @@ -236,10 +238,10 @@ std::string VmVariantList::DebugString() const {
}

void SetupVmBindings(pybind11::module m) {
CHECK_EQ(IREE_STATUS_OK, iree_vm_register_builtin_types());
CHECK_EQ(IREE_STATUS_OK, iree_hal_module_register_types());
CHECK_EQ(IREE_STATUS_OK, iree_tensorlist_module_register_types());
CHECK_EQ(IREE_STATUS_OK, iree_strings_module_register_types());
IREE_CHECK_OK(iree_vm_register_builtin_types());
IREE_CHECK_OK(iree_hal_module_register_types());
IREE_CHECK_OK(iree_tensorlist_module_register_types());
IREE_CHECK_OK(iree_strings_module_register_types());

// Built-in module creation.
m.def("create_hal_module", &CreateHalModule);
Expand Down
34 changes: 19 additions & 15 deletions iree/base/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,18 @@ iree_api_version_check(iree_api_version_t expected_version,
iree_api_version_t* out_actual_version) {
iree_api_version_t actual_version = IREE_API_VERSION_0;
*out_actual_version = actual_version;
return expected_version == actual_version ? IREE_STATUS_OK
: IREE_STATUS_OUT_OF_RANGE;
return expected_version == actual_version
? iree_ok_status()
: iree_make_status(IREE_STATUS_OUT_OF_RANGE,
"IREE version mismatch; application expected "
"%d but IREE is compiled as %d",
expected_version, actual_version);
}

IREE_API_EXPORT iree_status_t IREE_API_CALL iree_api_init(int* argc,
char*** argv) {
InitializeEnvironment(argc, argv);
return IREE_STATUS_OK;
return iree_ok_status();
}

//===----------------------------------------------------------------------===//
Expand All @@ -319,14 +323,14 @@ iree_relative_timeout_to_deadline_ns(iree_duration_t timeout_ns) {

IREE_API_EXPORT iree_status_t IREE_API_CALL iree_allocator_malloc(
iree_allocator_t allocator, iree_host_size_t byte_length, void** out_ptr) {
if (!allocator.alloc) return IREE_STATUS_INVALID_ARGUMENT;
if (!allocator.alloc) return iree_make_status(IREE_STATUS_INVALID_ARGUMENT);
return allocator.alloc(allocator.self, IREE_ALLOCATION_MODE_ZERO_CONTENTS,
byte_length, out_ptr);
}

IREE_API_EXPORT iree_status_t IREE_API_CALL iree_allocator_realloc(
iree_allocator_t allocator, iree_host_size_t byte_length, void** out_ptr) {
if (!allocator.alloc) return IREE_STATUS_INVALID_ARGUMENT;
if (!allocator.alloc) return iree_make_status(IREE_STATUS_INVALID_ARGUMENT);
return allocator.alloc(allocator.self,
IREE_ALLOCATION_MODE_TRY_REUSE_EXISTING, byte_length,
out_ptr);
Expand All @@ -345,9 +349,9 @@ iree_allocator_system_allocate(void* self, iree_allocation_mode_t mode,
IREE_TRACE_SCOPE0("iree_allocator_system_allocate");

if (!out_ptr) {
return IREE_STATUS_INVALID_ARGUMENT;
return iree_make_status(IREE_STATUS_INVALID_ARGUMENT);
} else if (byte_length <= 0) {
return IREE_STATUS_INVALID_ARGUMENT;
return iree_make_status(IREE_STATUS_INVALID_ARGUMENT);
}

void* existing_ptr = *out_ptr;
Expand All @@ -366,7 +370,7 @@ iree_allocator_system_allocate(void* self, iree_allocation_mode_t mode,
}
}
if (!ptr) {
return IREE_STATUS_RESOURCE_EXHAUSTED;
return iree_make_status(IREE_STATUS_RESOURCE_EXHAUSTED);
}

if (existing_ptr) {
Expand All @@ -375,7 +379,7 @@ iree_allocator_system_allocate(void* self, iree_allocation_mode_t mode,
IREE_TRACE_ALLOC(ptr, byte_length);

*out_ptr = ptr;
return IREE_STATUS_OK;
return iree_ok_status();
}

IREE_API_EXPORT void IREE_API_CALL iree_allocator_system_free(void* self,
Expand All @@ -397,7 +401,7 @@ iree_file_mapping_open_read(iree_string_view_t path, iree_allocator_t allocator,
IREE_TRACE_SCOPE0("iree_file_mapping_open_read");

if (!out_file_mapping) {
return IREE_STATUS_INVALID_ARGUMENT;
return iree_make_status(IREE_STATUS_INVALID_ARGUMENT);
}
*out_file_mapping = nullptr;

Expand All @@ -408,29 +412,29 @@ iree_file_mapping_open_read(iree_string_view_t path, iree_allocator_t allocator,
*out_file_mapping =
reinterpret_cast<iree_file_mapping_t*>(file_mapping.release());

return IREE_STATUS_OK;
return iree_ok_status();
}

IREE_API_EXPORT iree_status_t IREE_API_CALL
iree_file_mapping_retain(iree_file_mapping_t* file_mapping) {
IREE_TRACE_SCOPE0("iree_file_mapping_retain");
auto* handle = reinterpret_cast<FileMapping*>(file_mapping);
if (!handle) {
return IREE_STATUS_INVALID_ARGUMENT;
return iree_make_status(IREE_STATUS_INVALID_ARGUMENT);
}
handle->AddReference();
return IREE_STATUS_OK;
return iree_ok_status();
}

IREE_API_EXPORT iree_status_t IREE_API_CALL
iree_file_mapping_release(iree_file_mapping_t* file_mapping) {
IREE_TRACE_SCOPE0("iree_file_mapping_release");
auto* handle = reinterpret_cast<FileMapping*>(file_mapping);
if (!handle) {
return IREE_STATUS_INVALID_ARGUMENT;
return iree_make_status(IREE_STATUS_INVALID_ARGUMENT);
}
handle->ReleaseReference();
return IREE_STATUS_OK;
return iree_ok_status();
}

IREE_API_EXPORT iree_byte_span_t IREE_API_CALL
Expand Down
Loading

0 comments on commit a03076f

Please sign in to comment.