2626# suffixes: A list of file extensions to treat as test files.
2727config .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.
3232config .test_source_root = os .path .dirname (__file__ )
3333
3434# test_exec_root: The root path where tests should be run.
3535config .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
3741if 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
4546elif 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
5751elif 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
7360config .substitutions .append ( ('%sycl_libs_dir' , config .sycl_libs_dir ) )
7461config .substitutions .append ( ('%sycl_include' , config .sycl_include ) )
7966
8067llvm_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
9171backend = 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.
123107config .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+
125114cpu_run_substitute = "true"
126115cpu_run_on_linux_substitute = "true "
127116cpu_check_substitute = ""
128117cpu_check_on_linux_substitute = ""
129118
130119if 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+
138131config .substitutions .append ( ('%CPU_RUN_PLACEHOLDER' , cpu_run_substitute ) )
139132config .substitutions .append ( ('%CPU_RUN_ON_LINUX_PLACEHOLDER' , cpu_run_on_linux_substitute ) )
140133config .substitutions .append ( ('%CPU_CHECK_PLACEHOLDER' , cpu_check_substitute ) )
@@ -149,7 +142,8 @@ def getDeviceCount(device_type):
149142[gpu_count , cuda ] = getDeviceCount ("gpu" )
150143
151144if 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
166162config .substitutions .append ( ('%GPU_RUN_PLACEHOLDER' , gpu_run_substitute ) )
167163config .substitutions .append ( ('%GPU_RUN_ON_LINUX_PLACEHOLDER' , gpu_run_on_linux_substitute ) )
168164config .substitutions .append ( ('%GPU_CHECK_PLACEHOLDER' , gpu_check_substitute ) )
169165config .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-
176167acc_run_substitute = "true"
177168acc_check_substitute = ""
178169if 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" )
183177config .substitutions .append ( ('%ACC_RUN_PLACEHOLDER' , acc_run_substitute ) )
184178config .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+
200200for 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
208208try :
0 commit comments