1 // Check that specifying device as omp_get_initial_device():
2 // - Doesn't cause the runtime to fail.
3 // - Offloads code to the host.
4 // - Doesn't transfer data. In this case, just check that neither host data nor
5 // default device data are affected by the specified transfers.
6 // - Works whether it's specified directly or as the default device.
8 // RUN: %libomptarget-compile-run-and-check-generic
13 static void check(char *X
, int Dev
) {
14 printf(" host X = %c\n", *X
);
16 #pragma omp target device(Dev) map(from : DV)
18 printf("device X = %c\n", DV
);
21 #define CHECK_DATA() check(&X, DevDefault)
24 int DevDefault
= omp_get_default_device();
25 int DevInit
= omp_get_initial_device();
27 //--------------------------------------------------
28 // Initialize data on the host and default device.
29 //--------------------------------------------------
32 // CHECK-NEXT: device X = d
34 #pragma omp target enter data map(to : X)
38 //--------------------------------------------------
39 // Check behavior when specifying host directly.
40 //--------------------------------------------------
42 // CHECK-NEXT: omp_is_initial_device() = 1
43 // CHECK-NEXT: host X = h
44 // CHECK-NEXT: device X = d
45 #pragma omp target device(DevInit) map(always, tofrom : X)
46 printf("omp_is_initial_device() = %d\n", omp_is_initial_device());
49 // CHECK-NEXT: omp_is_initial_device() = 1
50 // CHECK-NEXT: host X = h
51 // CHECK-NEXT: device X = d
52 #pragma omp target teams device(DevInit) num_teams(1) map(always, tofrom : X)
53 printf("omp_is_initial_device() = %d\n", omp_is_initial_device());
56 // Check that __kmpc_push_target_tripcount_mapper doesn't fail. I'm not sure
57 // how to check that it actually pushes to the initial device.
58 #pragma omp target teams device(DevInit) num_teams(1)
59 #pragma omp distribute
60 for (int i
= 0; i
< 2; ++i
)
63 // CHECK-NEXT: host X = h
64 // CHECK-NEXT: device X = d
65 #pragma omp target data device(DevInit) map(always, tofrom : X)
69 // CHECK-NEXT: host X = h
70 // CHECK-NEXT: device X = d
71 #pragma omp target enter data device(DevInit) map(always, to : X)
75 // CHECK-NEXT: host X = h
76 // CHECK-NEXT: device X = d
77 #pragma omp target exit data device(DevInit) map(always, from : X)
81 // CHECK-NEXT: host X = h
82 // CHECK-NEXT: device X = d
83 #pragma omp target update device(DevInit) to(X)
87 // CHECK-NEXT: host X = h
88 // CHECK-NEXT: device X = d
89 #pragma omp target update device(DevInit) from(X)
93 //--------------------------------------------------
94 // Check behavior when device defaults to host.
95 //--------------------------------------------------
97 omp_set_default_device(DevInit
);
99 // CHECK-NEXT: omp_is_initial_device() = 1
100 // CHECK-NEXT: host X = h
101 // CHECK-NEXT: device X = d
102 #pragma omp target map(always, tofrom : X)
103 printf("omp_is_initial_device() = %d\n", omp_is_initial_device());
106 // CHECK-NEXT: omp_is_initial_device() = 1
107 // CHECK-NEXT: host X = h
108 // CHECK-NEXT: device X = d
109 #pragma omp target teams num_teams(1) map(always, tofrom : X)
110 printf("omp_is_initial_device() = %d\n", omp_is_initial_device());
113 // Check that __kmpc_push_target_tripcount_mapper doesn't fail. I'm not sure
114 // how to check that it actually pushes to the initial device.
115 #pragma omp target teams num_teams(1)
116 #pragma omp distribute
117 for (int i
= 0; i
< 2; ++i
)
120 // CHECK-NEXT: host X = h
121 // CHECK-NEXT: device X = d
122 #pragma omp target data map(always, tofrom : X)
126 // CHECK-NEXT: host X = h
127 // CHECK-NEXT: device X = d
128 #pragma omp target enter data map(always, to : X)
132 // CHECK-NEXT: host X = h
133 // CHECK-NEXT: device X = d
134 #pragma omp target exit data map(always, from : X)
138 // CHECK-NEXT: host X = h
139 // CHECK-NEXT: device X = d
140 #pragma omp target update to(X)
144 // CHECK-NEXT: host X = h
145 // CHECK-NEXT: device X = d
146 #pragma omp target update from(X)