"Dockerfile" did not exist on "6c79160ff0659c3bc1d7da7277442c265c8ff845"
CMakeLists.txt 3.67 KB
Newer Older
1
cmake_minimum_required(VERSION 3.10)
Lindsey Gray's avatar
Lindsey Gray committed
2
3
project(torchsparse)
set(CMAKE_CXX_STANDARD 14)
rusty1s's avatar
rusty1s committed
4
set(TORCHSPARSE_VERSION 0.6.15)
5
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
Lindsey Gray's avatar
Lindsey Gray committed
6
7

option(WITH_CUDA "Enable CUDA support" OFF)
8
option(WITH_PYTHON "Link to Python when building" ON)
9
option(WITH_METIS "Enable METIS support" OFF)
Lindsey Gray's avatar
Lindsey Gray committed
10
11
12
13

if(WITH_CUDA)
  enable_language(CUDA)
  add_definitions(-D__CUDA_NO_HALF_OPERATORS__)
14
  add_definitions(-DWITH_CUDA)
15
  set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr")
Lindsey Gray's avatar
Lindsey Gray committed
16
17
endif()

18
19
20
21
if (WITH_PYTHON)
  add_definitions(-DWITH_PYTHON)
  find_package(Python3 COMPONENTS Development)
endif()
Lindsey Gray's avatar
Lindsey Gray committed
22
23
find_package(Torch REQUIRED)

24
25
26
27
28
if (WITH_METIS)
  add_definitions(-DWITH_METIS)
  find_package(METIS)
endif()

rusty1s's avatar
rusty1s committed
29
file(GLOB HEADERS csrc/*.h)
Matthias Fey's avatar
Matthias Fey committed
30
file(GLOB OPERATOR_SOURCES csrc/*.* csrc/cpu/*.*)
Lindsey Gray's avatar
Lindsey Gray committed
31
32
33
34
35
if(WITH_CUDA)
  file(GLOB OPERATOR_SOURCES ${OPERATOR_SOURCES} csrc/cuda/*.h csrc/cuda/*.cu)
endif()

add_library(${PROJECT_NAME} SHARED ${OPERATOR_SOURCES})
36
target_link_libraries(${PROJECT_NAME} PRIVATE ${TORCH_LIBRARIES})
37
38
39
if (WITH_CUDA)
  target_link_libraries(${PROJECT_NAME} PRIVATE ${CUDA_cusparse_LIBRARY})
endif()
40
41
42
if (WITH_PYTHON)
  target_link_libraries(${PROJECT_NAME} PRIVATE Python3::Python)
endif()
43
44
45
46
47
48
49
50
51
52
53
if (WITH_METIS)
  target_include_directories(${PROJECT_NAME} PRIVATE ${METIS_INCLUDE_DIRS})
  target_link_libraries(${PROJECT_NAME} PRIVATE ${METIS_LIBRARIES})
endif()
find_package(OpenMP)
if (OPENMP_FOUND)
    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
#    set (CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler=${OpenMP_CXX_FLAGS}")
    set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()
Lindsey Gray's avatar
Lindsey Gray committed
54
55
56
57
58
59
60
61
62
set_target_properties(${PROJECT_NAME} PROPERTIES EXPORT_NAME TorchSparse)

target_include_directories(${PROJECT_NAME} INTERFACE
  $<BUILD_INTERFACE:${HEADERS}>
  $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

63
64
65
set(PHMAP_DIR third_party/parallel-hashmap)
target_include_directories(${PROJECT_NAME} PRIVATE ${PHMAP_DIR})

Lindsey Gray's avatar
Lindsey Gray committed
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
set(TORCHSPARSE_CMAKECONFIG_INSTALL_DIR "share/cmake/TorchSparse" CACHE STRING "install path for TorchSparseConfig.cmake")

configure_package_config_file(cmake/TorchSparseConfig.cmake.in
  "${CMAKE_CURRENT_BINARY_DIR}/TorchSparseConfig.cmake"
  INSTALL_DESTINATION ${TORCHSPARSE_CMAKECONFIG_INSTALL_DIR})

write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/TorchSparseConfigVersion.cmake
	VERSION ${TORCHSPARSE_VERSION}
  COMPATIBILITY AnyNewerVersion)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/TorchSparseConfig.cmake
  ${CMAKE_CURRENT_BINARY_DIR}/TorchSparseConfigVersion.cmake
  DESTINATION ${TORCHSPARSE_CMAKECONFIG_INSTALL_DIR})

install(TARGETS ${PROJECT_NAME}
  EXPORT TorchSparseTargets
  LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  )

install(EXPORT TorchSparseTargets
  NAMESPACE TorchSparse::
  DESTINATION ${TORCHSPARSE_CMAKECONFIG_INSTALL_DIR})

install(FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
install(FILES
  csrc/cpu/convert_cpu.h
rusty1s's avatar
rusty1s committed
92
  csrc/cpu/diag_cpu.h
Lindsey Gray's avatar
Lindsey Gray committed
93
94
95
  csrc/cpu/metis_cpu.h
  csrc/cpu/rw_cpu.h
  csrc/cpu/saint_cpu.h
rusty1s's avatar
rusty1s committed
96
  csrc/cpu/sample_cpu.h
Lindsey Gray's avatar
Lindsey Gray committed
97
  csrc/cpu/spmm_cpu.h
rusty1s's avatar
rusty1s committed
98
  csrc/cpu/spspmm_cpu.h
Lindsey Gray's avatar
Lindsey Gray committed
99
100
101
102
103
104
105
106
107
108
  DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/cpu)
if(WITH_CUDA)
  install(FILES
    csrc/cuda/convert_cuda.h
    csrc/cuda/diag_cuda.h
    csrc/cuda/rw_cuda.h
    csrc/cuda/spmm_cuda.h
    csrc/cuda/spspmm_cuda.h
    DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/cuda)
endif()
Lindsey Gray's avatar
Lindsey Gray committed
109
110
111
112
113

if(WITH_CUDA)
  set_property(TARGET torch_cuda PROPERTY INTERFACE_COMPILE_OPTIONS "")
  set_property(TARGET torch_cpu PROPERTY INTERFACE_COMPILE_OPTIONS "")
endif()