@@ -10,6 +10,8 @@ set(FLATBUFFERS_PATH ${sof_top_dir}/../flatbuffers)
1010set (GEMMLOWP_PATH ${sof_top_dir} /../gemmlowp)
1111set (RUY_PATH ${sof_top_dir} /../ruy)
1212
13+ if (CMAKE_C_COMPILER_ID STREQUAL "Xtensa" )
14+ set (TFLM_EXTRA_LIBS nn_hifi_lib)
1315add_library (nn_hifi_lib STATIC
1416 ${NN_HIFI_PATH} /algo/common/src/xa_nnlib_common_api.c
1517 ${NN_HIFI_PATH} /algo/kernels/reorg/hifi4/xa_nn_pad_8.c
@@ -43,6 +45,7 @@ add_library(nn_hifi_lib STATIC
4345 ${NN_HIFI_PATH} /algo/kernels/cnn/hifi4/xa_nn_conv2d_pointwise_sym8sxsym16s.c
4446 ${NN_HIFI_PATH} /algo/kernels/cnn/hifi4/xa_nn_conv2d_pointwise_8x16.c
4547 ${NN_HIFI_PATH} /algo/kernels/cnn/hifi4/xa_nn_circ_buf.c
48+
4649 ${NN_HIFI_PATH} /algo/kernels/cnn/hifi4/xa_nn_conv2d_std_8x8.c
4750 ${NN_HIFI_PATH} /algo/kernels/cnn/hifi4/xa_nn_conv2d_depthwise.c
4851 ${NN_HIFI_PATH} /algo/kernels/cnn/hifi4/xa_nn_matXvec_16x16_16_circ.c
@@ -206,18 +209,79 @@ target_compile_options(nn_hifi_lib PRIVATE
206209 -fsigned-char
207210 -fno-exceptions
208211 -mlongcalls
209- -INLINE:requested
210- -mcoproc
211212 -fno-zero-initialized-in-bss
212213 -mtext-section-literals
213214 -Wsign-compare
214- -m32
215215 -DMODEL_INT16
216216 -DNNLIB_V2
217217 -Dhifi4
218218 -DTFLITE_SINGLE_ROUNDING=1
219219)
220220
221+ target_compile_options (nn_hifi_lib PRIVATE
222+ -INLINE:requested
223+ -mcoproc
224+ -m32
225+ )
226+ else ()
227+ set (TFLM_EXTRA_LIBS "" )
228+ endif ()
229+
230+
231+
232+ if (CMAKE_C_COMPILER_ID STREQUAL "Xtensa" )
233+ set (TFLM_KERNEL_SOURCES
234+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/sub.cc
235+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/conv_hifi.cc
236+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/pooling_vision.cc
237+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/softmax_vision.cc
238+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/unidirectional_sequence_lstm.cc
239+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/transpose_conv.cc
240+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/fully_connected_common_xtensa.cc
241+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/lstm_eval_hifi.cc
242+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/add_vision.cc
243+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/depthwise_conv.cc
244+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/reshape.cc
245+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/softmax.cc
246+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/depthwise_conv_hifi.cc
247+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/conv_int16_reference.cc
248+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/conv_int8_reference.cc
249+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/fully_connected_int8.cc
250+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/pad_vision.cc
251+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/fully_connected_vision.cc
252+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/conv_int8_int16.cc
253+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/conv.cc
254+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/softmax_int8_int16.cc
255+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/logistic.cc
256+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/reduce.cc
257+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/lstm_eval.cc
258+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/reshape_vision.cc
259+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/pad.cc
260+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/reduce_vision.cc
261+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/dequantize.cc
262+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/add.cc
263+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/pooling_int8.cc
264+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/depthwise_conv_vision.cc
265+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/strided_slice.cc
266+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/conv_common_xtensa.cc
267+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/svdf.cc
268+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/fully_connected.cc
269+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/leaky_relu.cc
270+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/quantize.cc
271+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/pooling.cc
272+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/conv_vision.cc
273+ )
274+ else ()
275+ set (TFLM_KERNEL_SOURCES
276+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/sub.cc
277+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/conv.cc
278+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/depthwise_conv.cc
279+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/fully_connected.cc
280+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/reshape.cc
281+ ${TFLM_PATH} /tensorflow/lite/micro/kernels/softmax.cc
282+ )
283+ endif ()
284+
221285# TODO: complete sources have been added here from userspace build but
222286# not all are needed so this is a list of "needed" sources to build
223287# a memory and performance optimized TFLM for SOF.
@@ -325,46 +389,9 @@ add_library(tflm_lib STATIC
325389 #${TFLM_PATH}/tensorflow/lite/micro/kernels/var_handle.cc
326390 #${TFLM_PATH}/tensorflow/lite/micro/kernels/while.cc
327391 #${TFLM_PATH}/tensorflow/lite/micro/kernels/zeros_like.cc
328- # xtensa kernels
329- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/sub.cc
330- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/conv_hifi.cc
331- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/pooling_vision.cc
332- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/softmax_vision.cc
333- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/unidirectional_sequence_lstm.cc
334- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/transpose_conv.cc
335- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/fully_connected_common_xtensa.cc
336- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/lstm_eval_hifi.cc
337- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/add_vision.cc
338- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/depthwise_conv.cc
339- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/reshape.cc
340- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/softmax.cc
341- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/depthwise_conv_hifi.cc
342- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/conv_int16_reference.cc
343- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/conv_int8_reference.cc
344- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/fully_connected_int8.cc
345- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/pad_vision.cc
346- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/fully_connected_vision.cc
347- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/conv_int8_int16.cc
348- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/conv.cc
349- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/softmax_int8_int16.cc
350- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/logistic.cc
351- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/reduce.cc
352- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/lstm_eval.cc
353- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/reshape_vision.cc
354- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/pad.cc
355- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/reduce_vision.cc
356- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/dequantize.cc
357- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/add.cc
358- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/pooling_int8.cc
359- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/depthwise_conv_vision.cc
360- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/strided_slice.cc
361- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/conv_common_xtensa.cc
362- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/svdf.cc
363- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/fully_connected.cc
364- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/leaky_relu.cc
365- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/quantize.cc
366- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/pooling.cc
367- ${TFLM_PATH} /tensorflow/lite/micro/kernels/xtensa/conv_vision.cc
392+
393+ ${TFLM_KERNEL_SOURCES}
394+
368395 ${TFLM_PATH} /tensorflow/lite/micro/mock_micro_graph.cc
369396 ${TFLM_PATH} /tensorflow/lite/micro/flatbuffer_utils.cc
370397 ${TFLM_PATH} /tensorflow/lite/micro/micro_interpreter_graph.cc
@@ -420,7 +447,6 @@ target_include_directories(tflm_lib PRIVATE
420447#endif
421448target_compile_options (tflm_lib PRIVATE
422449 -std=c++17
423- -stdlib=libc++
424450 -fno-rtti
425451 -fno-exceptions
426452 -fno-threadsafe-statics
@@ -443,14 +469,30 @@ target_compile_options(tflm_lib PRIVATE
443469 -DKERNELS_OPTIMIZED_FOR_SPEED
444470 -DTF_LITE_MCU_DEBUG_LOG
445471 -DTF_LITE_USE_CTIME
446- --xtensa-core=ace10_LX7HiFi4_2022_10
447- -mcoproc
448472 -DHIFI4
449473 -mlongcalls
450474 -DNNLIB_V2
451475 -Wno-shadow
452476)
453477
478+ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
479+ target_compile_options (tflm_lib PRIVATE -stdlib=libc++ )
480+ endif ()
481+
482+ if (CMAKE_C_COMPILER_ID STREQUAL "Xtensa" )
483+ target_compile_options (tflm_lib PRIVATE
484+ --xtensa-core=ace10_LX7HiFi4_2022_10
485+ -mcoproc
486+ )
487+ endif ()
488+
489+
490+ if (CMAKE_C_COMPILER_ID STREQUAL "Xtensa" )
491+ set (TFLM_STD_LIBS c++ hal)
492+ else ()
493+ set (TFLM_STD_LIBS stdc++)
494+ endif ()
495+
454496sof_llext_build ("tflm"
455497 SOURCES ../tflm-classify.c ../llext-wrap.c
456498
@@ -459,7 +501,8 @@ sof_llext_build("tflm"
459501
460502 # TFLM is a C++ userspace application so hence we need to link
461503 # userspace C++, C, maths and C runtime for llext module usage.
462- LIBS tflm_lib nn_hifi_lib c++ m c gcc hal
504+ LIBS tflm_lib ${TFLM_EXTRA_LIBS} ${TFLM_STD_LIBS} m c gcc
463505 LIBS_PATH .
464506)
465507
508+
0 commit comments