mmp / pbrt-v4

Source code to pbrt, the ray tracer described in the forthcoming 4th edition of the "Physically Based Rendering: From Theory to Implementation" book.
https://pbrt.org
Apache License 2.0
2.8k stars 429 forks source link

How to set the CMAKE_CUDA_ARCHITECTURES value? nvcc fatal : Option '--ptx (-ptx)' is not allowed when compiling for multiple GPU architectures #374

Closed disini closed 1 year ago

disini commented 1 year ago

Hi Mr. Pharr,

Thank you so much for your timely replies!

after some modifies on the CMakeLists.txt, the cmake passed almostly:

- OpenEXR at commit: 5cfb5dab6dfada731586b0281bdb15ee75e26782
-- OpenVDB at commit: 414bed84c2fc22e188eac7b611aa85c7edd7a5a9
-- Ptex at commit: 4cd8e9a6db2b06e478dfbbd8c26eb6df97f84483
-- double-conversion at commit: cc1f75a114aca8d2af69f73a5a959aecbab0e87a
-- filesystem at commit: c5f9de30142453eb3c6fe991e82dfc2583373116
-- glfw at commit: 4cb36872a5fe448c205d0b46f0e8c8b57530cfe0
-- libdeflate at commit: 1fd0bea6ca2073c68493632dafc4b1ddda1bcbc3
-- lodepng at commit: 8c6a9e30576f07bf470ad6f09458a2dcd7a6a84a
-- qoi at commit: 028c75fd26e5e0758c7c711216c00404994c1ad3
-- stb at commit: af1a5bc352164740c1cc1354942b1c6b72eacb8a
-- utf8proc at commit: 2484e2ed5e1d9c19edcccf392a7d9920ad90dfaf
-- zlib at commit: 54d591eabf9fe0e84c725638f8d5d8d202a093fa
-- Found OpenEXR version 3.2.0
CMake Deprecation Warning at src/ext/double-conversion/CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

CMake Deprecation Warning at src/ext/utf8proc/CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

-- Including X11 support
-- Found -lprofiler: /usr/lib/x86_64-linux-gnu/libprofiler.so
-- Found CUDA: 12.2.91
-- Detected CUDA Architecture: sm_61
-- Configuring done (2.4s)
-- Generating done (1.0s)
-- Build files have been written to: /media/liusheng/Projects/project/game_engines/pbrt/github/mmp/pbrt-v4/2023/20230717_clone/build_ubuntu/release

but it still has some warnings:

CMake Warning (dev) in CMakeLists.txt:
  Policy CMP0104 is not set: CMAKE_CUDA_ARCHITECTURES now detected for NVCC,
  empty CUDA_ARCHITECTURES not allowed.  Run "cmake --help-policy CMP0104"
  for policy details.  Use the cmake_policy command to set the policy and
  suppress this warning.

  CUDA_ARCHITECTURES is empty for target "optix.cu".
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) in CMakeLists.txt:
  Policy CMP0104 is not set: CMAKE_CUDA_ARCHITECTURES now detected for NVCC,
  empty CUDA_ARCHITECTURES not allowed.  Run "cmake --help-policy CMP0104"
  for policy details.  Use the cmake_policy command to set the policy and
  suppress this warning.

  CUDA_ARCHITECTURES is empty for target "pbrt_lib".
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) in CMakeLists.txt:
  Policy CMP0104 is not set: CMAKE_CUDA_ARCHITECTURES now detected for NVCC,
  empty CUDA_ARCHITECTURES not allowed.  Run "cmake --help-policy CMP0104"
  for policy details.  Use the cmake_policy command to set the policy and
  suppress this warning.

  CUDA_ARCHITECTURES is empty for target "pbrt_lib".
This warning is for project developers.  Use -Wno-dev to suppress it.

I tried to do make on this result, but the binaries that it maked can't using gpu.


Then I searched for a while, and someone suggests to add the follows :

if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
   set(CMAKE_CUDA_ARCHITECTURES "60")
endif(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)

then I try to make the project again, and it says:

nvcc fatal : Option '--ptx (-ptx)' is not allowed when compiling for multiple GPU architectures

[ 31%] Built target glfw
[ 31%] Building CXX object src/ext/ptex/src/tests/CMakeFiles/rtest.dir/rtest.cpp.o
[ 31%] Building CXX object src/ext/ptex/src/tests/CMakeFiles/halftest.dir/halftest.cpp.o
[ 31%] Building CXX object src/ext/ptex/src/utils/CMakeFiles/ptxinfo.dir/ptxinfo.cpp.o
[ 32%] Generating rgbspectrum_aces.cpp
[ 32%] Building CXX object src/ext/ptex/src/tests/CMakeFiles/ftest.dir/ftest.cpp.o
[ 32%] Building CXX object src/ext/ptex/src/tests/CMakeFiles/wtest.dir/wtest.cpp.o
Optimizing ACES2065_1 spectra...
[ 32%] Building CXX object src/ext/double-conversion/test/cctest/CMakeFiles/cctest.dir/gay-fixed.cc.o
[ 33%] Building CUDA object CMakeFiles/optix.cu.dir/src/pbrt/gpu/optix.ptx
nvcc fatal   : Option '--ptx (-ptx)' is not allowed when compiling for multiple GPU architectures
make[2]: *** [CMakeFiles/optix.cu.dir/build.make:77: CMakeFiles/optix.cu.dir/src/pbrt/gpu/optix.ptx] Error 1
make[1]: *** [CMakeFiles/Makefile2:385: CMakeFiles/optix.cu.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 34%] Building CXX object src/ext/double-conversion/test/cctest/CMakeFiles/cctest.dir/gay-precision.cc.o
[ 35%] Linking CXX executable ftest
[ 35%] Built target ftest

Then I checked the cmake log before , I found the line it output: -- Detected CUDA Architecture: sm_61

so I tried to replace the value with it instead of 60:

if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
   set(CMAKE_CUDA_ARCHITECTURES " sm_61")
endif(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)

and did the cmake and make again :

the cmake passed as before:

untu/release$ cmake ../../
-- OpenEXR at commit: 5cfb5dab6dfada731586b0281bdb15ee75e26782
-- OpenVDB at commit: 414bed84c2fc22e188eac7b611aa85c7edd7a5a9
-- Ptex at commit: 4cd8e9a6db2b06e478dfbbd8c26eb6df97f84483
-- double-conversion at commit: cc1f75a114aca8d2af69f73a5a959aecbab0e87a
-- filesystem at commit: c5f9de30142453eb3c6fe991e82dfc2583373116
-- glfw at commit: 4cb36872a5fe448c205d0b46f0e8c8b57530cfe0
-- libdeflate at commit: 1fd0bea6ca2073c68493632dafc4b1ddda1bcbc3
-- lodepng at commit: 8c6a9e30576f07bf470ad6f09458a2dcd7a6a84a
-- qoi at commit: 028c75fd26e5e0758c7c711216c00404994c1ad3
-- stb at commit: af1a5bc352164740c1cc1354942b1c6b72eacb8a
-- utf8proc at commit: 2484e2ed5e1d9c19edcccf392a7d9920ad90dfaf
-- zlib at commit: 54d591eabf9fe0e84c725638f8d5d8d202a093fa
-- Found OpenEXR version 3.2.0
CMake Deprecation Warning at src/ext/double-conversion/CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

CMake Deprecation Warning at src/ext/utf8proc/CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

-- Including X11 support
-- Found -lprofiler: /usr/lib/x86_64-linux-gnu/libprofiler.so
-- Found CUDA: 12.2.91
-- Detected CUDA Architecture: sm_61
-- Configuring done (2.3s)
-- Generating done (0.9s)
-- Build files have been written to: /media/liusheng/Projects/project/game_engines/pbrt/github/mmp/pbrt-v4/2023/20230717_clone/build_ubuntu/release

but on the make stage it gives some errors:

[ 32%] Building CUDA object CMakeFiles/optix.cu.dir/src/pbrt/gpu/optix.ptx
nvcc fatal   : Unsupported gpu architecture 'compute_sm_61'
make[2]: *** [CMakeFiles/optix.cu.dir/build.make:77: CMakeFiles/optix.cu.dir/src/pbrt/gpu/optix.ptx] Error 1
make[1]: *** [CMakeFiles/Makefile2:385: CMakeFiles/optix.cu.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 33%] Built target ftest
[ 34%] Built target wtest
[ 35%] Built target ptxinfo
[ 36%] Built target rtest
[ 43%] Built target cctest
[ 43%] Building CXX object CMakeFiles/pbrt_lib.dir/rgbspectrum_dci_p3.cpp.o
[ 43%] Building CXX object CMakeFiles/pbrt_lib.dir/rgbspectrum_srgb.cpp.o
[ 43%] Building CXX object CMakeFiles/pbrt_lib.dir/rgbspectrum_aces.cpp.o
[ 44%] Building CXX object CMakeFiles/pbrt_lib.dir/rgbspectrum_rec2020.cpp.o
[ 45%] Building CUDA object CMakeFiles/pbrt_lib.dir/src/pbrt/bsdf.cpp.o
[ 46%] Building CUDA object CMakeFiles/pbrt_lib.dir/src/pbrt/bxdfs.cpp.o
[ 46%] Building CUDA object CMakeFiles/pbrt_lib.dir/src/pbrt/bssrdf.cpp.o
nvcc fatal   : Unsupported gpu architecture 'compute_sm_61'
make[2]: *** [CMakeFiles/pbrt_lib.dir/build.make:159: CMakeFiles/pbrt_lib.dir/src/pbrt/bsdf.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
[ 46%] Building CUDA object CMakeFiles/pbrt_lib.dir/src/pbrt/cameras.cpp.o
nvcc fatal   : Unsupported gpu architecture 'compute_sm_61'
make[2]: *** [CMakeFiles/pbrt_lib.dir/build.make:189: CMakeFiles/pbrt_lib.dir/src/pbrt/bxdfs.cpp.o] Error 1
nvcc fatal   : Unsupported gpu architecture 'compute_sm_61'
make[2]: *** [CMakeFiles/pbrt_lib.dir/build.make:174: CMakeFiles/pbrt_lib.dir/src/pbrt/bssrdf.cpp.o] Error 1
nvcc fatal   : Unsupported gpu architecture 'compute_sm_61'
make[2]: *** [CMakeFiles/pbrt_lib.dir/build.make:204: CMakeFiles/pbrt_lib.dir/src/pbrt/cameras.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:465: CMakeFiles/pbrt_lib.dir/all] Error 2
make: *** [Makefile:146: all] Error 2

so , how should I set the CMAKE_CUDA_ARCHITECTURES value? Many thanks!

disini commented 1 year ago

My OS is UBUNTU 22.04.2, with cuda 12.2 and optix 7.7, and using a intel 6700k cpu and gtx 1070 gpu.

pierremoreau commented 1 year ago

Try without the "sm_" prefix, i.e.

if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
   set(CMAKE_CUDA_ARCHITECTURES 61)
endif(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)

Alternatively, if you are using CMake >= 3.20, you could define the environment variable before configuring the project with CMake CUDAARCHS=61, or passing -DCMAKE_CUDA_ARCHITURES=61 to the cmake command (if invoking on the command-line).

If you are using CMake 3.18, the best might be to call cmake_policy(SET CMP0104 NEW), so that the default behaviour is for CMAKE_CUDA_ARCHITURES to be initialised with the GPU architectures CUDA found in your computer.

disini commented 1 year ago

Try without the "sm_" prefix, i.e.

if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
   set(CMAKE_CUDA_ARCHITECTURES 61)
endif(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)

Alternatively, if you are using CMake >= 3.20, you could define the environment variable before configuring the project with CMake CUDAARCHS=61, or passing -DCMAKE_CUDA_ARCHITURES=61 to the cmake command (if invoking on the command-line).

If you are using CMake 3.18, the best might be to call cmake_policy(SET CMP0104 NEW), so that the default behaviour is for CMAKE_CUDA_ARCHITURES to be initialised with the GPU architectures CUDA found in your computer.

Much Appreciated! It works now! Thank you sir!