Skip to content

Commit 896f1b9

Browse files
authored
[UR][L0 adapter] Logs enabled for raii wrappers (#18756)
Handle wrappers in v2::raii ensure the proper destruction of handled objects. However, the destroy functions were not logged correctly, which misled the leak detector. Signed-off-by: Mateusz P. Nowak <mateusz.p.nowak@intel.com>
1 parent 3a0acb8 commit 896f1b9

File tree

1 file changed

+15
-19
lines changed
  • unified-runtime/source/adapters/level_zero/v2

1 file changed

+15
-19
lines changed

unified-runtime/source/adapters/level_zero/v2/common.hpp

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
namespace v2 {
2020
namespace raii {
2121

22-
template <typename ZeHandleT, ze_result_t (*destroy)(ZeHandleT)>
22+
template <typename ZeHandleT, ze_result_t (*destroy)(ZeHandleT),
23+
const char *destroyName>
2324
struct ze_handle_wrapper {
2425
ze_handle_wrapper(bool ownZeHandle = true)
2526
: handle(nullptr), ownZeHandle(ownZeHandle) {}
@@ -64,7 +65,8 @@ struct ze_handle_wrapper {
6465
}
6566

6667
if (ownZeHandle && checkL0LoaderTeardown()) {
67-
auto zeResult = destroy(handle);
68+
ze_result_t zeResult =
69+
ZE_CALL_NOCHECK_NAME(destroy, (handle), destroyName);
6870
// Gracefully handle the case that L0 was already unloaded.
6971
if (zeResult && (zeResult != ZE_RESULT_ERROR_UNINITIALIZED &&
7072
zeResult != ZE_RESULT_ERROR_UNKNOWN))
@@ -92,23 +94,17 @@ struct ze_handle_wrapper {
9294
bool ownZeHandle;
9395
};
9496

95-
using ze_kernel_handle_t =
96-
ze_handle_wrapper<::ze_kernel_handle_t, zeKernelDestroy>;
97-
98-
using ze_event_handle_t =
99-
ze_handle_wrapper<::ze_event_handle_t, zeEventDestroy>;
100-
101-
using ze_event_pool_handle_t =
102-
ze_handle_wrapper<::ze_event_pool_handle_t, zeEventPoolDestroy>;
103-
104-
using ze_context_handle_t =
105-
ze_handle_wrapper<::ze_context_handle_t, zeContextDestroy>;
106-
107-
using ze_command_list_handle_t =
108-
ze_handle_wrapper<::ze_command_list_handle_t, zeCommandListDestroy>;
109-
110-
using ze_image_handle_t =
111-
ze_handle_wrapper<::ze_image_handle_t, zeImageDestroy>;
97+
#define HANDLE_WRAPPER_TYPE(ZeHandleT, DestroyFunc) \
98+
inline constexpr char ZeHandleT##_destroyName[] = #DestroyFunc; \
99+
using ZeHandleT = \
100+
ze_handle_wrapper<::ZeHandleT, DestroyFunc, ZeHandleT##_destroyName>;
101+
102+
HANDLE_WRAPPER_TYPE(ze_kernel_handle_t, zeKernelDestroy)
103+
HANDLE_WRAPPER_TYPE(ze_event_handle_t, zeEventDestroy)
104+
HANDLE_WRAPPER_TYPE(ze_event_pool_handle_t, zeEventPoolDestroy)
105+
HANDLE_WRAPPER_TYPE(ze_context_handle_t, zeContextDestroy)
106+
HANDLE_WRAPPER_TYPE(ze_command_list_handle_t, zeCommandListDestroy)
107+
HANDLE_WRAPPER_TYPE(ze_image_handle_t, zeImageDestroy)
112108

113109
} // namespace raii
114110
} // namespace v2

0 commit comments

Comments
 (0)