Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Last active January 24, 2024 11:22
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save unitycoder/7e59247ad0f36f77bc8402cd9a22d4fb to your computer and use it in GitHub Desktop.
Save unitycoder/7e59247ad0f36f77bc8402cd9a22d4fb to your computer and use it in GitHub Desktop.
How to compile Nvidia NeRF (NVlabs / instant-ngp) on Windows 10 and VS 2019

NeRF

Repo: https://github.com/NVlabs/instant-ngp

Steps (see their readme also)

IMPORTANT NOTES

  • Install all tools into default locations and everything is 100x easier! (vs, cuda, cmake..) *most of these errors happened before i did that
  • 2022 is not supportet yet, NVlabs/instant-ngp#132 (comment)
  • VS2019 requires desktop development with c++
  • VCTargetsPath REQUIRES backslash in the end: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\

ERRORS

> cmake . -B build

CMake 3.18 or higher is required. You are running version 3.15.5 Update cmake from https://cmake.org/download/

CMake Error at CMakeLists.txt:11 (project): Failed to run MSBuild command: C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/MSBuild/Current/Bin/MSBuild.exe, to get the value of VCTargetsPath, The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Microsoft\VC\v160\Microsoft.Cpp.Default.props" was not found, Failed to run MSBuild command:d:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe to get the value of VCTargetsPath:

echo %VCTargetsPath% shows wrong path. props path: (but doesnt fix error) D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.Cpp.Default.props Cleaned up PATH variables (some duplicates and too many and many broken paths)

NOTE: wrong msbuild version is runned, 2022, even though where msbuild returns 2019 C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\vsdevcmd\core msbuild.bat

Solution: 2019 didnt have c++ tools intalled! even though the msbuild folder was there..?

Random fix test, path had extra \ coming from this screen: (this fix not needed in the end?) @REM Add path to MSBuild Binaries @REM if exist "%VSINSTALLDIR%\MSBuild\Current\Bin" ( if exist "%VSINSTALLDIR%MSBuild\Current\Bin" ( @REM set "PATH=%VSINSTALLDIR%\MSBuild\Current\Bin;%PATH%" set "PATH=%VSINSTALLDIR%MSBuild\Current\Bin;%PATH%" ) else ( set /A __VSCMD_msbuild_failcount=__VSCMD_msbuild_failcount+1 )

E:\apps\NeRF\instant-ngp\build\CMakeFiles\3.23.2\VCTargetsPath.vcxproj(15,2): error MSB4102: The value ""D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160"\Microsoft.Cpp.Default.props" of the "Project" attribute in element is invalid. Illegal characters in path.

this fails: set VCTargetsPath=D:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Microsoft/VC/v160 this works: (backslash!) set VCTargetsPath=D:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Microsoft/VC/v160/ set VCTargetsPath=C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Microsoft/VC/v160/ set VCTargetsPath=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\

env var was missing backslash: D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160

> cmake . -B build, CMake Error at CMakeLists.txt:11 (project): Generator Visual Studio 16 2019 could not find specified instance of Visual Studio: d:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise

delete build/ folder, it was generated when had that version installed?

"D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" The input line is too long. The syntax of the command is incorrect.

In my case it was caused by the PATH environment variable being too long. The errors were solved after removing some unnecessary lines from PATH. https://intellij-support.jetbrains.com/hc/en-us/community/posts/360009001580-I-can-not-build-CUDA-project

No CUDA toolset found.

install cuda, i used 11.4

-- The CUDA compiler identification is unknown, Failed to detect a default CUDA architecture.

(doesnt fix it) set TCNN_CUDA_ARCHITECTURES=86 delete old build/ folder (but doesnt fix it)

if added "set TCNN_CUDA_ARCHITECTURES=86", then error "CMAKE_CUDA_ARCHITECTURES must be valid if set"

delete old build/ folder (but doesnt fix it) install older version of CMAKE 3.22.5

No CMAKE_CUDA_COMPILER could be found

copying these files from extracked cuda installer temp folder didnt help, and the files were already there mitsuba-renderer/mitsuba2#103 (comment)

add this to CMakeList.txt

set(CMAKE_CUDA_COMPILER "D:/sdk/CUDA/bin/")

CUDA_ARCHITECTURES is empty for target "cmTC_5d02e"

downgrade to cmake 3.21, doesnt help

"I managed to correct this issue by fully uninstalling Visual Studio and CUDA and reinstalling both on the system drive without changing the installation path" NVlabs/instant-ngp#461 (comment) *im using d: drive path

add: set(TCNN_CUDA_ARCHITECTURES "86") set(CUDA_ARCHITECTURES "86") set(CMAKE_CUDA_ARCHITECTURES "86") set(CudaToolkitDir "D:/sdk/CUDA/")

D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\BuildCustomizations\CUDA 11.7.targets(611,9): error : The CUDA Toolkit v11.7 directory '' does not exist. Please verify the CUDA Toolkit is installed properly or define the CudaToolkitDir property to resolve this error

these variables are empty? since the props was copied from temp, not yet set? Text="CudaToolkitDir : '$(CudaToolkitDir)'" />

if set in cmd, set CudaToolkitDir="D:/sdk/CUDA/bin/" then other errors

can set it manually in cmake.txt, but then error:

v160\Microsoft.CppBuild.targets(455,5): error MSB8052: MSVC Toolset Version '14.32.31326' is not compatible with 'v142' Platform Toolset. Please either change Platform Toolset to v143 or MSVC Toolset Version (VCToolsVersion property) to the version with the format '14.2*.*'. To use default MSVC Toolset Version for a given Platform Toolset don't set VCToolsVersion property

note its wrong msbuild, Failed to run MSBuild command: d:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe to get the value of VCTargetsPath:

(after installed c++ tools for 2022, so uninstall it again)

after remove c++ tools from 2022, could not find specified instance of Visual Studio: d:/Program Files/Microsoft Visual Studio/2022/Community

delete build folder

E:\apps\NeRF\instant-ngp\build\CMakeFiles\3.21.0\CompilerIdCUDA>"D:/sdk/CUDA/bin\bin\nvcc.exe" -gencode=arch=compute_86,code="sm_86,compute_86" --use-local-env -ccbin "d:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64" -x cu -ID:/sdk/CUDA/bin\include -ID:/sdk/CUDA/bin\include -G --keep-dir x64\Debug -maxrregcount=0 --machine 64 --compile -cudart static -v -g -D_MBCS -Xcompiler "/EHsc /W0 /nologo /Od /FdDebug\vc142.pdb /FS /Zi /RTC1 /MDd " -o E:\apps\NeRF\instant-ngp\build\CMakeFiles\3.21.0\CompilerIdCUDA\x64\Debug\CMakeCUDACompilerId.cu.obj "E:\apps\NeRF\instant-ngp\build\CMakeFiles\3.21.0\CompilerIdCUDA\CMakeCUDACompilerId.cu"

The system cannot find the path specified.

note double BIN in filepath, remove that from: set CudaToolkitDir="D:/sdk/CUDA/bin/" after that build works?

cmake --build build --config RelWithDebInfo -j 16

nvcc fatal : Could not set up the environment for Microsoft Visual Studio using 'd:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/../../../../../../../VC/Auxiliary/Build/vcvars64.bat' D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\BuildCustomizations\CUDA 11.7.targets(879,9): error MSB3721: The command ""D:/sdk/CUDA\bin\nvcc.exe" -dlink -o ngp.dir\RelWithDebInfo\ngp.device-link.obj -Xcompiler "/EHs c /W1 /nologo /O2 /FdE:\apps\NeRF\instant-ngp\build\RelWithDebInfo\ngp.pdb /Zi /MD /GR" -LD:/sdk/CUDA\bin/crt -LD:/sdk/CUDA\lib\x64 dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\context.obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\init. obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\input.obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\monitor.obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\vulkan.obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\windo w.obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\win32_init.obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\win32_joystick.obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\win32_monitor.obj dependencies\glfw\src\glfw_objects.dir \RelWithDebInfo\win32_time.obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\win32_thread.obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\win32_window.obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\wgl_context.obj dependencies\gl fw\src\glfw_objects.dir\RelWithDebInfo\egl_context.obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\osmesa_context.obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\glfw.res opengl32.lib "dependencies\tiny-cuda-nn\RelWithDebInfo\tiny-cuda-nn .lib" cuda.lib cublas.lib cudadevrt.lib cudart.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib -forward-unknown-to-host-compiler -Wno-deprecated-gpu-targets -ge ncode=arch=compute_86,code=compute_86 -gencode=arch=compute_86,code=sm_86 --machine 64 ngp.dir\RelWithDebInfo\camera_path.obj ngp.dir\RelWithDebInfo\common_device.obj ngp.dir\RelWithDebInfo\marching_cubes.obj ngp.dir\RelWithDebInfo\nerf_loader.obj ngp.dir\R elWithDebInfo\render_buffer.obj ngp.dir\RelWithDebInfo\testbed.obj ngp.dir\RelWithDebInfo\testbed_image.obj ngp.dir\RelWithDebInfo\testbed_nerf.obj ngp.dir\RelWithDebInfo\testbed_sdf.obj ngp.dir\RelWithDebInfo\testbed_volume.obj ngp.dir\RelWithDebInfo\tinyex r_wrapper.obj ngp.dir\RelWithDebInfo\triangle_bvh.obj" exited with code 1. [E:\apps\NeRF\instant-ngp\build\ngp.vcxproj]

note: error MSB3721: The command ""D:/sdk/CUDA\bin\nvcc.exe" double "" ?

https://stackoverflow.com/a/56416687

run manually, new error: "D:/sdk/CUDA/bin\nvcc.exe" -dlink -o ngp.dir\RelWithDebInfo\ngp.device-link.obj -Xcompiler "/EHsc /W1 /nologo /O2 /FdE:\apps\NeRF\instant-ngp\build\RelWithDebInfo\ngp.pdb /Zi /MD /GR" -LD:/sdk/CUDA/bin/crt -LD:/sdk/CUDA/lib\x64 dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\context.obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\init.obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\input.obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\monitor.obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\vulkan.obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\window.obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\win32_init.obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\win32_joystick.obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\win32_monitor.obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\win32_time.obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\win32_thread.obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\win32_window.obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\wgl_context.obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\egl_context.obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\osmesa_context.obj dependencies\glfw\src\glfw_objects.dir\RelWithDebInfo\glfw.res opengl32.lib "dependencies\tiny-cuda-nn\RelWithDebInfo\tiny-cuda-nn.lib" cuda.lib cublas.lib cudadevrt.lib cudart.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib -forward-unknown-to-host-compiler -Wno-deprecated-gpu-targets -gencode=arch=compute_86,code=compute_86 -gencode=arch=compute_86,code=sm_86 --machine 64 ngp.dir\RelWithDebInfo\camera_path.obj ngp.dir\RelWithDebInfo\common_device.obj ngp.dir\RelWithDebInfo\marching_cubes.obj ngp.dir\RelWithDebInfo\nerf_loader.obj ngp.dir\RelWithDebInfo\render_buffer.obj ngp.dir\RelWithDebInfo\testbed.obj ngp.dir\RelWithDebInfo\testbed_image.obj ngp.dir\RelWithDebInfo\testbed_nerf.obj ngp.dir\RelWithDebInfo\testbed_sdf.obj ngp.dir\RelWithDebInfo\testbed_volume.obj ngp.dir\RelWithDebInfo\tinyexr_wrapper.obj ngp.dir\RelWithDebInfo\triangle_bvh.obj

nvlink fatal : Could not open input file 'dependencies/glfw/src/glfw_objects.dir/RelWithDebInfo/context.obj'

??? downgraded cuda..

during j16 build, tiny-cuda-nn\include\tiny-cuda-nn/optimizers/shampoo.h(484): error : identifier "cublasComputeType_t" is undefined [E:\apps\NeRF\instant-ngp\build\dependencies\tiny-cuda-nn\tiny-cuda-nn.vcxproj]

D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\BuildCustomizations\CUDA 11.7.targets(790,9): error MSB3721: The command ""D:/sdk/CUDA/bin\nvcc.exe" -gencode=arch=compute_86,code="compute_86,compute_86" -gencode=arch

=compute_86,code="sm_86,compute_86" --use-local-env -ccbin "d:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64" -x cu -I"E:\apps\NeRF\instant-ngp\dependencies\tiny-cuda-nn\include" -I"E:\apps\NeRF\inst ant-ngp\dependencies\tiny-cuda-nn\dependencies" -I"E:\apps\NeRF\instant-ngp\dependencies\tiny-cuda-nn\dependencies\cutlass\include" -I"E:\apps\NeRF\instant-ngp\dependencies\tiny-cuda-nn\dependencies\cutlass\tools\util\include" -ID:/sdk/CUDA/include --kee p-dir x64\RelWithDebInfo -maxrregcount=0 --machine 64 --compile -cudart shared --extended-lambda --expt-relaxed-constexpr -std=c++14 -Xcompiler="/EHsc -Zi -Ob1 -bigobj" -D_WINDOWS -DNDEBUG -DTCNN_MIN_GPU_ARCH=86 -DTCNN_SHAMPOO -D"CMAKE_INTDIR="RelWithDe bInfo"" -D_MBCS -D"CMAKE_INTDIR="RelWithDebInfo"" -Xcompiler "/EHsc /W1 /nologo /O2 /FdE:\apps\NeRF\instant-ngp\build\dependencies\tiny-cuda-nn\RelWithDebInfo\tiny-cuda-nn.pdb /FS /Zi /MD /GR" -o tiny-cuda-nn.dir\RelWithDebInfo\optimizer.obj "E:\apps\NeR F\instant-ngp\dependencies\tiny-cuda-nn\src\optimizer.cu"" exited with code 1. [E:\apps\NeRF\instant-ngp\build\dependencies\tiny-cuda-nn\tiny-cuda-nn.vcxproj]

note forward and backslahes ""D:/sdk/CUDA/bin\nvcc.exe"

nvcc fatal : Compiler 'cl.exe' in PATH different than the one specified with -ccbin

???

open testbed.vcxproj and build in vs?

same error, exited with code 1. https://stackoverflow.com/a/33623587

try update cuda? NVlabs/instant-ngp#685 (comment)

opening project in visual studio, fails to open projects "Invalid static method invocation syntax: "

run vs as admin still fails on those other errors, exited with code 1

The build tools for v143 (Platform Toolset = 'v143') cannot be found. To build using the v143 build tools

install 142 latest build tools from vs installer

error MSB4019: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160Platforms\x64\Platform.props" was not found

missing backslash from VCTargetsPath (notice \v160Platforms\ , should be \v160\Platforms)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment