|
13 | 13 | if (NOT ONNX_MODELS_DIR) |
14 | 14 | set(ONNX_MODELS_DIR input_models) |
15 | 15 | endif() |
| 16 | +get_filename_component(ONNX_MODELS_DIR "${ONNX_MODELS_DIR}" ABSOLUTE) |
16 | 17 |
|
17 | | -# Finding .onnx files to be parsed and creating the appropriate code to |
18 | | -# parse all file. It is much faster to combine all parsing in a single executable |
19 | | -# which will avoid initialization time (especially when using ROOT) |
20 | | -set(CAPTURE_STR "EmitModel( \"@1\", \"@2\");") |
21 | | -set(ALL_CAPTURES "") |
22 | | -# Finding .onnx files to be parsed and creating the appropriate command |
23 | | -file(GLOB ONNX_FILES "${ONNX_MODELS_DIR}/*.onnx") |
24 | | -foreach(onnx_file ${ONNX_FILES}) |
25 | | - get_filename_component(fname ${onnx_file} NAME_WE) |
26 | | - get_filename_component(fdir ${onnx_file} DIRECTORY) |
27 | | - string(REPLACE "@1" ${onnx_file} cap ${CAPTURE_STR}) |
28 | | - string(REPLACE "@2" ${fname} cap ${cap}) |
29 | | - list(APPEND ALL_CAPTURES ${cap}) |
30 | | -endforeach() |
31 | | -string(REPLACE ";" ";\n" EMIT_CAPTURES "${ALL_CAPTURES}") |
32 | | -configure_file(EmitFromONNX.cxx.in EmitFromONNX_all.cxx @ONLY) |
33 | | - |
34 | | -ROOTTEST_GENERATE_EXECUTABLE(emitFromONNX EmitFromONNX_all.cxx |
| 18 | +# The parsing of all .onnx files is combined in a single executable, which is |
| 19 | +# much faster than one process per model because it avoids the repeated |
| 20 | +# initialization time (especially when using ROOT). |
| 21 | +# |
| 22 | +# The list of models is globbed at build time by GenerateEmitFromONNX.cmake, |
| 23 | +# which (re-)generates EmitFromONNX_all.cxx right before the emitFromONNX |
| 24 | +# executable is built. Like this, adding or removing a model does not require |
| 25 | +# re-running CMake, and the generated file is only touched when the model list |
| 26 | +# actually changed, so no needless recompilation is triggered. |
| 27 | +set(EMIT_FROM_ONNX_SOURCE ${CMAKE_CURRENT_BINARY_DIR}/EmitFromONNX_all.cxx) |
| 28 | +add_custom_target(SofieEmitFromONNXSource |
| 29 | + COMMAND ${CMAKE_COMMAND} |
| 30 | + -DONNX_MODELS_DIR=${ONNX_MODELS_DIR} |
| 31 | + -DTEMPLATE_FILE=${CMAKE_CURRENT_SOURCE_DIR}/EmitFromONNX.cxx.in |
| 32 | + -DOUTPUT_FILE=${EMIT_FROM_ONNX_SOURCE} |
| 33 | + -P ${CMAKE_CURRENT_SOURCE_DIR}/GenerateEmitFromONNX.cmake |
| 34 | + BYPRODUCTS ${EMIT_FROM_ONNX_SOURCE} |
| 35 | + COMMENT "Updating EmitFromONNX_all.cxx from the ONNX models in ${ONNX_MODELS_DIR}") |
| 36 | + |
| 37 | +ROOTTEST_GENERATE_EXECUTABLE(emitFromONNX ${EMIT_FROM_ONNX_SOURCE} |
35 | 38 | LIBRARIES protobuf::libprotobuf ROOTTMVASofie ROOTTMVASofieParser |
| 39 | + DEPENDS SofieEmitFromONNXSource |
36 | 40 | FIXTURES_SETUP sofie-compile-models-onnx-build) |
37 | 41 |
|
38 | | -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/input_models/ConvAddReluFuseBug.onnx |
39 | | - ${CMAKE_CURRENT_BINARY_DIR}/ConvAddReluFuseBug.onnx COPYONLY) |
40 | | -ROOT_ADD_GTEST(TestParseConvAddFusion TestParseConvAddFusion.cxx |
41 | | - LIBRARIES Core ROOTTMVASofie ROOTTMVASofieParser) |
42 | | - |
43 | 42 | # silence protobuf warnings seen in version 3.0 and 3.6. Not needed from protobuf version 3.17 |
44 | 43 | target_compile_options(emitFromONNX PRIVATE -Wno-unused-parameter -Wno-array-bounds) |
45 | 44 |
|
46 | 45 | ROOTTEST_ADD_TEST(SofieCompileModels_ONNX |
47 | | - COMMAND ${CMAKE_COMMAND} -E env ROOTIGNOREPREFIX=1 ./emitFromONNX ${onnx_file} ${CMAKE_CURRENT_BINARY_DIR}/${fname} |
| 46 | + COMMAND ${CMAKE_COMMAND} -E env ROOTIGNOREPREFIX=1 ./emitFromONNX |
48 | 47 | FIXTURES_REQUIRED sofie-compile-models-onnx-build |
49 | 48 | FIXTURES_SETUP sofie-compile-models-onnx |
50 | 49 | ) |
|
0 commit comments