簡體   English   中英

CUDA的可能原因是Python3 / Theano獲取設備屬性錯誤?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM