Message Boards Message Boards


Using library code (specifically curand) with CUDALink

Posted 8 months ago
1 Reply
0 Total Likes
    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?

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!

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract