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