Skip to content

Commit 12ade6f

Browse files
authored
[libomptarget][test] Add support for APU testing feature. (llvm#82054)
Add test and support for `// REQUIRES: apu` for the category of tests which exercise APU specific behavior. Note: when running on an actual APU you may have to use the following if the architecture ID is not enough to determine if the underlying device is an APU: ``` IS_APU=1 ninja check-openmp ```
1 parent bb56f05 commit 12ade6f

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

openmp/libomptarget/test/lit.cfg

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ if 'OMP_TARGET_OFFLOAD' in os.environ:
3434
if 'HSA_ENABLE_SDMA' in os.environ:
3535
config.environment['HSA_ENABLE_SDMA'] = os.environ['HSA_ENABLE_SDMA']
3636

37+
# Architectures like gfx942 may or may not be APUs so an additional environment
38+
# variable is required as some tests can be APU specific.
39+
if 'IS_APU' in os.environ:
40+
config.environment['IS_APU'] = os.environ['IS_APU']
41+
3742
# set default environment variables for test
3843
if 'CHECK_OPENMP_ENV' in os.environ:
3944
test_env = os.environ['CHECK_OPENMP_ENV'].split()
@@ -111,6 +116,7 @@ if config.libomptarget_has_libc:
111116
# For CUDA, this is the case with compute capability 70 (Volta) or higher.
112117
# For all other targets, we currently assume it is.
113118
supports_unified_shared_memory = True
119+
supports_apu = False
114120
if config.libomptarget_current_target.startswith('nvptx'):
115121
try:
116122
cuda_arch = int(config.cuda_test_arch[:3])
@@ -126,8 +132,15 @@ elif config.libomptarget_current_target.startswith('amdgcn'):
126132
config.amdgpu_test_arch.startswith("gfx940") or
127133
config.amdgpu_test_arch.startswith("gfx942")):
128134
supports_unified_shared_memory = False
135+
# check if AMD architecture is an APU:
136+
if (config.amdgpu_test_arch.startswith("gfx940") or
137+
(config.amdgpu_test_arch.startswith("gfx942") and
138+
evaluate_bool_env(config.environment['IS_APU']))):
139+
supports_apu = True
129140
if supports_unified_shared_memory:
130141
config.available_features.add('unified_shared_memory')
142+
if supports_apu:
143+
config.available_features.add('apu')
131144

132145
# Setup environment to find dynamic library at runtime
133146
if config.operating_system == 'Windows':
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// clang-format off
2+
// RUN: %libomptarget-compilexx-generic
3+
// RUN: env HSA_XNACK=1 LIBOMPTARGET_INFO=30 %libomptarget-run-generic 2>&1 \
4+
// RUN: | %fcheck-generic -check-prefix=INFO_ZERO -check-prefix=CHECK
5+
6+
// RUN: %libomptarget-compilexx-generic
7+
// RUN: env HSA_XNACK=0 LIBOMPTARGET_INFO=30 %libomptarget-run-generic 2>&1 \
8+
// RUN: | %fcheck-generic -check-prefix=INFO_COPY -check-prefix=CHECK
9+
10+
// UNSUPPORTED: aarch64-unknown-linux-gnu
11+
// UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
12+
// UNSUPPORTED: nvptx64-nvidia-cuda
13+
// UNSUPPORTED: nvptx64-nvidia-cuda-LTO
14+
// UNSUPPORTED: x86_64-pc-linux-gnu
15+
// UNSUPPORTED: x86_64-pc-linux-gnu-LTO
16+
17+
// REQUIRES: apu
18+
19+
// clang-format on
20+
21+
#include <cstdio>
22+
23+
int main() {
24+
int n = 1024;
25+
26+
// test various mapping types
27+
int *a = new int[n];
28+
int k = 3;
29+
int b[n];
30+
31+
for (int i = 0; i < n; i++)
32+
b[i] = i;
33+
34+
// clang-format off
35+
// INFO_ZERO: Return HstPtrBegin 0x{{.*}} Size=4096 for unified shared memory
36+
// INFO_ZERO: Return HstPtrBegin 0x{{.*}} Size=4096 for unified shared memory
37+
38+
// INFO_COPY: Creating new map entry with HstPtrBase=0x{{.*}}, HstPtrBegin=0x{{.*}}, TgtAllocBegin=0x{{.*}}, TgtPtrBegin=0x{{.*}}, Size=4096,
39+
// INFO_COPY: Creating new map entry with HstPtrBase=0x{{.*}}, HstPtrBegin=0x{{.*}}, TgtAllocBegin=0x{{.*}}, TgtPtrBegin=0x{{.*}}, Size=4096,
40+
// INFO_COPY: Mapping exists with HstPtrBegin=0x{{.*}}, TgtPtrBegin=0x{{.*}}, Size=4096, DynRefCount=1 (update suppressed)
41+
// INFO_COPY: Mapping exists with HstPtrBegin=0x{{.*}}, TgtPtrBegin=0x{{.*}}, Size=4096, DynRefCount=1 (update suppressed)
42+
// clang-format on
43+
#pragma omp target teams distribute parallel for map(tofrom : a[ : n]) \
44+
map(to : b[ : n])
45+
for (int i = 0; i < n; i++)
46+
a[i] = i + b[i] + k;
47+
48+
int err = 0;
49+
for (int i = 0; i < n; i++)
50+
if (a[i] != i + b[i] + k)
51+
err++;
52+
53+
// CHECK: PASS
54+
if (err == 0)
55+
printf("PASS\n");
56+
return err;
57+
}

0 commit comments

Comments
 (0)