26
26
# suffixes: A list of file extensions to treat as test files.
27
27
config .suffixes = ['.c' , '.cpp' ] #add .spv. Currently not clear what to do with those
28
28
29
- config .excludes = ['CMakeLists.txt' , 'run_tests.sh' , 'README.txt' , ' Inputs' ]
29
+ config .excludes = ['Inputs' ]
30
30
31
31
# test_source_root: The root path where tests are located.
32
32
config .test_source_root = os .path .dirname (__file__ )
33
33
34
34
# test_exec_root: The root path where tests should be run.
35
35
config .test_exec_root = os .path .join (config .sycl_obj_root , 'test' )
36
36
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
37
41
if platform .system () == "Linux" :
38
42
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 )
44
45
45
46
elif platform .system () == "Windows" :
46
47
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 )
56
50
57
51
elif platform .system () == "Darwin" :
58
52
# 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 )
65
57
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 )
72
59
73
60
config .substitutions .append ( ('%sycl_libs_dir' , config .sycl_libs_dir ) )
74
61
config .substitutions .append ( ('%sycl_include' , config .sycl_include ) )
79
66
80
67
llvm_config .use_clang ()
81
68
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 ])
90
70
91
71
backend = lit_config .params .get ('SYCL_BE' , "PI_OPENCL" )
92
72
@@ -98,43 +78,56 @@ def getDeviceCount(device_type):
98
78
stdout = subprocess .PIPE )
99
79
(output , err ) = process .communicate ()
100
80
exit_code = process .wait ()
81
+
101
82
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 ))
104
85
return [0 ,False ]
86
+
105
87
result = output .decode ().replace ('\n ' , '' ).split (':' , 1 )
106
88
try :
107
89
value = int (result [0 ])
108
90
except ValueError :
109
91
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 ]):
115
98
if re .match (r".*cuda" , result [1 ]):
116
99
is_cuda = True ;
100
+
117
101
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 ))
120
104
return [value ,is_cuda ]
121
105
122
106
# Every SYCL implementation provides a host implementation.
123
107
config .available_features .add ('host' )
124
108
109
+ # Configure device-specific substitutions based on availability of corresponding
110
+ # devices/runtimes
111
+
112
+ found_at_least_one_device = False
113
+
125
114
cpu_run_substitute = "true"
126
115
cpu_run_on_linux_substitute = "true "
127
116
cpu_check_substitute = ""
128
117
cpu_check_on_linux_substitute = ""
129
118
130
119
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" )
132
122
cpu_run_substitute = "env SYCL_DEVICE_TYPE=CPU "
133
123
cpu_check_substitute = "| FileCheck %s"
134
124
config .available_features .add ('cpu' )
135
125
if platform .system () == "Linux" :
136
126
cpu_run_on_linux_substitute = "env SYCL_DEVICE_TYPE=CPU "
137
127
cpu_check_on_linux_substitute = "| FileCheck %s"
128
+ else :
129
+ lit_config .warning ("CPU device not found" )
130
+
138
131
config .substitutions .append ( ('%CPU_RUN_PLACEHOLDER' , cpu_run_substitute ) )
139
132
config .substitutions .append ( ('%CPU_RUN_ON_LINUX_PLACEHOLDER' , cpu_run_on_linux_substitute ) )
140
133
config .substitutions .append ( ('%CPU_CHECK_PLACEHOLDER' , cpu_check_substitute ) )
@@ -149,7 +142,8 @@ def getDeviceCount(device_type):
149
142
[gpu_count , cuda ] = getDeviceCount ("gpu" )
150
143
151
144
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" )
153
147
gpu_run_substitute = " env SYCL_DEVICE_TYPE=GPU "
154
148
gpu_check_substitute = "| FileCheck %s"
155
149
config .available_features .add ('gpu' )
@@ -162,47 +156,53 @@ def getDeviceCount(device_type):
162
156
gpu_check_on_linux_substitute = "| FileCheck %s"
163
157
if cuda :
164
158
gpu_run_on_linux_substitute += " SYCL_BE=PI_CUDA "
159
+ else :
160
+ lit_config .warning ("GPU device not found" )
165
161
166
162
config .substitutions .append ( ('%GPU_RUN_PLACEHOLDER' , gpu_run_substitute ) )
167
163
config .substitutions .append ( ('%GPU_RUN_ON_LINUX_PLACEHOLDER' , gpu_run_on_linux_substitute ) )
168
164
config .substitutions .append ( ('%GPU_CHECK_PLACEHOLDER' , gpu_check_substitute ) )
169
165
config .substitutions .append ( ('%GPU_CHECK_ON_LINUX_PLACEHOLDER' , gpu_check_on_linux_substitute ) )
170
166
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
-
176
167
acc_run_substitute = "true"
177
168
acc_check_substitute = ""
178
169
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" )
180
172
acc_run_substitute = " env SYCL_DEVICE_TYPE=ACC "
181
173
acc_check_substitute = "| FileCheck %s"
182
174
config .available_features .add ('accelerator' )
175
+ else :
176
+ lit_config .warning ("Accelerator device not found" )
183
177
config .substitutions .append ( ('%ACC_RUN_PLACEHOLDER' , acc_run_substitute ) )
184
178
config .substitutions .append ( ('%ACC_CHECK_PLACEHOLDER' , acc_check_substitute ) )
185
179
186
180
# 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 :
190
182
config .available_features .add ('opencl' )
191
183
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" ) )
192
188
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 ])
196
193
197
194
# Device AOT compilation tools aren't part of the SYCL project,
198
195
# 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
+
200
200
for aot_tool in aot_tools :
201
201
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 )
203
203
config .available_features .add (aot_tool )
204
204
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 )
206
206
207
207
# Set timeout for test = 10 mins
208
208
try :
0 commit comments