Skip to content

[SYCL][UR][L0 v2] Implement API logging using L0 loader #18475

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: sycl
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion sycl/ur_win_proxy_loader/ur_win_proxy_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,27 @@ void *&getDllHandle() {
return dllHandle;
}

static bool shouldLoadL0V2adapter() {
auto SyclEnv = std::getenv("SYCL_UR_USE_LEVEL_ZERO_V2");
auto UREnv = std::getenv("UR_LOADER_USE_LEVEL_ZERO_V2");

try {
if (SyclEnv && std::stoi(SyclEnv) == 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking further into this, why are we using stoi here but atoi for UREnv? If there's no specific reason, can we use the same for both?

return true;
}
} catch (...) {
}

try {
if (UREnv && std::atoi(UREnv) == 1) {
return true;
}
} catch (...) {
}

return false;
}

/// Load the adapter libraries
void preloadLibraries() {
// Suppress system errors.
Expand Down Expand Up @@ -142,7 +163,8 @@ void preloadLibraries() {
getDllHandle() = loadAdapter(UR_LIBRARY_NAME(loader));
loadAdapter(UR_LIBRARY_NAME(adapter_opencl));
loadAdapter(UR_LIBRARY_NAME(adapter_level_zero));
loadAdapter(UR_LIBRARY_NAME(adapter_level_zero_v2));
if (shouldLoadL0V2adapter())
loadAdapter(UR_LIBRARY_NAME(adapter_level_zero_v2));
loadAdapter(UR_LIBRARY_NAME(adapter_cuda));
loadAdapter(UR_LIBRARY_NAME(adapter_hip));
loadAdapter(UR_LIBRARY_NAME(adapter_native_cpu));
Expand Down
17 changes: 17 additions & 0 deletions unified-runtime/source/adapters/level_zero/adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()

if (UrL0Debug & UR_L0_DEBUG_BASIC) {
logger.setLegacySink(std::make_unique<ur_legacy_sink>());
#ifdef UR_ADAPTER_LEVEL_ZERO_V2
setEnvVar("ZEL_ENABLE_LOADER_LOGGING", "1");
setEnvVar("ZEL_LOADER_LOGGING_LEVEL", "trace");
setEnvVar("ZEL_LOADER_LOG_CONSOLE", "1");
setEnvVar("ZE_ENABLE_VALIDATION_LAYER", "1");
#endif
};

if (UrL0Debug & UR_L0_DEBUG_VALIDATION) {
Expand Down Expand Up @@ -419,6 +425,17 @@ ur_adapter_handle_t_::ur_adapter_handle_t_()
loader_version.patch >= 2)) {
useInitDrivers = true;
}

#ifdef UR_ADAPTER_LEVEL_ZERO_V2
if ((loader_version.major == 1 && loader_version.minor < 21) ||
(loader_version.major == 1 && loader_version.minor == 21 &&
loader_version.patch < 2)) {
UR_LOG(
WARN,
"WARNING: Level Zero Loader version is older than 1.21.2. "
"Please update to the latest version for API logging support.\n");
}
#endif
}

if (useInitDrivers) {
Expand Down
7 changes: 7 additions & 0 deletions unified-runtime/source/adapters/level_zero/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ void zeParseError(ze_result_t ZeError, const char *&ErrorString) {
} // switch
}

#ifdef UR_ADAPTER_LEVEL_ZERO_V2
ze_result_t ZeCall::doCall(ze_result_t ZeResult, const char *, const char *,
bool) {
return ZeResult;
}
#else
ze_result_t ZeCall::doCall(ze_result_t ZeResult, const char *ZeName,
const char *ZeArgs, bool TraceError) {
UR_LOG(DEBUG, "ZE ---> {}{}", ZeName, ZeArgs);
Expand All @@ -155,6 +161,7 @@ ze_result_t ZeCall::doCall(ze_result_t ZeResult, const char *ZeName,
}
return ZeResult;
}
#endif

// Specializations for various L0 structures
template <> ze_structure_type_t getZeStructureType<ze_event_pool_desc_t>() {
Expand Down
40 changes: 12 additions & 28 deletions unified-runtime/source/adapters/level_zero/v2/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,8 @@

#include "../common.hpp"
#include "logger/ur_logger.hpp"
namespace {
#define DECLARE_DESTROY_FUNCTION(name) \
template <typename ZeHandleT> ze_result_t name##_wrapped(ZeHandleT handle) { \
return ZE_CALL_NOCHECK_NAME(name, (handle), #name); \
}

#define HANDLE_WRAPPER_TYPE(handle, destroy) \
ze_handle_wrapper<handle, destroy##_wrapped<handle>>
} // namespace

namespace v2 {

DECLARE_DESTROY_FUNCTION(zeKernelDestroy)
DECLARE_DESTROY_FUNCTION(zeEventDestroy)
DECLARE_DESTROY_FUNCTION(zeEventPoolDestroy)
DECLARE_DESTROY_FUNCTION(zeContextDestroy)
DECLARE_DESTROY_FUNCTION(zeCommandListDestroy)
DECLARE_DESTROY_FUNCTION(zeImageDestroy)
namespace raii {

template <typename ZeHandleT, ze_result_t (*destroy)(ZeHandleT)>
Expand Down Expand Up @@ -108,23 +92,23 @@ struct ze_handle_wrapper {
bool ownZeHandle;
};

using ze_kernel_handle_t = HANDLE_WRAPPER_TYPE(::ze_kernel_handle_t,
zeKernelDestroy);
using ze_kernel_handle_t =
ze_handle_wrapper<::ze_kernel_handle_t, zeKernelDestroy>;

using ze_event_handle_t = HANDLE_WRAPPER_TYPE(::ze_event_handle_t,
zeEventDestroy);
using ze_event_handle_t =
ze_handle_wrapper<::ze_event_handle_t, zeEventDestroy>;

using ze_event_pool_handle_t = HANDLE_WRAPPER_TYPE(::ze_event_pool_handle_t,
zeEventPoolDestroy);
using ze_event_pool_handle_t =
ze_handle_wrapper<::ze_event_pool_handle_t, zeEventPoolDestroy>;

using ze_context_handle_t = HANDLE_WRAPPER_TYPE(::ze_context_handle_t,
zeContextDestroy);
using ze_context_handle_t =
ze_handle_wrapper<::ze_context_handle_t, zeContextDestroy>;

using ze_command_list_handle_t = HANDLE_WRAPPER_TYPE(::ze_command_list_handle_t,
zeCommandListDestroy);
using ze_command_list_handle_t =
ze_handle_wrapper<::ze_command_list_handle_t, zeCommandListDestroy>;

using ze_image_handle_t = HANDLE_WRAPPER_TYPE(::ze_image_handle_t,
zeImageDestroy);
using ze_image_handle_t =
ze_handle_wrapper<::ze_image_handle_t, zeImageDestroy>;

} // namespace raii
} // namespace v2