Running instant-ngp in WSL2

Posted on Sat, Jul 16, 2022 NeRF NVIDIA WSL

Instant Neural Graphics Primitives with a Multiresolution Hash Encoding

GitHub - NVlabs/instant-ngp: Instant neural graphics primitives: lightning fast NeRF and more

Ever wanted to train a NeRF model of a fox in under 5 seconds? Or fly around a scene captured from photos of a factory robot? Of course you have! Here you will find an implementation of four neural graphics primitives, being neural radiance fields (NeRF), signed distance functions (SDFs), neural images, and neural volumes.

Steps

Enable NVIDIA CUDA on WSL 2

Enable the NVIDIA CUDA preview on the Windows Subsystem for Linux

conda create -n instant-ngp
conda activate instant-ngp
conda install -c nvidia cuda-tools cuda-toolkit
conda install -c conda-forge cmake

export PATH="$CONDA_PREFIX/bin:$PATH"
export LD_LIBRARY_PATH="$CONDA_PREFIX/lib:$LD_LIBRARY_PATH"
sudo apt-get install build-essential git python3-dev python3-pip libopenexr-dev libxi-dev \
                     libglfw3-dev libglew-dev libomp-dev libxinerama-dev libxcursor-dev
git clone --recursive https://github.com/nvlabs/instant-ngp
cd instant-ngp
Segfault with WSL2 + GUI ยท Issue #268 ยท NVlabs/instant-ngp

CUDA: 11.6 GPU: RTX3080 OS: Ubuntu 20.04 - WSL2 When I try to run $ ./build/testbed --scene data/nerf/fox I run into a segmentation fault error as it tries to create the GUI. 23:09:29 INFO Loading NeRF dataset from 23:09:29 INFO data/ner...

GLTexture::CUDAMapping::CUDAMapping(GLuint texture_id, const Vector2i& size) : m_size{size} {
	// static bool s_is_cuda_interop_supported = true;
	static bool s_is_cuda_interop_supported = false;
	if (s_is_cuda_interop_supported) {
		cudaError_t err = cudaGraphicsGLRegisterImage(&m_graphics_resource, texture_id, GL_TEXTURE_2D, cudaGraphicsRegisterFlagsSurfaceLoadStore);
		if (err != cudaSuccess) {
			s_is_cuda_interop_supported = false;
			cudaGetLastError(); // Reset error
		}
	}

	if (!s_is_cuda_interop_supported) {
		// falling back to a regular cuda surface + CPU copy of data
		m_cuda_surface = std::make_unique<CudaSurface2D>();
		m_cuda_surface->resize(size);
		m_data_cpu.resize(m_size.prod() * 4);
		return;
	}

	CUDA_CHECK_THROW(cudaGraphicsMapResources(1, &m_graphics_resource));
	CUDA_CHECK_THROW(cudaGraphicsSubResourceGetMappedArray(&m_mapped_array, m_graphics_resource, 0, 0));

	struct cudaResourceDesc resource_desc;
	memset(&resource_desc, 0, sizeof(resource_desc));
	resource_desc.resType = cudaResourceTypeArray;
	resource_desc.res.array.array = m_mapped_array;

	CUDA_CHECK_THROW(cudaCreateSurfaceObject(&m_surface, &resource_desc));
}
cmake . -B build
cmake --build build --config RelWithDebInfo -j 16
./build/testbed --scene data/nerf/fox