Skip to content

Commit f1ab47c

Browse files
authored
[NFC][SYCL] Run device-agnostic tests separately (#2925)
* [NFC][SYCL] Run device-agnostic tests separately Tests which do not require backend were run for every target backend. It is waste of machine time. This PR: - move device-agnostic tests to separate target to run only once; - moved all device-specific LIT substitutions to on-device folder to avoid adding device-dependent tests to directory with device-agnostic tests; - move device-dependent tests to sycl/test/on-device folder. * [SYCL] Apply review comments
1 parent 23926b0 commit f1ab47c

File tree

6 files changed

+293
-149
lines changed

6 files changed

+293
-149
lines changed

sycl/test/CMakeLists.txt

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ configure_lit_site_cfg(
2020
${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
2121
)
2222

23+
configure_lit_site_cfg(
24+
${CMAKE_CURRENT_SOURCE_DIR}/on-device/lit.site.cfg.py.in
25+
${CMAKE_CURRENT_BINARY_DIR}/on-device/lit.site.cfg.py
26+
MAIN_CONFIG
27+
${CMAKE_CURRENT_SOURCE_DIR}/on-device/lit.cfg.py
28+
)
29+
2330
configure_lit_site_cfg(
2431
${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
2532
${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg.py
@@ -64,7 +71,7 @@ add_lit_testsuites(SYCL-DEPLOY ${CMAKE_CURRENT_SOURCE_DIR}
6471
)
6572

6673
add_lit_testsuite(check-sycl-opencl "Running the SYCL regression tests for OpenCL"
67-
${CMAKE_CURRENT_BINARY_DIR}
74+
${CMAKE_CURRENT_BINARY_DIR}/on-device
6875
ARGS ${RT_TEST_ARGS}
6976
PARAMS "SYCL_PLUGIN=opencl"
7077
DEPENDS ${SYCL_TEST_DEPS}
@@ -73,31 +80,47 @@ add_lit_testsuite(check-sycl-opencl "Running the SYCL regression tests for OpenC
7380
set_target_properties(check-sycl-opencl PROPERTIES FOLDER "SYCL tests")
7481

7582
add_lit_testsuite(check-sycl-level-zero "Running the SYCL regression tests for Level Zero"
76-
${CMAKE_CURRENT_BINARY_DIR}
83+
${CMAKE_CURRENT_BINARY_DIR}/on-device
7784
ARGS ${RT_TEST_ARGS}
7885
PARAMS "SYCL_PLUGIN=level_zero"
7986
DEPENDS ${SYCL_TEST_DEPS}
8087
EXCLUDE_FROM_CHECK_ALL
8188
)
89+
90+
add_lit_testsuite(check-sycl-spirv "Running device-agnostic SYCL regression tests for SPIR-V"
91+
${CMAKE_CURRENT_BINARY_DIR}
92+
ARGS ${RT_TEST_ARGS}
93+
PARAMS "SYCL_TRIPLE=spir64-unknown-linux-sycldevice"
94+
DEPENDS ${SYCL_TEST_DEPS}
95+
EXCLUDE_FROM_CHECK_ALL
96+
)
8297
set_target_properties(check-sycl-level-zero PROPERTIES FOLDER "SYCL tests")
8398

8499
add_custom_target(check-sycl)
85-
add_dependencies(check-sycl check-sycl-opencl check-sycl-level-zero)
100+
add_dependencies(check-sycl check-sycl-opencl check-sycl-level-zero check-sycl-spirv)
86101
set_target_properties(check-sycl PROPERTIES FOLDER "SYCL tests")
87102

88103
if(SYCL_BUILD_PI_CUDA)
89104
add_lit_testsuite(check-sycl-cuda "Running the SYCL regression tests for CUDA"
90-
${CMAKE_CURRENT_BINARY_DIR}
105+
${CMAKE_CURRENT_BINARY_DIR}/on-device
91106
ARGS ${RT_TEST_ARGS}
92107
PARAMS "SYCL_PLUGIN=cuda"
93108
DEPENDS ${SYCL_TEST_DEPS}
94109
EXCLUDE_FROM_CHECK_ALL
95110
)
96111
set_target_properties(check-sycl-cuda PROPERTIES FOLDER "SYCL CUDA tests")
97112

98-
add_dependencies(check-sycl check-sycl-cuda)
113+
add_lit_testsuite(check-sycl-ptx "Running device-agnostic SYCL regression tests for NVidia PTX"
114+
${CMAKE_CURRENT_BINARY_DIR}
115+
ARGS ${RT_TEST_ARGS}
116+
PARAMS "SYCL_TRIPLE=nvptx64-nvidia-cuda-sycldevice"
117+
DEPENDS ${SYCL_TEST_DEPS}
118+
EXCLUDE_FROM_CHECK_ALL
119+
)
120+
121+
add_dependencies(check-sycl check-sycl-cuda check-sycl-ptx)
99122

100-
add_lit_testsuites(SYCL-CUDA ${CMAKE_CURRENT_SOURCE_DIR}
123+
add_lit_testsuites(SYCL-CUDA ${CMAKE_CURRENT_SOURCE_DIR}/on-device
101124
PARAMS "SYCL_PLUGIN=cuda"
102125
DEPENDS ${SYCL_TEST_DEPS}
103126
EXCLUDE_FROM_CHECK_ALL

sycl/test/lit.cfg.py

Lines changed: 4 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
config.suffixes = ['.c', '.cpp', '.dump'] #add .spv. Currently not clear what to do with those
2828

2929
# feature tests are considered not so lightweight, so, they are excluded by default
30-
config.excludes = ['Inputs', 'feature-tests']
30+
config.excludes = ['Inputs', 'feature-tests', 'on-device']
3131

3232
# test_source_root: The root path where tests are located.
3333
config.test_source_root = os.path.dirname(__file__)
@@ -75,152 +75,13 @@
7575

7676
llvm_config.add_tool_substitutions(['llvm-spirv'], [config.sycl_tools_dir])
7777

78-
backend=lit_config.params.get('SYCL_PLUGIN', "opencl")
79-
lit_config.note("Backend: {}".format(backend))
80-
config.substitutions.append( ('%sycl_be', { 'opencl': 'PI_OPENCL', 'cuda': 'PI_CUDA', 'level_zero': 'PI_LEVEL_ZERO'}[backend]) )
81-
config.substitutions.append( ('%BE_RUN_PLACEHOLDER', "env SYCL_DEVICE_FILTER={SYCL_PLUGIN} ".format(SYCL_PLUGIN=backend)) )
8278
config.substitutions.append( ('%RUN_ON_HOST', "env SYCL_DEVICE_FILTER=host ") )
8379

84-
get_device_count_by_type_path = os.path.join(config.llvm_tools_dir, "get_device_count_by_type")
85-
86-
def getDeviceCount(device_type):
87-
is_cuda = False;
88-
is_level_zero = False;
89-
process = subprocess.Popen([get_device_count_by_type_path, device_type, backend],
90-
stdout=subprocess.PIPE)
91-
(output, err) = process.communicate()
92-
exit_code = process.wait()
93-
94-
if exit_code != 0:
95-
lit_config.error("getDeviceCount {TYPE} {BACKEND}: Non-zero exit code {CODE}".format(
96-
TYPE=device_type, BACKEND=backend, CODE=exit_code))
97-
return [0,False,False]
98-
99-
result = output.decode().replace('\n', '').split(':', 1)
100-
try:
101-
value = int(result[0])
102-
except ValueError:
103-
value = 0
104-
lit_config.error("getDeviceCount {TYPE} {BACKEND}: Cannot get value from output: {OUT}".format(
105-
TYPE=device_type, BACKEND=backend, OUT=result[0]))
106-
107-
# if we have found gpu and there is additional information, let's check
108-
# whether this is CUDA device or Level Zero device or none of these.
109-
if device_type == "gpu" and value > 0 and len(result[1]):
110-
if re.match(r".*cuda", result[1]):
111-
is_cuda = True;
112-
if re.match(r".*level zero", result[1]):
113-
is_level_zero = True;
114-
115-
if err:
116-
lit_config.warning("getDeviceCount {TYPE} {BACKEND} stderr:{ERR}".format(
117-
TYPE=device_type, BACKEND=backend, ERR=err))
118-
return [value,is_cuda,is_level_zero]
119-
12080
# Every SYCL implementation provides a host implementation.
12181
config.available_features.add('host')
122-
123-
# Configure device-specific substitutions based on availability of corresponding
124-
# devices/runtimes
125-
126-
found_at_least_one_device = False
127-
128-
cpu_run_substitute = "true"
129-
cpu_run_on_linux_substitute = "true "
130-
cpu_check_substitute = ""
131-
cpu_check_on_linux_substitute = ""
132-
133-
if getDeviceCount("cpu")[0]:
134-
found_at_least_one_device = True
135-
lit_config.note("Found available CPU device")
136-
cpu_run_substitute = "env SYCL_DEVICE_FILTER={SYCL_PLUGIN}:cpu ".format(SYCL_PLUGIN=backend)
137-
cpu_check_substitute = "| FileCheck %s"
138-
config.available_features.add('cpu')
139-
if platform.system() == "Linux":
140-
cpu_run_on_linux_substitute = "env SYCL_DEVICE_FILTER={SYCL_PLUGIN}:cpu ".format(SYCL_PLUGIN=backend)
141-
cpu_check_on_linux_substitute = "| FileCheck %s"
142-
else:
143-
lit_config.warning("CPU device not found")
144-
145-
config.substitutions.append( ('%CPU_RUN_PLACEHOLDER', cpu_run_substitute) )
146-
config.substitutions.append( ('%CPU_RUN_ON_LINUX_PLACEHOLDER', cpu_run_on_linux_substitute) )
147-
config.substitutions.append( ('%CPU_CHECK_PLACEHOLDER', cpu_check_substitute) )
148-
config.substitutions.append( ('%CPU_CHECK_ON_LINUX_PLACEHOLDER', cpu_check_on_linux_substitute) )
149-
150-
gpu_run_substitute = "true"
151-
gpu_run_on_linux_substitute = "true "
152-
gpu_check_substitute = ""
153-
gpu_check_on_linux_substitute = ""
154-
155-
cuda = False
156-
level_zero = False
157-
[gpu_count, cuda, level_zero] = getDeviceCount("gpu")
158-
159-
if gpu_count > 0:
160-
found_at_least_one_device = True
161-
lit_config.note("Found available GPU device")
162-
gpu_run_substitute = " env SYCL_DEVICE_FILTER={SYCL_PLUGIN}:gpu ".format(SYCL_PLUGIN=backend)
163-
gpu_check_substitute = "| FileCheck %s"
164-
config.available_features.add('gpu')
165-
if cuda:
166-
config.available_features.add('cuda')
167-
elif level_zero:
168-
config.available_features.add('level_zero')
169-
170-
if platform.system() == "Linux":
171-
gpu_run_on_linux_substitute = "env SYCL_DEVICE_FILTER={SYCL_PLUGIN}:gpu ".format(SYCL_PLUGIN=backend)
172-
gpu_check_on_linux_substitute = "| FileCheck %s"
173-
# ESIMD-specific setup. Requires OpenCL for now.
174-
esimd_run_substitute = " env SYCL_DEVICE_FILTER=opencl:gpu SYCL_PROGRAM_COMPILE_OPTIONS=-vc-codegen"
175-
config.substitutions.append( ('%ESIMD_RUN_PLACEHOLDER', esimd_run_substitute) )
176-
config.substitutions.append( ('%clangxx-esimd', "clang++ -fsycl-explicit-simd" ) )
177-
else:
178-
lit_config.warning("GPU device not found")
179-
180-
config.substitutions.append( ('%GPU_RUN_PLACEHOLDER', gpu_run_substitute) )
181-
config.substitutions.append( ('%GPU_RUN_ON_LINUX_PLACEHOLDER', gpu_run_on_linux_substitute) )
182-
config.substitutions.append( ('%GPU_CHECK_PLACEHOLDER', gpu_check_substitute) )
183-
config.substitutions.append( ('%GPU_CHECK_ON_LINUX_PLACEHOLDER', gpu_check_on_linux_substitute) )
184-
185-
acc_run_substitute = "true"
186-
acc_check_substitute = ""
187-
if getDeviceCount("accelerator")[0]:
188-
found_at_least_one_device = True
189-
lit_config.note("Found available accelerator device")
190-
acc_run_substitute = " env SYCL_DEVICE_FILTER={SYCL_PLUGIN}:acc ".format(SYCL_PLUGIN=backend)
191-
acc_check_substitute = "| FileCheck %s"
192-
config.available_features.add('accelerator')
193-
else:
194-
lit_config.warning("Accelerator device not found")
195-
config.substitutions.append( ('%ACC_RUN_PLACEHOLDER', acc_run_substitute) )
196-
config.substitutions.append( ('%ACC_CHECK_PLACEHOLDER', acc_check_substitute) )
197-
198-
# LIT testing either supports OpenCL or CUDA or Level Zero.
199-
if not cuda and not level_zero and found_at_least_one_device:
200-
config.available_features.add('opencl')
201-
202-
if cuda:
203-
config.substitutions.append( ('%sycl_triple', "nvptx64-nvidia-cuda-sycldevice" ) )
204-
else:
205-
config.substitutions.append( ('%sycl_triple', "spir64-unknown-linux-sycldevice" ) )
206-
207-
if "opencl-aot" in config.llvm_enable_projects:
208-
lit_config.note("Using opencl-aot version which is built as part of the project")
209-
config.available_features.add("opencl-aot")
210-
llvm_config.add_tool_substitutions(['opencl-aot'], [config.sycl_tools_dir])
211-
212-
# Device AOT compilation tools aren't part of the SYCL project,
213-
# so they need to be pre-installed on the machine
214-
aot_tools = ["ocloc", "aoc"]
215-
if "opencl-aot" not in config.llvm_enable_projects:
216-
aot_tools.append('opencl-aot')
217-
218-
for aot_tool in aot_tools:
219-
if find_executable(aot_tool) is not None:
220-
lit_config.note("Found pre-installed AOT device compiler " + aot_tool)
221-
config.available_features.add(aot_tool)
222-
else:
223-
lit_config.warning("Couldn't find pre-installed AOT device compiler " + aot_tool)
82+
triple=lit_config.params.get('SYCL_TRIPLE', 'spir64-unknown-linux-sycldevice')
83+
lit_config.note("Triple: {}".format(triple))
84+
config.substitutions.append( ('%sycl_triple', triple ) )
22485

22586
# Set timeout for test = 10 mins
22687
try:

0 commit comments

Comments
 (0)