brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.8 KiB · 4d07898 Raw
67 lines · c
1// RUN: %libomptarget-compile-and-run-generic2 3#include <omp.h>4#include <stdio.h>5#include <stdlib.h>6 7#define NUM_DIMS 38 9int main() {10  int d = omp_get_default_device();11  int id = omp_get_initial_device();12  int q[128], q2[128], i;13  void *p;14 15  if (d < 0 || d >= omp_get_num_devices())16    d = id;17 18  p = omp_target_alloc(130 * sizeof(int), d);19  if (p == NULL)20    return 0;21 22  if (omp_target_memcpy_rect_async(NULL, NULL, 0, 0, NULL, NULL, NULL, NULL,23                                   NULL, d, id, 0, NULL) < 3 ||24      omp_target_memcpy_rect_async(NULL, NULL, 0, 0, NULL, NULL, NULL, NULL,25                                   NULL, id, d, 0, NULL) < 3 ||26      omp_target_memcpy_rect_async(NULL, NULL, 0, 0, NULL, NULL, NULL, NULL,27                                   NULL, id, id, 0, NULL) < 3)28    abort();29 30  for (i = 0; i < 128; i++)31    q[i] = 0;32  if (omp_target_memcpy(p, q, 128 * sizeof(int), 0, 0, d, id) != 0)33    abort();34 35  for (i = 0; i < 128; i++)36    q[i] = i + 1;37 38  size_t volume[NUM_DIMS] = {1, 2, 3};39  size_t dst_offsets[NUM_DIMS] = {0, 0, 0};40  size_t src_offsets[NUM_DIMS] = {0, 0, 0};41  size_t dst_dimensions[NUM_DIMS] = {3, 4, 5};42  size_t src_dimensions[NUM_DIMS] = {2, 3, 4};43 44  if (omp_target_memcpy_rect_async(p, q, sizeof(int), NUM_DIMS, volume,45                                   dst_offsets, src_offsets, dst_dimensions,46                                   src_dimensions, d, id, 0, NULL) != 0)47    abort();48 49#pragma omp taskwait50 51  for (i = 0; i < 128; i++)52    q2[i] = 0;53  if (omp_target_memcpy(q2, p, 128 * sizeof(int), 0, 0, id, d) != 0)54    abort();55 56  /* q2 is expected to contain: 1 2 3 0 0 5 6 7 0 0 .. 0  */57  if (q2[0] != 1 || q2[1] != 2 || q2[2] != 3 || q2[3] != 0 || q2[4] != 0 ||58      q2[5] != 5 || q2[6] != 6 || q2[7] != 7)59    abort();60  for (i = 8; i < 128; ++i)61    if (q2[i] != 0)62      abort();63 64  omp_target_free(p, d);65  return 0;66}67