1 set(TFLCHEF_FILE_PATH $<TARGET_FILE:tflchef-file>)
2 set(TFLCHEF_REVERSE_PATH $<TARGET_FILE:tflchef-reverse>)
3 if(DEFINED ENV{BUILD_HOST_EXEC})
4 # TODO use better way to represent path for host executable
5 set(TFLCHEF_FILE_PATH $ENV{BUILD_HOST_EXEC}/compiler/tflchef/tools/file/tflchef-file)
6 set(TFLCHEF_REVERSE_PATH $ENV{BUILD_HOST_EXEC}/compiler/tflchef/tools/reverse/tflchef-reverse)
7 message(STATUS "TFLCHEF_FILE_PATH = ${TFLCHEF_FILE_PATH}")
8 endif(DEFINED ENV{BUILD_HOST_EXEC})
10 nncc_find_resource(TensorFlowLiteRecipes)
11 set(TENSORFLOWLITERECIPES_DIR "${TensorFlowLiteRecipes_DIR}")
13 file(GLOB RECIPES RELATIVE ${TENSORFLOWLITERECIPES_DIR} "${TENSORFLOWLITERECIPES_DIR}/*/test.recipe")
15 foreach(RECIPE IN ITEMS ${RECIPES})
16 get_filename_component(RECIPE_PREFIX ${RECIPE} DIRECTORY)
18 set(RECIPE_SOURCE_FILE "${RECIPE_PREFIX}.recipe")
19 set(RECIPE_OUTPUT_FILE "${RECIPE_PREFIX}.tflite")
22 add_custom_command(OUTPUT ${RECIPE_SOURCE_FILE}
23 COMMAND ${CMAKE_COMMAND} -E copy_if_different
24 "${TENSORFLOWLITERECIPES_DIR}/${RECIPE}" ${RECIPE_SOURCE_FILE}
25 DEPENDS "${TENSORFLOWLITERECIPES_DIR}/${RECIPE}"
26 COMMENT "Generating ${RECIPE_SOURCE_FILE}")
29 add_custom_command(OUTPUT ${RECIPE_OUTPUT_FILE}
30 COMMAND ${TFLCHEF_FILE_PATH} ${RECIPE_SOURCE_FILE} ${RECIPE_OUTPUT_FILE}
31 DEPENDS ${TFLCHEF_FILE_PATH} ${RECIPE_SOURCE_FILE}
32 COMMENT "Generating ${RECIPE_OUTPUT_FILE}")
34 list(APPEND TESTS ${RECIPE_PREFIX})
35 list(APPEND TESTFILES ${RECIPE_OUTPUT_FILE})
39 file(GLOB RECIPES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*/test.recipe")
41 foreach(RECIPE IN ITEMS ${RECIPES})
42 get_filename_component(RECIPE_PREFIX ${RECIPE} DIRECTORY)
44 set(RECIPE_SOURCE_FILE "${RECIPE_PREFIX}.recipe")
45 set(RECIPE_OUTPUT_FILE "${RECIPE_PREFIX}.tflite")
48 add_custom_command(OUTPUT ${RECIPE_SOURCE_FILE}
49 COMMAND ${CMAKE_COMMAND} -E copy_if_different
50 "${CMAKE_CURRENT_SOURCE_DIR}/${RECIPE}" ${RECIPE_SOURCE_FILE}
51 DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${RECIPE}"
52 COMMENT "Generating ${RECIPE_SOURCE_FILE}")
55 add_custom_command(OUTPUT ${RECIPE_OUTPUT_FILE}
56 COMMAND ${TFLCHEF_FILE_PATH} ${RECIPE_SOURCE_FILE} ${RECIPE_OUTPUT_FILE}
57 DEPENDS ${TFLCHEF_FILE_PATH} ${RECIPE_SOURCE_FILE}
58 COMMENT "Generating ${RECIPE_OUTPUT_FILE}")
60 list(APPEND TESTS ${RECIPE_PREFIX})
61 list(APPEND TESTFILES ${RECIPE_OUTPUT_FILE})
64 # Test tflchef-reverse
65 file(GLOB GEN_TFLITEFILES RELATIVE ${TENSORFLOWLITERECIPES_DIR} "${TENSORFLOWLITERECIPES_DIR}/*/test.reverse")
66 # Note: While in development, tflchef-reverse may not handle the operator.
67 # To separate this linkage scan empty test.reverse for test targets for tflchef-reverse.
69 foreach(TFLITEFILE IN ITEMS ${GEN_TFLITEFILES})
70 get_filename_component(TFLITE_PREFIX ${TFLITEFILE} DIRECTORY)
72 # file from above tflchef-file block
73 # use tflite file as input of tflchef-reverse generated from tflchef-file
74 set(RECIPE_OUTPUT_FILE "${TFLITE_PREFIX}.tflite")
75 set(RECIPE_GEN_OUTPUT_FILE "${TFLITE_PREFIX}.gen.recipe")
76 set(RECIPE_GEN_OUTPUT_FILE2 "${TFLITE_PREFIX}.gen.tflite")
78 # Generate .gen.recipe from generated .tflite
79 add_custom_command(OUTPUT ${RECIPE_GEN_OUTPUT_FILE}
80 COMMAND ${TFLCHEF_REVERSE_PATH} ${RECIPE_OUTPUT_FILE} ${RECIPE_GEN_OUTPUT_FILE}
81 DEPENDS ${TFLCHEF_REVERSE_PATH} ${RECIPE_OUTPUT_FILE}
82 COMMENT "Generating ${RECIPE_GEN_OUTPUT_FILE}")
84 # now we are going to generate .gen.tflite from .gen.recipe
85 # to check generated .gen.recipe file is correct by using it.
86 # as weight values may be different, binary comparision is not acceptable.
87 add_custom_command(OUTPUT ${RECIPE_GEN_OUTPUT_FILE2}
88 COMMAND ${TFLCHEF_FILE_PATH} ${RECIPE_GEN_OUTPUT_FILE} ${RECIPE_GEN_OUTPUT_FILE2}
89 DEPENDS ${TFLCHEF_FILE_PATH} ${RECIPE_GEN_OUTPUT_FILE}
90 COMMENT "Generating ${RECIPE_GEN_OUTPUT_FILE2}")
92 list(APPEND TESTS ${TFLITE_PREFIX}.gen)
93 list(APPEND TESTFILES ${RECIPE_GEN_OUTPUT_FILE2})
94 endforeach(TFLITEFILE)
96 # Test local tflchef-reverse
97 file(GLOB GEN_TFLITEFILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*/test.reverse")
99 foreach(TFLITEFILE IN ITEMS ${GEN_TFLITEFILES})
100 get_filename_component(TFLITE_PREFIX ${TFLITEFILE} DIRECTORY)
102 set(RECIPE_OUTPUT_FILE "${TFLITE_PREFIX}.tflite")
103 set(RECIPE_GEN_OUTPUT_FILE "${TFLITE_PREFIX}.gen.recipe")
104 set(RECIPE_GEN_OUTPUT_FILE2 "${TFLITE_PREFIX}.gen.tflite")
106 # Generate .gen.recipe from generated .tflite
107 add_custom_command(OUTPUT ${RECIPE_GEN_OUTPUT_FILE}
108 COMMAND ${TFLCHEF_REVERSE_PATH} ${RECIPE_OUTPUT_FILE} ${RECIPE_GEN_OUTPUT_FILE}
109 DEPENDS ${TFLCHEF_REVERSE_PATH} ${RECIPE_OUTPUT_FILE}
110 COMMENT "Generating ${RECIPE_GEN_OUTPUT_FILE}")
112 add_custom_command(OUTPUT ${RECIPE_GEN_OUTPUT_FILE2}
113 COMMAND ${TFLCHEF_FILE_PATH} ${RECIPE_GEN_OUTPUT_FILE} ${RECIPE_GEN_OUTPUT_FILE2}
114 DEPENDS ${TFLCHEF_FILE_PATH} ${RECIPE_GEN_OUTPUT_FILE}
115 COMMENT "Generating ${RECIPE_GEN_OUTPUT_FILE2}")
117 list(APPEND TESTS ${TFLITE_PREFIX}.gen)
118 list(APPEND TESTFILES ${RECIPE_GEN_OUTPUT_FILE2})
119 endforeach(TFLITEFILE)
121 # Add a dummy target to create a target-level dependency.
122 # TODO Find a way to create a dependency between tflchef_test and generated testfiles.
123 add_custom_target(tflchef_testfiles ALL DEPENDS ${TESTFILES})
125 # Using mio_tflite_validate for temporary as it only calls flatbuffer validate
126 # TODO do testing with running the model with runtime/interpreter
127 # NOTE for ARM32 cross build, $<TARGET_FILE:mio_tflite280_validate> is used as-is
128 # as test should run in ARM32 device
129 add_test(NAME tflchef_test
130 COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/runvalidate.sh"
131 $<TARGET_FILE:mio_tflite280_validate>