-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
113 lines (90 loc) · 3.37 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
cmake_minimum_required(VERSION 3.15)
project(simple_ml C CXX)
# In cmake 1.12 a new policy was added
cmake_policy(SET CMP0074 NEW)
# TODO: remove me
SET(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# MacOS only
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -undefined dynamic_lookup")
# find correct version of Python
execute_process(COMMAND python3.6-config --prefix
OUTPUT_VARIABLE Python_ROOT_DIR)
SET(Python3_FIND_VIRTUALENV "FIRST")
find_package(Python COMPONENTS Development Interpreter REQUIRED)
include_directories(${Python_INCLUDE_DIRS})
# find pybind
execute_process(COMMAND python3.6 -m pybind11 --cmakedir
RESULT_VARIABLE __pybind_exit_code
OUTPUT_VARIABLE __pybind_path
OUTPUT_STRIP_TRAILING_WHITESPACE)
find_package(pybind11 PATHS ${__pybind_path})
if(NOT MSVC)
set(CMAKE_CXX_FLAGS "-std=c++11 -O2 -march=native ${CMAKE_CXX_FLAGS}")
set(CMAKE_CUDA_STANDARD 14)
else()
set(CMAKE_CXX_FLAGS "/std:c++11 -O2 -march=native ${CMAKE_CXX_FLAGS}")
set(CMAKE_CUDA_STANDARD 14)
endif()
include_directories(SYSTEM ${pybind11_INCLUDE_DIRS})
list(APPEND LINKER_LIBS ${pybind11_LIBRARIES})
###################
### CPU BACKEND ###
###################
add_library(ndarray_backend_cpu MODULE src/ndarray_backend_cpu.cc)
target_link_libraries(ndarray_backend_cpu PUBLIC ${LINKER_LIBS})
pybind11_extension(ndarray_backend_cpu)
pybind11_strip(ndarray_backend_cpu)
# directly output to ffi folder
set_target_properties(ndarray_backend_cpu
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/simple_ml/backend_ndarray
CXX_VISIBILITY_PRESET "hidden"
)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set_property(TARGET ndarray_backend_cpu PROPERTY LINK_OPTIONS -undefined dynamic_lookup)
endif()
####################
### CUDA BACKEND ###
####################
find_package(CUDA)
if(CUDA_FOUND)
message(STATUS "Found cuda, building cuda backend")
include_directories(SYSTEM ${CUDA_INCLUDE_DIRS})
list(APPEND LINKER_LIBS ${CUDA_CUDART_LIBRARY})
CUDA_SELECT_NVCC_ARCH_FLAGS(ARCH_FLAGS Auto)
# set arch flags properly
CUDA_ADD_LIBRARY(ndarray_backend_cuda MODULE src/ndarray_backend_cuda.cu OPTIONS ${ARCH_FLAGS})
target_link_libraries(ndarray_backend_cuda ${LINKER_LIBS})
pybind11_extension(ndarray_backend_cuda)
pybind11_strip(ndarray_backend_cuda)
# directly output to ffi folder
set_target_properties(ndarray_backend_cuda
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/simple_ml/backend_ndarray
CXX_VISIBILITY_PRESET "hidden"
CUDA_VISIBILITY_PRESET "hidden"
)
else()
message(STATUS "Did not find CUDA")
endif()
######################
### OpenCL BACKEND ###
######################
find_package(OpenCL)
if(OpenCL_FOUND)
message(STATUS "Found OpenCL (${OpenCL_VERSION_STRING}), building OpenCL backend")
message(STATUS "OpenCL Include Dirs: ${OpenCL_INCLUDE_DIRS}")
message(STATUS "OpenCL Libraries: ${OpenCL_LIBRARIES}")
include_directories(SYSTEM ${OpenCL_INCLUDE_DIRS})
add_library(ndarray_backend_opencl MODULE src/ndarray_backend_opencl.cc)
target_link_libraries(ndarray_backend_opencl ${pybind11_LIBRARIES} ${OpenCL_LIBRARIES})
pybind11_extension(ndarray_backend_opencl)
pybind11_strip(ndarray_backend_opencl)
set_target_properties(ndarray_backend_opencl
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/simple_ml/backend_ndarray
CXX_VISIBILITY_PRESET "hidden"
)
else()
message(STATUS "Did not find OpenCL")
endif()