2017-02-23 79 views
3

我在運行Ubuntu 14.04.4 LTS x64的服務器上安裝了TensorFlow-GPU 1.0.0。強制TensorFlow-GPU從命令行使用CPU

我知道我可以用CUDA_VISIBLE_DEVICES隱藏一個或幾個GPU。有時,我想隱藏所有GPU,以便基於TensorFlow的程序只使用CPU。其結果是,我試圖

[email protected]:/scratch/coding/src$ CUDA_VISIBLE_DEVICES="" python my_script.py 

但是這給我的錯誤信息:

E tensorflow/stream_executor/cuda/cuda_driver.cc:509] failed call to cuInit: CUDA_ERROR_NO_DEVICE 

這裏是ConfigProto我用:

session_conf = tf.ConfigProto(
     device_count={'CPU': 1, 'GPU': 1}, 
     allow_soft_placement=True, 
     log_device_placement=False 
    ) 
sess = tf.Session(config=session_conf) 

我知道我可以使用device_count={'GPU': 0}防止基於TensorFlow的程序使用GPU,但我想知道這是否可以在啓動程序時從命令行實現(不需要更改ConfigProto)。

根據文檔,選項allow_soft_placement=True應該讓TensorFlow自動選擇現有和支持的設備,以便在指定的設備不​​存在的情況下運行操作。

我看到消息的第一反應是CUDA需要至少一個GPU才能成功加載,但我可以在機器上安裝GPU驅動程序並使用TensorFlow-GPU,即使機器沒有GPU。


這裏是my_script.py劇本我使用的測試:

import tensorflow as tf 
a = tf.constant(1, name = 'a') 
b = tf.constant(3, name = 'b') 
c = tf.constant(9, name = 'c') 
d = tf.add(a, b, name='d') 
e = tf.add(d, c, name='e') 

session_conf = tf.ConfigProto(
      device_count={'CPU': 1, 'GPU': 1}, 
      allow_soft_placement=True, 
      log_device_placement=False 
     ) 
sess = tf.Session(config=session_conf) 
print(sess.run([d, e])) 
+2

我認爲這實在是一個警告,而不是一個錯誤消息,我一直看到它的事情和工作 –

+0

@YaroslavBulatov謝謝你很高興知道。 –

+0

@YaroslavBulatov順便說一下,歡迎您將您的評論轉換爲答案:Stack up with 0 upvote and 0 answer可能會被自動刪除。 –

回答

1

我認爲,「E」應該已經是一個「W」或「I」,這只是一個參考消息和不應該影響你的程序的功能