Skip to content

Commit b0b48a4

Browse files
authored
[SYCL][UR][L0] Use leak checker and API logging (for v2) from loader (#17536)
1 parent b7093bf commit b0b48a4

19 files changed

+132
-204
lines changed

sycl/test-e2e/Adapters/level_zero/batch_barrier.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ void submit_kernel(queue &q) {
2121
}
2222

2323
int main(int argc, char *argv[]) {
24+
queue q;
25+
26+
submit_kernel(q); // starts a batch
27+
// CHECK: ---> urEnqueueKernelLaunch
28+
// CHECK-NOT: zeCommandQueueExecuteCommandLists
29+
2430
// Initialize Level Zero driver is required if this test is linked
2531
// statically with Level Zero loader, the driver will not be init otherwise.
2632
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
@@ -29,12 +35,6 @@ int main(int argc, char *argv[]) {
2935
return 1;
3036
}
3137

32-
queue q;
33-
34-
submit_kernel(q); // starts a batch
35-
// CHECK: ---> urEnqueueKernelLaunch
36-
// CHECK-NOT: zeCommandQueueExecuteCommandLists
37-
3838
// continue the batch
3939
event barrier = q.ext_oneapi_submit_barrier();
4040
// CHECK: ---> urEnqueueEventsWaitWithBarrierExt

sycl/test-e2e/Adapters/level_zero/interop-buffer-multi-dim.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@ using namespace sycl;
1616
int main() {
1717
#ifdef SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
1818
try {
19-
// Initialize Level Zero driver is required if this test is linked
20-
// statically with Level Zero loader, the driver will not be init otherwise.
21-
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
22-
if (result != ZE_RESULT_SUCCESS) {
23-
std::cout << "zeInit failed\n";
24-
return 1;
25-
}
26-
2719
platform Plt{gpu_selector_v};
2820

2921
auto Devices = Plt.get_devices();
@@ -33,6 +25,14 @@ int main() {
3325
return 0;
3426
}
3527

28+
// Initialize Level Zero driver is required if this test is linked
29+
// statically with Level Zero loader, the driver will not be init otherwise.
30+
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
31+
if (result != ZE_RESULT_SUCCESS) {
32+
std::cout << "zeInit failed\n";
33+
return 1;
34+
}
35+
3636
device Device = Devices[0];
3737
context Context{Device};
3838
queue Queue{Context, Device};

sycl/test-e2e/Adapters/level_zero/interop-buffer-ownership.cpp

+12-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// REQUIRES: gpu, level_zero, level_zero_dev_kit
22
// L0 adapter incorrectly reports memory leaks because it doesn't take into
33
// account direct calls to L0 API.
4-
// UNSUPPORTED: ze_debug, level_zero_v2_adapter
4+
// UNSUPPORTED: ze_debug
55
// RUN: %{build} %level_zero_options -o %t.out
66
// RUN: env SYCL_PI_LEVEL_ZERO_DISABLE_USM_ALLOCATOR=1 UR_L0_DEBUG=1 %{run} %t.out 2>&1 | FileCheck %s
77

@@ -17,6 +17,7 @@
1717

1818
// Keep ownership
1919
// CHECK: zeMemFree
20+
// CHECK: zeMemFree
2021

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

3233
// Transfer ownership
3334
// CHECK: zeMemFree
34-
// CHECK: zeMemFree
35-
36-
// No other calls to zeMemFree
37-
// CHECK-NOT: zeMemFree
35+
// For v2 adapter, all calls (even from this test) are logged
36+
// CHECK-OPT: zeMemFree
3837

3938
#include "interop-buffer-helpers.hpp"
4039
#include <sycl/detail/core.hpp>
@@ -119,14 +118,6 @@ void test_copyback_and_free(
119118
int main() {
120119
#ifdef SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
121120
try {
122-
// Initialize Level Zero driver is required if this test is linked
123-
// statically with Level Zero loader, the driver will not be init otherwise.
124-
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
125-
if (result != ZE_RESULT_SUCCESS) {
126-
std::cout << "zeInit failed\n";
127-
return 1;
128-
}
129-
130121
platform Plt{gpu_selector_v};
131122

132123
auto Devices = Plt.get_devices();
@@ -136,6 +127,14 @@ int main() {
136127
return 0;
137128
}
138129

130+
// Initialize Level Zero driver is required if this test is linked
131+
// statically with Level Zero loader, the driver will not be init otherwise.
132+
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
133+
if (result != ZE_RESULT_SUCCESS) {
134+
std::cout << "zeInit failed\n";
135+
return 1;
136+
}
137+
139138
device Dev1 = Devices[0];
140139
context Context1{Dev1};
141140
queue Queue1{Context1, Dev1};

sycl/test-e2e/Adapters/level_zero/interop-buffer.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@ class DiscreteSelector : public sycl::device_selector {
3636
int main() {
3737
#ifdef SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
3838
try {
39-
// Initialize Level Zero driver is required if this test is linked
40-
// statically with Level Zero loader, the driver will not be init otherwise.
41-
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
42-
if (result != ZE_RESULT_SUCCESS) {
43-
std::cout << "zeInit failed\n";
44-
return 1;
45-
}
46-
4739
queue Queue{};
4840

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

48+
// Initialize Level Zero driver is required if this test is linked
49+
// statically with Level Zero loader, the driver will not be init otherwise.
50+
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
51+
if (result != ZE_RESULT_SUCCESS) {
52+
std::cout << "zeInit failed\n";
53+
return 1;
54+
}
55+
5656
ze_host_mem_alloc_desc_t HostDesc = {};
5757
HostDesc.stype = ZE_STRUCTURE_TYPE_HOST_MEM_ALLOC_DESC;
5858
HostDesc.pNext = nullptr;

sycl/test-e2e/Adapters/level_zero/interop-get-native-mem.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ constexpr size_t SIZE = 16;
2626
int main() {
2727
#ifdef SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
2828
try {
29-
// Initialize Level Zero driver is required if this test is linked
30-
// statically with Level Zero loader, the driver will not be init otherwise.
31-
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
32-
if (result != ZE_RESULT_SUCCESS) {
33-
std::cout << "zeInit failed\n";
34-
return 1;
35-
}
36-
3729
platform Plt{gpu_selector_v};
3830

3931
auto Devices = Plt.get_devices();
@@ -43,6 +35,14 @@ int main() {
4335
return 0;
4436
}
4537

38+
// Initialize Level Zero driver is required if this test is linked
39+
// statically with Level Zero loader, the driver will not be init otherwise.
40+
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
41+
if (result != ZE_RESULT_SUCCESS) {
42+
std::cout << "zeInit failed\n";
43+
return 1;
44+
}
45+
4646
device Dev1 = Devices[0];
4747
context Context1{Dev1};
4848
queue Queue1{Context1, Dev1};

sycl/test-e2e/Adapters/level_zero/interop-image-get-native-mem.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ using namespace sycl;
4242

4343
int main() {
4444
#ifdef SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
45+
constexpr auto BE = sycl::backend::ext_oneapi_level_zero;
46+
sycl::device D =
47+
sycl::ext::oneapi::filter_selector("level_zero:gpu").select_device();
48+
4549
// Initialize Level Zero driver is required if this test is linked
4650
// statically with Level Zero loader, the driver will not be init otherwise.
4751
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
@@ -50,10 +54,6 @@ int main() {
5054
return 1;
5155
}
5256

53-
constexpr auto BE = sycl::backend::ext_oneapi_level_zero;
54-
sycl::device D =
55-
sycl::ext::oneapi::filter_selector("level_zero:gpu").select_device();
56-
5757
sycl::context Ctx{D};
5858
sycl::queue Q(Ctx, D);
5959
auto ZeContext = sycl::get_native<BE>(Ctx);

sycl/test-e2e/Adapters/level_zero/interop-image-ownership.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ void test(sycl::ext::oneapi::level_zero::ownership Ownership) {
144144

145145
int main() {
146146
#ifdef SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
147+
platform Plt{gpu_selector_v};
148+
147149
// Initialize Level Zero driver is required if this test is linked
148150
// statically with Level Zero loader, the driver will not be init otherwise.
149151
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);

sycl/test-e2e/Adapters/level_zero/interop-image.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ using namespace sycl;
3232

3333
int main() {
3434
#ifdef SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
35+
constexpr auto BE = sycl::backend::ext_oneapi_level_zero;
36+
37+
platform Plt{gpu_selector_v};
38+
39+
auto Devices = Plt.get_devices();
40+
3541
// Initialize Level Zero driver is required if this test is linked
3642
// statically with Level Zero loader, the driver will not be init otherwise.
3743
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
@@ -40,12 +46,6 @@ int main() {
4046
return 1;
4147
}
4248

43-
constexpr auto BE = sycl::backend::ext_oneapi_level_zero;
44-
45-
platform Plt{gpu_selector_v};
46-
47-
auto Devices = Plt.get_devices();
48-
4949
if (Devices.size() < 1) {
5050
std::cout << "Devices not found" << std::endl;
5151
return 0;

sycl/test-e2e/Adapters/level_zero/interop-keep-ownership.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
using namespace sycl;
1515

1616
int main() {
17+
// Creat SYCL platform/device
18+
device Device(gpu_selector_v);
19+
platform Platform = Device.get_info<info::device::platform>();
20+
1721
// Initialize Level Zero driver is required if this test is linked
1822
// statically with Level Zero loader, the driver will not be init otherwise.
1923
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
@@ -22,10 +26,6 @@ int main() {
2226
return 1;
2327
}
2428

25-
// Creat SYCL platform/device
26-
device Device(gpu_selector_v);
27-
platform Platform = Device.get_info<info::device::platform>();
28-
2929
// Create native Level-Zero context
3030
ze_context_handle_t ZeContext;
3131
ze_context_desc_t ZeContextDesc = {ZE_STRUCTURE_TYPE_CONTEXT_DESC, nullptr,

sycl/test-e2e/Adapters/level_zero/queue_profiling.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// REQUIRES: gpu, level_zero
2-
// UNSUPPORTED: ze_debug, level_zero_v2_adapter
2+
// UNSUPPORTED: ze_debug
33

44
// RUN: %{build} -o %t.out
55
// RUN: env UR_L0_DEBUG=-1 %{l0_leak_check} %{run} %t.out 2>&1 | FileCheck --check-prefixes=WITHOUT %s

sycl/test-e2e/Adapters/level_zero/usm_device_read_only.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// REQUIRES: gpu, level_zero
2-
// UNSUPPORTED: ze_debug, level_zero_v2_adapter
2+
// UNSUPPORTED: ze_debug
33

44
// RUN: %{build} -o %t.out
55
// RUN: env SYCL_UR_TRACE=2 UR_L0_DEBUG=1 %{run} %t.out 2>&1 | FileCheck %s

sycl/test-e2e/Basic/buffer/buffer_create.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// REQUIRES: gpu,level_zero,level_zero_dev_kit
22
// RUN: %{build} %level_zero_options -o %t.out
33
// RUN: env UR_L0_DEBUG=1 %{run} %t.out 2>&1 | FileCheck %s
4-
// UNSUPPORTED: ze_debug, level_zero_v2_adapter
4+
// UNSUPPORTED: ze_debug
55

66
#include <iostream>
77
#include <level_zero/ze_api.h>

sycl/test-e2e/Graph/Inputs/interop-level-zero-launch-kernel.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ std::vector<uint8_t> loadSpirvFromFile(std::string FileName) {
3737
}
3838

3939
int main(int, char **argv) {
40+
device Device;
41+
if (!getDevice(Device, backend::ext_oneapi_level_zero)) {
42+
// No suitable device found.
43+
return 0;
44+
}
45+
4046
// Initialize Level Zero driver is required if this test is linked
4147
// statically with Level Zero loader, the driver will not be init otherwise.
4248
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
@@ -45,12 +51,6 @@ int main(int, char **argv) {
4551
return 1;
4652
}
4753

48-
device Device;
49-
if (!getDevice(Device, backend::ext_oneapi_level_zero)) {
50-
// No suitable device found.
51-
return 0;
52-
}
53-
5454
std::vector<uint8_t> Spirv = loadSpirvFromFile(argv[1]);
5555

5656
const sycl::context Context{Device};

sycl/test-e2e/KernelAndProgram/disable-caching.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// This test ensures created program/kernels are not retained
22
// if and only if caching is disabled.
3-
// UNSUPPORTED: level_zero_v2_adapter
4-
// UNSUPPORTED-INTENDED: bug in L0 loader param validation (fixed in v.1.21.1)
53

64
// RUN: %{build} -o %t.out
75
// RUN: env ZE_DEBUG=-6 SYCL_UR_TRACE=2 SYCL_CACHE_IN_MEM=0 %{run} %t.out \

sycl/ur_win_proxy_loader/ur_win_proxy_loader.cpp

+23-1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,27 @@ void *&getDllHandle() {
107107
return dllHandle;
108108
}
109109

110+
static bool shouldLoadL0V2adapter() {
111+
auto SyclEnv = std::getenv("SYCL_UR_USE_LEVEL_ZERO_V2");
112+
auto UREvn = std::getenv("UR_LOADER_USE_LEVEL_ZERO_V2");
113+
114+
try {
115+
if (SyclEnv && std::stoi(SyclEnv) == 1) {
116+
return true;
117+
}
118+
} catch (...) {
119+
}
120+
121+
try {
122+
if (UREvn && std::atoi(UREvn) == 1) {
123+
return true;
124+
}
125+
} catch (...) {
126+
}
127+
128+
return false;
129+
}
130+
110131
/// Load the adapter libraries
111132
void preloadLibraries() {
112133
// Suppress system errors.
@@ -142,7 +163,8 @@ void preloadLibraries() {
142163
getDllHandle() = loadAdapter(UR_LIBRARY_NAME(loader));
143164
loadAdapter(UR_LIBRARY_NAME(adapter_opencl));
144165
loadAdapter(UR_LIBRARY_NAME(adapter_level_zero));
145-
loadAdapter(UR_LIBRARY_NAME(adapter_level_zero_v2));
166+
if (shouldLoadL0V2adapter())
167+
loadAdapter(UR_LIBRARY_NAME(adapter_level_zero_v2));
146168
loadAdapter(UR_LIBRARY_NAME(adapter_cuda));
147169
loadAdapter(UR_LIBRARY_NAME(adapter_hip));
148170
loadAdapter(UR_LIBRARY_NAME(adapter_native_cpu));

0 commit comments

Comments
 (0)