(root)/
gcc-13.2.0/
libgomp/
testsuite/
libgomp.c-c++-common/
requires-4a.c
       1  /* { dg-additional-options "-flto" } */
       2  /* { dg-additional-options "-foffload-options=nvptx-none=-misa=sm_35" { target { offload_target_nvptx } } } */
       3  /* { dg-additional-sources requires-4-aux.c } */
       4  
       5  /* Same as requires-4.c, but uses heap memory for 'a'.  */
       6  
       7  /* Check no diagnostic by device-compiler's or host compiler's lto1.
       8     Other file uses: 'requires reverse_offload', but that's inactive as
       9     there are no declare target directives, device constructs nor device routines  */
      10  
      11  /* Depending on offload device capabilities, it may print something like the
      12     following (only) if GOMP_DEBUG=1:
      13     "devices present but 'omp requires unified_address, unified_shared_memory, reverse_offload' cannot be fulfilled"
      14     and in that case does host-fallback execution.
      15  
      16     No offload devices support USM at present, so we may verify host-fallback
      17     execution by presence of separate memory spaces.  */
      18  
      19  #pragma omp requires unified_address,unified_shared_memory
      20  
      21  int *a;
      22  extern void foo (void);
      23  
      24  int
      25  main (void)
      26  {
      27    a = (int *) __builtin_calloc (sizeof (int), 10);
      28    #pragma omp target map(to: a)
      29    for (int i = 0; i < 10; i++)
      30      a[i] = i;
      31  
      32    for (int i = 0; i < 10; i++)
      33      if (a[i] != i)
      34        __builtin_abort ();
      35  
      36    foo ();
      37    __builtin_free (a);
      38    return 0;
      39  }