pierotofy / OpenSplat

Production-grade 3D gaussian splatting with CPU/GPU support for Windows, Mac and Linux 🚀
https://antimatter15.com/splat/?url=https://splat.uav4geo.com/banana.splat
GNU Affero General Public License v3.0
939 stars 87 forks source link

Docker build #12

Closed pierotofy closed 8 months ago

pierotofy commented 9 months ago

Would be cool to get automated docker builds (and CI tests)

cyango commented 9 months ago

Interested!

pierotofy commented 9 months ago

It's up for grabs if you want to open a pull request!

cyango commented 9 months ago

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?

pfxuan commented 9 months ago

@cyango the root cause seems related to cuda. Maybe you can use this build logic as a reference to fix your docker build error.

bchretien commented 9 months ago

@cyango: I managed to build it in Docker, with a few changes to the CMakeLists.txt (only tested on Linux) and Dockerfile:

+include(GNUInstallDirs) find_package(CUDAToolkit REQUIRED) find_package(Torch REQUIRED) -find_package(OpenCV HINTS "${OPENCV_DIR}" REQUIRED)

-if (NOT WIN32 AND NOT APPLE)

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.
cyango commented 9 months ago

Ok will test it on my Mac using --platform=linux/amd64

pfxuan commented 9 months ago

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