LLVM OpenMP 22.0.0git
omp_device_uid.c
Go to the documentation of this file.
1// RUN: %libomp-compile-and-run 2>&1 | FileCheck %s
2// Linking fails for icc 18
3// UNSUPPORTED: icc-18
4
5#include <omp_testsuite.h>
6#include <string.h>
7
8int test_omp_device_uid(int device_num) {
9 const char *device_uid = omp_get_uid_from_device(device_num);
10 if (device_uid == NULL) {
11 printf("FAIL for device %d: omp_get_uid_from_device returned NULL\n",
12 device_num);
13 return 0;
14 }
15
16 int device_num_from_uid = omp_get_device_from_uid(device_uid);
17 if (device_num_from_uid != device_num) {
18 printf(
19 "FAIL for device %d: omp_get_device_from_uid returned %d (UID: %s)\n",
20 device_num, device_num_from_uid, device_uid);
21 return 0;
22 }
23
24 if (device_num == omp_get_initial_device())
25 return 1;
26
27 int success = 1;
28
29// Note that the following code may be executed on the host if the host is the
30// device
31#pragma omp target map(tofrom : success) device(device_num)
32 {
33 int device_num = omp_get_device_num();
34
35 // omp_get_uid_from_device() in the device runtime is a dummy function
36 // returning NULL
37 const char *device_uid = omp_get_uid_from_device(device_num);
38
39 // omp_get_device_from_uid() in the device runtime is a dummy function
40 // returning omp_invalid_device.
41 int device_num_from_uid = omp_get_device_from_uid(device_uid);
42
43 // Depending on whether we're executing on the device or the host, we either
44 // got NULL as the device UID or the correct device UID. Consequently,
45 // omp_get_device_from_uid() either returned omp_invalid_device or the
46 // correct device number (aka omp_get_initial_device()).
47 if (device_uid ? device_num_from_uid != device_num
48 : device_num_from_uid != omp_invalid_device) {
49 printf("FAIL for device %d (target): omp_get_device_from_uid returned %d "
50 "(UID: %s)\n",
51 device_num, device_num_from_uid, device_uid);
52 success = 0;
53 }
54 }
55
56 return success;
57}
58
59int main() {
60 int num_devices = omp_get_num_devices();
61 int num_failed = 0;
62 // (also test initial device aka num_devices)
63 for (int i = 0; i < num_devices + 1; i++) {
64 if (!test_omp_device_uid(i)) {
65 printf("FAIL for device %d\n", i);
66 num_failed++;
67 }
68 }
69 if (num_failed) {
70 printf("FAIL\n");
71 return 1;
72 }
73 printf("PASS\n");
74 return 0;
75}
76
77// CHECK: PASS
int omp_get_num_devices(void)
#define i
Definition kmp_stub.cpp:87
int test_omp_device_uid(int device_num)
int main()
int omp_get_initial_device(void)