docs/dev/conditional_compilation.md
Conditional compilation can significantly reduce the size of OpenVINO™ binaries by excluding unnecessary components for inference of particular models. The components are:
However, conditional compilation has a significant drawback - the resulting OpenVINO runtime will properly infer only using the models and devices for which it was compiled. If just one model is used to collect statistics for compilation, only this particular model is guaranteed to work with the resulting OpenVINO runtime.
There are two conditional compilation build stages: SELECTIVE_BUILD=COLLECT and SELECTIVE_BUILD=ON.
SELECTIVE_BUILD=COLLECT enables analysis mode for annotated code regions. It can be used to collect statistics data using itt. Once this stage is completed, run an OpenVINO sample, such as benchmark_app, to generate actual statistic data. Then run itt_collector tool to dump the data into csv files. This stage can be enabled during the OpenVINO build with the options -DSELECTIVE_BUILD=COLLECT -DENABLE_PROFILING_ITT=FULL.
SELECTIVE_BUILD=ON excludes all inactive annotated code regions from the compiled binaries using csv files generated by the itt_collector tool. It is done by a header file which generated from the csv files. This stage need build OpenVINO with option -DSELECTIVE_BUILD=ON -DENABLE_PROFILING_ITT=OFF -DSELECTIVE_BUILD_STAT=<cc_data.csv>. Notice: -DENABLE_PROFILING_ITT=OFF is not must, if user wants to have ITT counters in final application, he can set it FULL: -DENABLE_PROFILING_ITT=FULL.
NOTE: If the above options are not enabled, conditional compilation will be OFF and the default behavior is kept, all OpenVINO features are enabled. You can ignore
SELECTIVE_BUILDor set option-DSELECTIVE_BUILD=OFF.
To take advantage of conditional compilation, install the following tools:
Conditional compilation has two stages:
flowchart LR
subgraph collect[Collect statistic]
cmake_collect[mkdir build\ncd build\ncmake -DENABLE_PROFILING_ITT=FULL -DSELECTIVE_BUILD=COLLECT ..]
build_collect[cmake --build .\ncmake --build . --target sea_itt_lib]
run_collect["python ../thirdparty/itt_collector/runtool/sea_runtool.py --bindir ${OPENVINO_LIBRARY_DIR} \ \n-o ${MY_MODEL_RESULT} ! ./benchmark_app -niter 1 -nireq 1 -m ${MY_MODEL}.xml\n..."]
cmake_collect-->build_collect
build_collect-->run_collect
run_collect-->run_collect
end
subgraph result[Build cutted OpenVINO]
cmake_res["cmake -DSELECTIVE_BUILD=ON \ \n-DSELECTIVE_BUILD_STAT=${ABSOLUTE_PATH_TO_STATISTICS_FILES}/*.csv \ \n -DENABLE_PROFILING_ITT=OFF .."]
build_res[cmake --build .]
cmake_res-->build_res
end
collect --> result
To apply conditional compilation, follow the steps below:
-DENABLE_PROFILING_ITT=FULL -DSELECTIVE_BUILD=COLLECT.sea_itt_lib target to build the ITT collector..csv format.python thirdparty/itt_collector/runtool/sea_runtool.py --bindir ${OPENVINO_LIBRARY_DIR} -o ${MY_MODEL_RESULT} ! ./benchmark_app -niter 1 -nireq 1 -m ${MY_MODEL}.xml-DSELECTIVE_BUILD=ON -DSELECTIVE_BUILD_STAT=${ABSOLUTE_PATH_TO_STATISTICS_FILES}/*.csv -DENABLE_PROFILING_ITT=OFFcmake --build <cmake_build_directory>The -niter 1 -nireq 1 flags are highly recommended for benchmark_app. Otherwise, the trace files will be very large.
If you are using an application other than benchmark_app, remember to limit the number of inference requests and iterations.
Building for devices with different ISA is quite similar to building for different models (see the previous chapter). The differences are only in the code usage analysis step. The analysis step should be performed on target devices and all CSV files with statistics should be copied to the build machine. These files will be used for the final build.