Anubhab Ghosh ddeab07ca6 [clang-repl][CUDA] Re-land: Initial interactive CUDA support for clang-repl
CUDA support can be enabled in clang-repl with --cuda flag.
Device code linking is not yet supported. inline must be used with all
__device__ functions.

Differential Revision: https://reviews.llvm.org/D146389
2023-05-27 13:54:42 +05:30

28 lines
774 B
Plaintext

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