I’m using 3D Gaussian Splatting, which consists of a Cuda/C++ based python extension. I want to use CMake to compile it in setup.py. My basic idea is to generate .so file with CMake, and use this file to build python extension, which is similar to the idea in this question
However, it seems that my setup.py could not use this .so file, and failed to build my python extension. This is my setup.py and CMakeList. Can you help me?
from setuptools import setup,Extension
from setuptools.command.build_ext import build_ext
from torch.utils.cpp_extension import CUDAExtension, BuildExtension
import subprocess
import os
import shutil
current_dir=os.path.dirname(os.path.abspath(__file__))
class CMakeBuildExt(BuildExtension):
def run(self):
build_dir = os.path.join(current_dir, 'build')
subprocess.check_call(['cmake', '..'], cwd=build_dir)
subprocess.check_call(['make', 'clean'], cwd=build_dir)
subprocess.check_call(['make'], cwd=build_dir)
shutil.copy(os.path.join(build_dir, 'libCudaRasterizer.so'),
os.path.join(current_dir, 'diff_surfel_rasterization', 'libCudaRasterizer.so'))
super().run()
setup(
name="diff_surfel_rasterization",
packages=['diff_surfel_rasterization'],
version='0.0.1',
cmdclass={
'build_ext': CMakeBuildExt
},
ext_modules=[
CUDAExtension(
name="diff_surfel_rasterization._C",
sources=[],
extra_compile_args={"nvcc": ["-I" + os.path.join(os.path.dirname(os.path.abspath(__file__)), "third_party/glm/")]})
],
)
#
# Copyright (C) 2023, Inria
# GRAPHDECO research group, https://team.inria.fr/graphdeco
# All rights reserved.
#
# This software is free for non-commercial, research and evaluation use
# under the terms of the LICENSE.md file.
#
# For inquiries contact [email protected]
#
cmake_minimum_required(VERSION 3.20)
project(DiffRast LANGUAGES CUDA CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
add_library(CudaRasterizer
cuda_rasterizer/backward.h
cuda_rasterizer/backward.cu
cuda_rasterizer/forward.h
cuda_rasterizer/forward.cu
cuda_rasterizer/auxiliary.h
cuda_rasterizer/rasterizer_impl.cu
cuda_rasterizer/rasterizer_impl.h
cuda_rasterizer/rasterizer.h
)
set_target_properties(CudaRasterizer PROPERTIES CUDA_ARCHITECTURES "70;75;86")
target_include_directories(CudaRasterizer PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/cuda_rasterizer)
target_include_directories(CudaRasterizer PRIVATE third_party/glm ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
I tried to generate .so file with CMake, and I expected setup.py would use this file to build python extension.However, it ended up building a python extension with a sole init file.
Peppasaur is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.