44 lines · plain
1// clang-format off2// RUN: %clang++ %flags -foffload-via-llvm --offload-arch=native %s -o %t3// RUN: %t | %fcheck-generic4// RUN: %clang++ %flags -foffload-via-llvm --offload-arch=native %s -o %t -fopenmp 5// RUN: %t | %fcheck-generic6// clang-format on7 8// REQUIRES: gpu9//10// FIXME: https://github.com/llvm/llvm-project/issues/16126511// UNSUPPORTED: gpu12 13#include <stdio.h>14 15extern "C" {16void *llvm_omp_target_alloc_shared(size_t Size, int DeviceNum);17void llvm_omp_target_free_shared(void *DevicePtr, int DeviceNum);18}19 20__global__ void square(int *Dst, short Q, int *Src, short P) {21 *Dst = (Src[0] + Src[1]) * (Q + P);22 Src[0] = Q;23 Src[1] = P;24}25 26int main(int argc, char **argv) {27 int DevNo = 0;28 int *Ptr = reinterpret_cast<int *>(llvm_omp_target_alloc_shared(4, DevNo));29 int *Src = reinterpret_cast<int *>(llvm_omp_target_alloc_shared(8, DevNo));30 *Ptr = 7;31 Src[0] = -2;32 Src[1] = 8;33 printf("Ptr %p, *Ptr: %i\n", Ptr, *Ptr);34 // CHECK: Ptr [[Ptr:0x.*]], *Ptr: 735 printf("Src: %i : %i\n", Src[0], Src[1]);36 // CHECK: Src: -2 : 837 square<<<1, 1>>>(Ptr, 3, Src, 4);38 printf("Ptr %p, *Ptr: %i\n", Ptr, *Ptr);39 // CHECK: Ptr [[Ptr]], *Ptr: 4240 printf("Src: %i : %i\n", Src[0], Src[1]);41 // CHECK: Src: 3 : 442 llvm_omp_target_free_shared(Ptr, DevNo);43}44