| /* The loops of simt-collapse-lastprivate-1.c with mapped iteration | |
| variables, in both forms, and the composite form of t_udown3. With the | |
| SIMT series, values that the region reads, such as .omp_data_i, through | |
| which the mapped variables are copied out, can be kept in vector | |
| registers that were written before the SIMT region entry, where only one | |
| lane is active. | |
| 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-xfail-run-if "SIMT region reads vector registers written before its entry" { offload_device_gcn } } */ | |
| /* { 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 | |
| int buf[SZ], ref[SZ]; | |
| #define DO_PRAGMA(X) _Pragma (#X) | |
| 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, as | |
| NAME_nc (target simd) and NAME_c (target teams distribute parallel for | |
| simd). */ | |
| #define TEST2_FORM(NAME, DIR, T, IL, JL, IDX, ...) \ | |
| static void \ | |
| NAME (int n, int m) \ | |
| { \ | |
| int visits = 0; \ | |
| T i = 77, j = 77; \ | |
| memset (ref, 0, sizeof ref); \ | |
| 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 map(tofrom: buf, i, j) firstprivate(n, m)) \ | |
| DO_PRAGMA (omp DIR collapse(2) __VA_ARGS__) \ | |
| for (IL) \ | |
| for (JL) \ | |
| buf[IDX] = 1; \ | |
| check (i, j, ri, rj, visits); \ | |
| } | |
| #define TEST2(NAME, T, IL, JL, IDX, ...) \ | |
| TEST2_FORM (NAME##_nc, simd, T, IL, JL, IDX, __VA_ARGS__) \ | |
| TEST2_FORM (NAME##_c, teams distribute parallel for simd, T, IL, JL, \ | |
| IDX, __VA_ARGS__) | |
| TEST2 (t_int, int, i = 0; i < n; i++, j = 0; j < m; j++, i * m + j) | |
| TEST2 (t_int_x, int, i = 0; i < n; i++, j = 0; j < m; j++, i * m + j, | |
| lastprivate(i, j)) | |
| TEST2 (t_safelen2, int, i = 0; i < n; i++, j = 0; j < m; j++, i * m + j, | |
| safelen(2)) | |
| TEST2 (t_safelen8, int, i = 0; i < n; i++, j = 0; j < m; j++, i * m + j, | |
| safelen(8)) | |
| TEST2 (t_step3, int, i = 0; i < n; i++, j = 0; j < m; j += 3, | |
| i * (m + 1) + j) | |
| TEST2 (t_outer5, int, i = 5; i < n * 5 + 5; i += 5, j = 0; j < m; j++, | |
| (i - 5) * m + j) | |
| TEST2 (t_down, int, i = 0; i < n; i++, j = m - 1; j >= 0; j--, i * m + j) | |
| TEST2 (t_unsigned, unsigned, i = 0; i < n; i++, j = 0; j < m; j++, | |
| i * m + j) | |
| /* Not composite, an unsigned innermost variable counting down takes the | |
| one-lane fallback. The simd-mode test defines SIMD_MODE: in simd mode, | |
| the non-composite loop faults on GCN, with or without lastprivate, | |
| independently of SIMT. */ | |
| TEST2 (t_udown3, unsigned, i = 0; i < n; i++, j = m; j > 2; j -= 3, | |
| i * (m + 1) + j) | |
| #define TEST3(NAME, DIR) \ | |
| static void \ | |
| NAME (int n, int m) \ | |
| { \ | |
| int visits = 0; \ | |
| int i = 77, j = 77, k = 77; \ | |
| memset (ref, 0, sizeof ref); \ | |
| 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 = 77, j = 77, k = 77; \ | |
| DO_PRAGMA (omp target map(tofrom: buf, i, j, k) firstprivate(n, m)) \ | |
| DO_PRAGMA (omp 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; \ | |
| check (i, j, ri, rj, visits); \ | |
| if (visits && k != rk) \ | |
| abort (); \ | |
| } | |
| TEST3 (t3_nc, simd) | |
| TEST3 (t3_c, teams distribute parallel for simd) | |
| 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 } | |
| }; | |
| for (unsigned x = 0; x < sizeof nm / sizeof nm[0]; x++) | |
| { | |
| int n = nm[x][0], m = nm[x][1]; | |
| t_int_nc (n, m); | |
| t_int_c (n, m); | |
| t_int_x_nc (n, m); | |
| t_int_x_c (n, m); | |
| t_safelen2_nc (n, m); | |
| t_safelen2_c (n, m); | |
| t_safelen8_nc (n, m); | |
| t_safelen8_c (n, m); | |
| t_step3_nc (n, m); | |
| t_step3_c (n, m); | |
| t_outer5_nc (n, m); | |
| t_outer5_c (n, m); | |
| t_down_nc (n, m); | |
| t_down_c (n, m); | |
| t_unsigned_nc (n, m); | |
| t_unsigned_c (n, m); | |
| #ifndef SIMD_MODE | |
| t_udown3_nc (n, m); | |
| #endif | |
| t_udown3_c (n, m); | |
| t3_nc (n, m); | |
| t3_c (n, m); | |
| } | |
| return 0; | |
| } | |
| /* { dg-final { scan-offload-tree-dump-times "GOMP_SIMT_ENTER" 19 "optimized" { target { offload_target_amdgcn || offload_target_nvptx } } } } */ |