题目限制100字,一个较为完整的报错信息应该是
W tensorflow/compiler/xla/service/gpu/nvptx_compiler.cc:73] Can't find libdevice directory ${CUDA_DIR}/nvvm/libdevice. This may result in compilation or runtime failures, if the program we try to run uses routines from libdevice.
W tensorflow/compiler/xla/service/gpu/nvptx_compiler.cc:74] Searched for CUDA in the following directories:
W tensorflow/compiler/xla/service/gpu/nvptx_compiler.cc:77] ./cuda_sdk_lib
W tensorflow/compiler/xla/service/gpu/nvptx_compiler.cc:77] C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.2
W tensorflow/compiler/xla/service/gpu/nvptx_compiler.cc:77] .
W tensorflow/compiler/xla/service/gpu/nvptx_compiler.cc:79] You can choose the search directory by setting xla_gpu_cuda_data_dir in HloModule's DebugOptions. For most apps, setting the environment variable XLA_FLAGS=--xla_gpu_cuda_data_dir=/path/to/cuda will work.
W tensorflow/compiler/xla/service/gpu/llvm_gpu_backend/gpu_backend_lib.cc:328] libdevice is required by this HLO module but was not found at ./libdevice.10.bc
W tensorflow/core/framework/op_kernel.cc:1767] OP_REQUIRES failed at xla_ops.cc:301 : Internal: libdevice not found at ./libdevice.10.bc
这个问题出现的原因有两个:
1、没有安装cudatoolkit、cuDNN这些;
2、在安装的时候更改路径,没有安装到默认的C:/Program Files/NVIDIA GPU Computing路径下。
针对第一个原因,没什么好说的,安装好即可;
针对第二个原因,则需要配置环境变量。
这里注意到报错中核心的一句
You can choose the search directory by setting xla_gpu_cuda_data_dir in HloModule's DebugOptions. For most apps, setting the environment variable XLA_FLAGS=--xla_gpu_cuda_data_dir=/path/to/cuda will work.
因此,在电脑系统中添加环境变量即可,环境变量名为
XLA_FLAGS
变量值为(具体路径当然需要根据实际情况进行修改(一句唠叨话))
--xla_gpu_cuda_data_dir='E:\CUDA\NVIDIA GPU Computing Toolkit\CUDA\v11.2'
注意两点:
1、此处的–xla_gpu_cuda_data_dir不可省,等号右边的单引号也不可省略;
2、在满足第一点的基础上,在电脑系统中配置环境变量,或是通过pycharm的设置等配置环境变量都可。
补充:
在stackoverflow论坛中找到的关于该问题的单双引号的表述
参考网址:
- 标题:设置python环境变量的三种方法(pycharm)
网址:https://www.iotword.com/5087.html - 标题:TensorFlow libdevice not found. Why is it not found in the searched path?
网址:https://stackoverflow.com/questions/68614547/tensorflow-libdevice-not-found-why-is-it-not-found-in-the-searched-path