|
19 | 19 | namespace v2 {
|
20 | 20 | namespace raii {
|
21 | 21 |
|
22 |
| -template <typename ZeHandleT, ze_result_t (*destroy)(ZeHandleT)> |
| 22 | +template <typename ZeHandleT, ze_result_t (*destroy)(ZeHandleT), |
| 23 | + const char *destroyName> |
23 | 24 | struct ze_handle_wrapper {
|
24 | 25 | ze_handle_wrapper(bool ownZeHandle = true)
|
25 | 26 | : handle(nullptr), ownZeHandle(ownZeHandle) {}
|
@@ -64,7 +65,8 @@ struct ze_handle_wrapper {
|
64 | 65 | }
|
65 | 66 |
|
66 | 67 | if (ownZeHandle && checkL0LoaderTeardown()) {
|
67 |
| - auto zeResult = destroy(handle); |
| 68 | + ze_result_t zeResult = |
| 69 | + ZE_CALL_NOCHECK_NAME(destroy, (handle), destroyName); |
68 | 70 | // Gracefully handle the case that L0 was already unloaded.
|
69 | 71 | if (zeResult && (zeResult != ZE_RESULT_ERROR_UNINITIALIZED &&
|
70 | 72 | zeResult != ZE_RESULT_ERROR_UNKNOWN))
|
@@ -92,23 +94,17 @@ struct ze_handle_wrapper {
|
92 | 94 | bool ownZeHandle;
|
93 | 95 | };
|
94 | 96 |
|
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) |
112 | 108 |
|
113 | 109 | } // namespace raii
|
114 | 110 | } // namespace v2
|
0 commit comments