| /* Check that offloaded simd collapse(n) loops whose iteration variables are | |
| lastprivate get a SIMT region, and leave the iteration variables with | |
| their values after sequential execution of the nest. The loops here are | |
| not composite; simt-collapse-lastprivate-2.c includes this file with | |
| COMPOSITE defined for the composite form. | |
| The iteration variables are declared outside the nest, so they are | |
| implicitly lastprivate, except in t_int_x, which has an explicit | |
| lastprivate clause. They are declare target variables, not mapped ones, | |
| which simt-collapse-lastprivate-3.c covers. Each nest runs once on the | |
| host into REF and once offloaded into BUF, and the elements visited and | |
| the final values must match. For a nest with no iterations, only that | |
| nothing is visited is checked. */ | |
| /* { dg-do run } */ | |
| /* { dg-additional-options "-O2" } */ | |
| /* { dg-xfail-if "--param=offload-gpu-mode=simt-directed needs the amdgcn SIMT series" { offload_target_amdgcn } } */ | |
| /* { dg-additional-options "--param=offload-gpu-mode=simt-directed" { target offload_target_amdgcn } } */ | |
| /* { dg-additional-options "-foffload-options=-fdump-tree-optimized" { target { offload_target_amdgcn || offload_target_nvptx } } } */ | |
| #include <stdlib.h> | |
| #include <string.h> | |
| #define SZ 20000 | |
| #pragma omp begin declare target | |
| int buf[SZ]; | |
| int n, m, s; | |
| int i, j, k; | |
| unsigned ui, uj; | |
| #pragma omp end declare target | |
| int ref[SZ]; | |
| #define DO_PRAGMA(X) _Pragma (#X) | |
| #ifdef COMPOSITE | |
| #define DIR(...) DO_PRAGMA (omp teams distribute parallel for simd __VA_ARGS__) | |
| #else | |
| #define DIR(...) DO_PRAGMA (omp simd __VA_ARGS__) | |
| #endif | |
| static void | |
| check (long vi, long vj, long ri, long rj, int visits) | |
| { | |
| if (memcmp (buf, ref, sizeof buf) != 0) | |
| abort (); | |
| if (visits && (vi != ri || vj != rj)) | |
| abort (); | |
| } | |
| /* Run the collapse(2) nest IL, JL with iteration variables I and J of type | |
| T, marking element IDX, on the host and offloaded with CLAUSES. */ | |
| #define TEST2(NAME, T, I, J, IL, JL, IDX, ...) \ | |
| static void \ | |
| NAME (void) \ | |
| { \ | |
| int visits = 0; \ | |
| memset (ref, 0, sizeof ref); \ | |
| I = 77, J = 77; \ | |
| for (IL) \ | |
| for (JL) \ | |
| ref[IDX] = 1, visits++; \ | |
| T ri = I, rj = J; \ | |
| memset (buf, 0, sizeof buf); \ | |
| I = 77, J = 77; \ | |
| DO_PRAGMA (omp target update to(buf, n, m, s, I, J)) \ | |
| DO_PRAGMA (omp target) \ | |
| DIR (collapse(2) __VA_ARGS__) \ | |
| for (IL) \ | |
| for (JL) \ | |
| buf[IDX] = 1; \ | |
| DO_PRAGMA (omp target update from(buf, I, J)) \ | |
| check (I, J, ri, rj, visits); \ | |
| } | |
| TEST2 (t_int, int, i, j, i = 0; i < n; i++, j = 0; j < m; j++, i * m + j) | |
| TEST2 (t_int_x, int, i, j, i = 0; i < n; i++, j = 0; j < m; j++, i * m + j, | |
| lastprivate(i, j)) | |
| TEST2 (t_safelen2, int, i, j, i = 0; i < n; i++, j = 0; j < m; j++, | |
| i * m + j, safelen(2)) | |
| TEST2 (t_safelen8, int, i, j, i = 0; i < n; i++, j = 0; j < m; j++, | |
| i * m + j, safelen(8)) | |
| TEST2 (t_step3, int, i, j, i = 0; i < n; i++, j = 0; j < m; j += 3, | |
| i * (m + 1) + j) | |
| TEST2 (t_outer5, int, i, j, i = 5; i < n * 5 + 5; i += 5, j = 0; j < m; j++, | |
| (i - 5) * m + j) | |
| TEST2 (t_down, int, i, j, i = 0; i < n; i++, j = m - 1; j >= 0; j--, | |
| i * m + j) | |
| TEST2 (t_unsigned, unsigned, ui, uj, ui = 0; ui < n; ui++, uj = 0; uj < m; | |
| uj++, ui * m + uj) | |
| /* Steps known only at run time: the final values are computed with a | |
| division by the step. When the nest is not composite, the rows of the | |
| one with a runtime inner step are iterated by an alternate IV. */ | |
| TEST2 (t_rstep, int, i, j, i = 0; i < n; i++, j = 0; j < m; j += s, | |
| i * m + j) | |
| TEST2 (t_outer_rstep, int, i, j, i = 5; i < n * s + 5; i += s, j = 0; j < m; | |
| j++, (i - 5) * m + j) | |
| #if !defined COMPOSITE && !defined SIMD_MODE | |
| /* Not composite, an unsigned innermost variable counting down takes the | |
| one-lane fallback. The composite form is in | |
| simt-collapse-lastprivate-3.c. The simd-mode test defines SIMD_MODE: | |
| in simd mode, this loop faults on GCN, with or without lastprivate, | |
| independently of SIMT. */ | |
| TEST2 (t_udown3, unsigned, ui, uj, ui = 0; ui < n; ui++, uj = m; uj > 2; | |
| uj -= 3, ui * (m + 1) + uj) | |
| #endif | |
| static void | |
| t3 (void) | |
| { | |
| int visits = 0; | |
| memset (ref, 0, sizeof ref); | |
| i = j = k = 77; | |
| for (i = 0; i < n; i++) | |
| for (j = 0; j < m; j++) | |
| for (k = 0; k < 19; k++) | |
| ref[(i * m + j) * 19 + k] = 1, visits++; | |
| int ri = i, rj = j, rk = k; | |
| memset (buf, 0, sizeof buf); | |
| i = j = k = 77; | |
| #pragma omp target update to(buf, n, m, i, j, k) | |
| #pragma omp target | |
| DIR (collapse(3)) | |
| for (i = 0; i < n; i++) | |
| for (j = 0; j < m; j++) | |
| for (k = 0; k < 19; k++) | |
| buf[(i * m + j) * 19 + k] = 1; | |
| #pragma omp target update from(buf, i, j, k) | |
| check (i, j, ri, rj, visits); | |
| if (visits && k != rk) | |
| abort (); | |
| } | |
| int | |
| main (void) | |
| { | |
| static const int nm[][2] = { | |
| { 5, 70 }, { 5, 3 }, { 3, 64 }, { 7, 65 }, { 2, 200 }, { 100, 1 }, | |
| { 1, 1 }, { 2, 3 }, { 0, 10 }, { 10, 0 } | |
| }; | |
| s = 3; | |
| for (unsigned x = 0; x < sizeof nm / sizeof nm[0]; x++) | |
| { | |
| n = nm[x][0], m = nm[x][1]; | |
| t_int (); | |
| t_int_x (); | |
| t_safelen2 (); | |
| t_safelen8 (); | |
| t_step3 (); | |
| t_outer5 (); | |
| t_down (); | |
| t_unsigned (); | |
| t_rstep (); | |
| t_outer_rstep (); | |
| #if !defined COMPOSITE && !defined SIMD_MODE | |
| t_udown3 (); | |
| #endif | |
| t3 (); | |
| } | |
| return 0; | |
| } | |
| /* { dg-final { scan-offload-tree-dump-times "GOMP_SIMT_ENTER" 11 "optimized" { target { offload_target_amdgcn || offload_target_nvptx } } } } */ |