Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build ONNXRuntime wheels #288

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 66 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
SSOCR_VERSION \
LIBCEC_VERSION \
PICOTTS_HASH \
TELLDUS_COMMIT
TELLDUS_COMMIT \
ONNXRUNTIME_VERSION

# Add Home Assistant wheels repository
ENV WHEELS_LINKS=https://wheels.home-assistant.io/musllinux/
Expand Down Expand Up @@ -144,6 +145,70 @@
/usr/src/telldus \
/usr/src/telldus-fix-gcc-11-issues.patch \
/usr/src/telldus-fix-alpine-3-17-issues.patch

# ONNX Runtime
COPY patches/onnx-0001-Remove-MATH_NO_EXCEPT-macro.patch /usr/src/
COPY patches/onnx-0002-prevent-object-destruction-compile-error-16134.patch /usr/src/
COPY patches/onnx-cxx17.patch /usr/src/
COPY patches/onnx-no-execinfo.patch /usr/src/
COPY patches/onnx-system.patch /usr/src/
RUN \

Check failure on line 155 in Dockerfile

View workflow job for this annotation

GitHub Actions / lint

SC2102 info: Ranges can only match single chars (mentioned due to duplicates).
apk add --no-cache \
abseil-cpp-log-internal-check-op \
abseil-cpp-log-internal-message \
abseil-cpp-raw-hash-set \
libprotobuf-lite \
libstdc++ \
re2 \
&& apk add --no-cache --virtual .build-dependencies \
build-base \
abseil-cpp-dev \
patchelf \
cmake \
icu-dev \
linux-headers \
nlohmann-json \
patch \
protobuf-dev \
re2-dev \
samurai \
zlib-dev \
&& pip3 install --no-cache-dir --no-index --only-binary=:all: --find-links "${WHEELS_LINKS}" numpy packaging \
&& pip3 install --no-cache-dir pybind11[global] auditwheel \
&& mkdir /usr/src/onnxruntime \
&& curl -J -L -o /tmp/onnxruntime.tar.gz \
"https://github.com/microsoft/onnxruntime/archive/refs/tags/v${ONNXRUNTIME_VERSION}.tar.gz" \
&& tar zxvf \
/tmp/onnxruntime.tar.gz \
--strip 1 -C /usr/src/onnxruntime \
&& cd onnxruntime \
&& patch -p1 < ../onnx-0001-Remove-MATH_NO_EXCEPT-macro.patch \
&& patch -p1 < ../onnx-0002-prevent-object-destruction-compile-error-16134.patch \
&& patch -p1 < ../onnx-cxx17.patch \
&& patch -p1 < ../onnx-no-execinfo.patch \
&& patch -p1 < ../onnx-system.patch \
&& cmake -S cmake -B build -G Ninja \
-DCMAKE_BUILD_TYPE=None \
-DCMAKE_INSTALL_PREFIX=/usr \
-DBUILD_ONNX_PYTHON=ON \
-Donnxruntime_BUILD_SHARED_LIB=ON \
-Donnxruntime_ENABLE_PYTHON=ON \
&& sed -i 's|CMAKE_CXX_STANDARD 11|CMAKE_CXX_STANDARD 17|' build/_deps/onnx-src/CMakeLists.txt \
&& cd build \
&& cmake --build . \
&& cmake --install . \
&& python3 ../setup.py bdist_wheel \
&& auditwheel repair dist/*.whl \
\
# Here they are...
&& ls -la wheelhouse/*.whl \
\
&& apk del .build-dependencies \
&& rm -rf \
/tmp/onnxruntime.tar.gz \
/usr/src/onnxruntime \
/usr/src/onnx-*.patch

###
# Base S6-Overlay
COPY rootfs /
1 change: 1 addition & 0 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ labels:
args:
SSOCR_VERSION: 2.22.1
LIBCEC_VERSION: 6.0.2
ONNXRUNTIME_VERSION: 1.15.1
TELLDUS_COMMIT: 2598bbed16ffd701f2a07c99582f057a3decbaf3
PICOTTS_HASH: e3ba46009ee868911fa0b53db672a55f9cc13b1c
49 changes: 49 additions & 0 deletions patches/onnx-0001-Remove-MATH_NO_EXCEPT-macro.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
From 8caf31352140d655e2c88fb9784982c4e5db3b5b Mon Sep 17 00:00:00 2001
From: sudotac <[email protected]>
Date: Sun, 6 Aug 2023 23:46:28 +0900
Subject: [PATCH] Remove MATH_NO_EXCEPT macro

Signed-off-by: sudotac <[email protected]>
---
.../test/providers/cpu/math/element_wise_ops_test.cc | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc b/onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc
index 04fbd05669..5ec4d915f5 100644
--- a/onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc
+++ b/onnxruntime/test/providers/cpu/math/element_wise_ops_test.cc
@@ -2603,13 +2603,7 @@ TEST(MathOpTest, Mean_8) {
test.Run(OpTester::ExpectResult::kExpectSuccess, "", {kTensorrtExecutionProvider}); // TensorRT: Input batch size is inconsistent
}

-#ifdef _LIBCPP_VERSION
-#define MATH_NO_EXCEPT
-#else
-#define MATH_NO_EXCEPT noexcept
-#endif
-
-template <float (&op)(float value) MATH_NO_EXCEPT>
+template <float (&op)(float value)>
void TrigFloatTest(OpTester& test, std::initializer_list<float> input) {
std::vector<int64_t> dims{static_cast<int64_t>(input.size())};

@@ -2622,7 +2616,7 @@ void TrigFloatTest(OpTester& test, std::initializer_list<float> input) {
test.Run();
}

-template <double (&op)(double value) MATH_NO_EXCEPT>
+template <double (&op)(double value)>
void TrigDoubleTest(OpTester& test, std::initializer_list<double> input,
const std::unordered_set<std::string> excluded_provider_types = {}) {
std::vector<int64_t> dims{static_cast<int64_t>(input.size())};
@@ -2636,7 +2630,7 @@ void TrigDoubleTest(OpTester& test, std::initializer_list<double> input,
test.Run(OpTester::ExpectResult::kExpectSuccess, "", excluded_provider_types);
}

-template <float (&op)(float value) MATH_NO_EXCEPT>
+template <float (&op)(float value)>
void TrigFloat16Test(OpTester& test, std::initializer_list<float> input) {
std::vector<int64_t> dims{static_cast<int64_t>(input.size())};

--
2.41.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
From b674a15d5c0133e76f3b1c4372ff4cf50d6cb608 Mon Sep 17 00:00:00 2001
From: Somdev Sangwan <[email protected]>
Date: Fri, 2 Jun 2023 23:49:53 +0530
Subject: [PATCH] prevent object destruction compile error (#16134)

### Description
The proposed fix is to store the result of AsBlockSparse() in a variable
to ensure the object isn't destroyed until the end of the current scope.

### Motivation and Context
"own_buffer_tensor" is a temporary object that is destroyed at the end
of the expression and causes a compile error.
---
onnxruntime/test/framework/sparse_kernels_test.cc | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/onnxruntime/test/framework/sparse_kernels_test.cc b/onnxruntime/test/framework/sparse_kernels_test.cc
index 1a535144f4..b269b3231b 100644
--- a/onnxruntime/test/framework/sparse_kernels_test.cc
+++ b/onnxruntime/test/framework/sparse_kernels_test.cc
@@ -1815,7 +1815,8 @@ TEST(SparseTensorConversionTests, BlockSparse) {
ASSERT_EQ(data_blocks.size(), data_span.size());
ASSERT_TRUE(std::equal(data_blocks.cbegin(), data_blocks.cend(), data_span.begin(), data_span.end()));

- const auto& indices = own_buffer_tensor.AsBlockSparse().Indices();
+ auto block_sparse = own_buffer_tensor.AsBlockSparse();
+ const auto& indices = block_sparse.Indices();
ASSERT_EQ(indices_shape, indices.Shape());
auto indices_span = indices.DataAsSpan<int32_t>();
ASSERT_TRUE(std::equal(blocksparse_indices.cbegin(), blocksparse_indices.cend(),
@@ -1834,7 +1835,8 @@ TEST(SparseTensorConversionTests, BlockSparse) {
ASSERT_EQ(data_blocks.size(), data_span.size());
ASSERT_TRUE(std::equal(data_blocks.cbegin(), data_blocks.cend(), data_span.begin(), data_span.end()));

- const auto& indices = user_buffer_tensor.AsBlockSparse().Indices();
+ auto block_sparse = user_buffer_tensor.AsBlockSparse();
+ const auto& indices = block_sparse.Indices();
ASSERT_EQ(indices_shape, indices.Shape());
auto indices_span = indices.DataAsSpan<int32_t>();
ASSERT_TRUE(std::equal(blocksparse_indices.cbegin(), blocksparse_indices.cend(),
@@ -1855,7 +1857,8 @@ TEST(SparseTensorConversionTests, BlockSparse) {
ASSERT_EQ(expected_span.size(), data_span.size());
ASSERT_TRUE(std::equal(expected_span.begin(), expected_span.end(), data_span.begin(), data_span.end()));

- const auto& indices = own_buffer_tensor.AsBlockSparse().Indices();
+ auto block_sparse = own_buffer_tensor.AsBlockSparse();
+ const auto& indices = block_sparse.Indices();
ASSERT_EQ(indices_shape, indices.Shape());
auto indices_span = indices.DataAsSpan<int32_t>();
ASSERT_TRUE(std::equal(blocksparse_indices.cbegin(), blocksparse_indices.cend(),
--
2.41.0
26 changes: 26 additions & 0 deletions patches/onnx-cxx17.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
diff --git a/js/node/CMakeLists.txt b/js/node/CMakeLists.txt
index 5557440..f8c8b19 100644
--- a/js/node/CMakeLists.txt
+++ b/js/node/CMakeLists.txt
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.11)

project (onnxruntime-node)

-set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD 17)

add_compile_definitions(NAPI_VERSION=${napi_build_version})
add_compile_definitions(ORT_API_MANUAL_INIT)
diff --git a/onnxruntime/python/tools/tensorrt/perf/mem_test/CMakeLists.txt b/onnxruntime/python/tools/tensorrt/perf/mem_test/CMakeLists.txt
index 2d969cf..fd9de3e 100644
--- a/onnxruntime/python/tools/tensorrt/perf/mem_test/CMakeLists.txt
+++ b/onnxruntime/python/tools/tensorrt/perf/mem_test/CMakeLists.txt
@@ -4,7 +4,7 @@ set(CMAKE_BUILD_TYPE Debug)

cmake_minimum_required (VERSION 2.6)

-set(CMAKE_CXX_STANDARD 14)
+set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include_directories(
22 changes: 22 additions & 0 deletions patches/onnx-no-execinfo.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/onnxruntime/core/platform/posix/stacktrace.cc b/onnxruntime/core/platform/posix/stacktrace.cc
index 76864b2..185f131 100644
--- a/onnxruntime/core/platform/posix/stacktrace.cc
+++ b/onnxruntime/core/platform/posix/stacktrace.cc
@@ -3,7 +3,7 @@

#include "core/common/common.h"

-#if !defined(__ANDROID__) && !defined(__wasm__) && !defined(_OPSCHEMA_LIB_) && !defined(_AIX)
+#if defined(__GLIBC__) && !defined(__ANDROID__) && !defined(__wasm__) && !defined(_OPSCHEMA_LIB_) && !defined(_AIX)
#include <execinfo.h>
#endif
#include <vector>
@@ -13,7 +13,7 @@ namespace onnxruntime {
std::vector<std::string> GetStackTrace() {
std::vector<std::string> stack;

-#if !defined(NDEBUG) && !defined(__ANDROID__) && !defined(__wasm__) && !defined(_OPSCHEMA_LIB_)
+#if defined(__GLIBC__) && !defined(NDEBUG) && !defined(__ANDROID__) && !defined(__wasm__) && !defined(_OPSCHEMA_LIB_)
constexpr int kCallstackLimit = 64; // Maximum depth of callstack

void* array[kCallstackLimit];
57 changes: 57 additions & 0 deletions patches/onnx-system.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
diff --git a/cmake/external/onnxruntime_external_deps.cmake b/cmake/external/onnxruntime_external_deps.cmake
index 9effd1a2db..ed15ad31aa 100644
--- a/cmake/external/onnxruntime_external_deps.cmake
+++ b/cmake/external/onnxruntime_external_deps.cmake
@@ -20,16 +20,16 @@ endforeach()
message("Loading Dependencies ...")
# ABSL should be included before protobuf because protobuf may use absl
if(NOT onnxruntime_DISABLE_ABSEIL)
- include(external/abseil-cpp.cmake)
+ find_package(absl REQUIRED)
+ set(ABSEIL_LIBS absl::inlined_vector absl::flat_hash_set
+ absl::flat_hash_map absl::node_hash_set absl::node_hash_map absl::base absl::throw_delegate absl::raw_hash_set
+ absl::hash absl::city absl::low_level_hash absl::raw_logging_internal)
endif()
+find_package(Protobuf REQUIRED)
+find_package(re2 REQUIRED)
+find_package(nlohmann_json REQUIRED)

set(RE2_BUILD_TESTING OFF CACHE BOOL "" FORCE)
-FetchContent_Declare(
- re2
- URL ${DEP_URL_re2}
- URL_HASH SHA1=${DEP_SHA1_re2}
- FIND_PACKAGE_ARGS NAMES re2
-)

if (onnxruntime_BUILD_UNIT_TESTS)
# WebAssembly threading support in Node.js is still an experimental feature and
@@ -163,7 +163,6 @@ if (onnxruntime_DISABLE_RTTI)
set(protobuf_DISABLE_RTTI ON CACHE BOOL "Remove runtime type information in the binaries" FORCE)
endif()

-include(protobuf_function)
#protobuf end

set(ENABLE_DATE_TESTING OFF CACHE BOOL "" FORCE)
@@ -303,7 +302,7 @@ FetchContent_Declare(
)

# The next line will generate an error message "fatal: not a git repository", but it is ok. It is from flatbuffers
-onnxruntime_fetchcontent_makeavailable(Protobuf nlohmann_json mp11 re2 safeint GSL flatbuffers)
+onnxruntime_fetchcontent_makeavailable(mp11 safeint GSL flatbuffers)
if(NOT flatbuffers_FOUND)
if(NOT TARGET flatbuffers::flatbuffers)
add_library(flatbuffers::flatbuffers ALIAS flatbuffers)
diff --git a/cmake/onnxruntime_unittests.cmake b/cmake/onnxruntime_unittests.cmake
index 9347be180d..8c60ff40f4 100644
--- a/cmake/onnxruntime_unittests.cmake
+++ b/cmake/onnxruntime_unittests.cmake
@@ -876,6 +876,7 @@ endif()
onnxruntime_add_include_to_target(onnx_test_data_proto onnx_proto)
target_include_directories(onnx_test_data_proto PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
set_target_properties(onnx_test_data_proto PROPERTIES FOLDER "ONNXRuntimeTest")
+include(protobuf_function)
onnxruntime_protobuf_generate(APPEND_PATH IMPORT_DIRS ${onnx_SOURCE_DIR} TARGET onnx_test_data_proto)

#
Loading