Skip to content

Commit f903251

Browse files
authored
[SYCL] Remove use of deprecated environment variables (intel#72)
Use of SYCL_BE and SYCL_DEVICE_TYPE was removed from LIT framework. SYCL_DEVICE_FILTER is used instead: - update [CPU|GPU|ACC]_RUN_PLACEHOLDER to use SYCL_DEVICE_FILTER; - change values format used to define a backend and a device type to match SYCL_DEVICE_FILTER requirements; - add BE_RUN_PLACEHOLDER to set backend only for tests which require that; - add mapping from old SYCL backend name format to new one to avoid impact on CI automation.
1 parent f72222d commit f903251

File tree

2 files changed

+35
-29
lines changed

2 files changed

+35
-29
lines changed

SYCL/ESIMD/esimd_test_utils.hpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <fstream>
1616
#include <iostream>
1717
#include <iterator>
18+
#include <string>
1819
#include <vector>
1920

2021
using namespace cl::sycl;
@@ -30,19 +31,21 @@ namespace esimd_test {
3031
// was returned for all devices, then the selection process will cause an
3132
// exception.
3233
class ESIMDSelector : public device_selector {
33-
// Require GPU device unless HOST is requested in SYCL_DEVICE_TYPE env
34+
// Require GPU device unless HOST is requested in SYCL_DEVICE_FILTER env
3435
virtual int operator()(const device &device) const {
35-
if (const char *dev_type = getenv("SYCL_DEVICE_TYPE")) {
36-
if (!strcmp(dev_type, "GPU"))
36+
if (const char *dev_filter = getenv("SYCL_DEVICE_FILTER")) {
37+
std::string filter_string(dev_filter);
38+
if (filter_string.find("gpu") != std::string::npos)
3739
return device.is_gpu() ? 1000 : -1;
38-
if (!strcmp(dev_type, "HOST"))
40+
if (filter_string.find("host") != std::string::npos)
3941
return device.is_host() ? 1000 : -1;
40-
std::cerr << "Supported 'SYCL_DEVICE_TYPE' env var values are 'GPU' and "
41-
"'HOST', '"
42-
<< dev_type << "' is not.\n";
42+
std::cerr
43+
<< "Supported 'SYCL_DEVICE_FILTER' env var values are 'gpu' and "
44+
"'host', '"
45+
<< filter_string << "' does not contain such substrings.\n";
4346
return -1;
4447
}
45-
// If "SYCL_DEVICE_TYPE" not defined, only allow gpu device
48+
// If "SYCL_DEVICE_FILTER" not defined, only allow gpu device
4649
return device.is_gpu() ? 1000 : -1;
4750
}
4851
};

SYCL/lit.cfg.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -112,28 +112,31 @@
112112
llvm_config.add_tool_substitutions(['llvm-spirv'], [config.sycl_tools_dir])
113113

114114
if not config.sycl_be:
115-
config.sycl_be="PI_OPENCL"
115+
lit_config.error("SYCL backend is not specified")
116+
117+
# Mapping from SYCL_BE backend definition style to SYCL_DEVICE_FILTER used
118+
# for backward compatibility
119+
try:
120+
config.sycl_be = { 'PI_OPENCL': 'opencl', 'PI_CUDA': 'cuda', 'PI_LEVEL_ZERO': 'level_zero'}[config.sycl_be]
121+
except:
122+
# do nothing a we expect that new format of plugin values are used
123+
pass
116124

117-
config.substitutions.append( ('%sycl_be', config.sycl_be) )
118125
lit_config.note("Backend: {BACKEND}".format(BACKEND=config.sycl_be))
119126

127+
config.substitutions.append( ('%sycl_be', config.sycl_be) )
128+
config.available_features.add(config.sycl_be)
129+
config.substitutions.append( ('%BE_RUN_PLACEHOLDER', "env SYCL_DEVICE_FILTER={SYCL_PLUGIN} ".format(SYCL_PLUGIN=config.sycl_be)) )
130+
120131
if config.dump_ir_supported:
121132
config.available_features.add('dump_ir')
122133

123-
cuda = False
124-
if ( config.sycl_be == "PI_OPENCL" ):
125-
config.available_features.add('opencl')
126-
elif ( config.sycl_be == "PI_CUDA" ):
127-
config.available_features.add('cuda')
128-
cuda = True
129-
elif ( config.sycl_be == "PI_LEVEL_ZERO" ):
130-
config.available_features.add('level_zero')
131-
else:
134+
if config.sycl_be not in ['host', 'opencl','cuda', 'level_zero']:
132135
lit_config.error("Unknown SYCL BE specified '" +
133136
config.sycl_be +
134-
"' supported values are PI_OPENCL, PI_CUDA, PI_LEVEL_ZERO")
137+
"' supported values are opencl, cuda, level_zero")
135138

136-
esimd_run_substitute = "env SYCL_BE={SYCL_BE} SYCL_DEVICE_TYPE=GPU SYCL_PROGRAM_COMPILE_OPTIONS=-vc-codegen".format(SYCL_BE=config.sycl_be)
139+
esimd_run_substitute = "env SYCL_DEVICE_FILTER={SYCL_PLUGIN}:gpu SYCL_PROGRAM_COMPILE_OPTIONS=-vc-codegen".format(SYCL_PLUGIN=config.sycl_be)
137140
config.substitutions.append( ('%ESIMD_RUN_PLACEHOLDER', esimd_run_substitute) )
138141

139142
config.substitutions.append( ('%clangxx-esimd', config.dpcpp_compiler +
@@ -163,11 +166,11 @@
163166
if 'host' in config.target_devices.split(','):
164167
found_at_least_one_device = True
165168
lit_config.note("Test HOST device")
166-
host_run_substitute = "env SYCL_DEVICE_TYPE=HOST SYCL_BE={SYCL_BE} ".format(SYCL_BE=config.sycl_be)
169+
host_run_substitute = "env SYCL_DEVICE_FILTER={SYCL_PLUGIN}:host ".format(SYCL_PLUGIN=config.sycl_be)
167170
host_check_substitute = "| FileCheck %s"
168171
config.available_features.add('host')
169172
if platform.system() == "Linux":
170-
host_run_on_linux_substitute = "env SYCL_DEVICE_TYPE=HOST SYCL_BE={SYCL_BE} ".format(SYCL_BE=config.sycl_be)
173+
host_run_on_linux_substitute = "env SYCL_DEVICE_FILTER={SYCL_PLUGIN}:host ".format(SYCL_PLUGIN=config.sycl_be)
171174
host_check_on_linux_substitute = "| FileCheck %s"
172175
else:
173176
lit_config.warning("HOST device not used")
@@ -185,11 +188,11 @@
185188
if 'cpu' in config.target_devices.split(','):
186189
found_at_least_one_device = True
187190
lit_config.note("Test CPU device")
188-
cpu_run_substitute = "env SYCL_DEVICE_TYPE=CPU SYCL_BE={SYCL_BE} ".format(SYCL_BE=config.sycl_be)
191+
cpu_run_substitute = "env SYCL_DEVICE_FILTER={SYCL_PLUGIN}:cpu ".format(SYCL_PLUGIN=config.sycl_be)
189192
cpu_check_substitute = "| FileCheck %s"
190193
config.available_features.add('cpu')
191194
if platform.system() == "Linux":
192-
cpu_run_on_linux_substitute = "env SYCL_DEVICE_TYPE=CPU SYCL_BE={SYCL_BE} ".format(SYCL_BE=config.sycl_be)
195+
cpu_run_on_linux_substitute = "env SYCL_DEVICE_FILTER={SYCL_PLUGIN}:cpu ".format(SYCL_PLUGIN=config.sycl_be)
193196
cpu_check_on_linux_substitute = "| FileCheck %s"
194197
else:
195198
lit_config.warning("CPU device not used")
@@ -208,12 +211,12 @@
208211
if 'gpu' in config.target_devices.split(','):
209212
found_at_least_one_device = True
210213
lit_config.note("Test GPU device")
211-
gpu_run_substitute = " env SYCL_DEVICE_TYPE=GPU SYCL_BE={SYCL_BE} ".format(SYCL_BE=config.sycl_be)
214+
gpu_run_substitute = " env SYCL_DEVICE_FILTER={SYCL_PLUGIN}:gpu ".format(SYCL_PLUGIN=config.sycl_be)
212215
gpu_check_substitute = "| FileCheck %s"
213216
config.available_features.add('gpu')
214217

215218
if platform.system() == "Linux":
216-
gpu_run_on_linux_substitute = "env SYCL_DEVICE_TYPE=GPU SYCL_BE={SYCL_BE} ".format(SYCL_BE=config.sycl_be)
219+
gpu_run_on_linux_substitute = "env SYCL_DEVICE_FILTER={SYCL_PLUGIN}:gpu ".format(SYCL_PLUGIN=config.sycl_be)
217220
gpu_check_on_linux_substitute = "| FileCheck %s"
218221

219222
else:
@@ -229,15 +232,15 @@
229232
if 'acc' in config.target_devices.split(','):
230233
found_at_least_one_device = True
231234
lit_config.note("Tests accelerator device")
232-
acc_run_substitute = " env SYCL_DEVICE_TYPE=ACC "
235+
acc_run_substitute = " env SYCL_DEVICE_FILTER={SYCL_PLUGIN}:acc ".format(SYCL_PLUGIN=config.sycl_be)
233236
acc_check_substitute = "| FileCheck %s"
234237
config.available_features.add('accelerator')
235238
else:
236239
lit_config.warning("Accelerator device not used")
237240
config.substitutions.append( ('%ACC_RUN_PLACEHOLDER', acc_run_substitute) )
238241
config.substitutions.append( ('%ACC_CHECK_PLACEHOLDER', acc_check_substitute) )
239242

240-
if cuda:
243+
if config.sycl_be == 'cuda':
241244
config.substitutions.append( ('%sycl_triple', "nvptx64-nvidia-cuda-sycldevice" ) )
242245
else:
243246
config.substitutions.append( ('%sycl_triple', "spir64-unknown-linux-sycldevice" ) )

0 commit comments

Comments
 (0)