Skip to content

Commit 6d19714

Browse files
committed
[SYCL][UR] Do not log L0 API calls
instead, rely on logging provided by L0 loader. Also, remove ZeCall and option to serialize all L0 calls. It wasn't used correctly anyway, the function call in ZE2UR_CALL* was done before taking the lock.
1 parent 4037677 commit 6d19714

File tree

6 files changed

+24
-65
lines changed

6 files changed

+24
-65
lines changed

unified-runtime/source/adapters/level_zero/adapter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
308308

309309
if (UrL0Debug & UR_L0_DEBUG_BASIC) {
310310
logger.setLegacySink(std::make_unique<ur_legacy_sink>());
311+
setEnvVar("ZEL_ENABLE_LOADER_LOGGING", "1");
312+
setEnvVar("ZEL_LOADER_LOGGING_LEVEL", "trace");
313+
setEnvVar("ZEL_LOADER_LOG_CONSOLE", "1");
314+
setEnvVar("ZE_ENABLE_VALIDATION_LAYER", "1");
311315
};
312316

313317
if (UrL0Debug & UR_L0_DEBUG_VALIDATION) {

unified-runtime/source/adapters/level_zero/common.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,6 @@ void zeParseError(ze_result_t ZeError, const char *&ErrorString) {
137137
} // switch
138138
}
139139

140-
ze_result_t ZeCall::doCall(ze_result_t ZeResult, const char *ZeName,
141-
const char *ZeArgs, bool TraceError) {
142-
logger::debug("ZE ---> {}{}", ZeName, ZeArgs);
143-
144-
if (TraceError) {
145-
const char *ErrorString = "Unknown";
146-
zeParseError(ZeResult, ErrorString);
147-
logger::error("Error ({}) in {}", ErrorString, ZeName);
148-
}
149-
return ZeResult;
150-
}
151-
152140
// Specializations for various L0 structures
153141
template <> ze_structure_type_t getZeStructureType<ze_event_pool_desc_t>() {
154142
return ZE_STRUCTURE_TYPE_EVENT_POOL_DESC;

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

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ const int UrL0InitAllDrivers = [] {
241241
enum {
242242
UrL0SerializeNone =
243243
0, // no locking or blocking (except when SYCL RT requested blocking)
244-
UrL0SerializeLock = 1, // locking around each UR_CALL
245244
UrL0SerializeBlock =
246245
2, // blocking UR calls, where supported (usually in enqueue commands)
247246
};
@@ -288,20 +287,10 @@ class ZeCall {
288287
static std::mutex GlobalLock;
289288

290289
public:
291-
ZeCall() {
292-
if ((UrL0Serialize & UrL0SerializeLock) != 0) {
293-
GlobalLock.lock();
294-
}
290+
template <typename F> static auto underLock(F &&f) {
291+
std::lock_guard<std::mutex> Lock(GlobalLock);
292+
return f();
295293
}
296-
~ZeCall() {
297-
if ((UrL0Serialize & UrL0SerializeLock) != 0) {
298-
GlobalLock.unlock();
299-
}
300-
}
301-
302-
// The non-static version just calls static one.
303-
ze_result_t doCall(ze_result_t ZeResult, const char *ZeName,
304-
const char *ZeArgs, bool TraceError = true);
305294
};
306295

307296
// This function will ensure compatibility with both Linux and Windows for
@@ -352,25 +341,19 @@ void zeParseError(ze_result_t ZeError, const char *&ErrorString);
352341
// Trace a call to Level-Zero RT
353342
#define ZE2UR_CALL(ZeName, ZeArgs) \
354343
{ \
355-
ze_result_t ZeResult = ZeName ZeArgs; \
356-
if (auto Result = ZeCall().doCall(ZeResult, #ZeName, #ZeArgs, true)) \
344+
if (auto Result = ZeName ZeArgs) \
357345
return ze2urResult(Result); \
358346
}
359347

360348
// Trace a call to Level-Zero RT, throw on error
361349
#define ZE2UR_CALL_THROWS(ZeName, ZeArgs) \
362350
{ \
363-
ze_result_t ZeResult = ZeName ZeArgs; \
364-
if (auto Result = ZeCall().doCall(ZeResult, #ZeName, #ZeArgs, true)) \
351+
if (auto Result = ZeName ZeArgs) \
365352
throw ze2urResult(Result); \
366353
}
367354

368355
// Perform traced call to L0 without checking for errors
369-
#define ZE_CALL_NOCHECK(ZeName, ZeArgs) \
370-
ZeCall().doCall(ZeName ZeArgs, #ZeName, #ZeArgs, false)
371-
372-
#define ZE_CALL_NOCHECK_NAME(ZeName, ZeArgs, callName) \
373-
ZeCall().doCall(ZeName ZeArgs, callName, #ZeArgs, false)
356+
#define ZE_CALL_NOCHECK(ZeName, ZeArgs) ZeName ZeArgs
374357

375358
// This wrapper around std::atomic is created to limit operations with reference
376359
// counter and to make allowed operations more transparent in terms of

unified-runtime/source/adapters/level_zero/kernel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ ur_result_t urKernelSetExecInfo(
10031003
else
10041004
// Unexpected cache configuration value.
10051005
return UR_RESULT_ERROR_INVALID_VALUE;
1006-
ZE2UR_CALL(zeKernelSetCacheConfig, (ZeKernel, ZeCacheConfig););
1006+
ZE2UR_CALL(zeKernelSetCacheConfig, (ZeKernel, ZeCacheConfig));
10071007
} else {
10081008
logger::error("urKernelSetExecInfo: unsupported ParamName");
10091009
return UR_RESULT_ERROR_INVALID_VALUE;

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

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,8 @@
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
2718

2819
namespace v2 {
29-
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);
35-
DECLARE_DESTROY_FUNCTION(zeImageDestroy);
3620
namespace raii {
3721

3822
template <typename ZeHandleT, ze_result_t (*destroy)(ZeHandleT)>
@@ -104,23 +88,23 @@ struct ze_handle_wrapper {
10488
bool ownZeHandle;
10589
};
10690

107-
using ze_kernel_handle_t = HANDLE_WRAPPER_TYPE(::ze_kernel_handle_t,
108-
zeKernelDestroy);
91+
using ze_kernel_handle_t =
92+
ze_handle_wrapper<::ze_kernel_handle_t, zeKernelDestroy>;
10993

110-
using ze_event_handle_t = HANDLE_WRAPPER_TYPE(::ze_event_handle_t,
111-
zeEventDestroy);
94+
using ze_event_handle_t =
95+
ze_handle_wrapper<::ze_event_handle_t, zeEventDestroy>;
11296

113-
using ze_event_pool_handle_t = HANDLE_WRAPPER_TYPE(::ze_event_pool_handle_t,
114-
zeEventPoolDestroy);
97+
using ze_event_pool_handle_t =
98+
ze_handle_wrapper<::ze_event_pool_handle_t, zeEventPoolDestroy>;
11599

116-
using ze_context_handle_t = HANDLE_WRAPPER_TYPE(::ze_context_handle_t,
117-
zeContextDestroy);
100+
using ze_context_handle_t =
101+
ze_handle_wrapper<::ze_context_handle_t, zeContextDestroy>;
118102

119-
using ze_command_list_handle_t = HANDLE_WRAPPER_TYPE(::ze_command_list_handle_t,
120-
zeCommandListDestroy);
103+
using ze_command_list_handle_t =
104+
ze_handle_wrapper<::ze_command_list_handle_t, zeCommandListDestroy>;
121105

122-
using ze_image_handle_t = HANDLE_WRAPPER_TYPE(::ze_image_handle_t,
123-
zeImageDestroy);
106+
using ze_image_handle_t =
107+
ze_handle_wrapper<::ze_image_handle_t, zeImageDestroy>;
124108

125109
} // namespace raii
126110
} // namespace v2

unified-runtime/source/adapters/level_zero/v2/kernel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ ur_result_t ur_kernel_handle_t_::setExecInfo(ur_kernel_exec_info_t propName,
262262
// Unexpected cache configuration value.
263263
return UR_RESULT_ERROR_INVALID_VALUE;
264264
ZE2UR_CALL(zeKernelSetCacheConfig,
265-
(kernel->hKernel.get(), zeCacheConfig););
265+
(kernel->hKernel.get(), zeCacheConfig));
266266
} else {
267267
logger::error("urKernelSetExecInfo: unsupported ParamName");
268268
return UR_RESULT_ERROR_INVALID_VALUE;

0 commit comments

Comments
 (0)