Skip to content

Commit 866ca61

Browse files
committed
[SYCL][E2E] make sure zeInit in test is called after UR is initialized
UR internally sets env variables to control behavior or L0 loader (e.g. enabling validation layer). If zeInit in test is called first the vars will have no effect.
1 parent d4f2316 commit 866ca61

11 files changed

+64
-58
lines changed

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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 8 additions & 8 deletions
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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,6 @@ void test_copyback_and_free(
118118
int main() {
119119
#ifdef SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
120120
try {
121-
// Initialize Level Zero driver is required if this test is linked
122-
// statically with Level Zero loader, the driver will not be init otherwise.
123-
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
124-
if (result != ZE_RESULT_SUCCESS) {
125-
std::cout << "zeInit failed\n";
126-
return 1;
127-
}
128-
129121
platform Plt{gpu_selector_v};
130122

131123
auto Devices = Plt.get_devices();
@@ -135,6 +127,14 @@ int main() {
135127
return 0;
136128
}
137129

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+
138138
device Dev1 = Devices[0];
139139
context Context1{Dev1};
140140
queue Queue1{Context1, Dev1};

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

Lines changed: 8 additions & 8 deletions
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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ constexpr size_t SIZE = 16;
2323
int main() {
2424
#ifdef SYCL_EXT_ONEAPI_BACKEND_LEVEL_ZERO
2525
try {
26-
// Initialize Level Zero driver is required if this test is linked
27-
// statically with Level Zero loader, the driver will not be init otherwise.
28-
ze_result_t result = zeInit(ZE_INIT_FLAG_GPU_ONLY);
29-
if (result != ZE_RESULT_SUCCESS) {
30-
std::cout << "zeInit failed\n";
31-
return 1;
32-
}
33-
3426
platform Plt{gpu_selector_v};
3527

3628
auto Devices = Plt.get_devices();
@@ -40,6 +32,14 @@ int main() {
4032
return 0;
4133
}
4234

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

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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 4 additions & 4 deletions
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/Graph/Inputs/interop-level-zero-launch-kernel.cpp

Lines changed: 6 additions & 6 deletions
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};

0 commit comments

Comments
 (0)