blob: b5b5f49e9a16362a3c91ce00f4fe08fd5bd2695d [file]
/* Check an offloaded composite simd collapse(2) loop with a third loop that
is not collapsed and whose trip count depends on the inner collapsed
variable: row (I, J) has J + 1 elements. Each lane runs the third loop
in full. The row offsets use shifts, because a division would take the
one-lane fallback.
With the SIMT series, the loop hangs on the GPU when N > 1, even with
M = 1. It passes with the row size (M * (M + 1)) >> 1 computed on the
host, with the same body under collapse(1), without the third loop, and
with a third loop of fixed trip count. */
/* { dg-do run } */
/* { dg-xfail-run-if "SIMT loop with a non-collapsed inner loop hangs" { 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];
/* 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_inner_tri (int n, int m)
{
for (int x = 0; x < MAXN + 2 * PAD; x++)
buf[x] = -1;
#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++)
for (int k = 0; k <= j; k++)
{
int x = i * ((m * (m + 1)) >> 1) + ((j * (j + 1)) >> 1) + k;
buf[PAD + x] = x * 7 + 3;
}
check (n * ((m * (m + 1)) >> 1));
}
int
main (void)
{
c2_inner_tri (7, 40);
c2_inner_tri (37, 5);
c2_inner_tri (2, 90);
c2_inner_tri (11, 1);
c2_inner_tri (1, 40);
return 0;
}
/* { dg-final { scan-offload-tree-dump "GOMP_SIMT_ENTER" "optimized" { target { offload_target_amdgcn || offload_target_nvptx } } } } */