Skip to content

Commit 4b84e0f

Browse files
authored
[OpenMP] Add test to print interop identifiers (#161434)
The test covers some of the identifier symbols in the interop runtime. This test, for now, is to guard against complete breakage, which was the result of the other `interop.c` test not being enabled on AMD and thus, not caught by our buildbots.
1 parent bd6ed29 commit 4b84e0f

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// RUN: %libomptarget-compile-amdgcn-amd-amdhsa
2+
// RUN: %libomptarget-run-generic 2>&1 | \
3+
// RUN: %fcheck-amdgcn-amd-amdhsa -check-prefixes=AMD
4+
5+
// RUN: %libomptarget-compile-nvptx64-nvidia-cuda
6+
// RUN: %libomptarget-run-generic 2>&1 | \
7+
// RUN: %fcheck-nvptx64-nvidia-cuda -check-prefixes=NVIDIA
8+
9+
// REQUIRES: gpu
10+
// XFAIL: nvptx64-nvidia-cuda
11+
12+
#include <omp.h>
13+
#include <stdio.h>
14+
15+
const char *interop_int_to_string(const int interop_int) {
16+
switch (interop_int) {
17+
case 1:
18+
return "cuda";
19+
case 2:
20+
return "cuda_driver";
21+
case 3:
22+
return "opencl";
23+
case 4:
24+
return "sycl";
25+
case 5:
26+
return "hip";
27+
case 6:
28+
return "level_zero";
29+
case 7:
30+
return "hsa";
31+
default:
32+
return "unknown";
33+
}
34+
}
35+
36+
int main(int argc, char **argv) {
37+
38+
// Loop over all available devices
39+
for (int id = 0; id < omp_get_num_devices(); ++id) {
40+
omp_interop_t iobj = omp_interop_none;
41+
42+
// TODO: Change targetsync to target when AMD toolchain supports it.
43+
#pragma omp interop init(target : iobj) device(id)
44+
45+
int err;
46+
int interop_int = omp_get_interop_int(iobj, omp_ipr_fr_id, &err);
47+
48+
if (err) {
49+
fprintf(stderr, "omp_get_interop_int failed: %d\n", err);
50+
return -1;
51+
}
52+
53+
// AMD: {{.*}} hsa
54+
// NVIDIA: {{.*}} cuda
55+
printf("omp_get_interop_int returned %s\n",
56+
interop_int_to_string(interop_int));
57+
58+
const char *interop_vendor =
59+
omp_get_interop_str(iobj, omp_ipr_vendor_name, &err);
60+
if (err) {
61+
fprintf(stderr, "omp_get_interop_str failed: %d\n", err);
62+
return -1;
63+
}
64+
65+
// AMD: {{.*}} amd
66+
// NVIDIA: {{.*}} nvidia
67+
printf("omp_get_interop_str returned %s\n", interop_vendor);
68+
69+
const char *interop_fr_name =
70+
omp_get_interop_str(iobj, omp_ipr_fr_name, &err);
71+
if (err) {
72+
fprintf(stderr, "omp_get_interop_str failed: %d\n", err);
73+
return -1;
74+
}
75+
76+
// AMD: {{.*}} hsa
77+
// NVIDIA: {{.*}} cuda
78+
printf("omp_get_interop_str returned %s\n", interop_fr_name);
79+
80+
#pragma omp interop destroy(iobj)
81+
}
82+
return 0;
83+
}

0 commit comments

Comments
 (0)