-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
165 lines (148 loc) · 5.63 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
155
156
157
158
159
160
161
162
163
164
165
cmake_minimum_required(VERSION 2.8.12)
project(intermittent-cnn)
set(MY_DEBUG "1" CACHE STRING "Local debug flag. See my_debug.h for details.")
option(USE_PROTOBUF "Use Protobuf to save results" OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# Too many parameters are unused if some features are not enabled
set(COMMON_FLAGS "-Wall -Wextra -Wshadow -Wundef -Wno-unused-parameter -Werror=undef -pedantic")
if (${MY_DEBUG} GREATER 1)
set(COMMON_FLAGS "${COMMON_FLAGS} -g3 -O0")
else ()
set(COMMON_FLAGS "${COMMON_FLAGS} -O3")
endif ()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_FLAGS} -Wstrict-prototypes -std=c11")
# Don't use something that require C++17 or newer, which are not supported by MSP-CGT yet
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_FLAGS} -std=c++14 -Wold-style-cast -Wsuggest-override -Wnon-virtual-dtor")
endif ()
if (USE_PROTOBUF)
find_package(Protobuf REQUIRED)
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${CMAKE_CURRENT_SOURCE_DIR}/exp/model_output.proto)
protobuf_generate_python(PROTO_PY ${CMAKE_CURRENT_SOURCE_DIR}/exp/model_output.proto)
add_custom_target(model_output_pb2 ALL DEPENDS ${PROTO_PY})
endif ()
set(COMMON_SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/common)
file(GLOB CCS_ARM_ROOT $ENV{HOME}/ti/ccs*/ccs/ccs_base/arm)
if (NOT "${CCS_ARM_ROOT}" STREQUAL "" AND NOT CMAKE_CROSSCOMPILING)
message(STATUS "Found CCS ARM root at ${CCS_ARM_ROOT}")
set(BUILD_MSP432 ON)
else ()
message(WARNING "No CCS ARM root found or cross-compiling detected. Not building plat-mcu.")
set(BUILD_MSP432 OFF)
endif ()
# Keep this list in sync with ARM-CMSIS/sync-cmsis.py
set(ARM_CMSIS_PATH ${CMAKE_CURRENT_SOURCE_DIR}/ARM-CMSIS/CMSIS)
add_library(arm_cmsis_dsp
${ARM_CMSIS_PATH}/DSP/Source/BasicMathFunctions/arm_add_q15.c
${ARM_CMSIS_PATH}/DSP/Source/BasicMathFunctions/arm_dot_prod_q15.c
${ARM_CMSIS_PATH}/DSP/Source/BasicMathFunctions/arm_mult_q15.c
${ARM_CMSIS_PATH}/DSP/Source/BasicMathFunctions/arm_offset_q15.c
${ARM_CMSIS_PATH}/DSP/Source/BasicMathFunctions/arm_scale_q15.c
${ARM_CMSIS_PATH}/DSP/Source/MatrixFunctions/arm_mat_init_q15.c
${ARM_CMSIS_PATH}/DSP/Source/MatrixFunctions/arm_mat_mult_fast_q15.c
${ARM_CMSIS_PATH}/DSP/Source/StatisticsFunctions/arm_max_q15.c
${ARM_CMSIS_PATH}/DSP/Source/StatisticsFunctions/arm_min_q15.c
${ARM_CMSIS_PATH}/DSP/Source/SupportFunctions/arm_fill_q15.c
)
target_include_directories(arm_cmsis_dsp
SYSTEM PUBLIC
${ARM_CMSIS_PATH}/Core/Include
${ARM_CMSIS_PATH}/DSP/Include
PRIVATE
${COMMON_SRC_PATH}
${CMAKE_BINARY_DIR}
)
target_compile_definitions(arm_cmsis_dsp
PRIVATE
ARM_MATH_MATRIX_CHECK
)
set(DSPLIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/TI-DSPLib)
add_library(dsplib
${DSPLIB_PATH}/source/matrix/msp_matrix_mpy_q15.c
${DSPLIB_PATH}/source/vector/msp_add_q15.c
${DSPLIB_PATH}/source/vector/msp_offset_q15.c
${DSPLIB_PATH}/source/vector/msp_mac_q15.c
${DSPLIB_PATH}/source/vector/msp_max_q15.c
${DSPLIB_PATH}/source/vector/msp_min_q15.c
${DSPLIB_PATH}/source/vector/msp_mpy_q15.c
${DSPLIB_PATH}/source/vector/msp_scale_q15.c
${DSPLIB_PATH}/source/utility/msp_deinterleave_q15.c
${DSPLIB_PATH}/source/utility/msp_interleave_q15.c
${DSPLIB_PATH}/source/utility/msp_fill_q15.c
)
target_include_directories(dsplib
SYSTEM PUBLIC
${DSPLIB_PATH}/include
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/msp430-compat
PRIVATE
${COMMON_SRC_PATH}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_BINARY_DIR}
)
set (intermittent_cnn_SOURCES
${COMMON_SRC_PATH}/intermittent-cnn.cpp
${COMMON_SRC_PATH}/op_handlers.cpp
${COMMON_SRC_PATH}/op_utils.cpp
${COMMON_SRC_PATH}/conv.cpp
${COMMON_SRC_PATH}/counters.cpp
${COMMON_SRC_PATH}/fc.cpp
${COMMON_SRC_PATH}/pooling.cpp
${COMMON_SRC_PATH}/cnn_common.cpp
${COMMON_SRC_PATH}/my_debug.cpp
${COMMON_SRC_PATH}/plat-pc.cpp
${COMMON_SRC_PATH}/platform.cpp
${COMMON_SRC_PATH}/my_dsplib.cpp
${COMMON_SRC_PATH}/dynbal.cpp
${COMMON_SRC_PATH}/dynbal-conv.cpp
${COMMON_SRC_PATH}/dynbal-fc.cpp
${COMMON_SRC_PATH}/layers.cpp
${CMAKE_BINARY_DIR}/data.cpp
)
if (USE_PROTOBUF)
list(APPEND intermittent_cnn_SOURCES ${PROTO_SRCS})
endif ()
add_executable(intermittent-cnn ${intermittent_cnn_SOURCES})
target_compile_definitions(intermittent-cnn
PRIVATE
PC_BUILD
MY_DEBUG=${MY_DEBUG}
)
target_include_directories(intermittent-cnn
PRIVATE
${COMMON_SRC_PATH}
${CMAKE_BINARY_DIR}
)
target_link_libraries(intermittent-cnn arm_cmsis_dsp dsplib)
if (USE_PROTOBUF)
target_compile_definitions(intermittent-cnn
PRIVATE
USE_PROTOBUF
)
target_include_directories(intermittent-cnn
PRIVATE ${CMAKE_CURRENT_BINARY_DIR} # for *.pb.h files
)
target_link_libraries(intermittent-cnn protobuf::libprotobuf)
endif ()
# Below is not actually used for the build on PC. I added it here so that
# clangd can identify platform-dependent codes
if (BUILD_MSP432)
add_library(plat-mcu ${COMMON_SRC_PATH}/plat-mcu.cpp)
target_include_directories(plat-mcu
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/msp432
)
target_include_directories(plat-mcu
SYSTEM PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/msp432/driverlib/MSP432P4xx
${CMAKE_BINARY_DIR}
${CCS_ARM_ROOT}/include
$<TARGET_PROPERTY:arm_cmsis_dsp,INCLUDE_DIRECTORIES>
)
target_compile_definitions(plat-mcu
PRIVATE
__MSP432__
__MSP432P401R__
)
endif ()