Force Python Script On GPU
Is there a way to force a Python script on GPU? In my code I use tensorflow and keras, and I have already the tensorflow-gpu version, but my code runs on CPU anyway. I'd like to kn
Solution 1:
For TensorFlow (but not python in general) there is a good description of how to do this here: https://www.tensorflow.org/guide/gpu
To force a function to be performed on a specific processor (CPU or GPU) use the TensorFlow call to tf.device() as follows:
import tensorflow as tf
with tf.device('/GPU:0'):
a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
b = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
c = tf.matmul(a, b)
in this case the data for a and b will be stored on GPU0, and the operation "matmul" will be performed on the GPU0 as well.
Solution 2:
There maybe an issue with your tensorflow-gpu installation. Try creating a separate environment and reinstall only tensorflow-gpu.
Post a Comment for "Force Python Script On GPU"