Python 在Django中执行scikits.cuda示例时出现内核转储SEGFULT
我尝试在控制台环境和Django框架中运行以下简单的cublas示例Python 在Django中执行scikits.cuda示例时出现内核转储SEGFULT,python,django,segmentation-fault,scipy,pycuda,Python,Django,Segmentation Fault,Scipy,Pycuda,我尝试在控制台环境和Django框架中运行以下简单的cublas示例 """ Demonstrates multiplication of two matrices on the GPU. """ import pycuda import pycuda.gpuarray as gpuarray import pycuda.driver as drv import numpy as np drv.init() #init pycuda driver current_dev = drv.Devi
"""
Demonstrates multiplication of two matrices on the GPU.
"""
import pycuda
import pycuda.gpuarray as gpuarray
import pycuda.driver as drv
import numpy as np
drv.init() #init pycuda driver
current_dev = drv.Device(0) #device we are working on
ctx = current_dev.make_context() #make a working context
ctx.push() #let context make the lead
import scikits.cuda.linalg as culinalg
import scikits.cuda.misc as cumisc
culinalg.init()
# Double precision is only supported by devices with compute
# capability >= 1.3:
import string
demo_types = [np.float32]
for t in demo_types:
print 'Testing matrix multiplication for type ' + str(np.dtype(t))
if np.iscomplexobj(t()):
a = np.asarray(np.random.rand(10, 5)+1j*np.random.rand(10, 5), t)
b = np.asarray(np.random.rand(5, 5)+1j*np.random.rand(5, 5), t)
c = np.asarray(np.random.rand(5, 5)+1j*np.random.rand(5, 5), t)
else:
a = np.asarray(np.random.rand(10, 5), t)
b = np.asarray(np.random.rand(5, 5), t)
c = np.asarray(np.random.rand(5, 5), t)
a_gpu = gpuarray.to_gpu(a)
b_gpu = gpuarray.to_gpu(b)
c_gpu = gpuarray.to_gpu(c)
temp_gpu = culinalg.dot(a_gpu, b_gpu)
d_gpu = culinalg.dot(temp_gpu, c_gpu)
temp_gpu.gpudata.free()
del(temp_gpu)
print 'Success status: ', np.allclose(np.dot(np.dot(a, b), c) , d_gpu.get())
print 'Testing vector multiplication for type ' + str(np.dtype(t))
if np.iscomplexobj(t()):
d = np.asarray(np.random.rand(5)+1j*np.random.rand(5), t)
e = np.asarray(np.random.rand(5)+1j*np.random.rand(5), t)
else:
d = np.asarray(np.random.rand(5), t)
e = np.asarray(np.random.rand(5), t)
d_gpu = gpuarray.to_gpu(d)
e_gpu = gpuarray.to_gpu(e)
temp = culinalg.dot(d_gpu, e_gpu)
print 'Success status: ', np.allclose(np.dot(d, e), temp)
ctx.pop() #deactivate again
ctx.detach() #delete it
在控制台环境中,我成功了。但当我想在django中运行时(我将该示例作为URL的get方法中的函数插入),它给了我一个分段错误(核心转储)
有人知道这个问题的原因吗?cuda gdb的回溯信息如下:
0 0x00007ffff782d267 in kill () from /lib/x86_64-linux-gnu/libc.so.6
1 0x000000000041f44e in ?? ()
2 0x000000000052c6d5 in PyEval_EvalFrameEx ()
3 0x000000000052cf32 in PyEval_EvalFrameEx ()
4 0x000000000055c594 in PyEval_EvalCodeEx ()
5 0x000000000052ca8d in PyEval_EvalFrameEx ()
6 0x000000000056d0aa in ?? ()
7 0x000000000052e1e6 in PyEval_EvalFrameEx ()
8 0x000000000056d0aa in ?? ()
9 0x000000000052e1e6 in PyEval_EvalFrameEx ()
10 0x000000000056d0aa in ?? ()
11 0x000000000052e1e6 in PyEval_EvalFrameEx ()
12 0x000000000055c594 in PyEval_EvalCodeEx ()
13 0x000000000052ca8d in PyEval_EvalFrameEx ()
14 0x000000000052cf32 in PyEval_EvalFrameEx ()
15 0x000000000055c594 in PyEval_EvalCodeEx ()
16 0x000000000052ca8d in PyEval_EvalFrameEx ()
17 0x000000000055c594 in PyEval_EvalCodeEx ()
18 0x00000000005b7392 in PyEval_EvalCode ()
19 0x0000000000469663 in ?? ()
20 0x00000000004699e3 in PyRun_FileExFlags ()
21 0x0000000000469f1c in PyRun_SimpleFileExFlags ()
22 0x000000000046ab81 in Py_Main ()
谢谢 我创建了一个新流程,使用子流程处理CUDA计算,解决了这个问题。原因可能是pycuda不是线程安全的。pycuda是线程安全的吗?@Thomas我想不是。这可能是原因。我试过龙卷风,它成功了。tornado是一个较轻的python webframe,它并不总是为get方法创建线程。在GPU上运行的代码永远不会在主机CPU上导致分段错误。在Python解释器API调用中,回溯非常清楚。我将从纯numpy代码开始,检查在没有PyCUDA或CUDA scikit的情况下是否可以正常工作,并逐步添加功能,直到找到破坏它的地方。我已经从这个问题中删除了CUDA标记,它本身与CUDA编程没有任何关系。@Talonmes感谢您的回答。我会试试看。