xref: /llvm-project/offload/test/offloading/target-tile.c (revision 330d8983d25d08580fc1642fea48b2473f47a9da)
1 // Check that omp tile (introduced in OpenMP 5.1) is permitted and behaves when
2 // strictly nested within omp target.
3 
4 // RUN: %libomptarget-compile-generic -fopenmp-version=51
5 // RUN: %libomptarget-run-generic 2>&1 | %fcheck-generic
6 
7 #include <stdio.h>
8 
9 #define I_NTILES 8
10 #define J_NTILES 9
11 #define I_NELEMS 2
12 #define J_NELEMS 3
13 
main()14 int main() {
15   int order[I_NTILES][J_NTILES][I_NELEMS][J_NELEMS];
16   int i, j;
17   #pragma omp target map(tofrom: i, j)
18   {
19     int next = 0;
20     #pragma omp tile sizes(I_NELEMS, J_NELEMS)
21     for (i = 0; i < I_NTILES * I_NELEMS; ++i) {
22       for (j = 0; j < J_NTILES * J_NELEMS; ++j) {
23         int iTile = i / I_NELEMS;
24         int jTile = j / J_NELEMS;
25         int iElem = i % I_NELEMS;
26         int jElem = j % J_NELEMS;
27         order[iTile][jTile][iElem][jElem] = next++;
28       }
29     }
30   }
31   int expected = 0;
32   for (int iTile = 0; iTile < I_NTILES; ++iTile) {
33     for (int jTile = 0; jTile < J_NTILES; ++jTile) {
34       for (int iElem = 0; iElem < I_NELEMS; ++iElem) {
35         for (int jElem = 0; jElem < J_NELEMS; ++jElem) {
36           int actual = order[iTile][jTile][iElem][jElem];
37           if (expected != actual) {
38             printf("error: order[%d][%d][%d][%d] = %d, expected %d\n",
39                    iTile, jTile, iElem, jElem, actual, expected);
40             return 1;
41           }
42           ++expected;
43         }
44       }
45     }
46   }
47   // Tiling leaves the loop variables with their values from the final iteration
48   // rather than with the usual +1.
49   expected = I_NTILES * I_NELEMS - 1;
50   if (i != expected) {
51     printf("error: i = %d, expected %d\n", i, expected);
52     return 1;
53   }
54   expected = J_NTILES * J_NELEMS - 1;
55   if (j != expected) {
56     printf("error: j = %d, expected %d\n", j, expected);
57     return 1;
58   }
59   // CHECK: success
60   printf("success\n");
61   return 0;
62 }
63