1 // Checks that a function is available in both __host__ and __device__
2 // RUN: cat %s | clang-repl --cuda | FileCheck %s
4 extern "C" int printf(const char*, ...);
6 __host__ __device__ inline int sum(int a, int b){ return a + b; }
7 __global__ void kernel(int * output){ *output = sum(40,2); }
9 printf("Host sum: %d\n", sum(41,1));
10 // CHECK: Host sum: 42
14 printf("cudaMalloc: %d\n", cudaMalloc((void **) &deviceVar, sizeof(int)));
15 // CHECK-NEXT: cudaMalloc: 0
17 kernel<<<1,1>>>(deviceVar);
18 printf("CUDA Error: %d\n", cudaGetLastError());
19 // CHECK-NEXT: CUDA Error: 0
21 printf("cudaMemcpy: %d\n", cudaMemcpy(&var, deviceVar, sizeof(int), cudaMemcpyDeviceToHost));
22 // CHECK-NEXT: cudaMemcpy: 0
24 printf("var: %d\n", var);
25 // CHECK-NEXT: var: 42