cuda - 我应该如何解释这个 CUDA 错误?

标签 cuda pycuda

我正在使用 pyCUDA 自学 CUDA。在本练习中,我想将一个包含 1024 个 float 的简单数组发送到 GPU 并将其存储在共享内存中。正如我在下面的论点中指定的那样,我仅在具有 1024 个线程的单个 block 上运行该内核。

import pycuda.driver as cuda
from pycuda.compiler import SourceModule
import pycuda.autoinit
import numpy as np
import matplotlib.pyplot as plt

arrayOfFloats = np.float64(np.random.sample(1024))
mod = SourceModule("""
  __global__ void myVeryFirstKernel(float* arrayOfFloats) {
    extern __shared__ float sharedData[];

    // Copy data to shared memory.
    sharedData[threadIdx.x] = arrayOfFloats[threadIdx.x];
  }
""")
func = mod.get_function('myVeryFirstKernel')
func(cuda.InOut(arrayOfFloats), block=(1024, 1, 1), grid=(1, 1))
print str(arrayOfFloats)

奇怪的是,我收到了这个错误。

[dfaux@harbinger CUDA_tutorials]$ python sharedMemoryExercise.py 
Traceback (most recent call last):
  File "sharedMemoryExercise.py", line 17, in <module>
    func(cuda.InOut(arrayOfFloats), block=(1024, 1, 1), grid=(1, 1))
  File "/software/linux/x86_64/epd-7.3-1-pycuda/lib/python2.7/site-packages/pycuda-2012.1-py2.7-linux-x86_64.egg/pycuda/driver.py", line 377, in function_call
    Context.synchronize()
pycuda._driver.LaunchError: cuCtxSynchronize failed: launch failed
PyCUDA WARNING: a clean-up operation failed (dead context maybe?)
cuMemFree failed: launch failed
PyCUDA WARNING: a clean-up operation failed (dead context maybe?)
cuModuleUnload failed: launch failed

我尝试通过更改发送到 GPU 的元素类型来调试此错误(例如,我使用 float32 而不是 float64)。我也曾尝试更改我的 block 和网格大小,但无济于事。

有什么问题吗?什么是死上下文?任何建议或想法表示赞赏。

最佳答案

我在您的代码中看到的一个问题是您使用了 extern __shared__ ..,这意味着您需要在启动内核时提交共享内存的大小。

在 pycuda 中,这是通过以下方式完成的:
func(cuda.InOut(arrayOfFloats), block=(1024, 1, 1), grid=(1, 1),shared=smem_size)
其中 smem_size 是以字节为单位的共享内存的大小。

在你的例子中,smem_size = 1024*sizeof(float)。

关于cuda - 我应该如何解释这个 CUDA 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13266528/

相关文章:

c++ - 使用CUDA convnet库编译错误

linux - 如何在 Linux 机器上获取我的 CUDA 规范?

python - 如何将二维数组传递到 pycuda 中的内核?

c++ - 使用 CUDA 实现、python (pycuda) 或 C++ 处理图像?

c++ - 升级到CUDA 11时cudaError/CUresult不兼容

c++ - 在cuda中定义模板化常量变量

python-2.7 - 在 ROS 中运行 tensorRT 时得到 "LogicError: explicit_context_dependent failed: invalid device context - no currently active context? "

python - 带有 Flask 的 pyCUDA 给出 pycuda._driver.LogicError : cuModuleLoadDataEx

c++ - 通过拒绝方法使用 CUDA 生成随机数。性能问题

cuda - src/cpp/cuda.hpp :14:10: fatal error: cuda. h:没有这样的文件或目录