首先创建一个conda环境,python这里用的是3.8:
conda create -n ngp_pl python=3.8
conda activate ngp_pl
安装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
cmake版本查看
cmake --version
若cmake版本低的,可直接通过pip安装cmake:
pip install cmake==3.22.1
搭建tinycudann
这部分参考了一位知乎博主nerfstudio环境里面tinycudann的方法,主页信息和连接放到下面供参考。之前官网尝试的方法都会报各种错误,这个一条命令直接安装好了,属于运气不错了。
成功安装的代码只有下面一行,运气好的话直接装上,我就直接装上了,不过中间遇到i一个小插曲,得益于之前的报错,成功解决。
pip install ninja git+https://github.com/NVlabs/tiny-cuda-nn/#subdirectory=bindings/torch
报错内容如下
解决方法是输入以下指令:
export CUDA_HOME=/usr/local/cuda-11.3
export LIBRARY_PATH="/usr/local/cuda/lib64/stubs:$LIBRARY_PATH"
export LIBRARY_PATH="/usr/local/cuda-11.3/lib64/stubs:$LIBRARY_PATH"
再输入上面的代码,就成功了,成功安装界面如下图
验证是否成功安装
如果下面的代码不会报错,就说明tinycudann安装成功了!
python
>>> import tinycudann as tcnn
参考这位知乎博主的博客,运气不好的话就得换另一种方法,另一种其实就是官方给的方法,也是我之前用的方法,结果是一直报错,反而是博主的第一个方法成功了,只能说走了不少弯路。
第二种方法如下:
#先看看环境要求是否需要更新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
这种方法我也没有成功过,一直报错,大家有成功的可以交流一下。报错截图和cuda版本我也提供一下。
CMakeOutput.log内容如下,主要是
Checking whether the CUDA compiler is NVIDIA using "" matched "nvcc: NVIDIA \(R\) Cuda compiler driver"
The system is: Linux - 5.15.0-79-generic - x86_64
Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" succeeded.
Compiler: /usr/bin/c++
Build flags:
Id flags:
The output was:
0
Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "a.out"
The CXX compiler identification is GNU, found in "/home/chenfang/tiny-cuda-nn/build/CMakeFiles/3.22.1/CompilerIdCXX/a.out"
Checking whether the CUDA compiler is NVIDIA using "" matched "nvcc: NVIDIA \(R\) Cuda compiler driver":
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Sun_Mar_21_19:15:46_PDT_2021
Cuda compilation tools, release 11.3, V11.3.58
Build cuda_11.3.r11.3/compiler.29745058_0
Checking whether the CUDA compiler is NVIDIA using "" matched "nvcc: NVIDIA \(R\) Cuda compiler driver":
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Sun_Mar_21_19:15:46_PDT_2021
Cuda compilation tools, release 11.3, V11.3.58
Build cuda_11.3.r11.3/compiler.29745058_0
Checking whether the CUDA compiler is NVIDIA using "" matched "nvcc: NVIDIA \(R\) Cuda compiler driver":
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Sun_Mar_21_19:15:46_PDT_2021
Cuda compilation tools, release 11.3, V11.3.58
Build cuda_11.3.r11.3/compiler.29745058_0
Checking whether the CUDA compiler is NVIDIA using "" matched "nvcc: NVIDIA \(R\) Cuda compiler driver":
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Sun_Mar_21_19:15:46_PDT_2021
Cuda compilation tools, release 11.3, V11.3.58
Build cuda_11.3.r11.3/compiler.29745058_0
cuda安装目录我也提供一下