gcc/libgomp/testsuite/libgomp.oacc-c++/ref-1.C
Nathan Sidwell e91eba31fd [nvptx] Fix calls to vector and worker routines
2018-04-20  Nathan Sidwell  <nathan@codesourcery.com>
	    Tom de Vries  <tom@codesourcery.com>

	PR target/85445
	* config/nvptx/nvptx.c (nvptx_emit_forking, nvptx_emit_joining):
	Emit insns for calls too.
	(nvptx_find_par): Always look for worker-level predecessor insn.
	(nvptx_propagate): Add is_call parm, return bool.  Copy frame for
	calls.
	(nvptx_vpropagate, nvptx_wpropagate): Adjust.
	(nvptx_process_pars): Propagate frames for calls.

	* testsuite/libgomp.oacc-c++/ref-1.C: New.

Co-Authored-By: Tom de Vries <tom@codesourcery.com>

From-SVN: r259523
2018-04-20 13:46:07 +00:00

79 lines
1.4 KiB
C

/* { dg-do run } */
#include <stdio.h>
#pragma acc routine vector
void __attribute__((noinline, noclone))
Vector (int *ptr, int n, const int &inc)
{
#pragma acc loop vector
for (unsigned ix = 0; ix < n; ix++)
ptr[ix] += inc;
}
#pragma acc routine worker
void __attribute__((noinline, noclone))
Worker (int *ptr, int m, int n, const int &inc)
{
#pragma acc loop worker
for (unsigned ix = 0; ix < m; ix++)
Vector(ptr + ix * n, n, inc);
}
int
main (void)
{
const int n = 32, m = 32;
int ary[m][n];
unsigned ix, iy;
for (ix = m; ix--;)
for (iy = n; iy--;)
ary[ix][iy] = (ix << 8) + iy;
#pragma acc parallel copy(ary)
{
Worker (&ary[0][0], m, n, 1 << 16);
}
int err = 0;
for (ix = m; ix--;)
for (iy = n; iy--;)
if (ary[ix][iy] != ((1 << 16) + (ix << 8) + iy))
{
printf ("ary[%u][%u] = %x expected %x\n",
ix, iy, ary[ix][iy], ((1 << 16) + (ix << 8) + iy));
err++;
}
if (err)
{
printf ("%d failed\n", err);
return 1;
}
#pragma acc parallel copy(ary)
{
Vector (&ary[0][0], m * n, (1 << 24) - (1 << 16));
}
for (ix = m; ix--;)
for (iy = n; iy--;)
if (ary[ix][iy] != ((1 << 24) + (ix << 8) + iy))
{
printf ("ary[%u][%u] = %x expected %x\n",
ix, iy, ary[ix][iy], ((1 << 24) + (ix << 8) + iy));
err++;
}
if (err)
{
printf ("%d failed\n", err);
return 1;
}
return 0;
}