aboutsummaryrefslogtreecommitdiff
path: root/clang/test/Interpreter/CUDA/device-function.cu
blob: 396f8f0f93e0cdebd0712fcebebcaf660d5ca7f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Tests __device__ function calls
// RUN: cat %s | clang-repl --cuda | FileCheck %s

extern "C" int printf(const char*, ...);

__device__ inline void test_device(int* value) { *value = 42; }
__global__ void test_kernel(int* value) { test_device(value); }

int var;
int* devptr = nullptr;
printf("cudaMalloc: %d\n", cudaMalloc((void **) &devptr, sizeof(int)));
// CHECK: cudaMalloc: 0

test_kernel<<<1,1>>>(devptr);
printf("CUDA Error: %d\n", cudaGetLastError());
// CHECK-NEXT: CUDA Error: 0

printf("cudaMemcpy: %d\n", cudaMemcpy(&var, devptr, sizeof(int), cudaMemcpyDeviceToHost));
// CHECK-NEXT: cudaMemcpy: 0

printf("Value: %d\n", var);
// CHECK-NEXT: Value: 42

%quit