2016-11-18 60 views
0

我想在Python3中使用多处理器和多处理器。我可以像运行一个简单的测试用例,执行以下操作:CUDA可能的原因是Python3/Theano的设备属性错误?

>> 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 

但是,在一个更复杂的:

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顺利拿到代码库,当我尝试设置相同的方案,将生成的辅助失败:

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相关的内容,但在上面的示例中没有问题。

有没有其他人追逐类似的东西?

+0

主机系统的操作系统是什么? –

+0

Ubuntu 16.04,CUDA 8.0和Theano 0.9-dev4。 –

+1

可能是'出血的边缘'部分可能是问题。你有没有试用稳定版本? –

回答

0

好吧,事实证明这很简单...我在前叉位置有一个流浪的import theano.sandbox.cuda,但这只需要在分叉后发生。还有必要将lasagne进口到叉后,以防其他人帮助。 (在我的情况下,实际上我需要基于lasagne的基于代码的信息,因此我必须生成一个抛弃过程,它会加载该过程并将相关值返回给主线程。相应地构建共享对象fork,随后每个进程构建自己的基于GPU的对象。)

0

在使用GTX-980的Windows PC中尝试使用Python3配置Theano之前,我经历过类似的问题。它在CPU上运行良好,但它只是不使用GPU。

之后,我尝试用Python2/Theano进行配置,问题得到解决。我想这可能是CUDA版本有问题。 你可以试试Python2/Theano(如果需要,可以使用虚拟环境)。

+0

很高兴知道我并不孤单!我们只是将所有东西都迁移到了Python3,并且没有回头路可走,但我喜欢你的建议,即设置虚拟环境并尝试不同的版本。我觉得自从示例代码片段起作用之后,必须还有其他东西需要导入或配置才会导致问题,我只需要找到它并在分叉进程之前将其关闭。 –

相关问题