Skip to content

Commit a33ffb5

Browse files
authored
[SYCL] Enable LIT testing for Level Zero (#1839)
* Support discovery of Level Zero devices in get_device_count_by_type tool * Support Level Zero backend in the lit scripts * Add check-level0 make target * Fix obvious mistake in the plugin in addMapping function * Disable lit tests failing for Level Zero Signed-off-by: Artur Gainullin <[email protected]>
1 parent c50a8d8 commit a33ffb5

21 files changed

+119
-17
lines changed

sycl/plugins/level_zero/pi_level0.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ class ReturnHelper {
146146
pi_result _pi_mem::addMapping(void *MappedTo, size_t Offset, size_t Size) {
147147
std::lock_guard<std::mutex> Lock(MappingsMutex);
148148
auto Res = Mappings.insert({MappedTo, {Offset, Size}});
149-
if (Res.second) {
149+
// False as the second value in pair means that mapping was not inserted
150+
// because mapping already exists.
151+
if (!Res.second) {
150152
zePrint("piEnqueueMemBufferMap: duplicate mapping detected\n");
151153
return PI_INVALID_VALUE;
152154
}

sycl/test/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ add_lit_target(check-sycl-inline-asm
7777
DEPENDS ${SYCL_TEST_DEPS}
7878
)
7979

80+
add_lit_testsuite(check-level0 "Running the SYCL regression tests for Level Zero"
81+
${CMAKE_CURRENT_BINARY_DIR}
82+
ARGS ${RT_TEST_ARGS}
83+
PARAMS "SYCL_BE=PI_LEVEL0"
84+
DEPENDS ${SYCL_TEST_DEPS}
85+
EXCLUDE_FROM_CHECK_ALL
86+
)
87+
88+
add_dependencies(check-sycl check-level0)
89+
8090
if(SYCL_BUILD_PI_CUDA)
8191
add_lit_testsuite(check-sycl-cuda "Running the SYCL regression tests for CUDA"
8292
${CMAKE_CURRENT_BINARY_DIR}

sycl/test/basic_tests/buffer/reinterpret.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// RUN: %CPU_RUN_PLACEHOLDER %t.out
33
// RUN: %GPU_RUN_PLACEHOLDER %t.out
44
// RUN: %ACC_RUN_PLACEHOLDER %t.out
5+
//
6+
// XFAIL: level0
57

68
//==---------- reinterpret.cpp --- SYCL buffer reinterpret basic test ------==//
79
//

sycl/test/basic_tests/image_accessor_readsampler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
66
// RUN: %CPU_RUN_PLACEHOLDER %t.out
77
// RUN: %GPU_RUN_PLACEHOLDER %t.out
8+
//
9+
// XFAIL: level0
810
//==------------------- image_accessor_readsampler.cpp ---------------------==//
911
//==-----------------image_accessor read API test with sampler--------------==//
1012
//

sycl/test/basic_tests/image_accessor_readwrite.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
66
// RUN: %CPU_RUN_PLACEHOLDER %t.out
77
// RUN: %GPU_RUN_PLACEHOLDER %t.out
8+
//
9+
// XFAIL: windows && level0
810

911
//==--------------------image_accessor_readwrite.cpp ----------------------==//
1012
//==----------image_accessor read without sampler & write API test---------==//

sycl/test/basic_tests/image_accessor_readwrite_half.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// RUN: env SYCL_DEVICE_TYPE=HOST %t.out
66
// RUN: %CPU_RUN_PLACEHOLDER %t.out
77
// RUN: %GPU_RUN_PLACEHOLDER %t.out
8+
//
9+
// XFAIL: windows && level0
810

911
//==--------------------image_accessor_readwrite_half.cpp -------------------==//
1012
//==-image_accessor read (without sampler)& write API test for half datatype-==//

sycl/test/basic_tests/kernel_info.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// RUN: %CPU_RUN_PLACEHOLDER %t.out
33
// RUN: %GPU_RUN_PLACEHOLDER %t.out
44
// RUN: %ACC_RUN_PLACEHOLDER %t.out
5+
//
6+
// Fail is flaky for level0, enable when fixed.
7+
// UNSUPPORTED: level0
58

69
//==--- kernel_info.cpp - SYCL kernel info test ----------------------------==//
710
//

sycl/test/basic_tests/parallel_for_indexers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
// TODO: Unexpected result
1010
// TODO: _indexers.cpp:37: int main(): Assertion `id == -1' failed.
11-
// XFAIL: cuda
11+
// XFAIL: cuda || level0
1212

1313
#include <CL/sycl.hpp>
1414

sycl/test/basic_tests/parallel_for_range.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// XFAIL: cuda
1+
// XFAIL: cuda || level0
22
// CUDA exposes broken hierarchical parallelism.
33

44
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out

sycl/test/host-interop-task/host-task-dependency.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// RUN: %CPU_RUN_PLACEHOLDER SYCL_PI_TRACE=-1 %t.out 2>&1 %CPU_CHECK_PLACEHOLDER
33
// RUN: %GPU_RUN_PLACEHOLDER SYCL_PI_TRACE=-1 %t.out 2>&1 %GPU_CHECK_PLACEHOLDER
44
// RUN: %ACC_RUN_PLACEHOLDER SYCL_PI_TRACE=-1 %t.out 2>&1 %ACC_CHECK_PLACEHOLDER
5+
//
6+
// TODO: Behaviour is unstable for level zero on Windows. Enable when fixed.
7+
// UNSUPPORTED: windows && level0
58

69
#include <atomic>
710
#include <condition_variable>

sycl/test/host-interop-task/host-task-two-queues.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// RUN: %CPU_RUN_PLACEHOLDER %t.out
33
// RUN: %GPU_RUN_PLACEHOLDER %t.out
44
// RUN: %ACC_RUN_PLACEHOLDER %t.out
5+
//
6+
// TODO: Flaky fail on Level Zero that is why mark as unsupported temporarily.
7+
// UNSUPPORTED: level0
58

69
#include <CL/sycl.hpp>
710
#include <vector>

sycl/test/lit.cfg.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181

8282
def getDeviceCount(device_type):
8383
is_cuda = False;
84+
is_level0 = False;
8485
process = subprocess.Popen([get_device_count_by_type_path, device_type, backend],
8586
stdout=subprocess.PIPE)
8687
(output, err) = process.communicate()
@@ -100,15 +101,17 @@ def getDeviceCount(device_type):
100101
TYPE=device_type, BACKEND=backend, OUT=result[0]))
101102

102103
# if we have found gpu and there is additional information, let's check
103-
# whether this is CUDA device or not
104+
# whether this is CUDA device or Level Zero device or none of these.
104105
if device_type == "gpu" and value > 0 and len(result[1]):
105106
if re.match(r".*cuda", result[1]):
106107
is_cuda = True;
108+
if re.match(r".*level zero", result[1]):
109+
is_level0 = True;
107110

108111
if err:
109112
lit_config.warning("getDeviceCount {TYPE} {BACKEND} stderr:{ERR}".format(
110113
TYPE=device_type, BACKEND=backend, ERR=err))
111-
return [value,is_cuda]
114+
return [value,is_cuda,is_level0]
112115

113116
# Every SYCL implementation provides a host implementation.
114117
config.available_features.add('host')
@@ -146,7 +149,8 @@ def getDeviceCount(device_type):
146149
gpu_check_on_linux_substitute = ""
147150

148151
cuda = False
149-
[gpu_count, cuda] = getDeviceCount("gpu")
152+
level0 = False
153+
[gpu_count, cuda, level0] = getDeviceCount("gpu")
150154

151155
if gpu_count > 0:
152156
found_at_least_one_device = True
@@ -156,6 +160,8 @@ def getDeviceCount(device_type):
156160
config.available_features.add('gpu')
157161
if cuda:
158162
config.available_features.add('cuda')
163+
elif level0:
164+
config.available_features.add('level0')
159165

160166
if platform.system() == "Linux":
161167
gpu_run_on_linux_substitute = "env SYCL_DEVICE_TYPE=GPU SYCL_BE={SYCL_BE} ".format(SYCL_BE=backend)
@@ -181,8 +187,8 @@ def getDeviceCount(device_type):
181187
config.substitutions.append( ('%ACC_RUN_PLACEHOLDER', acc_run_substitute) )
182188
config.substitutions.append( ('%ACC_CHECK_PLACEHOLDER', acc_check_substitute) )
183189

184-
# PI API either supports OpenCL or CUDA.
185-
if not cuda and found_at_least_one_device:
190+
# LIT testing either supports OpenCL or CUDA or Level Zero.
191+
if not cuda and not level0 and found_at_least_one_device:
186192
config.available_features.add('opencl')
187193

188194
if cuda:

sycl/test/regression/fsycl-save-temps.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ int main() {
2222
}
2323

2424
// TODO: Address a Windows-specific issue with integration header filenames
25-
// XFAIL: system-windows
25+
// XFAIL: system-windows && !level0
26+
// TODO: fail is flaky on Windows for Level Zero. Enable when fixed.
27+
// UNSUPPORTED: system-windows && level0

sycl/test/regression/image_access.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
// RUN: env SYCL_PI_TRACE=2 %GPU_RUN_PLACEHOLDER %t.out 2>&1 %GPU_CHECK_PLACEHOLDER
55
// TODO: For now PI checks are skipped for ACC device. To decide if it's good.
66
// RUN: env %ACC_RUN_PLACEHOLDER %t.out
7-
8-
// UNSUPPORTED: cuda
7+
//
8+
// UNSUPPORTED: cuda || windows && level0
99
// CUDA cannot support OpenCL spec conform images.
10+
// TODO: test hangs on level0, enable when fixed.
1011

1112
//==-------------- image_access.cpp - SYCL image accessors test -----------==//
1213
//

sycl/test/regression/static-buffer-dtor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// RUN: %CPU_RUN_PLACEHOLDER %t.out
1414
// RUN: %GPU_RUN_PLACEHOLDER %t.out
1515
// RUN: %ACC_RUN_PLACEHOLDER %t.out
16+
//
17+
// XFAIL: linux && level0
1618

1719
#include <CL/sycl.hpp>
1820

sycl/test/separate-compile/test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// UNSUPPORTED: cuda
22
// CUDA does not support SPIR-V.
3-
3+
//
44
// >> ---- compile src1
55
// >> device compilation...
66
// RUN: %clangxx -fsycl-device-only -Xclang -fsycl-int-header=sycl_ihdr_a.h %s -c -o a_kernel.bc -I %sycl_include -Wno-sycl-strict

sycl/test/spec_const/spec_const_hw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// TODO: re-enable after CI drivers are updated to newer which support spec
77
// constants:
88
// XFAIL: linux && opencl
9-
// UNSUPPORTED: cuda
9+
// UNSUPPORTED: cuda || level0
1010
//
1111
//==----------- spec_const_hw.cpp ------------------------------------------==//
1212
//

sycl/test/spec_const/spec_const_redefine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// TODO: re-enable after CI drivers are updated to newer which support spec
77
// constants:
88
// XFAIL: linux && opencl
9-
// UNSUPPORTED: cuda
9+
// UNSUPPORTED: cuda || level0
1010
//
1111
//==----------- spec_const_redefine.cpp ------------------------------------==//
1212
//

sycl/test/usm/allocator_vector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// XFAIL: cuda
1+
// XFAIL: cuda || level0
22
// piextUSM*Alloc functions for CUDA are not behaving as described in
33
// https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/USM/USM.adoc
44
// https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/USM/cl_intel_unified_shared_memory.asciidoc

sycl/tools/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,21 @@ add_subdirectory(sycl-ls)
66

77
# TODO: move each tool in its own sub-directory
88
add_executable(get_device_count_by_type get_device_count_by_type.cpp)
9-
add_dependencies(get_device_count_by_type ocl-headers ocl-icd)
9+
add_dependencies(get_device_count_by_type ocl-headers ocl-icd l0-loader)
10+
11+
if(MSVC)
12+
set(L0_LIBRARY
13+
"${LLVM_LIBRARY_OUTPUT_INTDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}ze_loader${CMAKE_STATIC_LIBRARY_SUFFIX}")
14+
else()
15+
set(L0_LIBRARY
16+
"${LLVM_LIBRARY_OUTPUT_INTDIR}/${CMAKE_SHARED_LIBRARY_PREFIX}ze_loader${CMAKE_SHARED_LIBRARY_SUFFIX}")
17+
endif()
1018

1119
target_link_libraries(get_device_count_by_type
1220
PRIVATE
1321
OpenCL::Headers
1422
${OpenCL_LIBRARIES}
23+
${L0_LIBRARY}
1524
$<$<BOOL:${SYCL_BUILD_PI_CUDA}>:cudadrv>
1625
)
1726
target_compile_definitions(get_device_count_by_type

sycl/tools/get_device_count_by_type.cpp

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include <CL/cl.h>
1616
#include <CL/cl_ext.h>
17+
#include <level_zero/zet_api.h>
1718

1819
#ifdef USE_PI_CUDA
1920
#include <cuda.h>
@@ -31,7 +32,7 @@ static const std::string help =
3132
" Help\n"
3233
" Example: ./get_device_count_by_type cpu opencl\n"
3334
" Supported device types: cpu/gpu/accelerator/default/all\n"
34-
" Supported backends: PI_CUDA/PI_OPENCL \n"
35+
" Supported backends: PI_CUDA/PI_OPENCL/PI_LEVEL0 \n"
3536
" Output format: <number_of_devices>:<additional_Information>";
3637

3738
// Return the string with all characters translated to lower case.
@@ -113,6 +114,56 @@ static bool queryOpenCL(cl_device_type deviceType, cl_uint &deviceCount,
113114
return true;
114115
}
115116

117+
static bool queryLevelZero(cl_device_type deviceType, cl_uint &deviceCount,
118+
std::string &msg) {
119+
deviceCount = 0u;
120+
ze_result_t zeResult = zeInit(ZE_INIT_FLAG_NONE);
121+
if (zeResult != ZE_RESULT_SUCCESS) {
122+
msg = "ERROR: Level Zero initialization error";
123+
return false;
124+
}
125+
126+
uint32_t zeDriverCount = 0;
127+
zeResult = zeDriverGet(&zeDriverCount, nullptr);
128+
if (zeResult != ZE_RESULT_SUCCESS) {
129+
msg = "ERROR: Level Zero error querying driver count";
130+
return false;
131+
}
132+
133+
if (zeDriverCount == 0) {
134+
msg = "ERROR: Level Zero no driver found";
135+
return false;
136+
}
137+
138+
ze_driver_handle_t zeDriver;
139+
zeResult = zeDriverGet(&zeDriverCount, &zeDriver);
140+
if (zeResult != ZE_RESULT_SUCCESS) {
141+
msg = "ERROR: Level Zero error querying driver";
142+
return false;
143+
}
144+
145+
switch (deviceType) {
146+
case CL_DEVICE_TYPE_DEFAULT: // Fall through.
147+
case CL_DEVICE_TYPE_ALL: // Fall through.
148+
case CL_DEVICE_TYPE_GPU: {
149+
uint32_t zeDeviceCount = 0;
150+
zeResult = zeDeviceGet(zeDriver, &zeDeviceCount, nullptr);
151+
if (zeResult != ZE_RESULT_SUCCESS) {
152+
msg = "ERROR: Level Zero error querying device count";
153+
return false;
154+
}
155+
deviceCount = static_cast<cl_uint>(zeDeviceCount);
156+
msg = "level zero ";
157+
msg += deviceTypeToString(deviceType);
158+
return true;
159+
} break;
160+
default:
161+
msg = "WARNING: Level Zero unsupported device type ";
162+
msg += deviceTypeToString(deviceType);
163+
return true;
164+
}
165+
}
166+
116167
static bool queryCUDA(cl_device_type deviceType, cl_uint &deviceCount,
117168
std::string &msg) {
118169
deviceCount = 0u;
@@ -208,6 +259,8 @@ int main(int argc, char *argv[]) {
208259

209260
if (backend == "opencl" || backend == "pi_opencl") {
210261
querySuccess = queryOpenCL(deviceType, deviceCount, msg);
262+
} else if (backend == "level0" || backend == "pi_level0") {
263+
querySuccess = queryLevelZero(deviceType, deviceCount, msg);
211264
} else if (backend == "cuda" || backend == "pi_cuda") {
212265
querySuccess = queryCUDA(deviceType, deviceCount, msg);
213266
} else {

0 commit comments

Comments
 (0)