简体   繁体   中英

How to make code run on GPU on Windows 10?

I want to run my code run on gpu in windows 10, like for google colab, we can just change the runtime option which is pretty easy to do to shift to gpu. Is there a possibility to do the same for jupyter notebook in windows.

You will actually need to use tensorflow-gpu to run your jupyter notebook on a gpu.

The best way to achieve this would be

  1. Install Anaconda on your system

  2. Download cuDNN & Cuda Toolkit 11.3 .

  3. Add cuDNN and Cuda Toolkit to your PATH.

  4. Create an environment in Anaconda

  5. pip install tensorflow-gpu

  6. pip install [jupyter-notebook/jupyterlab]

  7. Import tensorflow-gpu in your notebook

  8. Enjoy. You can now run your notebook on your GPU

Easy Direct way Create a new environment with TensorFlow-GPU and activate it whenever you want to run your code in GPU

Open Anaconda promote and Write

  1. Conda create --name tf_GPU tensorFlow-gpu

Now it's time to test if our code Run on GPU or CPU

  1. Conda activate tf_GPU --- (Activating the env)

  2. Jupyter notebook ----(Open notebook from the tf_GPU env)

if this Code gives you 1 this means you are runing on GPU

print("Num GPUs Available: ", len(tf.config.list_physical_devices('GPU')))

You can also use this code to make sure you run on GPU

tf.debugging.set_log_device_placement(True)

# Create some tensors
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)

print(c)

Geting output like this means you using CPU not GPU

Executing op _EagerConst in device /job:localhost/replica:0/task:0/device:CPU:0
Executing op _EagerConst in device /job:localhost/replica:0/task:0/device:CPU:0
Executing op MatMul in device /job:localhost/replica:0/task:0/device:CPU:0
tf.Tensor(
[[22. 28.]
 [49. 64.]], shape=(2, 2), dtype=float32)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM