xref: /llvm-project/offload/test/api/ompx_3d.cpp (revision 330d8983d25d08580fc1642fea48b2473f47a9da)
1 // RUN: %libomptarget-compilexx-run-and-check-generic
2 
3 #include <omp.h>
4 #include <ompx.h>
5 #include <stdio.h>
6 
foo(int device)7 void foo(int device) {
8   int tid = 0, bid = 0, bdim = 0;
9 #pragma omp target teams distribute parallel for map(from                      \
10                                                      : tid, bid, bdim)         \
11     device(device) thread_limit(2) num_teams(5)
12   for (int i = 0; i < 1000; ++i) {
13     if (i == 42) {
14       tid = ompx::block_dim_x();
15       bid = ompx::block_id_x();
16       bdim = ompx::grid_dim_x();
17     }
18   }
19   // CHECK: tid: 2, bid: 1, bdim: 5
20   // CHECK: tid: 2, bid: 0, bdim: 1
21   printf("tid: %i, bid: %i, bdim: %i\n", tid, bid, bdim);
22 }
23 
isGPU()24 int isGPU() { return 0; }
25 #pragma omp declare variant(isGPU) match(device = {kind(gpu)})
isGPUvariant()26 int isGPUvariant() { return 1; }
27 
defaultIsGPU()28 int defaultIsGPU() {
29   int r = 0;
30 #pragma omp target map(from : r)
31   r = isGPU();
32   return r;
33 }
34 
main()35 int main() {
36   if (defaultIsGPU())
37     foo(omp_get_default_device());
38   else
39     printf("tid: 2, bid: 1, bdim: 5\n");
40   foo(omp_get_initial_device());
41 }
42