Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

paddlepaddle-gpu安装后找不到cudnn库 #53009

Closed
ZOUG opened this issue Apr 17, 2023 · 6 comments
Closed

paddlepaddle-gpu安装后找不到cudnn库 #53009

ZOUG opened this issue Apr 17, 2023 · 6 comments
Assignees
Labels

Comments

@ZOUG
Copy link

ZOUG commented Apr 17, 2023

问题描述 Issue Description

使用conda按照官方网站说明安装paddlepaddle-gpu。完成后按说明验证安装,显示如下错误:

W0418 07:31:19.322589 21788 dynamic_loader.cc:278] Note: [Recommend] copy cudnn into CUDA installation directory. 
 For instance, download cudnn-10.0-windows10-x64-v7.6.5.32.zip from NVIDIA's official website, 
then, unzip it and copy it into C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0
You should do this according to your CUDA installation directory and CUDNN version.
Traceback (most recent call last):
    ...

    PreconditionNotMetError: The third-party dynamic library (cudnn64_8.dll) that Paddle depends on is not configured correctly. (error code is 126)
      Suggestions:
      1. Check if the third-party dynamic library (e.g. CUDA, CUDNN) is installed correctly and its version is matched with paddlepaddle you installed.
      2. Configure third-party dynamic library environment variables as follows:
      - Linux: set LD_LIBRARY_PATH by `export LD_LIBRARY_PATH=...`
      - Windows: set PATH by `set PATH=XXX; (at ..\paddle\phi\backends\dynload\dynamic_loader.cc:305)
      [operator < fill_constant > error]

Process finished with exit code 1

版本&环境信息 Version & Environment Information

PaddlePaddle-GPU版本: 2.4.2
GPU:CUDA 11.7,cuDNN 8.4.1
系统环境:Windows 10
Python版本:3.10

临时解决方案 Workaround

造成这个问题的原因在于paddlepaddle-gpu没有尝试在conda安装环境中寻找cudnn库。我尝试了一下,在Python程序中增加以下代码可以解决问题:

import os
import sys

cudnn_dir = os.path.join(os.path.dirname(sys.executable), r"Library\bin")

if cudnn_dir not in sys.path:
    os.environ["PATH"] = os.pathsep.join([os.environ["PATH"], cudnn_dir])
    sys.path.append(cudnn_dir)

使用conda安装时,每个conda环境中单独安装cudatoolkit,因此对应cudnn库的路径是不固定的,paddlepaddle-gpu启动程序应当尝试自动根据系统和安装环境信息寻找cudnn库。这里给出的临时解决方案只针对Windows + conda环境,若需要通用解决方案还需拓展到其它安装环境。

@ZOUG ZOUG added status/new-issue 新建 type/build 编译/安装问题 labels Apr 17, 2023
@ZOUG ZOUG changed the title Paddle-GPU安装后找不到cudnn库 paddlepaddle-gpu安装后找不到cudnn库 Apr 17, 2023
@winter-wang winter-wang added the type/enhancement 优化性建议 label Apr 18, 2023
@paddle-bot paddle-bot bot removed the type/build 编译/安装问题 label Apr 18, 2023
@winter-wang
Copy link
Contributor

你好,我们已经收到你的建议。我们会内部讨论是否需要提供通用解决方案。

@paddle-bot paddle-bot bot removed the status/new-issue 新建 label Apr 18, 2023
@zhwesky2010
Copy link
Contributor

@ZOUG 这个问题应该是conda安装的问题,没有将相应的安装信息添加到PATH环境变量里,可以手动在环境变量PATH里添加。或者重新安装conda时,勾选添加到系统环境变量相应的选项

@ZOUG
Copy link
Author

ZOUG commented Apr 20, 2023

@ZOUG 这个问题应该是conda安装的问题,没有将相应的安装信息添加到PATH环境变量里,可以手动在环境变量PATH里添加。或者重新安装conda时,勾选添加到系统环境变量相应的选项

@zhouwei25 我的主贴里特地强调了这个问题,你还是没理解。我举例详细说明一下吧。

假设我在Windows上安装了Anaconda,安装路径为D:\Software\Anaconda。那么conda可执行文件_conda.exe,以及conda的base环境默认会在这个目录下。如果在安装时添加环境变量,那么安装程序会将D:\Software\AnacondaD:\Software\Anaconda\Library\bin等目录添加到PATH环境变量中。

现在我要新建一个包含paddle的开发环境,起名为paddle1。我在conda命令行里执行conda create --name paddle1 paddlepaddle-gpu==2.4.2 cudatoolkit=11.2 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/Paddle/ -c conda-forge。这时候系统会将这个环境相关的文件都放在%USERPROFILE%\.conda\envs\paddle1\目录下。其中cudnn库的默认路径为%USERPROFILE%\.conda\envs\paddle1\Library\bin\cudnn64_8.dll因此,安装阶段添加的环境变量无法帮助找到cudnn库的正确位置!! 假如要让paddle正常运行,我必须人工将%USERPROFILE%\.conda\envs\paddle1\Library\bin加入PATH变量。

接下来,我因为开发需要又建立了一个包含paddle的环境,起名为paddle2。我执行conda create --name paddle2 paddlepaddle-gpu==2.4.2 cudatoolkit=11.2 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/Paddle/ -c conda-forge。那么,在这个环境里的cudnn库的默认路径是%USERPROFILE%\.conda\envs\paddle2\Library\bin\cudnn64_8.dll。这种情况下,假如%USERPROFILE%\.conda\envs\paddle1\Library\bin仍然在PATH变量里,那么paddle在启动时会去找paddle1环境里的cudnn64_8.dll,这是我们不希望看到的! 因为,这种情况下,我如果删除了paddle1环境,所有依赖于paddle的程序在paddle2环境里都无法执行了!!

再接下来,我因为开发需要又要新建一个包含paddle的环境,起名为paddle3。在这个环境里我需要安装其它工具包。由于兼容性要求,我必须要选择CUDA 10.2而不能选择CUDA 11.2。那么我会执行conda create --name paddle3 paddlepaddle-gpu==2.4.2 cudatoolkit=10.2 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/Paddle/ -c conda-forge。那么,在这个环境里的cudnn库的默认路径是%USERPROFILE%\.conda\envs\paddle3\Library\bin\cudnn64_7.dll。这种情况下,假如%USERPROFILE%\.conda\envs\paddle1\Library\bin仍然在PATH变量里,那么paddle在启动时会去paddle1环境里找cudnn64_7.dll,这也是我们不希望看到的! 因为,paddle1环境里安装的是cudnn 8,根本就没有cudnn 7!!

也就是说,一旦使用了conda,cudnn库的位置是不固定的。简单地往PATH变量里加一个固定的路径是无法解决问题的!! 必须在程序启动时根据运行环境动态找到正确的路径,把它加到当前程序的PATH变量里去(注意,这个操作只会改变当前程序的PATH变量,对其它程序没有影响),才能调用正确的cudnn库。

另外补充一句,%USERPROFILE%\.conda是系统默认的conda环境安装位置。由于conda环境占用硬盘空间巨大,如果我的系统盘不够用,是可以修改conda配置文件将环境路径设置到其它位置的,所以我在上面的临时解决方案程序里没有直接写死环境路径,而是通过当前启动的Python Interpreter路径sys.executable出发去找到正确cudnn库路径。

@waiwaic
Copy link

waiwaic commented Jun 25, 2023

使用宏变量

static constexpr char cuda_lib_path[] = CUDA_TOOLKIT_ROOT_DIR "/bin";

build时硬编码
if not defined CUDA_TOOLKIT_ROOT_DIR set CUDA_TOOLKIT_ROOT_DIR=C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2

应在运行时读取环境变量

@lai6964
Copy link

lai6964 commented Nov 23, 2023

ubuntu 系统有临时方案吗?大佬

Copy link

paddle-bot bot commented Nov 26, 2024

Since you haven't replied for more than a year, we have closed this issue/pr.
If the problem is not solved or there is a follow-up one, please reopen it at any time and we will continue to follow up.
由于您超过一年未回复,我们将关闭这个issue/pr。
若问题未解决或有后续问题,请随时重新打开,我们会继续跟进。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants