女人自慰AV免费观看内涵网,日韩国产剧情在线观看网址,神马电影网特片网,最新一级电影欧美,在线观看亚洲欧美日韩,黄色视频在线播放免费观看,ABO涨奶期羡澄,第一导航fulione,美女主播操b

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

關于TensorFlow在GPU中的使用規則

Tensorflowers ? 來源:cg ? 2018-12-04 09:27 ? 次閱讀

支持的設備

在一套標準系統中通常有多臺計算設備。TensorFlow 支持CPUGPU這兩種設備。它們均用strings表示。

例如:

"/cpu:0":機器的 CPU

"/device:GPU:0":機器的 GPU(如果有一個)

"/device:GPU:1":機器的第二個 GPU(以此類推)

如果 TensorFlow 指令中兼有 CPU 和 GPU 實現,當該指令分配到設備時,GPU 設備有優先權。例如,如果matmul同時存在 CPU 和 GPU 核函數,在同時有cpu:0和gpu:0設備的系統中,gpu:0會被選來運行matmul。

記錄設備分配方式

要找出您的指令和張量被分配到哪個設備,請創建會話并將log_device_placement配置選項設為True。

# Creates a graph.a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')c = tf.matmul(a, b)# Creates a session with log_device_placement set to True.sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))# Runs the op.print(sess.run(c))

您應該會看到以下輸出內容:

Device mapping:/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: Tesla K40c, pci busid: 0000:05:00.0b: /job:localhost/replica:0/task:0/device:GPU:0a: /job:localhost/replica:0/task:0/device:GPU:0MatMul: /job:localhost/replica:0/task:0/device:GPU:0[[ 22. 28.][ 49. 64.]]

手動分配設備

如果您希望特定指令在您選擇的設備(而非系統自動為您選擇的設備)上運行,您可以使用with tf.device創建設備上下文,這個上下文中的所有指令都將被分配在同一個設備上運行。

# Creates a graph.with tf.device('/cpu:0'): a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a') b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')c = tf.matmul(a, b)# Creates a session with log_device_placement set to True.sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))# Runs the op.print(sess.run(c))

您會看到現在a和b被分配到cpu:0。由于未明確指定運行MatMul指令的設備,因此 TensorFlow 運行時將根據指令和可用設備(此示例中的gpu:0)選擇一個設備,并會根據要求自動復制設備間的張量。

Device mapping:/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: Tesla K40c, pci busid: 0000:05:00.0b: /job:localhost/replica:0/task:0/cpu:0a: /job:localhost/replica:0/task:0/cpu:0MatMul: /job:localhost/replica:0/task:0/device:GPU:0[[ 22. 28.][ 49. 64.]]

允許增加 GPU 內存

默認情況下,TensorFlow 會映射進程可見的所有 GPU 的幾乎所有 GPU 內存(取決于CUDA_VISIBLE_DEVICES)。通過減少內存碎片,可以更有效地使用設備上相對寶貴的 GPU 內存資源。

在某些情況下,最理想的是進程只分配可用內存的一個子集,或者僅根據進程需要增加內存使用量。TensorFlow 在 Session 上提供兩個 Config 選項來進行控制。

第一個是allow_growth選項,它試圖根據運行時的需要來分配 GPU 內存:它剛開始分配很少的內存,隨著 Session 開始運行并需要更多 GPU 內存,我們會擴展 TensorFlow 進程所需的 GPU 內存區域。請注意,我們不會釋放內存,因為這可能導致出現更嚴重的內存碎片情況。要開啟此選項,請通過以下方式在 ConfigProto 中設置選項:

config = tf.ConfigProto()config.gpu_options.allow_growth = Truesession = tf.Session(config=config, ...)

如要真正限制 TensorFlow 進程可使用的 GPU 內存量,這非常實用。

在多 GPU 系統中使用單一 GPU

如果您的系統中有多個 GPU,則默認情況下將選擇 ID 最小的 GPU。如果您希望在其他 GPU 上運行,則需要顯式指定偏好設置:

# Creates a graph.with tf.device('/device:GPU:2'): a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a') b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b') c = tf.matmul(a, b)# Creates a session with log_device_placement set to True.sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))# Runs the op.print(sess.run(c))

如果您指定的設備不存在,您會看到InvalidArgumentError:

InvalidArgumentError: Invalid argument: Cannot assign a device to node 'b':Could not satisfy explicit device specification '/device:GPU:2' [[Node: b = Const[dtype=DT_FLOAT, value=Tensor, _device="/device:GPU:2"]()]]

當指定設備不存在時,如果您希望 TensorFlow 自動選擇現有的受支持設備來運行指令,則可以在創建會話時將配置選項中的allow_soft_placement設為True。

# Creates a graph.with tf.device('/device:GPU:2'): a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a') b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b') c = tf.matmul(a, b)# Creates a session with allow_soft_placement and log_device_placement set# to True.sess = tf.Session(config=tf.ConfigProto( allow_soft_placement=True, log_device_placement=True))# Runs the op.print(sess.run(c))

使用多個 GPU

如果您想要在多個 GPU 上運行 TensorFlow,則可以采用多塔式方式構建模型,其中每個塔都會分配給不同 GPU。例如:

# Creates a graph.c = []for d in ['/device:GPU:2', '/device:GPU:3']: with tf.device(d): a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3]) b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2]) c.append(tf.matmul(a, b))with tf.device('/cpu:0'): sum = tf.add_n(c)# Creates a session with log_device_placement set to True.sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))# Runs the op.print(sess.run(sum))

您會看到以下輸出內容:

Device mapping:/job:localhost/replica:0/task:0/device:GPU:0 -> device: 0, name: Tesla K20m, pci busid: 0000:02:00.0/job:localhost/replica:0/task:0/device:GPU:1 -> device: 1, name: Tesla K20m, pci busid: 0000:03:00.0/job:localhost/replica:0/task:0/device:GPU:2 -> device: 2, name: Tesla K20m, pci busid: 0000:83:00.0/job:localhost/replica:0/task:0/device:GPU:3 -> device: 3, name: Tesla K20m, pci busid: 0000:84:00.0Const_3: /job:localhost/replica:0/task:0/device:GPU:3Const_2: /job:localhost/replica:0/task:0/device:GPU:3MatMul_1: /job:localhost/replica:0/task:0/device:GPU:3Const_1: /job:localhost/replica:0/task:0/device:GPU:2Const: /job:localhost/replica:0/task:0/device:GPU:2MatMul: /job:localhost/replica:0/task:0/device:GPU:2AddN: /job:localhost/replica:0/task:0/cpu:0[[ 44. 56.][ 98. 128.]]

cifar10 教程就是個很好的例子(https://tensorflow.google.cn/tutorials/images/deep_cnn?hl=zh-CN),演示了如何使用多個 GPU 進行訓練。

聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。 舉報投訴
  • gpu
    gpu
    +關注

    關注

    28

    文章

    4912

    瀏覽量

    130675
  • tensorflow
    +關注

    關注

    13

    文章

    330

    瀏覽量

    61037

原文標題:TensorFlow 指南:GPU 的使用

文章出處:【微信號:tensorflowers,微信公眾號:Tensorflowers】歡迎添加關注!文章轉載請注明出處。

收藏 人收藏

    評論

    相關推薦
    熱點推薦

    關于 TensorFlow

    節點間相互聯系的多維數據數組,即張量(tensor)。它靈活的架構讓你可以多種平臺上展開計算,例如臺式計算機的一個或多個CPU(或GPU),服務器,移動設備等等。
    發表于 03-30 19:57

    使用 TensorFlow, 你必須明白 TensorFlow

    :1": 機器的第二個 GPU, 以此類推.閱讀使用GPU章節, 了解 TensorFlow GPU 使用的更多信息.交互式使用文檔的 P
    發表于 03-30 20:03

    阿里云Kubernetes容器服務上打造TensorFlow實驗室

    GPU的使用,同時支持最新的TensorFLow版本, 對于數據科學家來說既是復雜的,同時也是浪費精力的。阿里云的Kubernetes集群上,您可以通過簡單的按鈕提交創建一套完整的Tenso
    發表于 05-10 10:24

    可以vGPU配置文件上運行TensorFlow嗎?

    大家好,我有一些問題,你們可能知道答案。我閱讀了文檔,但我還不確定。開發團隊中有一些人正在為TensorFlow(AI項目)尋找GPU。我們對工作站和Dockers上運行的Quadro GP
    發表于 09-18 16:35

    深度學習框架TensorFlow&TensorFlow-GPU詳解

    TensorFlow&TensorFlow-GPU:深度學習框架TensorFlow&TensorFlow-GPU的簡介、安裝、使用方法詳細攻略
    發表于 12-25 17:21

    tensorflow-gpu安裝報錯的修改

    tensorflow-gpu安裝遇到的一些問題解決
    發表于 05-20 10:25

    TensorFlow是什么

    更長。TensorFlow 使這一切變得更加簡單快捷,從而縮短了想法到部署之間的實現時間。本教程,你將學習如何利用 TensorFlow 的功能來實現深度神經網絡。
    發表于 07-22 10:14

    TensorFlow安裝和下載(超詳細)

    TensorFlow安裝具體做法命令行中使用以下命令創建 conda 環境(如果使用 Windows,最好在命令行以管理員身份執行):conda create -n tensorflow
    發表于 07-22 10:25

    TensorFlow教程|常見問題

    (name): context 創建操作(operation),這樣可以指定的設備上運行操作(operation)。 關于 TensorFlow 怎樣將操作(operations)
    發表于 07-27 18:33

    TensorFlow XLA加速線性代數編譯器

    編譯:會話級別打開JIT編譯: 這是手動打開 JIT 編譯: 還可以通過將操作指定在特定的 XLA 設備(XLA_CPU 或 XLA_GPU)上,通過 XLA 來運行計算: AoT編譯:獨立使用 tfcompile 將
    發表于 07-28 14:31

    TensorFlow指定CPU和GPU設備操作詳解

    TensorFlow 支持 CPU 和 GPU。它也支持分布式計算。可以一個或多個計算機系統的多個設備上使用 TensorFlowTensorF
    發表于 07-28 14:33

    Mali GPU支持tensorflow或者caffe等深度學習模型嗎

    Mali GPU 支持tensorflow或者caffe等深度學習模型嗎? 好像caffe2go和tensorflow lit可以部署到ARM,但不知道是否支持
    發表于 09-16 14:13

    如何在AMD的GPU上運行TensorFlow

    ROCm 即 Radeon 開放生態系統 (Radeon Open Ecosystem),是我們 Linux 上進行 GPU 計算的開源軟件基礎。而 TensorFlow 實現則使用了 MIOpen,這是一個適用于深度學習的高
    的頭像 發表于 10-04 08:59 ?2.5w次閱讀

    GPU上利用TensorFlow Serving 部署ResNet

    本文中,我們將展示以同樣的方式運行經 TF-TRT 轉換的模型有多簡單。此 docker run 命令會啟動 TensorFlow Serving 服務器,以提供 /tmp/resnet 已下載
    的頭像 發表于 03-05 17:51 ?7865次閱讀
    <b class='flag-5'>在</b><b class='flag-5'>GPU</b>上利用<b class='flag-5'>TensorFlow</b> Serving 部署ResNet

    TensorFlow-DirectML TensorFlowGPU范圍擴展

    ./oschina_soft/tensorflow-directml.zip
    發表于 06-17 09:18 ?1次下載
    <b class='flag-5'>TensorFlow</b>-DirectML <b class='flag-5'>TensorFlow</b>的<b class='flag-5'>GPU</b>范圍擴展