llvm-project
31 строка · 818.0 Байт
1// RUN: %libomptarget-compilexx-run-and-check-generic
2
3#include <assert.h>4#include <iostream>5#include <omp.h>6
7struct view {8const int size = 10;9int *data_host;10int *data_device;11void foo() {12std::size_t bytes = size * sizeof(int);13const int host_id = omp_get_initial_device();14const int device_id = omp_get_default_device();15data_host = (int *)malloc(bytes);16data_device = (int *)omp_target_alloc(bytes, device_id);17#pragma omp target teams distribute parallel for is_device_ptr(data_device)18for (int i = 0; i < size; ++i)19data_device[i] = i;20omp_target_memcpy(data_host, data_device, bytes, 0, 0, host_id, device_id);21for (int i = 0; i < size; ++i)22assert(data_host[i] == i);23}24};25
26int main() {27view a;28a.foo();29// CHECK: PASSED30printf("PASSED\n");31}
32