1 // Tests __device__ function calls
2 // RUN: cat %s | clang-repl --cuda | FileCheck %s
4 extern "C" int printf(const char*, ...);
6 __device__ inline void test_device(int* value) { *value = 42; }
7 __global__ void test_kernel(int* value) { test_device(value); }
10 int* devptr = nullptr;
11 printf("cudaMalloc: %d\n", cudaMalloc((void **) &devptr, sizeof(int)));
12 // CHECK: cudaMalloc: 0
14 test_kernel<<<1,1>>>(devptr);
15 printf("CUDA Error: %d\n", cudaGetLastError());
16 // CHECK-NEXT: CUDA Error: 0
18 printf("cudaMemcpy: %d\n", cudaMemcpy(&var, devptr, sizeof(int), cudaMemcpyDeviceToHost));
19 // CHECK-NEXT: cudaMemcpy: 0
21 printf("Value: %d\n", var);
22 // CHECK-NEXT: Value: 42