Bump version to 19.1.0-rc3
[llvm-project.git] / offload / test / offloading / target-tile.c
blob8460b43b6f9c798aa0e2da550bd53cdbad6b9702
1 // Check that omp tile (introduced in OpenMP 5.1) is permitted and behaves when
2 // strictly nested within omp target.
4 // RUN: %libomptarget-compile-generic -fopenmp-version=51
5 // RUN: %libomptarget-run-generic 2>&1 | %fcheck-generic
7 #include <stdio.h>
9 #define I_NTILES 8
10 #define J_NTILES 9
11 #define I_NELEMS 2
12 #define J_NELEMS 3
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)
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++;
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;
42 ++expected;
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;
54 expected = J_NTILES * J_NELEMS - 1;
55 if (j != expected) {
56 printf("error: j = %d, expected %d\n", j, expected);
57 return 1;
59 // CHECK: success
60 printf("success\n");
61 return 0;