Zk1*_*001 17 gpu machine-learning computer-vision tensorflow
我的机器上有3个GTX Titan GPU.我使用cifar10_train.py运行Cifar10中提供的示例并获得以下输出:
I tensorflow/core/common_runtime/gpu/gpu_init.cc:60] cannot enable peer access from device ordinal 0 to device ordinal 1
I tensorflow/core/common_runtime/gpu/gpu_init.cc:60] cannot enable peer access from device ordinal 1 to device ordinal 0
I tensorflow/core/common_runtime/gpu/gpu_init.cc:127] DMA: 0 1
I tensorflow/core/common_runtime/gpu/gpu_init.cc:137] 0: Y N
I tensorflow/core/common_runtime/gpu/gpu_init.cc:137] 1: N Y
I tensorflow/core/common_runtime/gpu/gpu_device.cc:694] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX TITAN, pci bus id: 0000:03:00.0)
I tensorflow/core/common_runtime/gpu/gpu_device.cc:694] Creating TensorFlow device (/gpu:1) -> (device: 1, name: GeForce GTX TITAN, pci bus id: 0000:84:00.0)
Run Code Online (Sandbox Code Playgroud)
在我看来,TensorFlow正在尝试在两个设备(gpu0和gpu1)上初始化自己.
我的问题是为什么它只能在两个设备上执行此操作,是否有任何方法可以防止这种情况?(我只想让它像一个GPU一样运行)
Guy*_*der 22
请参阅:使用GPU
手动设备放置
如果您希望在您选择的设备上运行特定操作而不是为您自动选择tf.device的设备,则可以使用with 来创建设备上下文,以使该上下文中的所有操作具有相同的设备分配.
# 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))
Run Code Online (Sandbox Code Playgroud)
您将看到现在分配了a和b cpu:0.由于没有为MatMul操作明确指定设备,因此TensorFlow运行时将根据操作和可用设备(本例中为gpu:0)选择一个设备,并在需要时自动在设备之间复制张量.
Device mapping:
/job:localhost/replica:0/task:0/gpu:0 -> device: 0, name: Tesla K40c, pci bus
id: 0000:05:00.0
b: /job:localhost/replica:0/task:0/cpu:0
a: /job:localhost/replica:0/task:0/cpu:0
MatMul: /job:localhost/replica:0/task:0/gpu:0
[[ 22. 28.]
[ 49. 64.]]
Run Code Online (Sandbox Code Playgroud)
早期答案2.
请参阅:使用GPU
在多GPU系统上使用单个GPU
如果系统中有多个GPU,则默认情况下将选择ID最低的GPU.如果您想在不同的GPU上运行,则需要明确指定首选项:
# Creates a graph.
with tf.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)
Run Code Online (Sandbox Code Playgroud)
早期答案1.
来自CUDA_VISIBLE_DEVICES - 屏蔽GPU
您的CUDA应用程序是否需要针对特定的GPU?如果您正在编写支持GPU的代码,则通常会使用设备查询来选择所需的GPU.但是,快速简便的测试解决方案是使用环境变量CUDA_VISIBLE_DEVICES来限制CUDA应用程序看到的设备.如果您尝试在节点上共享资源,或者希望启用GPU的可执行文件以特定GPU为目标,则此功能非常有用.
环境变量语法
结果
CUDA_VISIBLE_DEVICES = 1只能看到设备1 CUDA_VISIBLE_DEVICES = 0,1设备0和1将可见CUDA_VISIBLE_DEVICES ="0,1"与上面相同,引号是可选的CUDA_VISIBLE_DEVICES = 0,2,3设备0,2,3将是可见的; 设备1被屏蔽
CUDA将枚举从零开始的可见设备.在最后一种情况下,设备0,2,3将显示为设备0,1,2.如果将字符串的顺序更改为"2,3,0",则设备2,3,0将枚举为0,分别为1,2.如果将CUDA_VISIBLE_DEVICES设置为不存在的设备,则将屏蔽所有设备.您可以指定有效和无效设备编号的混合.将枚举无效值之前的所有设备,同时屏蔽无效值之后的所有设备.
要确定系统中可用硬件的设备ID,可以运行CUDA SDK中包含的NVIDIA的deviceQuery可执行文件.编程愉快!
克里斯梅森
| 归档时间: |
|
| 查看次数: |
12670 次 |
| 最近记录: |