xref: /llvm-project/offload/test/offloading/ompx_bare.c (revision 92376c3ff5453cb954a614d368fa3d52d6d0fa99)
1 // RUN: %libomptarget-compile-generic
2 // RUN: env LIBOMPTARGET_INFO=63 %libomptarget-run-generic 2>&1 | \
3 // RUN:   %fcheck-generic
4 //
5 // REQUIRES: gpu
6 
7 #include <assert.h>
8 #include <ompx.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 
12 int main(int argc, char *argv[]) {
13   const int num_blocks = 64;
14   const int block_size = 64;
15   const int N = num_blocks * block_size;
16   int *data = (int *)malloc(N * sizeof(int));
17 
18   // CHECK: "PluginInterface" device 0 info: Launching kernel __omp_offloading_{{.*}} with [64,1,1] blocks and [64,1,1] threads in SPMD mode
19 
20 #pragma omp target teams ompx_bare num_teams(num_blocks) thread_limit(block_size) map(from: data[0:N])
21   {
22     int bid = ompx_block_id_x();
23     int bdim = ompx_block_dim_x();
24     int tid = ompx_thread_id_x();
25     int idx = bid * bdim + tid;
26     data[idx] = idx;
27   }
28 
29   for (int i = 0; i < N; ++i)
30     assert(data[i] == i);
31 
32   // CHECK: PASS
33   printf("PASS\n");
34 
35   return 0;
36 }
37