Skip to content

Commit bbeb2f1

Browse files
committed
[SYCL][NFC] Refactor lit.cfg.py
Switched to use "lit_config.note" instead of just "print": this emits potentially more usefult message, because it shows particular file and line where it was emitted, something like: ``` llvm-lit: /sycl/test/lit.cfg.py:117: note: Found available CPU device llvm-lit: /sycl/test/lit.cfg.py:154: warning: GPU device not found llvm-lit: /sycl/test/lit.cfg.py:169: warning: Accelerator device not found llvm-lit: /sycl/test/lit.cfg.py:198: warning: Couldn't find pre-installed AOT device compiler ocloc llvm-lit: /sycl/test/lit.cfg.py:198: warning: Couldn't find pre-installed AOT device compiler aoc llvm-lit: /sycl/test/lit.cfg.py:198: warning: Couldn't find pre-installed AOT device compiler opencl-aot ``` It also should be possible now to suppress this output via "-q" option to llvm-lit Removed extra items from "config.excludes" list since they were ignored anyway based on content of "config.suffixes" Simplified environment propagation by re-using existing helper functions Updated logic of `getDeviceCount` function to avoid printing useless messages Removed duplicated handling of path to SYCL tools directory Refactored handling of "opencl-aot" tool: now if it was built together with product, version from build directory will be used rather than a system one Signed-off-by: Alexey Sachkov <[email protected]>
1 parent 2b88867 commit bbeb2f1

File tree

2 files changed

+70
-69
lines changed

2 files changed

+70
-69
lines changed

sycl/test/lit.cfg.py

Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -26,49 +26,36 @@
2626
# suffixes: A list of file extensions to treat as test files.
2727
config.suffixes = ['.c', '.cpp'] #add .spv. Currently not clear what to do with those
2828

29-
config.excludes = ['CMakeLists.txt', 'run_tests.sh', 'README.txt', 'Inputs']
29+
config.excludes = ['Inputs']
3030

3131
# test_source_root: The root path where tests are located.
3232
config.test_source_root = os.path.dirname(__file__)
3333

3434
# test_exec_root: The root path where tests should be run.
3535
config.test_exec_root = os.path.join(config.sycl_obj_root, 'test')
3636

37+
# Propagate some variables from the host environment.
38+
llvm_config.with_system_environment(['PATH', 'OCL_ICD_FILENAME', 'SYCL_DEVICE_ALLOWLIST', 'SYCL_CONFIG_FILE_NAME'])
39+
40+
# Configure LD_LIBRARY_PATH or corresponding os-specific alternatives
3741
if platform.system() == "Linux":
3842
config.available_features.add('linux')
39-
# Propagate 'LD_LIBRARY_PATH' through the environment.
40-
if 'LD_LIBRARY_PATH' in os.environ:
41-
config.environment['LD_LIBRARY_PATH'] = os.path.pathsep.join((config.environment['LD_LIBRARY_PATH'], config.sycl_libs_dir))
42-
else:
43-
config.environment['LD_LIBRARY_PATH'] = config.sycl_libs_dir
43+
llvm_config.with_system_environment('LD_LIBRARY_PATH')
44+
llvm_config.with_environment('LD_LIBRARY_PATH', config.sycl_libs_dir, append_path=True)
4445

4546
elif platform.system() == "Windows":
4647
config.available_features.add('windows')
47-
if 'LIB' in os.environ:
48-
config.environment['LIB'] = os.path.pathsep.join((config.environment['LIB'], config.sycl_libs_dir))
49-
else:
50-
config.environment['LIB'] = config.sycl_libs_dir
51-
52-
if 'PATH' in os.environ:
53-
config.environment['PATH'] = os.path.pathsep.join((config.environment['PATH'], config.sycl_tools_dir))
54-
else:
55-
config.environment['PATH'] = config.sycl_tools_dir
48+
llvm_config.with_system_environment('LIB')
49+
llvm_config.with_environment('LIB', config.sycl_libs_dir, append_path=True)
5650

5751
elif platform.system() == "Darwin":
5852
# FIXME: surely there is a more elegant way to instantiate the Xcode directories.
59-
if 'CPATH' in os.environ:
60-
config.environment['CPATH'] = os.path.pathsep.join((os.environ['CPATH'], "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1"))
61-
else:
62-
config.environment['CPATH'] = "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1"
63-
config.environment['CPATH'] = os.path.pathsep.join((config.environment['CPATH'], "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/"))
64-
config.environment['DYLD_LIBRARY_PATH'] = config.sycl_libs_dir
53+
llvm_config.with_system_environment('CPATH')
54+
llvm_config.with_environment('CPATH', "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1", append_path=True)
55+
llvm_config.with_environment('CPATH', "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/", append_path=True)
56+
llvm_config.with_environment('DYLD_LIBRARY_PATH', config.sycl_libs_dir)
6557

66-
# propagate the environment variable OCL_ICD_FILANEMES to use proper runtime.
67-
if 'OCL_ICD_FILENAMES' in os.environ:
68-
config.environment['OCL_ICD_FILENAMES'] = os.environ['OCL_ICD_FILENAMES']
69-
70-
if 'SYCL_DEVICE_ALLOWLIST' in os.environ:
71-
config.environment['SYCL_DEVICE_ALLOWLIST'] = os.environ['SYCL_DEVICE_ALLOWLIST']
58+
llvm_config.with_environment('PATH', config.sycl_tools_dir, append_path=True)
7259

7360
config.substitutions.append( ('%sycl_libs_dir', config.sycl_libs_dir ) )
7461
config.substitutions.append( ('%sycl_include', config.sycl_include ) )
@@ -79,14 +66,7 @@
7966

8067
llvm_config.use_clang()
8168

82-
tools = ['llvm-spirv']
83-
tool_dirs = [config.sycl_tools_dir]
84-
llvm_config.add_tool_substitutions(tools, tool_dirs)
85-
86-
if "opencl-aot" in config.llvm_enable_projects:
87-
if 'PATH' in os.environ:
88-
print("Adding path to opencl-aot tool to PATH")
89-
os.environ['PATH'] = os.path.pathsep.join((os.getenv('PATH'), config.sycl_tools_dir))
69+
llvm_config.add_tool_substitutions(['llvm-spirv'], [config.sycl_tools_dir])
9070

9171
backend=lit_config.params.get('SYCL_BE', "PI_OPENCL")
9272

@@ -98,43 +78,56 @@ def getDeviceCount(device_type):
9878
stdout=subprocess.PIPE)
9979
(output, err) = process.communicate()
10080
exit_code = process.wait()
81+
10182
if exit_code != 0:
102-
print("getDeviceCount {TYPE}:Non-zero exit code {CODE}".format(
103-
TYPE=device_type, CODE=exit_code))
83+
lit_config.error("getDeviceCount {TYPE} {BACKEND}: Non-zero exit code {CODE}".format(
84+
TYPE=device_type, BACKEND=backend, CODE=exit_code))
10485
return [0,False]
86+
10587
result = output.decode().replace('\n', '').split(':', 1)
10688
try:
10789
value = int(result[0])
10890
except ValueError:
10991
value = 0
110-
print("getDeviceCount {TYPE}:Cannot get value from output.".format(
111-
TYPE=device_type))
112-
if len(result) > 1 and len(result[1]):
113-
print("getDeviceCount {TYPE}:{MSG}".format(
114-
TYPE=device_type, MSG=result[1]))
92+
lit_config.error("getDeviceCount {TYPE} {BACKEND}: Cannot get value from output: {OUT}".format(
93+
TYPE=device_type, BACKEND=backend, OUT=result[0]))
94+
95+
# if we have found gpu and there is additional information, let's check
96+
# whether this is CUDA device or not
97+
if device_type == "gpu" and value > 0 and len(result[1]):
11598
if re.match(r".*cuda", result[1]):
11699
is_cuda = True;
100+
117101
if err:
118-
print("getDeviceCount {TYPE}:{ERR}".format(
119-
TYPE=device_type, ERR=err))
102+
lit_config.warning("getDeviceCount {TYPE} {BACKEND} stderr:{ERR}".format(
103+
TYPE=device_type, BACKEND=backend, ERR=err))
120104
return [value,is_cuda]
121105

122106
# Every SYCL implementation provides a host implementation.
123107
config.available_features.add('host')
124108

109+
# Configure device-specific substitutions based on availability of corresponding
110+
# devices/runtimes
111+
112+
found_at_least_one_device = False
113+
125114
cpu_run_substitute = "true"
126115
cpu_run_on_linux_substitute = "true "
127116
cpu_check_substitute = ""
128117
cpu_check_on_linux_substitute = ""
129118

130119
if getDeviceCount("cpu")[0]:
131-
print("Found available CPU device")
120+
found_at_least_one_device = True
121+
lit_config.note("Found available CPU device")
132122
cpu_run_substitute = "env SYCL_DEVICE_TYPE=CPU "
133123
cpu_check_substitute = "| FileCheck %s"
134124
config.available_features.add('cpu')
135125
if platform.system() == "Linux":
136126
cpu_run_on_linux_substitute = "env SYCL_DEVICE_TYPE=CPU "
137127
cpu_check_on_linux_substitute = "| FileCheck %s"
128+
else:
129+
lit_config.warning("CPU device not found")
130+
138131
config.substitutions.append( ('%CPU_RUN_PLACEHOLDER', cpu_run_substitute) )
139132
config.substitutions.append( ('%CPU_RUN_ON_LINUX_PLACEHOLDER', cpu_run_on_linux_substitute) )
140133
config.substitutions.append( ('%CPU_CHECK_PLACEHOLDER', cpu_check_substitute) )
@@ -149,7 +142,8 @@ def getDeviceCount(device_type):
149142
[gpu_count, cuda] = getDeviceCount("gpu")
150143

151144
if gpu_count > 0:
152-
print("Found available GPU device")
145+
found_at_least_one_device = True
146+
lit_config.note("Found available GPU device")
153147
gpu_run_substitute = " env SYCL_DEVICE_TYPE=GPU "
154148
gpu_check_substitute = "| FileCheck %s"
155149
config.available_features.add('gpu')
@@ -162,47 +156,53 @@ def getDeviceCount(device_type):
162156
gpu_check_on_linux_substitute = "| FileCheck %s"
163157
if cuda:
164158
gpu_run_on_linux_substitute += " SYCL_BE=PI_CUDA "
159+
else:
160+
lit_config.warning("GPU device not found")
165161

166162
config.substitutions.append( ('%GPU_RUN_PLACEHOLDER', gpu_run_substitute) )
167163
config.substitutions.append( ('%GPU_RUN_ON_LINUX_PLACEHOLDER', gpu_run_on_linux_substitute) )
168164
config.substitutions.append( ('%GPU_CHECK_PLACEHOLDER', gpu_check_substitute) )
169165
config.substitutions.append( ('%GPU_CHECK_ON_LINUX_PLACEHOLDER', gpu_check_on_linux_substitute) )
170166

171-
if cuda:
172-
config.substitutions.append( ('%sycl_triple', "nvptx64-nvidia-cuda-sycldevice" ) )
173-
else:
174-
config.substitutions.append( ('%sycl_triple', "spir64-unknown-linux-sycldevice" ) )
175-
176167
acc_run_substitute = "true"
177168
acc_check_substitute = ""
178169
if getDeviceCount("accelerator")[0] and platform.system() == "Linux":
179-
print("Found available accelerator device")
170+
found_at_least_one_device = True
171+
lit_config.note("Found available accelerator device")
180172
acc_run_substitute = " env SYCL_DEVICE_TYPE=ACC "
181173
acc_check_substitute = "| FileCheck %s"
182174
config.available_features.add('accelerator')
175+
else:
176+
lit_config.warning("Accelerator device not found")
183177
config.substitutions.append( ('%ACC_RUN_PLACEHOLDER', acc_run_substitute) )
184178
config.substitutions.append( ('%ACC_CHECK_PLACEHOLDER', acc_check_substitute) )
185179

186180
# PI API either supports OpenCL or CUDA.
187-
opencl = False
188-
if not cuda:
189-
opencl = True
181+
if not cuda and found_at_least_one_device:
190182
config.available_features.add('opencl')
191183

184+
if cuda:
185+
config.substitutions.append( ('%sycl_triple', "nvptx64-nvidia-cuda-sycldevice" ) )
186+
else:
187+
config.substitutions.append( ('%sycl_triple', "spir64-unknown-linux-sycldevice" ) )
192188

193-
path = config.environment['PATH']
194-
path = os.path.pathsep.join((config.sycl_tools_dir, path))
195-
config.environment['PATH'] = path
189+
if "opencl-aot" in config.llvm_enable_projects:
190+
lit_config.note("Using opencl-aot version which is built as part of the project")
191+
config.available_features.add("opencl-aot")
192+
llvm_config.add_tool_substitutions(['opencl-aot'], [config.sycl_tools_dir])
196193

197194
# Device AOT compilation tools aren't part of the SYCL project,
198195
# so they need to be pre-installed on the machine
199-
aot_tools = ["opencl-aot", "ocloc", "aoc"]
196+
aot_tools = ["ocloc", "aoc"]
197+
if "opencl-aot" not in config.llvm_enable_projects:
198+
aot_tools.append('opencl-aot')
199+
200200
for aot_tool in aot_tools:
201201
if find_executable(aot_tool) is not None:
202-
print("Found AOT device compiler " + aot_tool)
202+
lit_config.note("Found pre-installed AOT device compiler " + aot_tool)
203203
config.available_features.add(aot_tool)
204204
else:
205-
print("Could not find AOT device compiler " + aot_tool)
205+
lit_config.warning("Couldn't find pre-installed AOT device compiler " + aot_tool)
206206

207207
# Set timeout for test = 10 mins
208208
try:

sycl/tools/get_device_count_by_type.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
#include <vector>
1919

2020
static const std::string help =
21-
" Help\n"
22-
" Example: ./get_device_count_by_type cpu opencl\n"
23-
" Support types: cpu/gpu/accelerator/default/all\n"
24-
" Support backends: cuda/opencl \n"
25-
" Output format: <number_of_devices>:<additional_Information>";
21+
" Help\n"
22+
" Example: ./get_device_count_by_type cpu opencl\n"
23+
" Supported device types: cpu/gpu/accelerator/default/all\n"
24+
" Supported backends: PI_CUDA/PI_OPENCL \n"
25+
" Output format: <number_of_devices>:<additional_Information>";
2626

2727
int main(int argc, char* argv[]) {
2828
if (argc < 3) {
@@ -45,7 +45,8 @@ int main(int argc, char* argv[]) {
4545

4646
auto err = cuDriverGetVersion(&runtime_version);
4747
if (runtime_version < 9020 || err != CUDA_SUCCESS) {
48-
std::cout << deviceCount << " :Unsupported CUDA Runtime " << std::endl;
48+
std::cout << deviceCount << ":Unsupported CUDA Runtime " << std::endl;
49+
return 1;
4950
}
5051

5152
if (type == "gpu") {
@@ -56,7 +57,7 @@ int main(int argc, char* argv[]) {
5657
msg += " type: ";
5758
msg += type;
5859
}
59-
std::cout << deviceCount << " : " << msg << std::endl;
60+
std::cout << deviceCount << ":" << msg << std::endl;
6061
return 0;
6162
}
6263
#endif // USE_PI_CUDA
@@ -108,7 +109,7 @@ int main(int argc, char* argv[]) {
108109
}
109110
}
110111

111-
std::cout << deviceCount << ":" << backend << std::endl;
112+
std::cout << deviceCount << ":" << std::endl;
112113

113114
return 0;
114115
}

0 commit comments

Comments
 (0)