1

代码如下:

import pycuda.driver as cuda
import pycuda.autoinit
from pycuda.compiler import SourceModule
import numpy
dtype = numpy.float32

total_size = numpy.int32(1500)
hist_rgb = numpy.random.randn(total_size)
his_rgb = hist_rgb.astype(dtype)
#print hist_rgb
a_gpu = cuda.mem_alloc(hist_rgb.nbytes)
#print a_gpu
cuda.memcpy_htod(a_gpu, hist_rgb)
numblock = 1500/256
print numblock
mod = SourceModule("""
__global__ void enhance(float *a_gpu,int total){
int pixel= threadIdx.x+blockIdx.x*blockDim.x;
    if(pixel<total){
      a_gpu[pixel]*=2;
    }
}
""")

func = mod.get_function("enhance")
func(a_gpu, total_size, block=(256,1,1), grid=(numblock,1)) 
result=numpy.empty_like(a_gpu)
cuda.memcpy_dtoh(result, a_gpu)
print result

但是我在终端中遇到如下错误:

Segmentation fault (core dumped)

我不知道这是怎么回事?有人帮忙吗?

4

0 回答 0