cuprintf help import cuprintf correctly in multiple cu files

Hi. I’m trying to use cuprintf in a setup where I have multiple files. a “main” file, and the function files… so I’ve made this small setup here. But I can’t seem to figure out how to import cuprintf.cu or cuprintf.cuh corretly .

Anyone having an idea on where I go wrong ?

KG.

The files are as follows

//test.cu

#include "cuPrintf.cuh"

extern "C" void launch_kernel ();

int main() {

cudaPrintfInit();

cudaPrintfDisplay(NULL, true);

cudaPrintfEnd();

return 0;

}

//test_kernels.cu

#include "cuPrintf.cu"

__global__ void testKernel(int val) { cuPrintf("Value is: %d\n", val); }

extern "C" void launch_kernel () {testKernel<<< 2, 3 >>>(10); }

I’ve never used cuPrintf(), but I believe you need to move host and device code into the same file as Cuda has no linker on the device side.

Something like this:

//test.cu

extern "C" void launch_kernel(void);

int main(void)

{

	launch_kernel();

	return 0;

}
//test_kernels.cu

#include "cuPrintf.cu"

__global__ void testKernel(int val)

{

	cuPrintf("Value is: %d\n", val);

}

extern "C" void launch_kernel(void)

{

	cudaPrintfInit();

	testKernel<<< 2, 3 >>>(10);

	cudaPrintfDisplay(NULL, true);

	cudaPrintfEnd();

}

Thanks a lot, tera… that works…