llvm-project
62 строки · 1.6 Кб
1// RUN: %libomptarget-compilexx-run-and-check-aarch64-unknown-linux-gnu
2// RUN: %libomptarget-compilexx-run-and-check-powerpc64-ibm-linux-gnu
3// RUN: %libomptarget-compilexx-run-and-check-powerpc64le-ibm-linux-gnu
4// RUN: %libomptarget-compilexx-run-and-check-x86_64-pc-linux-gnu
5// RUN: %libomptarget-compilexx-run-and-check-nvptx64-nvidia-cuda
6
7// REQUIRES: unified_shared_memory
8// UNSUPPORTED: amdgcn-amd-amdhsa
9
10#pragma omp declare target11int *ptr1;12#pragma omp end declare target13int a[10];14
15#include <stdio.h>16#include <stdlib.h>17int main() {18ptr1 = (int *)malloc(sizeof(int) * 100);19int *ptr2;20ptr2 = (int *)malloc(sizeof(int) * 100);21#pragma omp target map(ptr1, ptr1[ : 100])22{ ptr1[1] = 6; }23// CHECK: 624printf(" %d \n", ptr1[1]);25#pragma omp target data map(ptr1[ : 5])26{27#pragma omp target map(ptr1[2], ptr1, ptr1[3]) map(ptr2, ptr2[2])28{29ptr1[2] = 7;30ptr1[3] = 9;31ptr2[2] = 7;32}33}34// CHECK: 7 7 935printf(" %d %d %d \n", ptr2[2], ptr1[2], ptr1[3]);36free(ptr1);37#pragma omp target map(ptr2, ptr2[ : 100])38{ ptr2[1] = 6; }39// CHECK: 640printf(" %d \n", ptr2[1]);41free(ptr2);42
43a[1] = 111;44int *p = &a[0];45// CHECK: 11146printf("%d %p %p\n", p[1], p, &p); // 111 hst_p1 hst_p247#pragma omp target data map(to : p[1 : 3]) map(p)48#pragma omp target data use_device_addr(p)49{50#pragma omp target has_device_addr(p)51{52// CHECK: 11153printf("%d %p %p\n", p[1], p, &p); // 111 dev_p1 dev_p254p[1] = 222;55// CHECK: 22256printf("%d %p %p\n", p[1], p, &p); // 222 dev_p1 dev_p257}58}59// CHECK: 11160printf("%d %p %p\n", p[1], p, &p); // 111 hst_p1 hst_p261return 0;62}
63