编译 Pytorch 时 Conda CMAKE CXX 编译器错误

问题描述 投票:0回答:1

我正在关注如何从源代码构建 PyTorch 以便安装 Pytorch,因为我的旧显卡仅支持 Cuda 11.4。我在 Conda 环境中工作。在最后阶段我收到以下错误。

Building wheel torch-2.4.0a0+git2b1ba0c
-- Building version 2.4.0a0+git2b1ba0c
cmake -GNinja -DBUILD_PYTHON=True -DBUILD_TEST=True -DCMAKE_ARGS=-DCMAKE_AR=/home/sinfinities/.conda/envs/StableD/bin/x86_64-conda-linux-gnu-ar -DCMAKE_CXX_COMPILER_AR=/home/sinfinities/.conda/envs/StableD/bin/x86_64-conda-linux-gnu-gcc-ar -DCMAKE_C_COMPILER_AR=/home/sinfinities/.conda/envs/StableD/bin/x86_64-conda-linux-gnu-gcc-ar -DCMAKE_RANLIB=/home/sinfinities/.conda/envs/StableD/bin/x86_64-conda-linux-gnu-ranlib -DCMAKE_CXX_COMPILER_RANLIB=/home/sinfinities/.conda/envs/StableD/bin/x86_64-conda-linux-gnu-gcc-ranlib -DCMAKE_C_COMPILER_RANLIB=/home/sinfinities/.conda/envs/StableD/bin/x86_64-conda-linux-gnu-gcc-ranlib -DCMAKE_LINKER=/home/sinfinities/.conda/envs/StableD/bin/x86_64-conda-linux-gnu-ld -DCMAKE_STRIP=/home/sinfinities/.conda/envs/StableD/bin/x86_64-conda-linux-gnu-strip -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/home/sinfinities/Downloads/pytorch/torch -DCMAKE_PREFIX_PATH=/home/sinfinities/.conda/envs/StableD/lib/python3.12/site-packages;/home/sinfinities/.conda/envs/StableD:/home/sinfinities/.conda/envs/StableD/x86_64-conda-linux-gnu/sysroot/usr -DNUMPY_INCLUDE_DIR=/home/sinfinities/.conda/envs/StableD/lib/python3.12/site-packages/numpy/core/include -DPYTHON_EXECUTABLE=/home/sinfinities/.conda/envs/StableD/bin/python -DPYTHON_INCLUDE_DIR=/home/sinfinities/.conda/envs/StableD/include/python3.12 -DPYTHON_LIBRARY=/home/sinfinities/.conda/envs/StableD/lib/libpython3.12.a -DTORCH_BUILD_VERSION=2.4.0a0+git2b1ba0c -DUSE_NUMPY=True /home/sinfinities/Downloads/pytorch
-- The CXX compiler identification is GNU 9.5.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: /home/sinfinities/.conda/envs/StableD/bin/c++
-- Check for working CXX compiler: /home/sinfinities/.conda/envs/StableD/bin/c++ - broken
CMake Error at /home/sinfinities/.conda/envs/StableD/share/cmake-3.26/Modules/CMakeTestCXXCompiler.cmake:60 (message):
  The C++ compiler

    "/home/sinfinities/.conda/envs/StableD/bin/c++"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/sinfinities/Downloads/pytorch/build/CMakeFiles/CMakeScratch/TryCompile-tQ7Kro
    
    Run Build Command(s):/home/sinfinities/.conda/envs/StableD/bin/ninja -v cmTC_6d41d && [1/2] /home/sinfinities/.conda/envs/StableD/bin/c++    -o CMakeFiles/cmTC_6d41d.dir/testCXXCompiler.cxx.o -c /home/sinfinities/Downloads/pytorch/build/CMakeFiles/CMakeScratch/TryCompile-tQ7Kro/testCXXCompiler.cxx
    [2/2] : && /home/sinfinities/.conda/envs/StableD/bin/c++   CMakeFiles/cmTC_6d41d.dir/testCXXCompiler.cxx.o -o cmTC_6d41d   && :
    FAILED: cmTC_6d41d 
    : && /home/sinfinities/.conda/envs/StableD/bin/c++   CMakeFiles/cmTC_6d41d.dir/testCXXCompiler.cxx.o -o cmTC_6d41d   && :
    /home/sinfinities/.conda/envs/StableD/bin/../lib/gcc/x86_64-conda-linux-gnu/9.5.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/sinfinities/.conda/envs/StableD/bin/../lib/gcc/x86_64-conda-linux-gnu/9.5.0/libstdc++.so: undefined reference to `memcpy@GLIBC_2.14'
    /home/sinfinities/.conda/envs/StableD/bin/../lib/gcc/x86_64-conda-linux-gnu/9.5.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/sinfinities/.conda/envs/StableD/bin/../lib/gcc/x86_64-conda-linux-gnu/9.5.0/libstdc++.so: undefined reference to `aligned_alloc@GLIBC_2.16'
    /home/sinfinities/.conda/envs/StableD/bin/../lib/gcc/x86_64-conda-linux-gnu/9.5.0/../../../../x86_64-conda-linux-gnu/bin/ld: /home/sinfinities/.conda/envs/StableD/bin/../lib/gcc/x86_64-conda-linux-gnu/9.5.0/libstdc++.so: undefined reference to `clock_gettime@GLIBC_2.17'
    collect2: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    
    

  

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:29 (project)

我的 nvidia-smi 输出是

Sun Mar 31 22:59:04 2024       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 470.223.02   Driver Version: 470.223.02   CUDA Version: 11.4     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ...  Off  | 00000000:01:00.0 N/A |                  N/A |
| 33%   43C    P8    N/A /  N/A |     53MiB /  1999MiB |     N/A      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

nvcc --版本

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Wed_Jun__2_19:15:15_PDT_2021
Cuda compilation tools, release 11.4, V11.4.48
Build cuda_11.4.r11.4/compiler.30033411_0

gcc --版本

gcc (conda-forge gcc 9.5.0-17) 9.5.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

c++ --版本

c++ (conda-forge gcc 9.5.0-17) 9.5.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

我一直在反复思考这个问题,但不知道如何解决它。任何指导将不胜感激。

c++ cmake pytorch conda
1个回答
0
投票

在 @AlanBirtles 发表宝贵评论后,很明显问题出在 GLIBC 或 Libc 中。 在我用头撞墙一天后,我发现这是我需要做的一个愚蠢的改变。 让我提供完整的说明,以防像我这样的人被旧 GPU 困住。

您可以在 Conda 环境中安装整个东西。只需先安装 Nvidia 驱动程序即可运行

nvidia-smi 

并获得正确的输出。他们一步步运行以下命令。对我来说,我的 GPU 最大支持 Cuda 11.4 和 Cudnn 8.2。在 pythorch 论坛上我可以找到此规范将支持 Pytorch 2.1 因此,您可以根据您的规范制作 chanes。

conda create --name StableDiffusion
conda activate StableDiffusion
conda config --set channel_priority flexible
conda install nvidia/label/cuda-11.4.0::cuda-toolkit
conda install anaconda::cudnn=8.2
conda list cudnn
nvcc --version
nvidia-smi

conda install python-3.9
conda install conda-forge::gxx=9.5
conda install conda-forge::sysroot_linux-64=2.28

conda install cmake ninja
conda install intel::mkl-static intel::mkl-include
conda install -c pytorch magma-cuda113

git clone --recursive --branch v2.0.1 https://github.com/pytorch/pytorch
cd pytorch
pip install -r requirements.txt
git submodule sync
git submodule update --init --recursive
export _GLIBCXX_USE_CXX11_ABI=1
export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname $(which conda))/../"}
python setup.py install

如果你只是想知道我在哪里犯了错误,我是通过

安装GLIBC的
conda install conda-forge::sysroot_linux-64

安装 LIBC 2.14 将其更改为

conda install conda-forge::sysroot_linux-64=2.28

安装 LIBC 2.28

© www.soinside.com 2019 - 2024. All rights reserved.