Skip to content

Commit cb74dc9

Browse files
authored
Merge pull request #2531 from Xewar313/fix-ze-calls
Fix calls to ze destructors in level-zero adapter v2
2 parents 79b50d7 + 3dc0001 commit cb74dc9

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

source/adapters/level_zero/common.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,9 @@ void zeParseError(ze_result_t ZeError, const char *&ErrorString);
363363
#define ZE_CALL_NOCHECK(ZeName, ZeArgs) \
364364
ZeCall().doCall(ZeName ZeArgs, #ZeName, #ZeArgs, false)
365365

366+
#define ZE_CALL_NOCHECK_NAME(ZeName, ZeArgs, callName) \
367+
ZeCall().doCall(ZeName ZeArgs, callName, #ZeArgs, false)
368+
366369
// This wrapper around std::atomic is created to limit operations with reference
367370
// counter and to make allowed operations more transparent in terms of
368371
// thread-safety in the plugin. increment() and load() operations do not need a

source/adapters/level_zero/v2/common.hpp

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,23 @@
1515

1616
#include "../common.hpp"
1717
#include "logger/ur_logger.hpp"
18+
namespace {
19+
#define DECLARE_DESTROY_FUNCTION(name) \
20+
template <typename ZeHandleT> ze_result_t name##_wrapped(ZeHandleT handle) { \
21+
return ZE_CALL_NOCHECK_NAME(name, (handle), #name); \
22+
}
23+
24+
#define HANDLE_WRAPPER_TYPE(handle, destroy) \
25+
ze_handle_wrapper<handle, destroy##_wrapped<handle>>
26+
} // namespace
1827

1928
namespace v2 {
2029

30+
DECLARE_DESTROY_FUNCTION(zeKernelDestroy);
31+
DECLARE_DESTROY_FUNCTION(zeEventDestroy);
32+
DECLARE_DESTROY_FUNCTION(zeEventPoolDestroy);
33+
DECLARE_DESTROY_FUNCTION(zeContextDestroy);
34+
DECLARE_DESTROY_FUNCTION(zeCommandListDestroy);
2135
namespace raii {
2236

2337
template <typename ZeHandleT, ze_result_t (*destroy)(ZeHandleT)>
@@ -65,7 +79,7 @@ struct ze_handle_wrapper {
6579
}
6680

6781
if (ownZeHandle) {
68-
auto zeResult = ZE_CALL_NOCHECK(destroy, (handle));
82+
auto zeResult = destroy(handle);
6983
// Gracefully handle the case that L0 was already unloaded.
7084
if (zeResult && zeResult != ZE_RESULT_ERROR_UNINITIALIZED)
7185
throw ze2urResult(zeResult);
@@ -89,20 +103,20 @@ struct ze_handle_wrapper {
89103
bool ownZeHandle;
90104
};
91105

92-
using ze_kernel_handle_t =
93-
ze_handle_wrapper<::ze_kernel_handle_t, zeKernelDestroy>;
106+
using ze_kernel_handle_t = HANDLE_WRAPPER_TYPE(::ze_kernel_handle_t,
107+
zeKernelDestroy);
94108

95-
using ze_event_handle_t =
96-
ze_handle_wrapper<::ze_event_handle_t, zeEventDestroy>;
109+
using ze_event_handle_t = HANDLE_WRAPPER_TYPE(::ze_event_handle_t,
110+
zeEventDestroy);
97111

98-
using ze_event_pool_handle_t =
99-
ze_handle_wrapper<::ze_event_pool_handle_t, zeEventPoolDestroy>;
112+
using ze_event_pool_handle_t = HANDLE_WRAPPER_TYPE(::ze_event_pool_handle_t,
113+
zeEventPoolDestroy);
100114

101-
using ze_context_handle_t =
102-
ze_handle_wrapper<::ze_context_handle_t, zeContextDestroy>;
115+
using ze_context_handle_t = HANDLE_WRAPPER_TYPE(::ze_context_handle_t,
116+
zeContextDestroy);
103117

104-
using ze_command_list_handle_t =
105-
ze_handle_wrapper<::ze_command_list_handle_t, zeCommandListDestroy>;
118+
using ze_command_list_handle_t = HANDLE_WRAPPER_TYPE(::ze_command_list_handle_t,
119+
zeCommandListDestroy);
106120

107121
} // namespace raii
108122
} // namespace v2

source/adapters/level_zero/v2/queue_immediate_in_order.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ ur_command_list_handler_t::ur_command_list_handler_t(
7373
: commandList(hZeCommandList,
7474
[ownZeHandle](ze_command_list_handle_t hZeCommandList) {
7575
if (ownZeHandle) {
76-
zeCommandListDestroy(hZeCommandList);
76+
ZE_CALL_NOCHECK(zeCommandListDestroy, (hZeCommandList));
7777
}
7878
}) {}
7979

0 commit comments

Comments
 (0)