繁体   English   中英

运行 pytorch 时如何让 cuda 加载?

[英]How to get cuda to load when running pytorch?

我有一个带有 pytorch 和 cudatoolkit 10.1 的旧 conda 虚拟环境。 我能够运行代码,并且在开始时总是会收到以下消息:

I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.10.1

但是,我用 cudatoolkit 11.0 创建了一个新的虚拟环境,但是现在这条消息没有在代码的开头运行(我也没有收到一条错误消息说它找不到文件),并且代码在尝试时最终崩溃使用 gpu。 如何确保它正确加载 GPU 支持?

在 Tensorflow 中,为了确保代码在 GPU 上正常运行,运行此示例代码,

import tensorflow as tf
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 : It loads the GPU support
Executing op MatMul in device /job:localhost/replica:0/task:0/device:GPU: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