-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
88 lines (68 loc) · 3.81 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)
project(samplecv_op CXX)
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set (CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install"
CACHE PATH "default install path" FORCE)
# message(${CMAKE_INSTALL_PREFIX})
message (STATUS "Overwriting default install path to ./install, as the actuall installation happens with a python script")
endif()
find_package(CUDA)
#####################################################################################
# Setting Up Automatic finding of TORCH Libraries
message("-- Looking for TORCH Libraries:")
message(" HINT: Call this command to setup the Torch Library Path, if autodetedct does not work!")
message(" export Torch_DIR=$(python -c 'import torch;print(torch.utils.cmake_prefix_path)')\n")
message(" CMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}")
message(" Torch_DIR=${Torch_DIR}")
message(" _GLIBCXX_USE_CXX11_ABI=${_GLIBCXX_USE_CXX11_ABI}")
message(" CMAKE_INTERNAL_PLATFORM_ABI=${CMAKE_INTERNAL_PLATFORM_ABI}")
exec_program("python -c \"import torch;print(torch.utils.cmake_prefix_path)\""
OUTPUT_VARIABLE TORCH_CMAKE_PATH_FROM_PYTHON
RETURN_VALUE RETVAL)
message(" Path Found: ")
message(" TORCH_CMAKE_PATH_FROM_PYTHON=${TORCH_CMAKE_PATH_FROM_PYTHON}")
find_package(Torch REQUIRED
HINTS "${TORCH_CMAKE_PATH_FROM_PYTHON}/" )
message( "\n-- TORCH_LIBRARIES: ${TORCH_LIBRARIES}")
message(" TORCH_CXX_FLAGS= ${TORCH_CXX_FLAGS}")
# message(" TORCH_CXX_FLAGS= ${TORCH_CXX_FLAGS}")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
find_library(TORCH_PYTHON_LIBRARY torch_python PATHS "${TORCH_INSTALL_PREFIX}/lib")
message(" TORCH_INSTALL_PREFIX= ${TORCH_INSTALL_PREFIX}")
message(" TORCH_SO_LIB_PATH= ${TORCH_INSTALL_PREFIX}/lib")
####################################################################################
####################################################################################
# Checking C++11 ABI
exec_program("python -c \"import torch; print(int(torch._C._GLIBCXX_USE_CXX11_ABI))\""
OUTPUT_VARIABLE TORCH_CXX_ABI)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI=${TORCH_CXX_ABI}")
message(" CMAKE_CXX_FLAGS= ${CMAKE_CXX_FLAGS}")
#####################################################################################
cuda_add_library(samplecv_op SHARED src/sample_cv.cpp src/sample_cv_cuda.cu)
target_include_directories(samplecv_op PUBLIC "src/include/")
# Setup To use CUDAs own FP16 types and not those of pytorch
# https://discuss.pytorch.org/t/error-more-than-one-operator-matches-these-operands-in-thcnumerics-cuh/89935
target_compile_definitions(samplecv_op PUBLIC
CUDA_HAS_FP16=1
__CUDA_NO_HALF_OPERATORS__
__CUDA_NO_HALF_CONVERSIONS__
__CUDA_NO_HALF2_OPERATORS__)
target_compile_features(samplecv_op PRIVATE cxx_std_14)
set_target_properties(samplecv_op PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
set_target_properties(samplecv_op PROPERTIES PUBLIC_HEADER src/include/sample_cv.hpp)
target_link_libraries(samplecv_op "${TORCH_LIBRARIES}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")
# Setting up RPATH => allowing library to keep path to system libraries from pytorch
# set(CMAKE_SKIP_RPATH FALSE)
# set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set_target_properties(samplecv_op PROPERTIES INSTALL_RPATH_USE_LINK_PATH True)
# These libs typically can be found under the following path
# set_target_properties(samplecv_op PROPERTIES INSTALL_RPATH "${TORCH_INSTALL_PREFIX}/lib")
configure_file(setup.py.cmake_in setup.py)
install(TARGETS samplecv_op
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
PUBLIC_HEADER DESTINATION include
)
install(CODE "execute_process(COMMAND python ${CMAKE_CURRENT_BINARY_DIR}/setup.py install WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})")