我在 CUDA 统一内存 [ 2 ] 上使用 PyCUDA 的接口 [ 1 ]。在某些时候,我添加了随机数生成器 [ 3 ] 并盯着 Jupyter Notebook 中的死内核:
我将问题缩小到创建随机数生成器。或者,准确地说,到我这样做的那一刻:
import pycuda.curandom
from pycuda import autoinit, driver
import numpy as np
gpu_data_1 = driver.managed_zeros(shape=5, dtype=np.int32, mem_flags=driver.mem_attach_flags.GLOBAL)
gpu_generator = pycuda.curandom.XORWOWRandomNumberGenerator(pycuda.curandom.seed_getter_uniform)
gpu_data_2 = driver.managed_zeros(shape=5, dtype=np.int32, mem_flags=driver.mem_attach_flags.GLOBAL)
上面的代码在没有任何错误消息的情况下失败,但是如果我将gpu_generator = ...
行放在更高或更低的一行,它似乎可以正常工作。
我相信 PyCUDA 可能会以某种方式无法执行prepare
call,这归结为这个内核:
extern "C" {
__global__ void prepare(curandStateXORWOW *s, const int n,
unsigned int *v, const unsigned int o)
{
const int id = blockIdx.x*blockDim.x+threadIdx.x;
if (id < n)
curand_init(v[id], id, o, &s[id]);
}
}
知道可能是什么问题吗?