Skip to content

Commit

Permalink
Merge pull request #82 from jcaesar/unvendor
Browse files Browse the repository at this point in the history
Make OpenSplat easier to package for distros
  • Loading branch information
pierotofy committed Apr 20, 2024
2 parents f38b97c + bed5427 commit 2dc4583
Show file tree
Hide file tree
Showing 464 changed files with 77 additions and 94,266 deletions.
66 changes: 57 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,36 @@ set(OPENCV_DIR "OPENCV_DIR-NOTFOUND" CACHE PATH "Path to the OPENCV installation
set(OPENSPLAT_MAX_CUDA_COMPATIBILITY OFF CACHE BOOL "Build for maximum CUDA device compatibility")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

# Don't complain about the override from NANOFLANN_BUILD_EXAMPLES
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
# Use time-of-extraction for FetchContent'ed files modification time
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()
include(FetchContent)
FetchContent_Declare(nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json
GIT_TAG v3.11.3
)
set(NANOFLANN_BUILD_EXAMPLES OFF)
set(NANOFLANN_BUILD_TESTS OFF)
FetchContent_Declare(nanoflann
GIT_REPOSITORY https://github.com/jlblancoc/nanoflann.git
GIT_TAG v1.5.5
)
FetchContent_Declare(cxxopts
GIT_REPOSITORY https://github.com/jarro2783/cxxopts.git
GIT_TAG v3.2.0
)
FetchContent_MakeAvailable(nlohmann_json nanoflann cxxopts)
if((GPU_RUNTIME STREQUAL "CUDA") OR (GPU_RUNTIME STREQUAL "HIP"))
FetchContent_Declare(glm
GIT_REPOSITORY https://github.com/g-truc/glm.git
GIT_TAG 1.0.1
)
FetchContent_MakeAvailable(glm)
endif()

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif()
Expand Down Expand Up @@ -73,7 +103,7 @@ elseif(GPU_RUNTIME STREQUAL "HIP")
set(CMAKE_MODULE_PATH "${HIP_PATH}/cmake" ${CMAKE_MODULE_PATH})
find_package(HIP REQUIRED)

file(GLOB_RECURSE GSPLAT_GPU_SRC LIST_DIRECTORIES False vendor/gsplat/*.cu)
file(GLOB_RECURSE GSPLAT_GPU_SRC LIST_DIRECTORIES False rasterizer/gsplat/*.cu)
set_source_files_properties(${GSPLAT_GPU_SRC} PROPERTIES LANGUAGE HIP)

if(WIN32)
Expand Down Expand Up @@ -115,7 +145,7 @@ set(OpenCV_LIBS opencv_core opencv_imgproc opencv_highgui opencv_calib3d)

set(GSPLAT_LIBS gsplat_cpu)
if((GPU_RUNTIME STREQUAL "CUDA") OR (GPU_RUNTIME STREQUAL "HIP"))
add_library(gsplat vendor/gsplat/forward.cu vendor/gsplat/backward.cu vendor/gsplat/bindings.cu vendor/gsplat/helpers.cuh)
add_library(gsplat rasterizer/gsplat/forward.cu rasterizer/gsplat/backward.cu rasterizer/gsplat/bindings.cu rasterizer/gsplat/helpers.cuh)
list(APPEND GSPLAT_LIBS gsplat)
if(GPU_RUNTIME STREQUAL "CUDA")
set(GPU_LIBRARIES "cuda")
Expand All @@ -125,13 +155,13 @@ if((GPU_RUNTIME STREQUAL "CUDA") OR (GPU_RUNTIME STREQUAL "HIP"))
target_compile_definitions(gsplat PRIVATE USE_HIP __HIP_PLATFORM_AMD__)
endif()
target_include_directories(gsplat PRIVATE
${PROJECT_SOURCE_DIR}/vendor/glm
${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
${TORCH_INCLUDE_DIRS}
)
target_link_libraries(gsplat PUBLIC glm::glm-header-only)
set_target_properties(gsplat PROPERTIES LINKER_LANGUAGE CXX)
elseif(GPU_RUNTIME STREQUAL "MPS")
add_library(gsplat vendor/gsplat-metal/gsplat_metal.mm)
add_library(gsplat rasterizer/gsplat-metal/gsplat_metal.mm)
list(APPEND GSPLAT_LIBS gsplat)
target_link_libraries(gsplat PRIVATE
${FOUNDATION_LIBRARY}
Expand All @@ -140,14 +170,14 @@ elseif(GPU_RUNTIME STREQUAL "MPS")
)
target_include_directories(gsplat PRIVATE ${TORCH_INCLUDE_DIRS})
# copy shader files to bin directory
configure_file(vendor/gsplat-metal/gsplat_metal.metal ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/gsplat_metal.metal COPYONLY)
configure_file(rasterizer/gsplat-metal/gsplat_metal.metal ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/gsplat_metal.metal COPYONLY)
add_custom_command(
OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/default.metallib
COMMAND xcrun -sdk macosx metal ${XC_FLAGS} -c ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/gsplat_metal.metal -o ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/gsplat_metal.air
COMMAND xcrun -sdk macosx metallib ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/gsplat_metal.air -o ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/default.metallib
COMMAND rm -f ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/gsplat_metal.air
COMMAND rm -f ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/gsplat_metal.metal
DEPENDS vendor/gsplat-metal/gsplat_metal.metal
DEPENDS rasterizer/gsplat-metal/gsplat_metal.metal
COMMENT "Compiling Metal kernels"
)

Expand All @@ -157,13 +187,22 @@ elseif(GPU_RUNTIME STREQUAL "MPS")
)
endif()

add_library(gsplat_cpu vendor/gsplat-cpu/gsplat_cpu.cpp)
add_library(gsplat_cpu rasterizer/gsplat-cpu/gsplat_cpu.cpp)
target_include_directories(gsplat_cpu PRIVATE ${TORCH_INCLUDE_DIRS})

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 colmap.cpp opensfm.cpp input_data.cpp tensor_math.cpp)
install(TARGETS opensplat DESTINATION bin)
set_property(TARGET opensplat PROPERTY CXX_STANDARD 17)
target_include_directories(opensplat PRIVATE ${PROJECT_SOURCE_DIR}/vendor/glm ${GPU_INCLUDE_DIRS})
target_include_directories(opensplat PRIVATE
${PROJECT_SOURCE_DIR}/rasterizer
${GPU_INCLUDE_DIRS}
)
target_link_libraries(opensplat PUBLIC ${STDPPFS_LIBRARY} ${GPU_LIBRARIES} ${GSPLAT_LIBS} ${TORCH_LIBRARIES} ${OpenCV_LIBS})
target_link_libraries(opensplat PRIVATE
nlohmann_json::nlohmann_json
cxxopts::cxxopts
nanoflann::nanoflann
)
if (NOT WIN32)
target_link_libraries(opensplat PUBLIC pthread)
endif()
Expand All @@ -177,8 +216,17 @@ endif()

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})
install(TARGETS simple_trainer DESTINATION bin)
target_include_directories(simple_trainer PRIVATE
${PROJECT_SOURCE_DIR}/rasterizer
${GPU_INCLUDE_DIRS}
)
target_link_libraries(simple_trainer PUBLIC ${GPU_LIBRARIES} ${GSPLAT_LIBS} ${TORCH_LIBRARIES} ${OpenCV_LIBS})
target_link_libraries(simple_trainer PRIVATE
nlohmann_json::nlohmann_json
cxxopts::cxxopts
nanoflann::nanoflann
)
if (NOT WIN32)
target_link_libraries(simple_trainer PUBLIC pthread)
endif()
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ RUN apt-get update && \
apt-get install -y \
build-essential \
cmake \
git \
ninja-build \
libopencv-dev \
unzip \
Expand Down
10 changes: 5 additions & 5 deletions gsplat.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#ifndef GSPLAT_H
#define GSPLAT_H

#include "vendor/gsplat/config.h"
#include <gsplat/config.h>

#if defined(USE_HIP) || defined(USE_CUDA)
#include "vendor/gsplat/bindings.h"
#include <gsplat/bindings.h>
#endif

#if defined(USE_MPS)
#include "vendor/gsplat-metal/bindings.h"
#include <gsplat-metal/bindings.h>
#endif

#include "vendor/gsplat-cpu/bindings.h"
#include <gsplat-cpu/bindings.h>

#endif
#endif
2 changes: 1 addition & 1 deletion kdtree_tensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define KDTREE_TENSOR

#include <torch/torch.h>
#include "vendor/nanoflann/nanoflann.hpp"
#include <nanoflann.hpp>

struct PointsTensor {
torch::Tensor tensor;
Expand Down
2 changes: 1 addition & 1 deletion nerfstudio.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <filesystem>
#include <cstdlib>
#include "vendor/json/json.hpp"
#include <nlohmann/json.hpp>
#include "nerfstudio.hpp"
#include "point_io.hpp"
#include "cv_utils.hpp"
Expand Down
2 changes: 1 addition & 1 deletion nerfstudio.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include <string>
#include <fstream>
#include <torch/torch.h>
#include <nlohmann/json_fwd.hpp>
#include "input_data.hpp"
#include "vendor/json/json_fwd.hpp"

using json = nlohmann::json;

Expand Down
2 changes: 1 addition & 1 deletion opensfm.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <filesystem>
#include <cstdlib>
#include "vendor/json/json.hpp"
#include <nlohmann/json.hpp>
#include "opensfm.hpp"
#include "point_io.hpp"
#include "cv_utils.hpp"
Expand Down
2 changes: 1 addition & 1 deletion opensfm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <fstream>
#include <unordered_map>
#include <torch/torch.h>
#include <nlohmann/json_fwd.hpp>
#include "input_data.hpp"
#include "vendor/json/json_fwd.hpp"

using json = nlohmann::json;

Expand Down
4 changes: 2 additions & 2 deletions opensplat.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include <filesystem>
#include "vendor/json/json.hpp"
#include <nlohmann/json.hpp>
#include "opensplat.hpp"
#include "input_data.hpp"
#include "utils.hpp"
#include "cv_utils.hpp"
#include "vendor/cxxopts.hpp"
#include <cxxopts.hpp>

namespace fs = std::filesystem;
using namespace torch::indexing;
Expand Down
2 changes: 1 addition & 1 deletion point_io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <pdal/io/BufferReader.hpp>
#endif

#include "vendor/nanoflann/nanoflann.hpp"
#include <nanoflann.hpp>

struct XYZ {
float x;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions rasterizer/gsplat/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This is a modified version of gsplat (https://github.com/nerfstudio-project/gsplat)

It is released under the AGPLv3 license. The original project is licensed under Apache2.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions vendor/gsplat/helpers.cuh → rasterizer/gsplat/helpers.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <cuda_runtime.h>
#endif

#include "../glm/glm/glm.hpp"
#include "../glm/glm/gtc/type_ptr.hpp"
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <iostream>

inline __device__ float ndc2pix(const float x, const float W, const float cx) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion simple_trainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "rasterize_gaussians.hpp"
#include "constants.hpp"
#include "cv_utils.hpp"
#include "vendor/cxxopts.hpp"
#include <cxxopts.hpp>

using namespace torch::indexing;
namespace fs = std::filesystem;
Expand Down
Loading

0 comments on commit 2dc4583

Please sign in to comment.