From bf3d76a4ec625e35956efbeb3b47aadf9bab3c1e Mon Sep 17 00:00:00 2001 From: Omar Emara Date: Tue, 12 Oct 2021 17:23:16 +0200 Subject: [PATCH 1/2] Fix default device wrap native function Currently, an attempt to call device_wrap_native on a target that uses the default device wrap native function will result in an error of type halide_error_device_interface_no_device, namely in the OpenGLCompute and the Hexagon targets. This happens because the default wrap native function calls debug_log_and_validate_buf after the device_interface is set in halide_device_wrap_native but before the device handle is set, which is validated as a bad state. This patch removes the validation call and adds an assert for the handle much like the other wrap_native implementations in other targets. --- src/runtime/device_interface.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/runtime/device_interface.cpp b/src/runtime/device_interface.cpp index 0956a1172c0c..beb104d11329 100644 --- a/src/runtime/device_interface.cpp +++ b/src/runtime/device_interface.cpp @@ -409,9 +409,9 @@ WEAK int halide_device_detach_native(void *user_context, struct halide_buffer_t } WEAK int halide_default_device_wrap_native(void *user_context, struct halide_buffer_t *buf, uint64_t handle) { - int result = debug_log_and_validate_buf(user_context, buf, "halide_default_device_wrap_native"); - if (result != 0) { - return result; + halide_assert(user_context, buf->device == 0); + if (buf->device != 0) { + return -2; } buf->device_interface->impl->use_module(); buf->device = handle; From afd705939efb779de52adf49aeef490a6d1f53e7 Mon Sep 17 00:00:00 2001 From: Omar Emara Date: Tue, 12 Oct 2021 20:13:58 +0200 Subject: [PATCH 2/2] Use approperiate error code --- src/runtime/device_interface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/device_interface.cpp b/src/runtime/device_interface.cpp index beb104d11329..a494d05a9574 100644 --- a/src/runtime/device_interface.cpp +++ b/src/runtime/device_interface.cpp @@ -411,7 +411,7 @@ WEAK int halide_device_detach_native(void *user_context, struct halide_buffer_t WEAK int halide_default_device_wrap_native(void *user_context, struct halide_buffer_t *buf, uint64_t handle) { halide_assert(user_context, buf->device == 0); if (buf->device != 0) { - return -2; + return halide_error_code_device_wrap_native_failed; } buf->device_interface->impl->use_module(); buf->device = handle;