为什么我的VSCode尝试使用cuda,即使我安装了directml(我在amd上)?



我有一个张量流对象检测项目,我想构建并读取它在cpu上很慢。这时有人告诉我使用directml,因为我用的是AMD的gpu,而不是NVIDIA的。

我创造了一个蟒蛇般的环境,我称之为"直接"。并安装了tensorflow和directml(见图)。如果我现在尝试运行从本教程中找到的测试应用程序(https://learn.microsoft.com/en-us/windows/ai/directml/gpu-tensorflow-windows):

)
import tensorflow.compat.v1 as tf 
tf.enable_eager_execution(tf.ConfigProto(log_device_placement=True)) 
print(tf.add([1.0, 2.0], [3.0, 4.0]))

我没有得到想要的输出:


2020-06-15 11:27:18.240065: I tensorflow/core/common_runtime/dml/dml_device_factory.cc:32] DirectML: creating device on adapter 0 (AMD Radeon VII) 
2020-06-15 11:27:18.323949: I tensorflow/stream_executor/platform/default/dso_loader.cc:60] Successfully opened dynamic library DirectMLba106a7c621ea741d2159d8708ee581c11918380.dll 
2020-06-15 11:27:18.337830: I tensorflow/core/common_runtime/eager/execute.cc:571] Executing op Add in device /job:localhost/replica:0/task:0/device:DML:0 
tf.Tensor([4. 6.], shape=(2,), dtype=float32)

但是我得到了这个:

2021-09-16 17:15:03.700209: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_100.dll'; dlerror: cudart64_100.dll not found
2021-09-16 17:15:03.700418: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2021-09-16 17:15:05.192685: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found
2021-09-16 17:15:05.192902: E tensorflow/stream_executor/cuda/cuda_driver.cc:318] failed call to cuInit: UNKNOWN ERROR (303)
2021-09-16 17:15:05.197503: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: DESKTOP-N3L36AL
2021-09-16 17:15:05.197857: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: DESKTOP-N3L36AL
2021-09-16 17:15:05.198376: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2021-09-16 17:15:05.202832: I tensorflow/core/common_runtime/eager/execute.cc:571] Executing op Add in device /job:localhost/replica:0/task:0/device:CPU:0
tf.Tensor([4. 6.], shape=(2,), dtype=float32)

对我来说,它看起来像tensorflow试图使用cuda而不是直接使用,但我不知道为什么会这样。我的Windows和AMD驱动都是最新的。

你不应该只安装tensorflow-directml。因为现在python导入的是tensorflow而不是tensorflow-directml。卸载tensorflow,它应该修复导入。

最新更新