在Scikit-Cuda中删除FFT计划会破坏Pycuda上下文
我想使用 pycuda 和FFT功能来自 scikit-cuda 一起。下面的代码
- 创建
skcuda.fft.plan
, - 删除计划,然后
- 尝试分配
pycuda.gpuarray.gpuarray.gpuarray
。
import pycuda.autoinit
import numpy as np
import pycuda
import skcuda
import skcuda.fft as cufft
plan = cufft.Plan((2,2), np.complex64, np.complex64)
del plan # equivalent to `skcuda.cufft.cufftDestroy(plan.handle)`
#skcuda.cufft.cufftDestroy(plan.handle) # equivalent to `del plan`
pycuda.gpuarray.empty((2,2), np.float32)
最后一行投掷pycuda._driver.logicerror:cumemalloc失败:上下文被销毁
。
不知何故,skcuda.cufft.cufftdestroy(plan.handle)
还摧毁了pycuda上下文(即类型pycuda> pycuda._driver._driver.context
)。
有人可以看到一个好的修复吗?
I would like to use pycuda and the FFT functions from scikit-cuda together. The code below
- creates a
skcuda.fft.Plan
, - deletes that plan and then
- tries to allocate a
pycuda.gpuarray.GPUArray
.
import pycuda.autoinit
import numpy as np
import pycuda
import skcuda
import skcuda.fft as cufft
plan = cufft.Plan((2,2), np.complex64, np.complex64)
del plan # equivalent to `skcuda.cufft.cufftDestroy(plan.handle)`
#skcuda.cufft.cufftDestroy(plan.handle) # equivalent to `del plan`
pycuda.gpuarray.empty((2,2), np.float32)
The last line throws pycuda._driver.LogicError: cuMemAlloc failed: context is destroyed
.
Somehow, skcuda.cufft.cufftDestroy(plan.handle)
also destroys the pycuda context (which is of type pycuda._driver.Context
).
Can somebody see a good fix?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
主人回答( https://github.com/inducer.com/inducer/pycuda/pycuda/discussions/356 ):
上面我特定问题的解决方案是保留主要上下文,而不是让Pycuda创建一个新的上下文。最简单的方法是通过:
导入pycuda.autaprimaryctx
而不是导入pycuda.autoinit
voila,现在一切正常。另请参见文档 //github.com/inducer/pycuda/blob/main/pycuda/autaprimaryctx.py“ rel =“ nofollow noreferrer”>代码 for
pycuda.autoprimaryctx
。The master replied (https://github.com/inducer/pycuda/discussions/356):
The solution to my specific problem above is retaining the primary context instead of letting pyCUDA create a new context. The easiest way to do this is via:
import pycuda.autoprimaryctx
instead ofimport pycuda.autoinit
Voila, everything works now. See also the documentation and the code for
pycuda.autoprimaryctx
.