-
Notifications
You must be signed in to change notification settings - Fork 106
/
CMakeLists.txt
executable file
·154 lines (136 loc) · 6.38 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
cmake_minimum_required(VERSION 3.3)
project(mluops VERSION ${BUILD_VERSION})
include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/test")
set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wdeprecated-declarations -fPIC -std=c++11 -pthread -pipe")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -Wl,--gc-sections -fPIC")
################################################################################
# Build Environment
################################################################################
set(MLUOP_BUILD_SPECIFIC_OP ${MLUOP_BUILD_SPECIFIC_OP})
message("-- MLUOP_BUILD_SPECIFIC_OP=${MLUOP_BUILD_SPECIFIC_OP}")
set(MLUOP_MLU_ARCH_LIST ${MLUOP_MLU_ARCH_LIST})
message("-- MLUOP_MLU_ARCH_LIST=${MLUOP_MLU_ARCH_LIST}")
################################################################################
# Environment and BANG Setup
################################################################################
if (NOT CMAKE_BUILD_TYPE)
set(_CMAKE_BUILD_TYPE_LOWER "release")
else()
string(TOLOWER ${CMAKE_BUILD_TYPE} _CMAKE_BUILD_TYPE_LOWER)
endif()
if(${MLUOP_BUILD_COVERAGE_TEST} MATCHES "ON")
message("-- MLU_OP_COVERAGE_TEST=${MLUOP_BUILD_COVERAGE_TEST}")
set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "-u__llvm_profile_runtime ${NEUWARE_HOME}/lib/clang/11.0.0/lib/linux/libclang_rt.profile-x86_64.a")
set(CNRT_DUMP_PGO 1)
set(CNRT_PGO_OUTPUT_DIR=output)
set(BANG_CNCC_FLAGS "${BANG_CNCC_FLAGS} -fprofile-instr-generate -fcoverage-mapping -D COVERAGE")
endif()
################################################################################
# ASAN Check and memcheck
################################################################################
# -- leak detector
if(${MLUOP_BUILD_ASAN_CHECK} MATCHES "ON")
message("-- Address sanitizer enabled")
set(CMAKE_ASAN_FLAGS "-fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_ASAN_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_ASAN_FLAGS}")
endif()
# check `NEUWARE_HOME` env
message("-- NEUWARE_HOME=${NEUWARE_HOME}")
if(EXISTS ${NEUWARE_HOME})
include_directories("${NEUWARE_HOME}/include")
link_directories("${NEUWARE_HOME}/lib64")
link_directories("${NEUWARE_HOME}/lib")
set(NEUWARE_ROOT_DIR "${NEUWARE_HOME}")
else()
message(FATAL_ERROR "NEUWARE directory cannot be found, refer README.md to prepare NEUWARE_HOME environment.")
endif()
# setup cmake search path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
"${CMAKE_SOURCE_DIR}/cmake"
"${NEUWARE_HOME}/cmake"
"${NEUWARE_HOME}/cmake/modules"
)
# include FindBANG.cmake and check cncc
find_package(BANG)
if(NOT BANG_FOUND)
message(FATAL_ERROR "BANG cannot be found.")
elseif (NOT BANG_CNCC_EXECUTABLE)
message(FATAL_ERROR "cncc not found, please ensure cncc is in your PATH env or set variable BANG_CNCC_EXECUTABLE from cmake. Otherwise you should check path used by find_program(BANG_CNCC_EXECUTABLE) in FindBANG.cmake")
endif()
# setup cncc flags
set(BANG_CNCC_FLAGS "${BANG_CNCC_FLAGS} -Werror -Wdeprecated-declarations -Wall -std=c++11 -fPIC -pthread")
if(${_CMAKE_BUILD_TYPE_LOWER} MATCHES "debug")
message(STATUS "build debug version")
set(BANG_CNCC_FLAGS "${BANG_CNCC_FLAGS} -g3 -O0")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g3 -O0")
elseif(${_CMAKE_BUILD_TYPE_LOWER} MATCHES "release")
message(STATUS "build release version")
set(BANG_CNCC_FLAGS "${BANG_CNCC_FLAGS} -O3 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG")
endif()
if (NOT MLUOP_MLU_ARCH_LIST)
message(STATUS "build all arch")
set(BANG_CNCC_FLAGS "${BANG_CNCC_FLAGS}" "--bang-mlu-arch=mtp_270"
"--bang-mlu-arch=mtp_290"
"--bang-mlu-arch=mtp_372"
"--bang-mlu-arch=mtp_592")
else()
foreach (arch ${MLUOP_MLU_ARCH_LIST})
set(CNCC_FLAGS_ARCH ${CNCC_FLAGS_ARCH} "--bang-mlu-arch=${arch}" )
endforeach ()
message(STATUS "build specific arch:${CNCC_FLAGS_ARCH}")
set(BANG_CNCC_FLAGS "${BANG_CNCC_FLAGS}" "${CNCC_FLAGS_ARCH}")
endif()
message(STATUS "BANG_CNCC_FLAGS:${BANG_CNCC_FLAGS}")
# resolve kernel dependency in MLUOP_BUILD_SPECIFIC_OP
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/mluop_kernel_depends.cmake)
# populate_op is provided by mluop_kernel_depends.cmake
if (MLUOP_BUILD_SPECIFIC_OP)
populate_op(MLUOP_BUILD_SPECIFIC_OP SPECIFIC_OP ${MLUOP_BUILD_SPECIFIC_OP})
message(STATUS "MLUOP_BUILD_SPECIFIC_OP (populated): ${MLUOP_BUILD_SPECIFIC_OP}")
endif()
if (NOT MLUOP_BUILD_SPECIFIC_OP)
message(STATUS "Build all kernels")
file(GLOB all_kernels "${CMAKE_CURRENT_LIST_DIR}/kernels/*")
foreach (o ${all_kernels})
if (IS_DIRECTORY ${o})
get_filename_component(kernelname ${o} NAME)
set(build_kernel ${kernelname} ${build_kernel})
endif()
endforeach ()
else()
set(build_kernel ${MLUOP_BUILD_SPECIFIC_OP})
endif()
list(SORT build_kernel)
message(STATUS "build_kernel:[${build_kernel}]")
foreach(kernel ${build_kernel})
if (NOT IS_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/kernels/${kernel}")
message(WARNING "kernel/${kernel} is not a directory, ${kernel} is an alias")
continue()
endif()
file(GLOB_RECURSE src_files ${src_files} "${CMAKE_CURRENT_SOURCE_DIR}/kernels/${kernel}/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/kernels/${kernel}/*.mlu")
file(GLOB_RECURSE obj_files ${obj_files} "${CMAKE_CURRENT_SOURCE_DIR}/kernels/${kernel}/${MLUOP_TARGET_CPU_ARCH}/*.o")
endforeach()
file(GLOB_RECURSE core_src_files ${core_src_files} "${CMAKE_CURRENT_SOURCE_DIR}/core/*.cpp")
# set(src_files ${src_files} "${CMAKE_CURRENT_SOURCE_DIR}/test/main.cpp")
bang_add_library(mluops SHARED ${core_src_files} ${src_files})
target_link_libraries(mluops cnrt cndrv dl)
target_link_libraries(mluops ${obj_files})
set_target_properties(mluops PROPERTIES
OUTPUT_NAME "mluops"
PREFIX "lib"
VERSION "${BUILD_VERSION}"
SOVERSION "${MAJOR_VERSION}"
)
################################################################################
# Build MLUOP GTEST
################################################################################
option(MLU_OP_BUILD_GTEST "Build mlu-ops gtest" ON)
message("-- MLU_OP_BUILD_GTEST=${MLU_OP_BUILD_GTEST}")
if(${MLU_OP_BUILD_GTEST} MATCHES "ON")
message("-- Build MLUOP Gtest")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/test/mlu_op_gtest" "mlu_op_gtest")
endif()