(root)/
gcc-13.2.0/
libgomp/
testsuite/
libgomp.c-c++-common/
target-memcpy-rect-async-1.c
       1  /* Test for omp_target_memcpy_rect_async without considering dependence
       2     objects.  */
       3  
       4  #include <omp.h>
       5  #include <stdlib.h>
       6  
       7  #define NUM_DIMS 3
       8  
       9  int
      10  main ()
      11  {
      12    int d = omp_get_default_device ();
      13    int id = omp_get_initial_device ();
      14    int q[128], q2[128], i;
      15    void *p;
      16  
      17    if (d < 0 || d >= omp_get_num_devices ())
      18      d = id;
      19  
      20    p = omp_target_alloc (130 * sizeof (int), d);
      21    if (p == NULL)
      22      return 0;
      23  
      24    if (omp_target_memcpy_rect_async (NULL, NULL, 0, 0, NULL, NULL, NULL, NULL,
      25  				    NULL, d, id, 0, NULL) < 3
      26        || omp_target_memcpy_rect_async (NULL, NULL, 0, 0, NULL, NULL, NULL, NULL,
      27  				       NULL, id, d, 0, NULL) < 3
      28        || omp_target_memcpy_rect_async (NULL, NULL, 0, 0, NULL, NULL, NULL, NULL,
      29  				       NULL, id, id, 0, NULL) < 3)
      30      abort ();
      31  
      32    for (i = 0; i < 128; i++)
      33      q[i] = 0;
      34    if (omp_target_memcpy (p, q, 128 * sizeof (int), 0, 0, d, id) != 0)
      35      abort ();
      36  
      37    for (i = 0; i < 128; i++)
      38      q[i] = i + 1;
      39  
      40    size_t volume[NUM_DIMS] = { 1, 2, 3 };
      41    size_t dst_offsets[NUM_DIMS] = { 0, 0, 0 };
      42    size_t src_offsets[NUM_DIMS] = { 0, 0, 0 };
      43    size_t dst_dimensions[NUM_DIMS] = { 3, 4, 5 };
      44    size_t src_dimensions[NUM_DIMS] = { 2, 3, 4 };
      45  
      46    if (omp_target_memcpy_rect_async (p, q, sizeof (int), NUM_DIMS, volume,
      47  				    dst_offsets, src_offsets, dst_dimensions,
      48  				    src_dimensions, d, id, 0, NULL) != 0)
      49      abort ();
      50  
      51    #pragma omp taskwait
      52  
      53    for (i = 0; i < 128; i++)
      54      q2[i] = 0;
      55    if (omp_target_memcpy (q2, p, 128 * sizeof (int), 0, 0, id, d) != 0)
      56      abort ();
      57  
      58    /* q2 is expected to contain: 1 2 3 0 0 5 6 7 0 0 .. 0  */
      59    if (q2[0] != 1 || q2[1] != 2 || q2[2] !=3 || q2[3] != 0 || q2[4] != 0
      60        || q2[5] != 5 || q2[6] != 6 || q2[7] != 7)
      61      abort ();
      62    for (i = 8; i < 128; ++i)
      63      if (q2[i] != 0)
      64        abort ();
      65  
      66    omp_target_free (p, d);
      67    return 0;
      68  }