The problem is with the tensor with a GPU on the matrix. GPU not recognized

I installed tensor flow with gpu, cuda 7.0 and cudnn 6.5. When I import shadoworflow, it works well.

I am trying to run simple matrix multiplication by Tensorflow and it does not want to use my gpu, although it seems to recognize it. I have this problem on my computer with nvidia geforce 970m and on a cluster with two Z titans.

My first code is:

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) 

This code works and the result is:

 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 

So, in my way, shadoworflow uses my gpu to create a constant, but not for matmul (this is weird). Then I force gpu as follows:

 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) 

And returns Tensorflow:

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

If anyone has the same problem or idea, I will be happy to read your answer!

+5
source share
1 answer

I do not have enough reputation for comments, I encountered a similar problem, my question is here

TensorFlow: critical graph operations assigned to the processor, not gpu

+2
source

Source: https://habr.com/ru/post/1243115/


All Articles