-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
157 lines (132 loc) · 5.86 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
cmake_minimum_required(VERSION 3.16)
###############################################################################
# Application related definitions
###############################################################################
set(TARGET_NAME vww)
###############################################################################
# CMake pre initialization
###############################################################################
include($ENV{GAP_SDK_HOME}/utils/cmake/setup.cmake)
set(APP_MSG_PREFIX "[${BoldRed}VWW${ColourReset}]")
if (CONFIG_MOBILENET)
set(TRAINED_MODEL ${CMAKE_CURRENT_SOURCE_DIR}/models/vww_96_int8.tflite)
set(NN_WIN 96)
set(NN_HIN 96)
set(INPUT_IMAGE "${CMAKE_CURRENT_SOURCE_DIR}/images/COCO_val2014_000000174838_1_96x96.ppm")
elseif (CONFIG_MIT_PROXYLESSNAS)
set(TRAINED_MODEL ${CMAKE_CURRENT_SOURCE_DIR}/models/visual_wake_quant.tflite)
set(INPUT_IMAGE "${CMAKE_CURRENT_SOURCE_DIR}/images/COCO_val2014_000000174838_1_238x208.ppm")
set(NN_WIN 238)
set(NN_HIN 208)
endif()
message(STATUS "${APP_MSG_PREFIX} Using the ${TRAINED_MODEL}")
if(CONFIG_INFERENCE)
message(STATUS "${APP_MSG_PREFIX} Building App in INFERENCE Mode")
if (CONFIG_INFERENCE_RESIZER)
set(INPUT_IMAGE "${CMAKE_CURRENT_SOURCE_DIR}/images/COCO_val2014_000000174838_1_160x120.ppm")
set(RESIZER_FLAG --insert_resizer)
set(NN_WIN 160)
set(NN_HIN 120)
endif()
set(MAIN vww.c)
elseif(CONFIG_DEMO)
message(STATUS "${APP_MSG_PREFIX} Building App in DEMO Mode")
set(RESIZER_FLAG --insert_resizer)
set(NN_WIN 160)
set(NN_HIN 120)
set(MAIN vww_demo.c)
endif()
###############################################################################
# Autotiler Variables
###############################################################################
set(NN_NNTOOL_SCRIPT ${CMAKE_SOURCE_DIR}/nntool_generate_model.py)
set(NN_DIR ${CMAKE_BINARY_DIR}/BUILD_MODEL)
set(NN_AT_MODEL_PATH ${NN_DIR}/vwwModel.c)
set(NN_AT_TENSORS_DIR ${NN_DIR}/weight_tensors)
autotiler_add_model(
TARGET_NAME ${TARGET_NAME}
MODEL_PATH ${NN_AT_MODEL_PATH}
MODEL_TENSORS_DIR ${NN_AT_TENSORS_DIR}
MODEL_BUILDDIR ${NN_DIR}
PRI1_USED TRUE
PRI1_FLASH mram
PRI1_FILENAME "L3_Flash_Const.dat"
L1_MEMORY ${CONFIG_MODEL_L1_MEMORY}
L2_MEMORY ${CONFIG_MODEL_L2_MEMORY}
L3_MEMORY ${CONFIG_MODEL_L3_MEMORY}
L2STATIC_MEMORY ${CONFIG_MODEL_L2STATIC_MEMORY}
L3STATIC_MEMORY ${CONFIG_MODEL_L3STATIC_MEMORY}
)
add_custom_command(
OUTPUT ${NN_AT_MODEL_PATH} ${NN_AT_TENSORS_DIR} ${CONFIG_MODEL_BUILDDIR}/Expression_Kernels.c
COMMENT "Generating the autotiler model"
DEPENDS ${NN_NNTOOL_SCRIPT}
COMMAND python3 ${NN_NNTOOL_SCRIPT}
--trained_model=${TRAINED_MODEL}
${RESIZER_FLAG}
--at_model_path=${NN_AT_MODEL_PATH}
--tensors_dir=${NN_AT_TENSORS_DIR}
--flash_type="AT_MEM_L3_MRAMFLASH"
--ram_type="AT_MEM_L3_DEFAULTRAM"
)
add_custom_target(${NNTOOL_TARGET_PREFIX}clean_model
COMMENT "clean_model: removing ${COMMON_MODEL_BUILDDIR}/${MODEL_GEN}"
COMMAND rm -rf ${NN_AT_MODEL_PATH}
)
add_custom_target(test_nntool_inference
COMMENT "Testing the model via NNTool ${TRAINED_MODEL}"
DEPENDS ${NN_NNTOOL_SCRIPT}
COMMAND python3 ${NN_NNTOOL_SCRIPT}
--trained_model=${TRAINED_MODEL}
--mode="test"
--image_path=${INPUT_IMAGE}
)
###############################################################################
# Application dependencies
###############################################################################
list(APPEND TARGET_SRCS ${MAIN}
${CNN_LIB}
${CONFIG_MODEL_BUILDDIR}/${KERNEL_C}
${CONFIG_MODEL_BUILDDIR}/Expression_Kernels.c
${MODEL_EXPRESSIONS}
)
list(APPEND TARGET_INCS -I.
-I${TILER_INC}
-I${TILER_EMU_INC}
-I$ENV{GAP_SDK_HOME}/libs/gap_lib/include
${CNN_LIB_INCLUDE}
-I${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_MODEL_BUILDDIR}
-I${CMAKE_CURRENT_SOURCE_DIR}
-I${CMAKE_CURRENT_SOURCE_DIR}/at_model)
list(APPEND TARGET_CFLAGS -O3)
set(FREQ_CL 370)
set(FREQ_FC 370)
set(FREQ_PE 370)
message(STATUS "Clock speeds - Cluster ${FREQ_CL} FC ${FREQ_FC} Peripheral ${FREQ_PE}")
# math(EXPR FREQ_CL ${CONFIG_FREQUENCY_CLUSTER}/1000000 OUTPUT_FORMAT DECIMAL)
# math(EXPR FREQ_FC ${CONFIG_FREQUENCY_FC}/1000000 OUTPUT_FORMAT DECIMAL)
# math(EXPR FREQ_PE ${CONFIG_FREQUENCY_PERIPH}/1000000 OUTPUT_FORMAT DECIMAL)
list(APPEND TARGET_PREPROCESSOR -DPERF
-DAT_MODEL_PREFIX=${MODEL_PREFIX}
-DSTACK_SIZE=${CONFIG_CL_MASTER_CORE_STACK_SIZE}
-DSLAVE_STACK_SIZE=${CONFIG_CL_SLAVE_CORE_STACK_SIZE}
-DFREQ_CL=${FREQ_CL}
-DFREQ_FC=${FREQ_FC}
-DFREQ_PE=${FREQ_PE}
-DINPUT_IMAGE=${INPUT_IMAGE}
-DNN_HIN=${NN_HIN}
-DNN_WIN=${NN_WIN}
)
if (NOT ${CONFIG_CI_TARGET} EQUAL 0)
list(APPEND TARGET_PREPROCESSOR -DCI_TARGET=${CONFIG_CI_TARGET})
endif()
project(${TARGET_NAME} C ASM)
add_executable(${TARGET_NAME} ${TARGET_SRCS})
target_link_libraries(${TARGET_NAME} PUBLIC m)
target_compile_options(${TARGET_NAME} PUBLIC ${TARGET_CFLAGS}
${TARGET_INCS}
${TARGET_PREPROCESSOR})
###############################################################################
# CMake post initialization
###############################################################################
setupos(${TARGET_NAME})