Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 73aeb2a

Browse files
authored
[SCYL][ROCM] Support for ROCm backend (#348)
* ROCm flags added to test suite, readme updated with docs, basic test update
1 parent 40171d0 commit 73aeb2a

File tree

6 files changed

+75
-12
lines changed

6 files changed

+75
-12
lines changed

SYCL/FilterSelector/select.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ int main() {
3939
bool HasLevelZeroDevices = false;
4040
bool HasOpenCLDevices = false;
4141
bool HasCUDADevices = false;
42+
bool HasROCmDevices = false;
4243
bool HasOpenCLGPU = false;
4344
bool HasLevelZeroGPU = false;
4445

@@ -50,6 +51,8 @@ int main() {
5051
HasOpenCLDevices = true;
5152
} else if (Backend == backend::cuda) {
5253
HasCUDADevices = true;
54+
} else if (Backend == backend::rocm) {
55+
HasROCmDevices = true;
5356
}
5457
}
5558

@@ -64,6 +67,7 @@ int main() {
6467
std::cout << "HasLevelZeroDevices = " << HasLevelZeroDevices << std::endl;
6568
std::cout << "HasOpenCLDevices = " << HasOpenCLDevices << std::endl;
6669
std::cout << "HasCUDADevices = " << HasCUDADevices << std::endl;
70+
std::cout << "HasROCmDevices = " << HasROCmDevices << std::endl;
6771
std::cout << "HasOpenCLGPU = " << HasOpenCLGPU << std::endl;
6872
std::cout << "HasLevelZeroGPU = " << HasLevelZeroGPU << std::endl;
6973

@@ -198,5 +202,17 @@ int main() {
198202
std::cout << "...PASS" << std::endl;
199203
}
200204

205+
if (HasROCmDevices) {
206+
std::cout << "Test 'rocm'";
207+
device d19(ONEAPI::filter_selector("rocm"));
208+
assert(d19.get_platform().get_backend() == backend::rocm);
209+
std::cout << "...PASS" << std::endl;
210+
211+
std::cout << "test 'rocm:gpu'";
212+
device d20(ONEAPI::filter_selector("rocm:gpu"));
213+
assert(d20.is_gpu() && d19.get_platform().get_backend() == backend::rocm);
214+
std::cout << "...PASS" << std::endl;
215+
}
216+
201217
return 0;
202218
}

SYCL/Plugin/sycl-ls-gpu-rocm.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// REQUIRES: gpu, rocm, sycl-ls
2+
3+
// RUN: env SYCL_DEVICE_FILTER=rocm sycl-ls --verbose >%t.rocm.out
4+
// RUN: FileCheck %s --check-prefixes=CHECK-BUILTIN-GPU-ROCM,CHECK-CUSTOM-GPU-ROCM --input-file %t.rocm.out
5+
6+
// CHECK-BUILTIN-GPU-ROCM: gpu_selector(){{.*}}GPU :{{.*}}ROCM
7+
// CHECK-CUSTOM-GPU-ROCM: custom_selector(gpu){{.*}}GPU :{{.*}}ROCM
8+
9+
//==---- sycl-ls-gpu-rocm.cpp - SYCL test for discovered/selected devices --==//
10+
//
11+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
12+
// See https://llvm.org/LICENSE.txt for license information.
13+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14+
//
15+
//===----------------------------------------------------------------------===//

SYCL/Plugin/sycl-ls-gpu-sycl-be.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// REQUIRES: gpu, cuda, opencl
1+
// REQUIRES: gpu, cuda, rocm, opencl, sycl-ls
22

33
// RUN: sycl-ls --verbose >%t.default.out
44
// RUN: FileCheck %s --check-prefixes=CHECK-BUILTIN-GPU-OPENCL,CHECK-CUSTOM-GPU-OPENCL --input-file %t.default.out
@@ -15,6 +15,12 @@
1515
// CHECK-BUILTIN-GPU-CUDA: gpu_selector(){{.*}}GPU : CUDA
1616
// CHECK-CUSTOM-GPU-CUDA: custom_selector(gpu){{.*}}GPU : CUDA
1717

18+
// RUN: env SYCL_DEVICE_FILTER=rocm sycl-ls --verbose >%t.rocm.out
19+
// RUN: FileCheck %s --check-prefixes=CHECK-BUILTIN-GPU-ROCM,CHECK-CUSTOM-GPU-ROCM --input-file %t.rocm.out
20+
21+
// CHECK-BUILTIN-GPU-ROCM: gpu_selector(){{.*}}GPU : ROCm
22+
// CHECK-CUSTOM-GPU-ROCM: custom_selector(gpu){{.*}}GPU : ROCm
23+
1824
//==---- sycl-ls-gpu-sycl-be.cpp - SYCL test for discovered/selected devices
1925
//--==//
2026
//

SYCL/README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,19 @@ list of configurations. Each configuration includes backend separated
8181
from comma-separated list of target devices with colon. Example:
8282

8383
```
84-
-DCHECK_SYCL_ALL="opencl:cpu,host;level_zero:gpu,host;cuda:gpu"
84+
-DCHECK_SYCL_ALL="opencl:cpu,host;level_zero:gpu,host;cuda:gpu;rocm:gpu"
8585
```
8686

8787
***SYCL_BE*** SYCL backend to be used for testing. Supported values are:
8888
- **opencl** - for OpenCL backend;
8989
- **cuda** - for CUDA backend;
90+
- **rocm** - for ROCm backend;
9091
- **level_zero** - Level Zero backend.
9192

9293
***SYCL_TARGET_DEVICES*** comma separated list of target devices for testing.
9394
Default value is cpu,gpu,acc,host. Supported values are:
9495
- **cpu** - CPU device available in OpenCL backend only;
95-
- **gpu** - GPU device available in OpenCL, Level Zero and CUDA backends;
96+
- **gpu** - GPU device available in OpenCL, Level Zero, CUDA, and ROCm backends;
9697
- **acc** - FPGA emulator device available in OpenCL backend only;
9798
- **host** - SYCL Host device available with all backends.
9899

@@ -105,6 +106,15 @@ specified by this variable.
105106

106107
***LEVEL_ZERO_LIBS_DIR*** path to Level Zero libraries.
107108

109+
***ROCM_PLATFORM*** platform selection for ROCm targeted devices.
110+
Defaults to AMD if no value is given. Supported values are:
111+
- **AMD** - for ROCm to target AMD GPUs
112+
- **NVIDIA** - for ROCm to target NVIDIA GPUs
113+
114+
***MCPU*** Flag must be set for when using ROCm triple.
115+
For example it may be set to "gfx906".
116+
117+
108118
# Special test categories
109119

110120
There are two special directories for extended testing. See documentation at:
@@ -124,7 +134,7 @@ unavailable.
124134

125135
* **windows**, **linux** - host OS;
126136
* **cpu**, **gpu**, **host**, **accelerator** - target device;
127-
* **cuda**, **opencl**, **level_zero** - target backend;
137+
* **cuda**, **rocm**, **opencl**, **level_zero** - target backend;
128138
* **sycl-ls** - sycl-ls tool availability;
129139
* **cl_options** - CL command line options recognized (or not) by compiler;
130140
* **opencl_icd** - OpenCL ICD loader availability;
@@ -142,7 +152,7 @@ configure specific single test execution in the command line:
142152
* **dpcpp_compiler** - full path to dpcpp compiler;
143153
* **target_device** - comma-separated list of target devices (cpu, gpu, acc,
144154
host);
145-
* **sycl_be** - SYCL backend to be used (opencl, level_zero, cuda);
155+
* **sycl_be** - SYCL backend to be used (opencl, level_zero, cuda, rocm);
146156
* **dump_ir** - if IR dumping is supported for compiler (True, False);
147157
* **gpu-intel-dg1** - tells LIT infra that Intel GPU DG1 is present in the
148158
system. It is developer / CI infra responsibility to make sure that the

SYCL/lit.cfg.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@
154154
# Mapping from SYCL_BE backend definition style to SYCL_DEVICE_FILTER used
155155
# for backward compatibility
156156
try:
157-
config.sycl_be = { 'PI_OPENCL': 'opencl', 'PI_CUDA': 'cuda', 'PI_LEVEL_ZERO': 'level_zero'}[config.sycl_be]
157+
config.sycl_be = { 'PI_OPENCL': 'opencl', 'PI_CUDA': 'cuda', 'PI_ROCM': 'rocm', 'PI_LEVEL_ZERO': 'level_zero'}[config.sycl_be]
158158
except:
159159
# do nothing a we expect that new format of plugin values are used
160160
pass
@@ -168,12 +168,24 @@
168168
if config.dump_ir_supported:
169169
config.available_features.add('dump_ir')
170170

171-
if config.sycl_be not in ['host', 'opencl','cuda', 'level_zero']:
172-
lit_config.error("Unknown SYCL BE specified '" +
173-
config.sycl_be +
174-
"' supported values are opencl, cuda, level_zero")
171+
if config.sycl_be not in ['host', 'opencl', 'cuda', 'rocm', 'level_zero']:
172+
lit_config.error("Unknown SYCL BE specified '" +
173+
config.sycl_be +
174+
"' supported values are opencl, cuda, rocm, level_zero")
175175

176-
config.substitutions.append( ('%clangxx', ' '+ config.dpcpp_compiler + ' ' + config.cxx_flags ) )
176+
# If ROCM_PLATFORM flag is not set, default to AMD, and check if ROCM platform is supported
177+
supported_rocm_platforms=["AMD", "NVIDIA"]
178+
if config.rocm_platform == "":
179+
config.rocm_platform = "AMD"
180+
if config.rocm_platform not in supported_rocm_platforms:
181+
lit_config.error("Unknown ROCm platform '" + config.rocm_platform + "' supported platforms are " + ', '.join(supported_rocm_platforms))
182+
183+
if config.sycl_be == "rocm" and config.rocm_platform == "AMD":
184+
mcpu_flag = '-mcpu=' + config.mcpu
185+
else:
186+
mcpu_flag = ""
187+
188+
config.substitutions.append( ('%clangxx', ' '+ config.dpcpp_compiler + ' ' + config.cxx_flags + ' ' + mcpu_flag) )
177189
config.substitutions.append( ('%clang', ' ' + config.dpcpp_compiler + ' ' + config.c_flags ) )
178190
config.substitutions.append( ('%threads_lib', config.sycl_threads_lib) )
179191

@@ -275,8 +287,10 @@
275287
config.substitutions.append( ('%ACC_RUN_PLACEHOLDER', acc_run_substitute) )
276288
config.substitutions.append( ('%ACC_CHECK_PLACEHOLDER', acc_check_substitute) )
277289

278-
if config.sycl_be == 'cuda':
290+
if config.sycl_be == 'cuda' or (config.sycl_be == 'rocm' and config.rocm_platform == 'NVIDIA'):
279291
config.substitutions.append( ('%sycl_triple', "nvptx64-nvidia-cuda-sycldevice" ) )
292+
elif config.sycl_be == 'rocm' and config.rocm_platform == 'AMD':
293+
config.substitutions.append( ('%sycl_triple', "amdgcn-amd-amdhsa-sycldevice" ) )
280294
else:
281295
config.substitutions.append( ('%sycl_triple', "spir64-unknown-unknown-sycldevice" ) )
282296

SYCL/lit.site.cfg.py.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ config.level_zero_include = "@LEVEL_ZERO_INCLUDE@"
2222
config.opencl_include_dir = os.path.join(config.sycl_include, 'sycl')
2323
config.target_devices = lit_config.params.get("target_devices", "@SYCL_TARGET_DEVICES@")
2424
config.sycl_be = lit_config.params.get("sycl_be", "@SYCL_BE@")
25+
config.rocm_platform = "@ROCM_PLATFORM@"
26+
config.mcpu = "@MCPU@"
2527
config.sycl_threads_lib = '@SYCL_THREADS_LIB@'
2628
config.extra_environment = lit_config.params.get("extra_environment", "@LIT_EXTRA_ENVIRONMENT@")
2729
config.cxx_flags = "@CMAKE_CXX_FLAGS@"

0 commit comments

Comments
 (0)