Skip to content

Commit 0404048

Browse files
Start with LTO patch
Add LTO options to the Dockerfile. This includes a patch that is applied to the openvino repo after it's downloaded.
1 parent 747cbb1 commit 0404048

File tree

4 files changed

+90
-8
lines changed

4 files changed

+90
-8
lines changed

.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# Optimizations used for TF Serving release builds.
1818
build:release --copt=-mavx
1919
build:release --copt=-msse4.2
20+
build:linux --copt="-march=haswell"
2021

2122
# Options used to build with CUDA.
2223
build:cuda --crosstool_top=@local_config_cuda//crosstool:toolchain

Dockerfile.redhat

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ SHELL ["/bin/bash", "-xo", "pipefail", "-c"]
2626

2727
ARG JOBS=8
2828
ARG VERBOSE_LOGS=OFF
29+
ARG LTO_ENABLE=OFF
30+
ARG LTO_CXX_FLAGS=""
31+
ARG LTO_LD_FLAGS="-Wl,-z,relro"
2932

3033
# hadolint ignore=DL3041
3134
RUN echo -e "max_parallel_downloads=8\nretries=50" >> /etc/dnf/dnf.conf && \
@@ -51,7 +54,10 @@ WORKDIR /boost
5154
RUN wget -nv https://sourceforge.net/projects/boost/files/boost/1.68.0/boost_1_68_0.tar.gz && \
5255
if [ "$VERBOSE_LOGS" == "ON" ] ; then export BVERBOSE="-d+2" ; else export BVERBOSE="" ; fi && \
5356
tar xf boost_1_68_0.tar.gz && cd boost_1_68_0 && ./bootstrap.sh && \
54-
./b2 -j ${JOBS} cxxstd=17 link=static cxxflags='-fPIC' cflags='-fPIC' \
57+
./b2 -j ${JOBS} cxxstd=17 link=static variant=release \
58+
cxxflags="-fPIC $LTO_CXX_FLAGS" \
59+
cflags="-fPIC $LTO_CXX_FLAGS" \
60+
linkflags="$LTO_LD_FLAGS" \
5561
--with-chrono --with-date_time --with-filesystem \
5662
--with-program_options --with-system \
5763
--with-random --with-thread --with-atomic --with-regex \
@@ -65,7 +71,9 @@ COPY third_party/pugixml /ovms/third_party/pugixml
6571
RUN git clone -b v1.13 https://github.com/zeux/pugixml && \
6672
cd pugixml && \
6773
patch -p1 < /ovms/third_party/pugixml/pugixml_v1.13_flags.patch && \
68-
cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_VERBOSE_MAKEFILE=${VERBOSE_LOGS} && \
74+
cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_VERBOSE_MAKEFILE=${VERBOSE_LOGS} \
75+
-DCMAKE_CXX_FLAGS="${LTO_CXX_FLAGS}" \
76+
-DCMAKE_SHARED_LINKER_FLAGS="${LTO_LD_FLAGS}" && \
6977
make all -j ${JOBS} && \
7078
cp -P libpugixml.so* /usr/lib64/
7179

@@ -79,10 +87,10 @@ RUN git clone --recurse-submodules --depth 1 --branch v2.10.16 https://github.co
7987
patch -d /azure/azure-storage-cpp/ -p1 </ovms/third_party/azure/azure_sdk.patch
8088

8189
WORKDIR /azure/cpprestsdk/Release/build.release
82-
RUN cmake .. -DCMAKE_VERBOSE_MAKEFILE=${VERBOSE_LOGS} -DCMAKE_CXX_FLAGS="-fPIC" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DBoost_USE_STATIC_RUNTIME=ON -DBoost_USE_STATIC_LIBS=ON -DWERROR=OFF -DBUILD_SAMPLES=OFF -DBUILD_TESTS=OFF && make --jobs=$JOBS install
90+
RUN cmake .. -DCMAKE_VERBOSE_MAKEFILE=${VERBOSE_LOGS} -DCMAKE_CXX_FLAGS="-fPIC ${LTO_CXX_FLAGS}" -DCMAKE_SHARED_LINKER_FLAGS="${LTO_LD_FLAGS}" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DBoost_USE_STATIC_RUNTIME=ON -DBoost_USE_STATIC_LIBS=ON -DWERROR=OFF -DBUILD_SAMPLES=OFF -DBUILD_TESTS=OFF && make --jobs=$JOBS install
8391

8492
WORKDIR /azure/azure-storage-cpp/Microsoft.WindowsAzure.Storage/build.release
85-
RUN CASABLANCA_DIR=/azure/cpprestsdk cmake .. -DCMAKE_CXX_FLAGS="-fPIC" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DBoost_USE_STATIC_RUNTIME=ON -DBoost_USE_STATIC_LIBS=ON -DCMAKE_VERBOSE_MAKEFILE=${VERBOSE_LOGS} && make --jobs=$JOBS && make --jobs=$JOBS install
93+
RUN CASABLANCA_DIR=/azure/cpprestsdk cmake .. -DCMAKE_CXX_FLAGS="-fPIC ${LTO_CXX_FLAGS}" -DCMAKE_SHARED_LINKER_FLAGS="${LTO_LD_FLAGS}" -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DBoost_USE_STATIC_RUNTIME=ON -DBoost_USE_STATIC_LIBS=ON -DCMAKE_VERBOSE_MAKEFILE=${VERBOSE_LOGS} && make --jobs=$JOBS && make --jobs=$JOBS install
8694
####### End of Azure SDK
8795

8896
####### Build OpenCV
@@ -99,6 +107,7 @@ SHELL ["/bin/bash", "-xo", "pipefail", "-c"]
99107

100108
ARG JOBS=40
101109
ARG VERBOSE_LOGS=OFF
110+
ARG LTO_ENABLE=OFF
102111

103112
# hadolint ignore=DL3041
104113
RUN dnf install -y https://rpmfind.net/linux/almalinux/8.10/PowerTools/x86_64/os/Packages/opencl-headers-2.2-1.20180306gite986688.el8.noarch.rpm && \
@@ -175,9 +184,12 @@ RUN dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.n
175184
# hadolint ignore=DL3003
176185
RUN if [ "$ov_use_binary" == "0" ] ; then true ; else exit 0 ; fi ; git clone https://github.com/$ov_source_org/openvino.git /openvino && cd /openvino && git checkout $ov_source_branch && git submodule update --init --recursive
177186
RUN if [ "$ov_use_binary" == "0" ]; then true ; else exit 0 ; fi ; if ! [[ $debug_bazel_flags == *"py_off"* ]]; then true ; else exit 0 ; fi ; pip3 install --no-cache-dir -r /openvino/src/bindings/python/wheel/requirements-dev.txt
187+
WORKDIR /openvino
188+
COPY openvino-lto.patch .
189+
RUN if [ "$ov_use_binary" == "0" ]; then patch -p1 < openvino-lto.patch ; rm -f openvino-lto.patch ; fi
178190
WORKDIR /openvino/build
179-
RUN if [ "$ov_use_binary" == "0" ] && [[ $debug_bazel_flags == *"PYTHON_DISABLE=1"* ]]; then true ; else exit 0 ; fi ; if ! [[ $debug_bazel_flags == *"PYTHON_DISABLE=1"* ]]; then true ; else exit 0 ; fi ; cmake -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE -DCMAKE_VERBOSE_MAKEFILE="${VERBOSE_LOGS}" -DENABLE_PYTHON=ON -DENABLE_INTEL_NPU=OFF -DENABLE_SAMPLES=0 -DCMAKE_CXX_FLAGS=" -Wno-error=parentheses " ..
180-
RUN if [ "$ov_use_binary" == "0" ] ; then true ; else exit 0 ; fi ; cmake -DCMAKE_BUILD_TYPE="$CMAKE_BUILD_TYPE" -DCMAKE_VERBOSE_MAKEFILE="${VERBOSE_LOGS}" -DENABLE_SAMPLES=0 -DENABLE_INTEL_NPU=OFF -DCMAKE_CXX_FLAGS=" -Wno-error=parentheses " ..
191+
RUN if [ "$ov_use_binary" == "0" ] && [[ $debug_bazel_flags == *"PYTHON_DISABLE=1"* ]]; then true ; else exit 0 ; fi ; if ! [[ $debug_bazel_flags == *"PYTHON_DISABLE=1"* ]]; then true ; else exit 0 ; fi ; cmake -DCMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE -DCMAKE_VERBOSE_MAKEFILE="${VERBOSE_LOGS}" -DENABLE_LTO=${LTO_ENABLE} -DENABLE_PYTHON=ON -DENABLE_INTEL_NPU=OFF -DENABLE_SAMPLES=0 -DCMAKE_CXX_FLAGS=" -Wno-error=parentheses ${LTO_CXX_FLAGS} " -DCMAKE_SHARED_LINKER_FLAGS="${LTO_LD_FLAGS}" ..
192+
RUN if [ "$ov_use_binary" == "0" ] ; then true ; else exit 0 ; fi ; cmake -DCMAKE_BUILD_TYPE="$CMAKE_BUILD_TYPE" -DCMAKE_VERBOSE_MAKEFILE="${VERBOSE_LOGS}" -DENABLE_LTO=${LTO_ENABLE} -DENABLE_SAMPLES=0 -DENABLE_INTEL_NPU=OFF -DCMAKE_CXX_FLAGS=" -Wno-error=parentheses ${LTO_CXX_FLAGS} " -DCMAKE_SHARED_LINKER_FLAGS="${LTO_LD_FLAGS}" ..
181193
RUN if [ "$ov_use_binary" == "0" ] ; then true ; else exit 0 ; fi ; make --jobs=$JOBS
182194
RUN if [ "$ov_use_binary" == "0" ] ; then true ; else exit 0 ; fi ; make install
183195
RUN if [ "$ov_use_binary" == "0" ] ; then true ; else exit 0 ; fi ; \
@@ -225,7 +237,7 @@ ARG ov_tokenizers_branch=85be884a69f10270703f81f970a5ee596a4c8df7
225237
# hadolint ignore=DL3003
226238
RUN git clone https://github.com/openvinotoolkit/openvino_tokenizers.git /openvino_tokenizers && cd /openvino_tokenizers && git checkout $ov_tokenizers_branch && git submodule update --init --recursive
227239
WORKDIR /openvino_tokenizers/build
228-
RUN cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE="${VERBOSE_LOGS}" && cmake --build . --parallel $JOBS ; cp /openvino_tokenizers/build/src/lib*.so /opt/intel/openvino/runtime/lib/intel64/
240+
RUN cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE="${VERBOSE_LOGS}" -DCMAKE_CXX_FLAGS=" ${LTO_CXX_FLAGS} " -DCMAKE_SHARED_LINKER_FLAGS="${LTO_LD_FLAGS}" && cmake --build . --parallel $JOBS ; cp /openvino_tokenizers/build/src/lib*.so /opt/intel/openvino/runtime/lib/intel64/
229241

230242
# Build OpenVINO Model Server
231243
WORKDIR /ovms

openvino-lto.patch

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
diff --git a/CMakeLists.txt b/CMakeLists.txt
2+
index 2187deb8e8..ad15a73395 100644
3+
--- a/CMakeLists.txt
4+
+++ b/CMakeLists.txt
5+
@@ -65,6 +65,7 @@ if(ENABLE_COVERAGE)
6+
include(cmake/coverage.cmake)
7+
endif()
8+
9+
+set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})
10+
if(APPLE AND CMAKE_OSX_DEPLOYMENT_TARGET AND
11+
CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS 10.15)
12+
message(FATAL_ERROR "OpenVINO requires MACOSX_DEPLOYMENT_TARGET at least 10.15, specified ${CMAKE_OSX_DEPLOYMENT_TARGET}")
13+
diff --git a/src/frontends/common/CMakeLists.txt b/src/frontends/common/CMakeLists.txt
14+
index e4d2fe63e1..eace2a5593 100644
15+
--- a/src/frontends/common/CMakeLists.txt
16+
+++ b/src/frontends/common/CMakeLists.txt
17+
@@ -52,7 +52,8 @@ target_link_libraries(${TARGET_NAME}_obj PRIVATE openvino::util openvino::core::
18+
19+
# TODO: fix lto
20+
set_target_properties(${TARGET_NAME}_obj PROPERTIES
21+
- INTERPROCEDURAL_OPTIMIZATION_RELEASE OFF)
22+
+ INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})
23+
+ov_add_compiler_flags(-march=haswell)
24+
25+
set(FRONTEND_LIB_SUFFIX "${FRONTEND_NAME_SUFFIX}${OV_BUILD_POSTFIX}")
26+
if(APPLE)
27+
--- a/thirdparty/onnx/CMakeLists.txt
28+
+++ b/thirdparty/onnx/CMakeLists.txt
29+
@@ -21,7 +21,10 @@ endif()
30+
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
31+
# 4244 conversion from 'XXX' to 'YYY', possible loss of data
32+
ov_add_compiler_flags(/wd4244)
33+
+else()
34+
+ ov_add_compiler_flags(-march=haswell)
35+
endif()
36+
+set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})
37+
38+
set(PYTHON_EXECUTABLE "${Python3_EXECUTABLE}")
39+
set(ONNX_USE_PROTOBUF_SHARED_LIBS OFF CACHE BOOL "Use dynamic protobuf by ONNX library" FORCE)
40+
diff --git a/thirdparty/protobuf/CMakeLists.txt b/thirdparty/protobuf/CMakeLists.txt
41+
index a16bd56d11..2829926e68 100644
42+
--- a/thirdparty/protobuf/CMakeLists.txt
43+
+++ b/thirdparty/protobuf/CMakeLists.txt
44+
@@ -10,6 +10,7 @@ set(BUILD_SHARED_LIBS OFF)
45+
46+
if(CMAKE_COMPILER_IS_GNUCXX OR OV_COMPILER_IS_CLANG OR (OV_COMPILER_IS_INTEL_LLVM AND UNIX))
47+
ov_add_compiler_flags(-Wno-all)
48+
+ ov_add_compiler_flags(-march=haswell)
49+
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 11 AND CMAKE_COMPILER_IS_GNUCXX)
50+
ov_add_compiler_flags(-Wno-stringop-overflow)
51+
endif()
52+
@@ -48,6 +49,7 @@ else()
53+
set(protobuf_dir protobuf/cmake)
54+
endif()
55+
56+
+set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})
57+
add_subdirectory(${protobuf_dir} EXCLUDE_FROM_ALL)
58+
get_directory_property(protobuf_VERSION DIRECTORY ${protobuf_dir} DEFINITION protobuf_VERSION)
59+
60+
@@ -63,7 +65,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR OV_COMPILER_IS_CLANG OR OV_COMPILER_IS_INTEL_LLVM
61+
CXX_VISIBILITY_PRESET default
62+
C_VISIBILITY_PRESET default
63+
VISIBILITY_INLINES_HIDDEN OFF
64+
- INTERPROCEDURAL_OPTIMIZATION_RELEASE OFF)
65+
+ INTERPROCEDURAL_OPTIMIZATION_RELEASE ${ENABLE_LTO})
66+
endif()
67+
ov_disable_all_warnings(${_protoc_libs} libprotobuf-lite)
68+
set_target_properties(libprotobuf-lite PROPERTIES

third_party/opencv/opencv_cmake_flags.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
-D BUILD_LIST=core,improc,imgcodecs,calib3d,features2d,highgui,imgproc,video,videoio,optflow \
22
-D OPENCV_EXTRA_MODULES_PATH=/opt/opencv_contrib_repo/modules \
33
-D CMAKE_BUILD_TYPE=Release \
4+
-D ENABLE_LTO=${LTO_ENABLE} \
45
-D CMAKE_INSTALL_PREFIX=/opt/opencv \
56
-D OPENCV_LIB_INSTALL_PATH=lib \
67
-D BUILD_TESTS=OFF \
@@ -39,4 +40,4 @@
3940
-D WITH_JPEG=ON \
4041
-D WITH_PNG=ON \
4142
-D WITH_TIFF=OFF \
42-
-D WITH_OPENEXR=OFF
43+
-D WITH_OPENEXR=OFF

0 commit comments

Comments
 (0)