(root)/
gcc-13.2.0/
libgomp/
testsuite/
libgomp.oacc-c-c++-common/
kernels-private-vars-loop-vector-1.c
       1  /* Test of vector-private variables declared on loop directive.  */
       2  
       3  /* { dg-additional-options "--param=openacc-kernels=decompose" } */
       4  
       5  /* { dg-additional-options "-fopt-info-omp-all" }
       6     { dg-additional-options "-foffload=-fopt-info-omp-all" } */
       7  
       8  /* { dg-additional-options "--param=openacc-privatization=noisy" }
       9     { dg-additional-options "-foffload=--param=openacc-privatization=noisy" }
      10     Prune a few: uninteresting:
      11     { dg-prune-output {note: variable 'D\.[0-9]+' declared in block isn't candidate for adjusting OpenACC privatization level: not addressable} } */
      12  
      13  /* It's only with Tcl 8.5 (released in 2007) that "the variable 'varName'
      14     passed to 'incr' may be unset, and in that case, it will be set to [...]",
      15     so to maintain compatibility with earlier Tcl releases, we manually
      16     initialize counter variables:
      17     { dg-line l_dummy[variable c_compute 0 c_loop_i 0 c_loop_j 0 c_loop_k 0] }
      18     { dg-message "dummy" "" { target iN-VAl-Id } l_dummy } to avoid
      19     "WARNING: dg-line var l_dummy defined, but not used".  */
      20  
      21  #include <assert.h>
      22  
      23  int
      24  main (int argc, char* argv[])
      25  {
      26    int x, i, arr[32 * 32 * 32];
      27  
      28    for (i = 0; i < 32 * 32 * 32; i++)
      29      arr[i] = i;
      30  
      31    #pragma acc kernels copy(arr) /* { dg-line l_compute[incr c_compute] } */
      32    /* [PR104784] For some reason, for C++, the OpenACC 'kernels' decomposition
      33       decides that a data region is needed for 'j', and subsequently requests it
      34       to be made addressable.
      35       { dg-note {OpenACC 'kernels' decomposition: variable 'j' declared in block requested to be made addressable} {} { target c++ } l_compute$c_compute }
      36       { dg-note {variable 'j' made addressable} {} { target c++ } l_compute$c_compute }
      37       { dg-note {variable 'j' declared in block is candidate for adjusting OpenACC privatization level} {} { target c++ } l_compute$c_compute } */
      38    {
      39      int j;
      40  
      41      /* { dg-note {forwarded loop nest in OpenACC 'kernels' region to 'parloops' for analysis} {} { target *-*-* } .+1 } */
      42      #pragma acc loop gang(num:32) /* { dg-line l_loop_i[incr c_loop_i] } */
      43      /* { dg-note {variable 'j' declared in block isn't candidate for adjusting OpenACC privatization level: not addressable} {} { target c } l_loop_i$c_loop_i } */
      44      /* { dg-note {variable 'i' in 'private' clause isn't candidate for adjusting OpenACC privatization level: not addressable} {} { target *-*-* } l_loop_i$c_loop_i } */
      45      for (i = 0; i < 32; i++)
      46        {
      47          #pragma acc loop worker(num:32) /* { dg-line l_loop_j[incr c_loop_j] } */
      48  	/* { dg-note {variable 'j' in 'private' clause isn't candidate for adjusting OpenACC privatization level: not addressable} {} { target *-*-* } l_loop_j$c_loop_j } */
      49  	/* { dg-note {variable 'k' declared in block isn't candidate for adjusting OpenACC privatization level: not addressable} {} { target *-*-* } l_loop_j$c_loop_j } */
      50  	for (j = 0; j < 32; j++)
      51  	  {
      52  	    int k;
      53  
      54  	    #pragma acc loop vector(length:32) private(x) /* { dg-line l_loop_k[incr c_loop_k] } */
      55  	    /* { dg-note {variable 'k' in 'private' clause isn't candidate for adjusting OpenACC privatization level: not addressable} {} { target *-*-* } l_loop_k$c_loop_k } */
      56  	    /* { dg-note {variable 'x' in 'private' clause isn't candidate for adjusting OpenACC privatization level: not addressable} {} { target *-*-* } l_loop_k$c_loop_k } */
      57  	    for (k = 0; k < 32; k++)
      58  	      {
      59  		x = i ^ j * 3;
      60  		arr[i * 1024 + j * 32 + k] += x * k;
      61  	      }
      62  
      63  	    #pragma acc loop vector(length:32) private(x) /* { dg-line l_loop_k[incr c_loop_k] } */
      64  	    /* { dg-note {variable 'k' in 'private' clause isn't candidate for adjusting OpenACC privatization level: not addressable} {} { target *-*-* } l_loop_k$c_loop_k } */
      65  	    /* { dg-note {variable 'x' in 'private' clause isn't candidate for adjusting OpenACC privatization level: not addressable} {} { target *-*-* } l_loop_k$c_loop_k } */
      66  	    for (k = 0; k < 32; k++)
      67  	      {
      68  		x = i | j * 5;
      69  		arr[i * 1024 + j * 32 + k] += x * k;
      70  	      }
      71  	  }
      72        }
      73      /* { dg-optimized {assigned OpenACC seq loop parallelism} {} { target *-*-* } l_loop_i$c_loop_i } */
      74    }
      75  
      76    for (i = 0; i < 32; i++)
      77      for (int j = 0; j < 32; j++)
      78        for (int k = 0; k < 32; k++)
      79          {
      80  	  int idx = i * 1024 + j * 32 + k;
      81            assert (arr[idx] == idx + (i ^ j * 3) * k + (i | j * 5) * k);
      82  	}
      83  
      84    return 0;
      85  }