繁体   English   中英

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

[英]How to make code run on GPU on Windows 10?

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

您实际上需要使用 tensorflow-gpu 在 gpu 上运行您的 jupyter notebook。

实现这一目标的最佳方法是

  1. 在您的系统上安装Anaconda

  2. 下载cuDNNCuda 工具包 11.3

  3. 将 cuDNN 和 Cuda 工具包添加到您的 PATH。

  4. 在 Anaconda 中创建环境

  5. pip 安装tensorflow-gpu

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

  7. 在笔记本中导入 tensorflow-gpu

  8. 享受。 您现在可以在 GPU 上运行您的笔记本

Easy Direct 方式使用 TensorFlow-GPU 创建一个新环境,并在您想要运行代码时激活它 GPU

打开 Anaconda 推广并写入

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

现在是时候测试我们的代码是否在 GPU 或 CPU 上运行

  1. Conda 激活 tf_GPU ---(激活环境)

  2. Jupyter 笔记本 ----(从 tf_GPU 环境打开笔记本)

如果这段代码给你 1 这意味着你正在运行 GPU

print("Num GPUs Available: ", len(tf.config.list_physical_devices('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)

像这样获得 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