Message Boards Message Boards

Using library code (specifically curand) with CUDALink

Posted 6 years ago
Needs["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

andre at mathematica.stackexchange.com 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
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract