From e479642aba7f67250bbbb9c2dcaa453945264b2c Mon Sep 17 00:00:00 2001 From: Pengfei Xuan Date: Sat, 23 Mar 2024 09:33:24 -0400 Subject: [PATCH 1/6] Add CPU build pipeline --- .github/workflows/docker.yml | 2 +- .github/workflows/ubuntu-cpu.yml | 99 ++++++++++++++++++++++++++++++++ .github/workflows/ubuntu.yml | 2 +- .github/workflows/windows.yml | 2 +- 4 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/ubuntu-cpu.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 10fd510..77d047f 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -1,4 +1,4 @@ -name: OpenSplat (Docker) +name: OpenSplat (Docker CUDA) on: push: diff --git a/.github/workflows/ubuntu-cpu.yml b/.github/workflows/ubuntu-cpu.yml new file mode 100644 index 0000000..eb588a6 --- /dev/null +++ b/.github/workflows/ubuntu-cpu.yml @@ -0,0 +1,99 @@ +name: OpenSplat (Ubuntu CPU) + +on: + push: + branches: + - cpu-build + pull_request: + types: [ assigned, opened, synchronize, reopened ] + release: + types: [ published, edited ] + +jobs: + build: + name: ${{ matrix.os }}-cuda-${{ matrix.cuda-version }}-torch-${{ matrix.torch-version }}-${{ matrix.cmake-build-type }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-22.04, ubuntu-20.04] # [ubuntu-22.04, ubuntu-20.04, ubuntu-18.04] + arch: [x64] # [x64, x86] + torch-version: [2.1.2, 2.2.1] # [1.12.0, 1.13.0, 2.0.0, 2.1.0, 2.1.1, 2.1.2, 2.2.0, 2.2.1] + cmake-build-type: [Release] # [Debug, ClangTidy] + env: + CCACHE_DIR: ${{ github.workspace }}/ccache + CCACHE_BASEDIR: ${{ github.workspace }} + CL: /MP + CMAKE_GENERATOR: Ninja + CMAKE_GENERATOR_PLATFORM: ${{matrix.arch}} + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Setup Ubuntu + run: | + sudo apt-get update + sudo apt-get install -y \ + build-essential \ + cmake \ + ninja-build \ + libopencv-dev \ + wget + wget -nv https://github.com/ccache/ccache/releases/download/v4.9.1/ccache-4.9.1-linux-x86_64.tar.xz + sudo tar xf ccache-4.9.1-linux-x86_64.tar.xz -C /usr/bin --strip-components=1 --no-same-owner ccache-4.9.1-linux-x86_64/ccache + rm -f ccache-*-linux-x86_64.tar.xz + ccache --version + + - name: Sudo Tar Wrapper + run: | + # Workaround: https://github.com/containers/podman/discussions/17868 + sudo mv -fv /usr/bin/tar /usr/bin/tar.orig + echo -e '#!/bin/sh\n\nsudo /usr/bin/tar.orig "$@"' | sudo tee -a /usr/bin/tar + sudo chmod +x /usr/bin/tar + + - name: Restore LibTorch Cache + uses: actions/cache@v4 + id: libtorch-cache + with: + key: libtorch-${{ matrix.torch-version }}-${{env.CUDA_VER_SHORT}}-ubuntu + path: | + ${{ github.workspace }}/libtorch + + - name: Install LibTorch + if: ${{ steps.libtorch-cache.outputs.cache-hit != 'true' }} + run: | + wget --no-check-certificate -nv https://download.pytorch.org/libtorch/cpu/libtorch-shared-with-deps-${{ matrix.torch-version }}%2B$cpu.zip -O libtorch.zip + unzip -q ${{ github.workspace }}/libtorch.zip -d ${{ github.workspace }}/ + rm ${{ github.workspace }}/libtorch.zip + + - name: Cache Build + uses: actions/cache@v4 + id: cache-builds + with: + key: ${{ matrix.os }}-cpu-torch-${{ matrix.cmake-build-type }}-ccache-${{ github.run_id }} + restore-keys: ${{ matrix.os }}-cpu-torch-${{ matrix.cmake-build-type }}-ccache- + path: ${{ env.CCACHE_DIR }} + + - name: Configure And Build + run: | + set -x + mkdir build + cd build + cmake .. \ + -G${CMAKE_GENERATOR} \ + -DCMAKE_BUILD_TYPE=${{ matrix.cmake-build-type }} \ + -DCMAKE_C_COMPILER_LAUNCHER=$(which ccache) \ + -DCMAKE_CXX_COMPILER_LAUNCHER=$(which ccache) \ + -DCMAKE_PREFIX_PATH=${{ github.workspace }}/libtorch \ + -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install + ninja + + - name: Clean Compiler Cache + run: | + set -x + ccache --show-stats + ccache --evict-older-than 7d + ccache -s + ccache --show-stats diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 23d02f3..1144d32 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -1,4 +1,4 @@ -name: OpenSplat (Ubuntu) +name: OpenSplat (Ubuntu CUDA) on: push: diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 85aef52..d824563 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -1,4 +1,4 @@ -name: OpenSplat (Windows) +name: OpenSplat (Windows CUDA) on: push: From 52f8cc8350d456d4d058553abe8073c7010dfea5 Mon Sep 17 00:00:00 2001 From: Pengfei Xuan Date: Sat, 23 Mar 2024 09:36:36 -0400 Subject: [PATCH 2/6] Fix CPU libtorch download link --- .github/workflows/ubuntu-cpu.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ubuntu-cpu.yml b/.github/workflows/ubuntu-cpu.yml index eb588a6..9c69ce7 100644 --- a/.github/workflows/ubuntu-cpu.yml +++ b/.github/workflows/ubuntu-cpu.yml @@ -11,7 +11,7 @@ on: jobs: build: - name: ${{ matrix.os }}-cuda-${{ matrix.cuda-version }}-torch-${{ matrix.torch-version }}-${{ matrix.cmake-build-type }} + name: ${{ matrix.os }}-cpu-torch-${{ matrix.torch-version }}-${{ matrix.cmake-build-type }} runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -64,7 +64,7 @@ jobs: - name: Install LibTorch if: ${{ steps.libtorch-cache.outputs.cache-hit != 'true' }} run: | - wget --no-check-certificate -nv https://download.pytorch.org/libtorch/cpu/libtorch-shared-with-deps-${{ matrix.torch-version }}%2B$cpu.zip -O libtorch.zip + wget --no-check-certificate -nv https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-${{ matrix.torch-version }}%2Bcpu.zip -O libtorch.zip unzip -q ${{ github.workspace }}/libtorch.zip -d ${{ github.workspace }}/ rm ${{ github.workspace }}/libtorch.zip From 90a33771a400e7cea8c58e167312bfec1e86566b Mon Sep 17 00:00:00 2001 From: Pengfei Xuan Date: Sat, 23 Mar 2024 10:15:37 -0400 Subject: [PATCH 3/6] Add pthread for unix platform --- .github/workflows/ubuntu-cpu.yml | 11 ++++++++++- CMakeLists.txt | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ubuntu-cpu.yml b/.github/workflows/ubuntu-cpu.yml index 9c69ce7..fac2f11 100644 --- a/.github/workflows/ubuntu-cpu.yml +++ b/.github/workflows/ubuntu-cpu.yml @@ -87,9 +87,18 @@ jobs: -DCMAKE_C_COMPILER_LAUNCHER=$(which ccache) \ -DCMAKE_CXX_COMPILER_LAUNCHER=$(which ccache) \ -DCMAKE_PREFIX_PATH=${{ github.workspace }}/libtorch \ - -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install + -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install \ + -DOPENSPLAT_BUILD_SIMPLE_TRAINER=ON ninja + - name: Save Artifacts + uses: actions/upload-artifact@v4 + with: + path: | + build/libgsplat.a + build/opensplat + build/simple_trainer + - name: Clean Compiler Cache run: | set -x diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e5f4b8..606a7d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,6 +86,9 @@ add_executable(opensplat opensplat.cpp point_io.cpp nerfstudio.cpp model.cpp kdt set_property(TARGET opensplat PROPERTY CXX_STANDARD 17) target_include_directories(opensplat PRIVATE ${PROJECT_SOURCE_DIR}/vendor/glm ${GPU_INCLUDE_DIRS}) target_link_libraries(opensplat PUBLIC ${STDPPFS_LIBRARY} ${GPU_LIBRARIES} ${GSPLAT_LIBS} ${TORCH_LIBRARIES} ${OpenCV_LIBS}) +if (NOT WIN32) + target_link_libraries(opensplat PUBLIC pthread) +endif() if(GPU_RUNTIME STREQUAL "HIP") target_compile_definitions(opensplat PRIVATE USE_HIP __HIP_PLATFORM_AMD__) elseif(GPU_RUNTIME STREQUAL "CUDA") @@ -96,6 +99,9 @@ if(OPENSPLAT_BUILD_SIMPLE_TRAINER) add_executable(simple_trainer simple_trainer.cpp project_gaussians.cpp rasterize_gaussians.cpp cv_utils.cpp) target_include_directories(simple_trainer PRIVATE ${PROJECT_SOURCE_DIR}/vendor/glm ${GPU_INCLUDE_DIRS}) target_link_libraries(simple_trainer PUBLIC ${GPU_LIBRARIES} ${GSPLAT_LIBS} ${TORCH_LIBRARIES} ${OpenCV_LIBS}) + if (NOT WIN32) + target_link_libraries(simple_trainer PUBLIC pthread) + endif() set_property(TARGET simple_trainer PROPERTY CXX_STANDARD 17) if(GPU_RUNTIME STREQUAL "HIP") target_compile_definitions(simple_trainer PRIVATE USE_HIP __HIP_PLATFORM_AMD__) From 4318ccb602ccfbdb4bb4eec91356c99c3729e92e Mon Sep 17 00:00:00 2001 From: Pengfei Xuan Date: Sat, 23 Mar 2024 10:44:22 -0400 Subject: [PATCH 4/6] Save the build artifacts (latest versions) across all platforms --- .github/workflows/hip.yml | 3 ++- .github/workflows/ubuntu-cpu.yml | 4 +++- .github/workflows/ubuntu.yml | 12 +++++++++++- .github/workflows/windows.yml | 12 +++++++++++- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/.github/workflows/hip.yml b/.github/workflows/hip.yml index 2ffc4c7..962631d 100644 --- a/.github/workflows/hip.yml +++ b/.github/workflows/hip.yml @@ -174,7 +174,8 @@ jobs: -DOPENSPLAT_BUILD_SIMPLE_TRAINER=ON ninja - - name: Save Converted Artifacts + - name: Save Artifacts + if: ${{ matrix.os == 'ubuntu-22.04' && matrix.rocm-version == '5.7.1' && matrix.torch-version == '2.2.1' && matrix.cmake-build-type == 'Release' }} uses: actions/upload-artifact@v4 with: path: | diff --git a/.github/workflows/ubuntu-cpu.yml b/.github/workflows/ubuntu-cpu.yml index fac2f11..0a9b2fe 100644 --- a/.github/workflows/ubuntu-cpu.yml +++ b/.github/workflows/ubuntu-cpu.yml @@ -90,12 +90,14 @@ jobs: -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install \ -DOPENSPLAT_BUILD_SIMPLE_TRAINER=ON ninja + ls -l . - name: Save Artifacts + if: ${{ matrix.os == 'ubuntu-22.04' && matrix.torch-version == '2.2.1' && matrix.cmake-build-type == 'Release' }} uses: actions/upload-artifact@v4 with: path: | - build/libgsplat.a + build/libgsplat_cpu.a build/opensplat build/simple_trainer diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 1144d32..fcb91b4 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -122,9 +122,19 @@ jobs: -DCMAKE_CXX_COMPILER_LAUNCHER=$(which ccache) \ -DCMAKE_PREFIX_PATH=${{ github.workspace }}/libtorch \ -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install \ - -DCUDA_TOOLKIT_ROOT_DIR=$CUDA_HOME + -DCUDA_TOOLKIT_ROOT_DIR=$CUDA_HOME \ + -DOPENSPLAT_BUILD_SIMPLE_TRAINER=ON ninja + - name: Save Artifacts + if: ${{ matrix.os == 'ubuntu-22.04' && matrix.cuda-version == '12.1.1' && matrix.torch-version == '2.2.1' && matrix.cmake-build-type == 'Release' }} + uses: actions/upload-artifact@v4 + with: + path: | + build/libgsplat.a + build/opensplat + build/simple_trainer + - name: Clean Compiler Cache run: | set -x diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index d824563..46baeb6 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -136,9 +136,19 @@ jobs: -DCMAKE_CXX_COMPILER_LAUNCHER:FILEPATH=ccache ` -DCMAKE_PREFIX_PATH=${{ github.workspace }}\libtorch ` -DOPENCV_DIR=${{ github.workspace }}\OpenCV\opencv\build ` - -DTORCH_CUDA_ARCH_LIST="${{ env.TORCH_CUDA_ARCH_LIST }}" + -DTORCH_CUDA_ARCH_LIST="${{ env.TORCH_CUDA_ARCH_LIST }}" ` + -DOPENSPLAT_BUILD_SIMPLE_TRAINER=ON cmake --build . --parallel --config ${{ matrix.cmake-build-type }} + - name: Save Artifacts + if: ${{ matrix.os == 'windows-2022' && matrix.torch-version == '2.2.1' && matrix.cmake-build-type == 'Release' }} + uses: actions/upload-artifact@v4 + with: + path: | + build/libgsplat.so + build/opensplat + build/simple_trainer + - name: Clean Compiler Cache shell: pwsh run: | From 9db47fdb569a1fb99bb0ab1ff391aabd7d244a3d Mon Sep 17 00:00:00 2001 From: Pengfei Xuan Date: Sat, 23 Mar 2024 10:51:12 -0400 Subject: [PATCH 5/6] Switch ci tigger back to the main branch --- .github/workflows/ubuntu-cpu.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ubuntu-cpu.yml b/.github/workflows/ubuntu-cpu.yml index 0a9b2fe..1d50701 100644 --- a/.github/workflows/ubuntu-cpu.yml +++ b/.github/workflows/ubuntu-cpu.yml @@ -3,7 +3,7 @@ name: OpenSplat (Ubuntu CPU) on: push: branches: - - cpu-build + - main pull_request: types: [ assigned, opened, synchronize, reopened ] release: @@ -90,7 +90,6 @@ jobs: -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install \ -DOPENSPLAT_BUILD_SIMPLE_TRAINER=ON ninja - ls -l . - name: Save Artifacts if: ${{ matrix.os == 'ubuntu-22.04' && matrix.torch-version == '2.2.1' && matrix.cmake-build-type == 'Release' }} From 99525c683f33cf6c4778e2f63412fa183b6dc815 Mon Sep 17 00:00:00 2001 From: Pengfei Xuan Date: Sat, 23 Mar 2024 11:08:44 -0400 Subject: [PATCH 6/6] Format the cache key for CPU libtorch --- .github/workflows/ubuntu-cpu.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ubuntu-cpu.yml b/.github/workflows/ubuntu-cpu.yml index 1d50701..98cba0c 100644 --- a/.github/workflows/ubuntu-cpu.yml +++ b/.github/workflows/ubuntu-cpu.yml @@ -57,7 +57,7 @@ jobs: uses: actions/cache@v4 id: libtorch-cache with: - key: libtorch-${{ matrix.torch-version }}-${{env.CUDA_VER_SHORT}}-ubuntu + key: libtorch-${{ matrix.torch-version }}-cpu-ubuntu path: | ${{ github.workspace }}/libtorch