gpt4 book ai didi

gpu - matmul 上 GPU 的 Tensorflow 问题。无法识别 GPU

转载 作者:行者123 更新时间:2023-12-04 20:36:03 25 4
gpt4 key购买 nike

我用 gpu、cuda 7.0 和 cudnn 6.5 安装了 tensorflow。当我导入 tensorflow 时,它运行良好。

我正在尝试在 Tensorflow 上运行一个简单的矩阵乘法,但它不想使用我的 GPU,尽管它似乎可以识别它。我在装有 nvidia geforce 970m 的计算机和装有两个 Titan Z 的集群上遇到此问题。

我的第一个代码是:

import tensorflow as tf
import numpy as np

size=100
#I create 2 matrix
mat1 = np.random.random_sample([size, size])*100
mat2 = np.random.random_sample([size, size])*100

a = tf.constant(mat1)
b = tf.constant(mat2)
c = tf.matmul(a, b)
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
sess.run(c)

此代码有效,结果是:
Const_1: /job:localhost/replica:0/task:0/gpu:0
I tensorflow/core/common_runtime/simple_placer.cc:289] Const_1: /job:localhost/replica:0/task:0/gpu:0
Const: /job:localhost/replica:0/task:0/gpu:0
I tensorflow/core/common_runtime/simple_placer.cc:289] Const: /job:localhost/replica:0/task:0/gpu:0
MatMul: /job:localhost/replica:0/task:0/cpu:0
I tensorflow/core/common_runtime/simple_placer.cc:289] MatMul: /job:localhost/replica:0/task:0/cpu:0

所以以我的方式,tensorflow 使用我的 gpu 来创建常量而不是 matmul(这很奇怪)。然后,我像这样强制 gpu:
with tf.device("/gpu:0"):
a = tf.constant(mat1)
b = tf.constant(mat2)
c = tf.matmul(a, b)
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
sess.run(c)

Tensorflow 返回:
InvalidArgumentError: Cannot assign a device to node 'MatMul': Could not satisfy explicit device specification '/gpu:0'

如果有人有同样的问题或想法,我会很高兴阅读您的回答!

最佳答案

我没有足够的声誉发表评论,我遇到过类似的问题,我的问题在这里

TensorFlow: critical graph operations assigned to cpu rather than gpu

关于gpu - matmul 上 GPU 的 Tensorflow 问题。无法识别 GPU,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35428297/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com