ngp这里采用的是他的一个python实现。(但是这个项目其实只要用到tinycudann库),这里还是完整搭建ngp_pl库。
首先创建一个conda环境,python这里用的是3.8:
conda create -n 环境名称 python=3.8
然后激活该环境
conda activate 环境名称
安装pytorch等
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.3 -c pytorch
安装torch_scatter
conda install pytorch-scatter -c pyg
确保gcc版本>=7.5,cmake版本>=3.21.0
gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.1.0-1ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --disable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-11-2V7zgg/gcc-11-11.1.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-2V7zgg/gcc-11-11.1.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.1.0 (Ubuntu 11.1.0-1ubuntu1~20.04)
cmake版本查看
cmake --version
cmake version 3.22.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
若cmake版本低的,可直接通过pip安装cmake:
pip install cmake==3.22.1
搭建tinycudann
#先看看环境要求是否需要更新cuda等,满足则先运行如下指令
sudo apt-get install build-essential git
#再export cuda路径,注意将cuda版本改成自己的cuda版本(nvidia-smi的cuda版本)
export PATH="/usr/local/cuda-11.7/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda-11.7/lib64:$LD_LIBRARY_PATH"
export CUDA_HOME="/usr/local/cuda-11.7:$CUDA_HOME"
# 再将repo克隆到本地,然后依次运行如下指令
git clone --recursive https://github.com/nvlabs/tiny-cuda-nn
cd tiny-cuda-nn
cmake . -B build
cmake --build build --config RelWithDebInfo -j
cd bindings/torch
python setup.py install
python setup.py install如果出现如下报错:
Building PyTorch extension for tiny-cuda-nn version 1.7
Obtained compute capability 86 from PyTorch
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Jun__8_16:49:14_PDT_2022
Cuda compilation tools, release 11.7, V11.7.99
Build cuda_11.7.r11.7/compiler.31442593_0
Detected CUDA version 11.7
running install
/data/niuzy/anaconda3/envs/nice-slam/lib/python3.7/site-packages/setuptools/command/install.py:37: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
setuptools.SetuptoolsDeprecationWarning,
/data/niuzy/anaconda3/envs/nice-slam/lib/python3.7/site-packages/setuptools/command/easy_install.py:147: EasyInstallDeprecationWarning: easy_install command is deprecated. Use build and pip and other standards-based tools.
EasyInstallDeprecationWarning,
running bdist_egg
running egg_info
creating tinycudann.egg-info
writing tinycudann.egg-info/PKG-INFO
writing dependency_links to tinycudann.egg-info/dependency_links.txt
writing top-level names to tinycudann.egg-info/top_level.txt
writing manifest file 'tinycudann.egg-info/SOURCES.txt'
reading manifest file 'tinycudann.egg-info/SOURCES.txt'
writing manifest file 'tinycudann.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
creating build
creating build/lib.linux-x86_64-3.7
creating build/lib.linux-x86_64-3.7/tinycudann
copying tinycudann/__init__.py -> build/lib.linux-x86_64-3.7/tinycudann
copying tinycudann/modules.py -> build/lib.linux-x86_64-3.7/tinycudann
copying tinycudann/bindings.cpp -> build/lib.linux-x86_64-3.7/tinycudann
running build_ext
error: [Errno 2] No such file or directory: '/usr/local/cuda-11.7:/bin/nvcc': '/usr/local/cuda-11.7:/bin/nvcc'
(nice-slam) niuzy@amax:~/Python/tiny-cuda-nn/bindings/torch$ export LIBRARY_PATH="/usr/local/cuda/lib64/stubs:$LIBRARY_PATH"
(nice-slam) niuzy@amax:~/Python/tiny-cuda-nn/bindings/torch$ export LIBRARY_PATH="/usr/local/cuda-11.7/lib64/stubs:$LIBRARY_PATH"
输入下面一句指令:
export CUDA_HOME=/usr/local/cuda-11.7