我是pycuda编程和尝试使用python中的代码this的新手。
我更改了参数,如下面的代码所示。 rpy2用于从python调用R函数。但是在SourceModule ro内部会出错。
import rpy2.robjects as ro
import pycuda.driver as cuda
import pycuda.autoinit
from pycuda.compiler import SourceModule
import numpy
data="/path/some.json"
path="/path/to/the/R/function"
data_gpu = cuda.mem_alloc(len(data))
path_gpu = cuda.mem_alloc(len(path))
data_bytes=ecgdata.encode('utf-8')
path_bytes=path.encode('utf-8')
cuda.memcpy_htod(data_gpu, data_bytes)
cuda.memcpy_htod(path_gpu, path_bytes)
mod = SourceModule("""
__global__ void Analysis(char **ecgdata,char **path)
{
int idx = threadIdx.x + threadIdx.y*4;
r=ro.r
r.source("/path/to/Rprogram.R")
p[idx]=r.analysis_ver15(data,path) //R function
return p
}
""")
func = mod.get_function("Analysis")
func(ecgdata_gpu,path_gpu, block=(4,4,1))
a_doubled = numpy.empty_like(data)
cuda.memcpy_dtoh(a_doubled, data_gpu)
print (a_doubled)
print (data)
错误:pycuda.driver.CompileError:的nvcc编译 /tmp/tmpi6szkm5g/kernel.cu失败 [命令:nvcc --cubin -arch sm_50 -I / home / anaconda3 / lib / python3.6 / site-packages / pycuda-2017.1-py3.6-linux-x86_64.egg / pycuda / cuda kernel.cu] [stderr: kernel.cu(6):错误:标识符“ r”未定义
kernel.cu(6): error: identifier "ro" is undefined kernel.cu(7): error: expected a ";" kernel.cu(10): warning: parsing restarts here after previous syntax error kernel.cu(5): warning: variable "idx" was declared but never referenced 3 errors detected in the compilation of "/tmp/tmpxft_00002e53_00000000-7_kernel.cpp1.ii".
我正在处理字符串,而不是整数或浮点数。这种方法是否错误?任何帮助表示赞赏。