解决这个问题参考的是这篇回答
python - TensorFlow libdevice not found. Why is it not found in the searched path? - Stack Overflow
由于我使用的是windows下anaconda环境,所以需要根据这篇回答进行下修改
首先需要在C:\xx\anaconda3\envs\环境名\Library\bin下找到文件"libdevice.10.bc",复制该文件,在当前路径下创建一个“nvvm”的文件,点击进入“nvvm”,再创建一个文件“libdevice”,将“libdevice.10.bc”粘贴到“libdevice”下
其次在windows下的编辑系统环境变量,新建一个变量“XLA_FLAGS”,变量值为“--xla_gpu_cuda_data_dir=C:\xx\anaconda3\envs\环境名\Library\bin\nvvm\libdevice”
最后需要重启下虚拟环境
在运行后,可以找到libdevice,但出现了如下的错误
:E tensorflow/core/platform/windows/subprocess.cc:287] Call to CreateProcess failed. Error code: 2, command: '"ptxas.exe" "--version"'
:W tensorflow/stream_executor/gpu/asm_compiler.cc:80] Couldn't get ptxas version string: INTERNAL: Couldn't invoke ptxas.exe --version
: E tensorflow/core/platform/windows/subprocess.cc:287] Call to CreateProcess failed. Error code: 2, command: '"ptxas.exe" "~\AppData\Local\Temp\/tempfile-OMENZY-4cdc-21752-60c5cf2ceb660" "-o" "~\AppData\Local\Temp\/tempfile-OMENZY-4cdc-21752-60c5cf2cecd52" "-arch=sm_89" "--warn-on-spills"'
: F tensorflow/compiler/xla/service/gpu/nvptx_compiler.cc:453] ptxas returned an error during compilation of ptx to sass: 'INTERNAL: Failed to launch ptxas' If the error message indicates that a file could not be written, please verify that sufficient filesystem space is provided.
[info] Dispose Kernel process 21752.
[info] End cell 9 execution after -1702443180.579s, completed
说无法获得ptxas的版本号,可以使用以下代码解决
conda install -c nvidia cuda-nvcc
该代码确保ptxas是在你的conda环境下运行的