| /* Offloaded composite simd collapse(2) loop with runtime bounds and more | |
| iterations than threads, so that thread shares span rows. With the SIMT | |
| series, a runtime bound can be kept in a vector register that was written | |
| before the SIMT region entry, where only one lane is active, and then be | |
| read inside the region, collapsed or not. | |
| The loop declares its iteration variables in the for-init, so that they | |
| are private, not implicitly lastprivate. The result array has guard | |
| elements on both sides, which catch writes outside the iteration space. */ | |
| /* { 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> | |
| #define PAD 256 | |
| #define MAXN 8192 | |
| int buf[MAXN + 2 * PAD]; | |
| static void | |
| clear (void) | |
| { | |
| for (int x = 0; x < MAXN + 2 * PAD; x++) | |
| buf[x] = -1; | |
| } | |
| /* BUF[PAD + I] must be I * 7 + 3 for the I in [0, N), and -1 elsewhere. */ | |
| static void | |
| check (int n) | |
| { | |
| for (int x = 0; x < MAXN + 2 * PAD; x++) | |
| { | |
| int i = x - PAD; | |
| int want = (i >= 0 && i < n) ? i * 7 + 3 : -1; | |
| if (buf[x] != want) | |
| abort (); | |
| } | |
| } | |
| static void | |
| c2_gen (int n, int m) | |
| { | |
| #pragma omp target teams distribute parallel for simd collapse(2) \ | |
| map(tofrom: buf) firstprivate(n, m) | |
| for (int i = 0; i < n; i++) | |
| for (int j = 0; j < m; j++) | |
| buf[PAD + i * m + j] = (i * m + j) * 7 + 3; | |
| check (n * m); | |
| } | |
| #define RUN(F) do { clear (); F; } while (0) | |
| int | |
| main (void) | |
| { | |
| RUN (c2_gen (31, 71)); | |
| RUN (c2_gen (64, 64)); | |
| return 0; | |
| } | |
| /* { dg-final { scan-offload-tree-dump "GOMP_SIMT_ENTER" "optimized" { target { offload_target_amdgcn || offload_target_nvptx } } } } */ |