国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

基于tensorflow指定GPU運行及GPU資源分配的幾種方式小結

2020-02-15 21:26:53
字體:
來源:轉載
供稿:網友

1. 在終端執行時設置使用哪些GPU(兩種方式)

(1) 如下(export 語句執行一次就行了,以后再運行代碼不用執行)

(2) 如下

2. 代碼中指定(兩種方式)

(1)

import osos.environ["CUDA_VISIBLE_DEVICES"] = "1"

(2)

# Creates a graph.with tf.device('/gpu:1'): 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)

若想使用多個GPU,如下

c = []for d in ['/gpu:0', '/gpu:1']: 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)

3.GPU資源分配

(1) 設置允許GPU增長

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

(2) 設置每個GPU內存使用多少

config = tf.ConfigProto()config.gpu_options.per_process_gpu_memory_fraction = 0.4session = tf.Session(config=config, ...)

以上這篇基于tensorflow指定GPU運行及GPU資源分配的幾種方式小結就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林站長站。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 班玛县| 福建省| 新巴尔虎右旗| 常德市| 修文县| 新晃| 桓仁| 遵义市| 平安县| 丽水市| 隆林| 电白县| 莆田市| 望江县| 崇信县| 砀山县| 竹溪县| 绥棱县| 伊宁县| 丁青县| 千阳县| 新巴尔虎左旗| 崇明县| 登封市| 班玛县| 华蓥市| 西充县| 三河市| 河南省| 临漳县| 红桥区| 绵竹市| 双柏县| 海门市| 清涧县| 盐亭县| 丽水市| 石景山区| 长沙县| 孟村| 曲水县|