I am trying to generate random numbers using pycuda, code without random number generation code works fine. Any help will be appreciated.
from pycuda.compiler import SourceModule
code="""
#include <stdio.h>
#include <curand.h>
#include <curand_kernel.h>
__global__ void testrand2(unsigned long seed, float *a){
int idx = threadIdx.x + blockIdx.x * blockDim.x;
curandState state;
curand_init(seed, idx, 0, &state);
a[idx] = curand_uniform(&state);
}
__global__ void test(float *arr)
{
dim3 threadsPerBlock(256,1,1);
dim3 numBlocks(1,1);
testrand2<<<threadsPerBlock,numBlocks>>>(1, arr);
}
"""
mod = SourceModule(code)
test = mod.get_function("test")
d = np.zeros(256, dtype=np.float32)
test (drv.InOut(d), block=(1,1,1), grid=(1,1))
print(d)
ERORR:
--------------------------------------------------------------------------- CompileError Traceback (most recent call last) in () 22 """ 23 ---> 24 mod = SourceModule(code) 25 test = mod.get_function("test") 26 print("main_Correlation Called")
2 frames /usr/local/lib/python3.7/dist-packages/pycuda/compiler.py in compile_plain(source, options, keep, nvcc, cache_dir, target) 153 cmdline, 154 stdout=stdout.decode("utf-8", "replace"), --> 155 stderr=stderr.decode("utf-8", "replace"), 156 ) 157
CompileError: nvcc compilation of /tmp/tmprygdeq52/kernel.cu failed [command: nvcc --cubin -arch sm_75 -I/usr/local/lib/python3.7/dist-packages/pycuda/cuda kernel.cu] [stderr: /usr/local/cuda/bin/../targets/x86_64-linux/include/curand_kernel.h(507): error: this declaration may not have extern "C" linkage
/usr/local/cuda/bin/../targets/x86_64-linux/include/curand_kernel.h(527): error: this declaration may not have extern "C" linkage
/usr/local/cuda/bin/../targets/x86_64-linux/include/curand_kernel.h(583): error: this declaration may not have extern "C" linkage
............ ............
/usr/local/cuda/bin/../targets/x86_64-linux/include/curand_discrete2.h(86): error: this declaration may not have extern "C" linkage
kernel.cu(19): error: kernel launch from device or global functions requires separate compilation mode
31 errors detected in the compilation of "kernel.cu". ]
Aucun commentaire:
Enregistrer un commentaire