![](/img/trans.png)
[英]WARNING (theano.sandbox.cuda): CUDA is installed, but device gpu is not available (error: cuda unavailable)
[英]Possible causes of CUDA get device properties error with Python3 / Theano?
我正在尝试在Python3中使用多个GPU进行多重处理。 我可以运行一个简单的测试用例,如下所示:
import theano
import theano.tensor as T
import multiprocessing as mp
import time
# import lasagne
def target():
import theano.sandbox.cuda
print("target about to use")
theano.sandbox.cuda.use('gpu1')
print("target is using")
import lasagne
time.sleep(15)
print("target is exiting")
x = T.scalar('x', dtype='float32')
p = mp.Process(target=target)
p.start()
time.sleep(1)
import theano.sandbox.cuda
print("master about to use")
theano.sandbox.cuda.use('gpu0')
print("master is using")
import lasagne
time.sleep(4)
print("master will join")
p.join()
print("master is exiting")
运行此命令时,可以成功使用GPU分别获得主控和生成的进程:
>> target about to use
>> master about to use
>> Using gpu device 1: GeForce GTX 1080 (CNMeM is enabled with initial size: 50.0% of memory, cuDNN 5105)
>> target is using
>> Using gpu device 0: GeForce GTX 1080 (CNMeM is enabled with initial size: 50.0% of memory, cuDNN 5105)
>> master is using
>> master will join
>> target is exiting
>> master is exiting
但是在更复杂的代码库中,当我尝试设置相同的方案时,产生的工作程序失败,并显示以下信息:
ERROR (theano.sandbox.cuda): ERROR: Not using GPU. Initialisation of device 1 failed:
Unable to get properties of gpu 1: initialization error
ERROR (theano.sandbox.cuda): ERROR: Not using GPU. Initialisation of device gpu failed:
Not able to select available GPU from 2 cards (initialization error).
而且我很难追究造成这种情况的原因。 在上面的代码段中,如果在分叉之前从顶部进口lasagne
,则会重新产生问题。 但是我设法阻止了我的代码导入lasagne
直到分叉并尝试使用GPU之后(我检查了sys.modules.keys()
),问题仍然存在。 除了theano
本身和theano.tensor
在分叉之前导入之外,我没有看到与Theano相关的任何内容,但是在上面的示例中,这很好。
还有其他人追逐过类似的东西吗?
在尝试使用GTX-980的Windows PC中使用Python3配置Theano之前,我曾经历过类似的问题。 它可以在CPU上正常工作,但不使用GPU。
之后,我尝试使用Python2 / Theano配置它,此问题已解决。 我想CUDA版本可能有问题。 您可以尝试使用Python2 / Theano(如果需要,可以使用虚拟环境)。
好的,事实证明这很简单...我在前叉位置杂散地import theano.sandbox.cuda
,但这仅需要在分叉之后才发生。 为了帮助其他人,仍然有必要将lasagne
进口也转移到叉子之后。
(在我的情况下,实际上我在派生之前需要来自基于lasagne
的代码的信息,因此我必须产生一个抛出过程,该过程将进行加载并将相关值返回给主线程。然后,主服务器可以相应地构建共享对象。 ,fork,然后每个进程都会构建自己的基于lasagne
的对象,这些对象可以在自己的GPU上运行。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.