xmrig / xmrig-cuda

NVIDIA CUDA plugin for XMRig miner
GNU General Public License v3.0
368 stars 155 forks source link

Linux build fails with GCC 10.3.0 (compiler bug) #138

Open f-fusco opened 2 years ago

f-fusco commented 2 years ago

Not related to xmrig-cuda per se but it's worth pointing out for people like me that have to go through the error-prone process of building from source.

A workaround is to compile with GCC 9:

cmake -DCMAKE_C_COMPILER=gcc-9 -DCMAKE_CXX_COMPILER=g++-9 -DCUDA_TOOLKIT_ROOT_DIR="/usr/lib/cuda" .
cmake --build .

Same issue in another repo: https://github.com/kokkos/kokkos/issues/4334

Craftit7 commented 2 years ago

That didn't work for me though. Err:-

CMake Error at CMakeLists.txt:2 (project):
  The CMAKE_C_COMPILER:

    gcc-9

  is not a full path and was not found in the PATH.

  Tell CMake where to find the compiler by setting either the environment
  variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
  the compiler, or to the compiler name if it is in the PATH.

CMake Error at CMakeLists.txt:2 (project):
  The CMAKE_CXX_COMPILER:

    g++-9

  is not a full path and was not found in the PATH.

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.
f-fusco commented 2 years ago

Of course you need to have gcc 9 installed in your system for this to work. You can also try clang alternatively.

Spudz76 commented 2 years ago

@TeamRazen you have to have g++-9 package installed for it to be available...

CUDA Toolkit always has specific compiler requirements, which is the whole reason it's a plugin. So you can use the old garbage CUDA requires for the CUDA parts, while also compiling the main miner with a legitimate current compiler.

CUDA Toolkits before 11.4.1 did not support newer than gcc-9.

You can find the supported maximum gcc version listed in the Installation Guide for Linux within the versioned documentation of each release. That is how I just went back and found where the docs said gcc-9 and then at 11.4.1 it jumps ahead to gcc-11. If you are using an older CUDA due to an older GPU family (Fermi/Kepler) being unsupported in newer toolkits then you are limited by what the maximum compiler was "back then". CUDA 8.0GA2 requires gcc-5 for example.

Craftit7 commented 2 years ago

Thanks for the help, anyways, I fixed my install with just adding #include <cstddef> to the Algorithms.h

Spudz76 commented 2 years ago

That is also pending merge in #120

DeeDeeRanged commented 2 years ago

I am running Debian testing (bookworm) and is already gcc 12 although I have gcc 9/10/11 also still installed, so I was able to compile with -DCMAKE_C_COMPILER=gcc-10 -DCMAKE_CXX_COMPILER=g++-10 Is this already merged in the dev branch for gcc 11?

Never mind I see #include is already added

metal3d commented 1 year ago

For those who have the same problem, there is a solution to install (non-destructive) older versions of tools like GCC.

The solution I use is "Spack".

# install spack in local directory
mkdir -p ~/.local/share
git clone -c feature.manyFiles=true https://github.com/spack/spack.git ~/.local/share/spack

# type this, you can also add this in your bashrc or bashrc.d 
source ~/.local/share/spack/share/spack/setup-env.sh

# now, spack command exists, install gcc@11
# because the build is a bit heavy, change your TMPDIR to not fill your RAM
TMPDIR=/var/tmp spack install gcc@11

# it takes a long time...

# then, when you need to use gcc v11, you can type (session)
spack load gcc@11

# Then build the plugin
git clone git@github.com:xmrig/xmrig-cuda.git
cd xmrig-cuda
mkdir build
cd build
cmake .. && make

This works on Fedora 38.

xmg333 commented 10 months ago

Due to the Kepler arch's support are dropped in CUDA 12.x (which is compute_35 I believe), just remove these flags in cmake file. Following is what I did to my /cmake/CUDA.cmake file. And it do work.

set(DEFAULT_CUDA_ARCH "75")

# Fermi GPUs are only supported with CUDA < 9.0
#if (CUDA_VERSION VERSION_LESS 9.0)
        #    list(APPEND DEFAULT_CUDA_ARCH "20;21")
    #endif()

# Kepler GPUs are only supported with CUDA < 11.0
#if (CUDA_VERSION VERSION_LESS 11.0)
        #list(APPEND DEFAULT_CUDA_ARCH "30")
    #else()
        #list(APPEND DEFAULT_CUDA_ARCH "35")
    #endif()

# add Pascal support for CUDA >= 8.0
#if (NOT CUDA_VERSION VERSION_LESS 8.0)
#    list(APPEND DEFAULT_CUDA_ARCH "60")
#endif()

# add Volta support for CUDA >= 9.0
#if (NOT CUDA_VERSION VERSION_LESS 9.0)
#    list(APPEND DEFAULT_CUDA_ARCH "70")
#endif()

# add Turing support for CUDA >= 10.0
if (NOT CUDA_VERSION VERSION_LESS 10.0)
    list(APPEND DEFAULT_CUDA_ARCH "75")
endif()

# add Ampere support for CUDA >= 11.0
if (NOT CUDA_VERSION VERSION_LESS 11.0)
    list(APPEND DEFAULT_CUDA_ARCH "80")
endif()
list(SORT DEFAULT_CUDA_ARCH)

BTW, I'm using fedora39, and it has gcc13 by default which is not supported by nvcc. I added set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}" -allow-unsupported-compiler) in the same file to by pass the error.

yhilgjff commented 7 months ago

For those who have the same problem, there is a solution to install (non-destructive) older versions of tools like GCC.

The solution I use is "Spack".

# install spack in local directory
mkdir -p ~/.local/share
git clone -c feature.manyFiles=true https://github.com/spack/spack.git ~/.local/share/spack

# type this, you can also add this in your bashrc or bashrc.d 
source ~/.local/share/spack/share/spack/setup-env.sh

# now, spack command exists, install gcc@11
# because the build is a bit heavy, change your TMPDIR to not fill your RAM
TMPDIR=/var/tmp spack install gcc@11

# it takes a long time...

# then, when you need to use gcc v11, you can type (session)
spack load gcc@11

# Then build the plugin
git clone git@github.com:xmrig/xmrig-cuda.git
cd xmrig-cuda
mkdir build
cd build
cmake .. && make

This works on Fedora 38.

After following all of this, it ended up not working with debian bookworm. Rest is in https://github.com/xmrig/xmrig-nvidia/issues/348