(root)/
gcc-13.2.0/
libgomp/
testsuite/
libgomp.oacc-c-c++-common/
routine-w-1.c
       1  /* { dg-additional-options "-Wopenacc-parallelism" } for testing/documenting
       2     aspects of that functionality.  */
       3  
       4  #include <stdio.h>
       5  #include <openacc.h>
       6  #include <gomp-constants.h>
       7  
       8  #define N (32*32*32+17)
       9  
      10  #pragma acc routine worker
      11  void __attribute__ ((noinline)) worker (int ary[N])
      12  /* { dg-warning "region is vector partitioned but does not contain vector partitioned code" "" { target *-*-* } .-1 } */
      13  {
      14  #pragma acc loop worker
      15    for (unsigned ix = 0; ix < N; ix++)
      16      {
      17        if (acc_on_device (acc_device_not_host))
      18  	{
      19  	  int g, w, v;
      20  
      21  	  g = __builtin_goacc_parlevel_id (GOMP_DIM_GANG);
      22  	  w = __builtin_goacc_parlevel_id (GOMP_DIM_WORKER);
      23  	  v = __builtin_goacc_parlevel_id (GOMP_DIM_VECTOR);
      24  	  ary[ix] = (g << 16) | (w << 8) | v;
      25  	}
      26        else
      27  	ary[ix] = ix;
      28      }
      29  }
      30  
      31  int main ()
      32  {
      33    int ary[N];
      34    int ix;
      35    int exit = 0;
      36    int ondev = 0;
      37    int workersize;
      38  
      39    for (ix = 0; ix < N;ix++)
      40      ary[ix] = -1;
      41    
      42  #define NW 32
      43  #define VL 32
      44  #pragma acc parallel num_workers(NW) vector_length(VL) \
      45  	    copy(ary) copy(ondev)
      46    {
      47      ondev = acc_on_device (acc_device_not_host);
      48      worker (ary);
      49    }
      50    workersize = NW;
      51  #ifdef ACC_DEVICE_TYPE_radeon
      52    /* AMD GCN has an upper limit of 'num_workers(16)'.  */
      53    if (workersize > 16)
      54      workersize = 16;
      55  #endif
      56  
      57    for (ix = 0; ix < N; ix++)
      58      {
      59        int expected = ix;
      60        if(ondev)
      61  	{
      62  	  int g = 0;
      63  	  int w = ix % workersize;
      64  	  int v = 0;
      65  
      66  	  expected = (g << 16) | (w << 8) | v;
      67  	}
      68        
      69        if (ary[ix] != expected)
      70  	{
      71  	  exit = 1;
      72  	  printf ("ary[%d]=%x expected %x\n", ix, ary[ix], expected);
      73  	}
      74      }
      75    
      76    return exit;
      77  }