Skip to content

[SYCL][UR][L0] Use leak checker and API logging (for v2) from loader #17536

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

Merged
merged 6 commits into from
May 7, 2025
Merged
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
12 changes: 6 additions & 6 deletions sycl/test-e2e/Adapters/level_zero/batch_barrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ void submit_kernel(queue &q) {
}

int main(int argc, char *argv[]) {
queue q;

submit_kernel(q); // starts a batch
// CHECK: ---> urEnqueueKernelLaunch
// CHECK-NOT: zeCommandQueueExecuteCommandLists

// Initialize Level Zero driver is required if this test is linked
// statically with Level Zero loader, the driver will not be init otherwise.
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
Expand All @@ -29,12 +35,6 @@ int main(int argc, char *argv[]) {
return 1;
}

queue q;

submit_kernel(q); // starts a batch
// CHECK: ---> urEnqueueKernelLaunch
// CHECK-NOT: zeCommandQueueExecuteCommandLists

// continue the batch
event barrier = q.ext_oneapi_submit_barrier();
// CHECK: ---> urEnqueueEventsWaitWithBarrierExt
Expand Down
16 changes: 8 additions & 8 deletions sycl/test-e2e/Adapters/level_zero/interop-buffer-multi-dim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ using namespace sycl;
int main() {
#ifdef SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
try {
// Initialize Level Zero driver is required if this test is linked
// statically with Level Zero loader, the driver will not be init otherwise.
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
if (result != ZE_RESULT_SUCCESS) {
std::cout << "zeInit failed\n";
return 1;
}

platform Plt{gpu_selector_v};

auto Devices = Plt.get_devices();
Expand All @@ -33,6 +25,14 @@ int main() {
return 0;
}

// Initialize Level Zero driver is required if this test is linked
// statically with Level Zero loader, the driver will not be init otherwise.
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
if (result != ZE_RESULT_SUCCESS) {
std::cout << "zeInit failed\n";
return 1;
}

device Device = Devices[0];
context Context{Device};
queue Queue{Context, Device};
Expand Down
25 changes: 12 additions & 13 deletions sycl/test-e2e/Adapters/level_zero/interop-buffer-ownership.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// REQUIRES: gpu, level_zero, level_zero_dev_kit
// L0 adapter incorrectly reports memory leaks because it doesn't take into
// account direct calls to L0 API.
// UNSUPPORTED: ze_debug, level_zero_v2_adapter
// UNSUPPORTED: ze_debug
// RUN: %{build} %level_zero_options -o %t.out
// RUN: env SYCL_PI_LEVEL_ZERO_DISABLE_USM_ALLOCATOR=1 UR_L0_DEBUG=1 %{run} %t.out 2>&1 | FileCheck %s

Expand All @@ -17,6 +17,7 @@

// Keep ownership
// CHECK: zeMemFree
// CHECK: zeMemFree

// Account for zeMemFree used to query page sizes by the UMF (only affects v2 L0
// adapter)
Expand All @@ -31,10 +32,8 @@

// Transfer ownership
// CHECK: zeMemFree
// CHECK: zeMemFree

// No other calls to zeMemFree
// CHECK-NOT: zeMemFree
// For v2 adapter, all calls (even from this test) are logged
// CHECK-OPT: zeMemFree

#include "interop-buffer-helpers.hpp"
#include <sycl/detail/core.hpp>
Expand Down Expand Up @@ -119,14 +118,6 @@ void test_copyback_and_free(
int main() {
#ifdef SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
try {
// Initialize Level Zero driver is required if this test is linked
// statically with Level Zero loader, the driver will not be init otherwise.
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
if (result != ZE_RESULT_SUCCESS) {
std::cout << "zeInit failed\n";
return 1;
}

platform Plt{gpu_selector_v};

auto Devices = Plt.get_devices();
Expand All @@ -136,6 +127,14 @@ int main() {
return 0;
}

// Initialize Level Zero driver is required if this test is linked
// statically with Level Zero loader, the driver will not be init otherwise.
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
if (result != ZE_RESULT_SUCCESS) {
std::cout << "zeInit failed\n";
return 1;
}

device Dev1 = Devices[0];
context Context1{Dev1};
queue Queue1{Context1, Dev1};
Expand Down
16 changes: 8 additions & 8 deletions sycl/test-e2e/Adapters/level_zero/interop-buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,6 @@ class DiscreteSelector : public sycl::device_selector {
int main() {
#ifdef SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
try {
// Initialize Level Zero driver is required if this test is linked
// statically with Level Zero loader, the driver will not be init otherwise.
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
if (result != ZE_RESULT_SUCCESS) {
std::cout << "zeInit failed\n";
return 1;
}

queue Queue{};

auto Context = Queue.get_info<info::queue::context>();
Expand All @@ -53,6 +45,14 @@ int main() {
auto ZeContext = get_native<backend::ext_oneapi_level_zero>(Context);
auto ZeDevice = get_native<backend::ext_oneapi_level_zero>(Device);

// Initialize Level Zero driver is required if this test is linked
// statically with Level Zero loader, the driver will not be init otherwise.
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
if (result != ZE_RESULT_SUCCESS) {
std::cout << "zeInit failed\n";
return 1;
}

ze_host_mem_alloc_desc_t HostDesc = {};
HostDesc.stype = ZE_STRUCTURE_TYPE_HOST_MEM_ALLOC_DESC;
HostDesc.pNext = nullptr;
Expand Down
16 changes: 8 additions & 8 deletions sycl/test-e2e/Adapters/level_zero/interop-get-native-mem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ constexpr size_t SIZE = 16;
int main() {
#ifdef SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
try {
// Initialize Level Zero driver is required if this test is linked
// statically with Level Zero loader, the driver will not be init otherwise.
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
if (result != ZE_RESULT_SUCCESS) {
std::cout << "zeInit failed\n";
return 1;
}

platform Plt{gpu_selector_v};

auto Devices = Plt.get_devices();
Expand All @@ -40,6 +32,14 @@ int main() {
return 0;
}

// Initialize Level Zero driver is required if this test is linked
// statically with Level Zero loader, the driver will not be init otherwise.
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
if (result != ZE_RESULT_SUCCESS) {
std::cout << "zeInit failed\n";
return 1;
}

device Dev1 = Devices[0];
context Context1{Dev1};
queue Queue1{Context1, Dev1};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ using namespace sycl;

int main() {
#ifdef SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
constexpr auto BE = sycl::backend::ext_oneapi_level_zero;
sycl::device D =
sycl::ext::oneapi::filter_selector("level_zero:gpu").select_device();

// Initialize Level Zero driver is required if this test is linked
// statically with Level Zero loader, the driver will not be init otherwise.
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
Expand All @@ -50,10 +54,6 @@ int main() {
return 1;
}

constexpr auto BE = sycl::backend::ext_oneapi_level_zero;
sycl::device D =
sycl::ext::oneapi::filter_selector("level_zero:gpu").select_device();

sycl::context Ctx{D};
sycl::queue Q(Ctx, D);
auto ZeContext = sycl::get_native<BE>(Ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ void test(sycl::ext::oneapi::level_zero::ownership Ownership) {

int main() {
#ifdef SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
platform Plt{gpu_selector_v};

// Initialize Level Zero driver is required if this test is linked
// statically with Level Zero loader, the driver will not be init otherwise.
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
Expand Down
12 changes: 6 additions & 6 deletions sycl/test-e2e/Adapters/level_zero/interop-image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ using namespace sycl;

int main() {
#ifdef SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
constexpr auto BE = sycl::backend::ext_oneapi_level_zero;

platform Plt{gpu_selector_v};

auto Devices = Plt.get_devices();

// Initialize Level Zero driver is required if this test is linked
// statically with Level Zero loader, the driver will not be init otherwise.
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
Expand All @@ -40,12 +46,6 @@ int main() {
return 1;
}

constexpr auto BE = sycl::backend::ext_oneapi_level_zero;

platform Plt{gpu_selector_v};

auto Devices = Plt.get_devices();

if (Devices.size() < 1) {
std::cout << "Devices not found" << std::endl;
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
using namespace sycl;

int main() {
// Creat SYCL platform/device
device Device(gpu_selector_v);
platform Platform = Device.get_info<info::device::platform>();

// Initialize Level Zero driver is required if this test is linked
// statically with Level Zero loader, the driver will not be init otherwise.
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
Expand All @@ -22,10 +26,6 @@ int main() {
return 1;
}

// Creat SYCL platform/device
device Device(gpu_selector_v);
platform Platform = Device.get_info<info::device::platform>();

// Create native Level-Zero context
ze_context_handle_t ZeContext;
ze_context_desc_t ZeContextDesc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr,
Expand Down
2 changes: 1 addition & 1 deletion sycl/test-e2e/Adapters/level_zero/queue_profiling.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// REQUIRES: gpu, level_zero
// UNSUPPORTED: ze_debug, level_zero_v2_adapter
// UNSUPPORTED: ze_debug

// RUN: %{build} -o %t.out
// RUN: env UR_L0_DEBUG=-1 %{l0_leak_check} %{run} %t.out 2>&1 | FileCheck --check-prefixes=WITHOUT %s
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// REQUIRES: gpu, level_zero
// UNSUPPORTED: ze_debug, level_zero_v2_adapter
// UNSUPPORTED: ze_debug

// RUN: %{build} -o %t.out
// RUN: env SYCL_UR_TRACE=2 UR_L0_DEBUG=1 %{run} %t.out 2>&1 | FileCheck %s
Expand Down
2 changes: 1 addition & 1 deletion sycl/test-e2e/Basic/buffer/buffer_create.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// REQUIRES: gpu,level_zero,level_zero_dev_kit
// RUN: %{build} %level_zero_options -o %t.out
// RUN: env UR_L0_DEBUG=1 %{run} %t.out 2>&1 | FileCheck %s
// UNSUPPORTED: ze_debug, level_zero_v2_adapter
// UNSUPPORTED: ze_debug

#include <iostream>
#include <level_zero/ze_api.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ std::vector<uint8_t> loadSpirvFromFile(std::string FileName) {
}

int main(int, char **argv) {
device Device;
if (!getDevice(Device, backend::ext_oneapi_level_zero)) {
// No suitable device found.
return 0;
}

// Initialize Level Zero driver is required if this test is linked
// statically with Level Zero loader, the driver will not be init otherwise.
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
Expand All @@ -45,12 +51,6 @@ int main(int, char **argv) {
return 1;
}

device Device;
if (!getDevice(Device, backend::ext_oneapi_level_zero)) {
// No suitable device found.
return 0;
}

std::vector<uint8_t> Spirv = loadSpirvFromFile(argv[1]);

const sycl::context Context{Device};
Expand Down
2 changes: 0 additions & 2 deletions sycl/test-e2e/KernelAndProgram/disable-caching.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// This test ensures created program/kernels are not retained
// if and only if caching is disabled.
// UNSUPPORTED: level_zero_v2_adapter
// UNSUPPORTED-INTENDED: bug in L0 loader param validation (fixed in v.1.21.1)

// RUN: %{build} -o %t.out
// RUN: env ZE_DEBUG=-6 SYCL_UR_TRACE=2 SYCL_CACHE_IN_MEM=0 %{run} %t.out \
Expand Down
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 UREvn = std::getenv("UR_LOADER_USE_LEVEL_ZERO_V2");

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

try {
if (UREvn && std::atoi(UREvn) == 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
Loading