Message Boards Message Boards

Using library code (specifically curand) with CUDALink

    gausvSource = "
    #include <curand_kernel.h>
    __global__ void gausv( float *out  )
        curandState_t curand_state;
        curand_init ( 0, 0, 0, &curand_state );
        *out = curand_normal( &curand_state );
    CUDAFunctionLoad[gausvSource, "gausv", {{"Float", _, "Output"}}, 256]

yields a series of errors like:

curand_kernel.h(558): error: this declaration may not have extern "C" linkage

Wrapping the include, the function, or the whole thing in extern "C" { } changes the message to:

CUDALink encountered an invalid program.

So, how does one correctly use library code with CUDALink?

POSTED BY: John Doty
3 months ago

andre at found the answer. CUDAFunctionLoad wraps the function in extern "C" { }. I needed to unwrap the include as follows:

#include <curand_kernel.h>
extern \"C\" {

(backslashes needed to quote the quotes within a quoted string ;-). Thanks, andre!

POSTED BY: John Doty
3 months ago

Group Abstract Group Abstract