Closed pierotofy closed 8 months ago
Interested!
It's up for grabs if you want to open a pull request!
I'm relatively new to this, but I'm trying to run it inside a docker container with the following Dockerfile:
FROM --platform=linux/amd64 nvidia/cuda:12.3.1-devel-ubuntu22.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get install -y \
git \
python3-pip \
python3-dev \
python3-opencv \
libglib2.0-0 \
g++ \
make \
libopencv-dev \
wget \
unzip
# nvidia-cuda-toolkit
RUN wget https://github.com/Kitware/CMake/releases/download/v3.24.1/cmake-3.24.1-Linux-x86_64.sh \
-q -O /tmp/cmake-install.sh \
&& chmod u+x /tmp/cmake-install.sh \
&& mkdir /opt/cmake-3.24.1 \
&& /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-3.24.1 \
&& rm /tmp/cmake-install.sh \
&& ln -s /opt/cmake-3.24.1/bin/* /usr/local/bin
RUN python3 -m pip install --upgrade pip
RUN wget https://download.pytorch.org/libtorch/nightly/cpu/libtorch-shared-with-deps-latest.zip && \
unzip libtorch-shared-with-deps-latest.zip && \
rm libtorch-shared-with-deps-latest.zip
WORKDIR /app
COPY . /app
RUN cmake -DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda -DCMAKE_PREFIX_PATH=/libtorch .
RUN make -j$(nproc)
ENTRYPOINT [ "python3" ]
I'm getting this error:
"fatal error: cuda_runtime.h: No such file or directory"
How should i solve this?
@cyango the root cause seems related to cuda. Maybe you can use this build logic as a reference to fix your docker build error.
@cyango: I managed to build it in Docker, with a few changes to the CMakeLists.txt
(only tested on Linux) and Dockerfile
:
CMakeLists.txt
:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c194e5a..aa07998 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.18)
-project(opensplat)
+project(opensplat LANGUAGES CUDA CXX)
set(OPENSPLAT_BUILD_SIMPLE_TRAINER OFF CACHE BOOL "Build simple trainer applications")
set(OPENCV_DIR "OPENCV_DIR-NOTFOUND" CACHE "OPENCV_DIR" "Path to the OPENCV installation directory")
@@ -10,39 +10,39 @@ endif()
set(CMAKE_CUDA_ARCHITECTURES 70 75)
set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CUDA_STANDARD 17)
+set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr")
+set(TORCH_CUDA_ARCH_LIST "7.0;7.5")
if (NOT WIN32 AND NOT APPLE)
set(STDPPFS_LIBRARY stdc++fs)
endif()
-if (NOT WIN32 AND NOT APPLE)
set(CMAKE_CUDA_COMPILER "${CUDA_TOOLKIT_ROOT_DIR}/bin/nvcc") -endif() -set(OpenCV_LIBS opencv_core opencv_imgproc opencv_highgui opencv_calib3d) +find_package(OpenCV COMPONENTS core imgproc imgcodecs highgui calib3d HINTS "${OPENCV_DIR}" REQUIRED)
add_library(gsplat vendor/gsplat/forward.cu vendor/gsplat/backward.cu vendor/gsplat/bindings.cu vendor/gsplat/helpers.cuh) -target_link_libraries(gsplat PUBLIC cuda) +target_link_libraries(gsplat PUBLIC CUDA::cudart) target_include_directories(gsplat PRIVATE
${PROJECT_SOURCE_DIR}/vendor/glm
${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
${PROJECT_SOURCE_DIR}/vendor/glm ${TORCH_INCLUDE_DIRS} ) set_target_properties(gsplat PROPERTIES LINKER_LANGUAGE CXX) set_target_properties(gsplat PROPERTIES CUDA_ARCHITECTURES "70;75")
add_executable(opensplat opensplat.cpp point_io.cpp nerfstudio.cpp model.cpp kdtree_tensor.cpp spherical_harmonics.cpp cv_utils.cpp utils.cpp project_gaussians.cpp rasterize_gaussians.cpp ssim.cpp optim_scheduler.cpp) target_include_directories(opensplat PRIVATE ${PROJECT_SOURCE_DIR}/vendor/glm) -target_link_libraries(opensplat PUBLIC ${STDPPFS_LIBRARY} cuda gsplat ${TORCH_LIBRARIES} ${OpenCV_LIBS}) +target_link_libraries(opensplat PUBLIC ${STDPPFS_LIBRARY} gsplat ${TORCH_LIBRARIES} ${OpenCV_LIBS})
+set(INSTALL_TARGETS opensplat gsplat)
if(OPENSPLAT_BUILD_SIMPLE_TRAINER) add_executable(simple_trainer simple_trainer.cpp project_gaussians.cpp rasterize_gaussians.cpp) target_include_directories(simple_trainer PRIVATE ${PROJECT_SOURCE_DIR}/vendor/glm) target_link_libraries(simple_trainer PUBLIC cuda gsplat ${TORCH_LIBRARIES} ${OpenCV_LIBS})
list(APPEND INSTALL_TARGETS simple_trainer) endif()
@@ -58,3 +58,10 @@ if (MSVC)
${DLLS_TO_COPY}
$
+install(TARGETS ${INSTALL_TARGETS}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +)
Dockerfile
(I used CUDA 11.8 but you can adapt it, and used the CXX11 ABI for Torch to prevent clashes with OpenCV):
ARG CUDA_VERSION=11.8.0
ARG CUDA_VERSION_SHORT=11.8
ARG OS_VERSION=22.04
FROM --platform=linux/amd64 nvidia/cuda:${CUDA_VERSION}-devel-ubuntu${OS_VERSION}
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \ apt install -y --no-install-recommends \ git \ python3-pip \ python3-dev \ python3-opencv \ libglib2.0-0 \ g++ \ make \ libopencv-dev \ wget \ unzip
RUN wget https://github.com/Kitware/CMake/releases/download/v3.24.1/cmake-3.24.1-Linux-x86_64.sh \ -q -O /tmp/cmake-install.sh \ && chmod u+x /tmp/cmake-install.sh \ && mkdir /opt/cmake-3.24.1 \ && /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-3.24.1 \ && rm /tmp/cmake-install.sh \ && ln -s /opt/cmake-3.24.1/bin/* /usr/local/bin
RUN python3 -m pip install --upgrade pip
RUN wget https://download.pytorch.org/libtorch/cu118/libtorch-cxx11-abi-shared-with-deps-2.2.1%2Bcu118.zip && \ unzip libtorch-cxx11-abi-shared-with-deps-2.2.1+cu118.zip && \ mkdir -p /usr/local/share/cmake && \ mv libtorch/lib/ /usr/local/lib/ && \ mv libtorch/include/ /usr/local/include/ && \ mv libtorch/share/cmake/* /usr/local/share/cmake/ && \ rm -rf libtorch && \ rm libtorch-cxx11-abi-shared-with-deps-2.2.1+cu118.zip
WORKDIR /app
COPY . /app
RUN mkdir build \ && cd build \ && cmake -DCMAKE_PREFIX_PATH=/libtorch -DCMAKE_BUILD_TYPE=Release -DOPENSPLAT_BUILD_SIMPLE_TRAINER=ON .. \ && make -j$(nproc) \ && make install \ && cd .. \ && rm -rf build
There's still a bunch of issues remaining in the `CMakeLists.txt` (e.g. list of architectures to build for ~~not working~~ duplicated between `TORCH_CUDA_ARCH_LIST` and `CUDA_ARCHITECTURES`) and the `Dockerfile` can be more optimized for size, but now it builds, the simple trainer runs properly with CUDA, etc.
Ok will test it on my Mac using --platform=linux/amd64
I converted the existing ubuntu build workflow into this docker build. Feel free to give it a try: https://github.com/pierotofy/OpenSplat/pull/30
Would be cool to get automated docker builds (and CI tests)