1 // Tests device function templates
2 // RUN: cat %s | clang-repl --cuda | FileCheck %s
4 extern "C" int printf(const char*, ...);
6 template <typename T> __device__ inline T sum(T a, T b) { return a + b; }
7 __global__ void test_kernel(int* value) { *value = sum(40, 2); }
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