简体   繁体   English

如何让代码在 Windows 10 上运行 GPU?

[英]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.我想在 windows 10 中运行我的代码在 gpu 上运行,就像对于 google colab 一样,我们可以更改运行时选项,这很容易转移到 gpu。是否有可能对 windows 中的 jupyter notebook 执行相同的操作。

You will actually need to use tensorflow-gpu to run your jupyter notebook on a gpu.您实际上需要使用 tensorflow-gpu 在 gpu 上运行您的 jupyter notebook。

The best way to achieve this would be实现这一目标的最佳方法是

  1. Install Anaconda on your system在您的系统上安装Anaconda

  2. Download cuDNN & Cuda Toolkit 11.3 .下载cuDNNCuda 工具包 11.3

  3. Add cuDNN and Cuda Toolkit to your PATH.将 cuDNN 和 Cuda 工具包添加到您的 PATH。

  4. Create an environment in Anaconda在 Anaconda 中创建环境

  5. pip install tensorflow-gpu pip 安装tensorflow-gpu

  6. pip install [jupyter-notebook/jupyterlab] pip 安装 [jupyter-notebook/jupyterlab]

  7. Import tensorflow-gpu in your notebook在笔记本中导入 tensorflow-gpu

  8. Enjoy.享受。 You can now run your notebook on your GPU您现在可以在 GPU 上运行您的笔记本

Easy Direct way Create a new environment with TensorFlow-GPU and activate it whenever you want to run your code in GPU Easy Direct 方式使用 TensorFlow-GPU 创建一个新环境,并在您想要运行代码时激活它 GPU

Open Anaconda promote and Write打开 Anaconda 推广并写入

  1. Conda create --name tf_GPU tensorFlow-gpu Conda 创建 --name tf_GPU tensorFlow-gpu

Now it's time to test if our code Run on GPU or CPU现在是时候测试我们的代码是否在 GPU 或 CPU 上运行

  1. Conda activate tf_GPU --- (Activating the env) Conda 激活 tf_GPU ---(激活环境)

  2. Jupyter notebook ----(Open notebook from the tf_GPU env) Jupyter 笔记本 ----(从 tf_GPU 环境打开笔记本)

if this Code gives you 1 this means you are runing on GPU如果这段代码给你 1 这意味着你正在运行 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您还可以使用此代码来确保您在 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像这样获得 output 意味着您使用的是 CPU 而不是 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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