summaryrefslogtreecommitdiff
path: root/onnxruntime.spec
blob: 403c247932df37673fa3993cd92d80cc5e8bef72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
%global _empty_manifest_terminate_build 0
%global __cmake_build_dir "./cmake-build"

Name:		onnxruntime
Version:	1.16.3
Release:	1
Summary:	ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator
License:	MIT
URL:		https://github.com/microsoft/onnxruntime
Source0:	https://github.com/microsoft/onnxruntime/archive/v%{version}/%{name}-%{version}.tar.gz

Patch0:     0001-downgrade-cmake-from-3.26-to-3.24.patch
Patch1:     0001-use-system-Flatbuffers.patch
Patch2:     0001-use-system-cpuinfo.patch
Patch3:     0001-use-system-protobuf.patch
Patch4:     0001-use-system-python.patch
Patch5:     0001-remove-nsync.patch
Patch6:     0001-fix-forward-decl-flatbuffers.patch
Patch7:     0001-add-onnxruntime_INSTALL_UNIT_TESTS-option.patch
Patch8:     0001-gcc-false-positive.patch
Patch9:	    0001-versioned-onnxruntime-providers_shared.patch
# Patch10:    0001-use-system-gtest.patch

BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-setuptools_scm
BuildRequires:	python3-pbr
BuildRequires:	python3-pip
BuildRequires:	python3-wheel
BuildRequires:	python3-hatchling

BuildRequires:	python3-numpy
BuildRequires:  pybind11-devel

BuildRequires:	abseil-cpp-devel
BuildRequires:	protobuf-devel
BuildRequires:  eigen3-devel
BuildRequires:  boost-devel
BuildRequires:	bzip2
BuildRequires:	cmake
BuildRequires:	g++
	
BuildRequires:  flatbuffers-compiler
BuildRequires:  flatbuffers-devel >= 23.5.26
BuildRequires:  cpuinfo-devel
BuildRequires:  gtest-devel
BuildRequires:  gmock-devel
BuildRequires:  zlib-devel
BuildRequires:  gsl-devel

%description
onnxruntime is a cross-platform inferencing and training accelerator compatible
with many popular ML/DNN frameworks, including PyTorch, TensorFlow/Keras,
scikit-learn, and more.

%package 	devel
Summary:    The development part of the %{name} package
Requires:   %{name} = %{version}-%{release}

%description devel
The development part of the %{name} package

%package -n python3-onnxruntime
Summary:    %{summary}
Requires:   %{name} = %{version}-%{release}

%description -n python3-onnxruntime
Python bindings for the %{name} package

%package doc
Summary:    Documentation files for the %{name} package

%description doc
Documentation files for the %{name} package

%prep
rm -rf %{_sourcedir}/onnxruntime-1.16.3.tar.gz
cat %{_sourcedir}/onnxruntime-1.16.3.tar.gz* > %{_builddir}/onnxruntime-1.16.3.tar.gz
%autosetup -p1 -n %{name}-%{version}

%build
# Broken test in aarch64
%ifarch aarch64
rm -v onnxruntime/test/optimizer/nhwc_transformer_test.cc
%endif

# Re-generate flatbuffer headers
%{__python3} onnxruntime/core/flatbuffers/schema/compile_schema.py --flatc %{_bindir}/flatc

# Overrides BUILD_SHARED_LIBS flag since onnxruntime compiles individual components as static, and links
# all together into a single shared library when onnxruntime_BUILD_SHARED_LIB is ON.
# The array-bounds and dangling-reference checks have false positives.
%cmake \
    %_cmake_skip_rpath \
    -DCMAKE_INSTALL_LIBDIR=%{_lib} \
    -DCMAKE_INSTALL_INCLUDEDIR=%{_includedir} \
    -Donnxruntime_BUILD_SHARED_LIB=ON \
    -Donnxruntime_BUILD_UNIT_TESTS=ON \
    -Donnxruntime_INSTALL_UNIT_TESTS=OFF \
    -Donnxruntime_BUILD_BENCHMARKS=OFF \
    -Donnxruntime_USE_PREINSTALLED_EIGEN=OFF \
    -Donnxruntime_USE_FULL_PROTOBUF=ON \
    -DPYTHON_VERSION=%{python3_version} \
    -Donnxruntime_ENABLE_CPUINFO=ON \
    -Donnxruntime_DISABLE_ABSEIL=ON \
    -Donnxruntime_ENABLE_PYTHON=ON \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo \
    -B "%{__cmake_build_dir}" \
    -S cmake \

%{__cmake} --build "%{__cmake_build_dir}" %{?_smp_mflags} --verbose

# Build python libs
mv ./onnxruntime ./onnxruntime.src
cp -R %{__cmake_build_dir}/onnxruntime ./onnxruntime
cp %{__cmake_build_dir}/requirements.txt ./requirements.txt

%pyproject_build

%install
DESTDIR="%{buildroot}" %{__cmake} --install "%{__cmake_build_dir}"
find %{__cmake_build_dir}/ -name "*.so" -exec cp {} "%{buildroot}/%{_libdir}" \;

mkdir -p "%{buildroot}/%{_docdir}/"
cp --preserve=timestamps -r "./docs/" "%{buildroot}/%{_docdir}/%{name}"

%pyproject_install


%check
export GTEST_FILTER=-CApiTensorTest.load_huge_tensor_with_external_data
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:%{buildroot}/usr/lib64/
/usr/bin/ctest --test-dir "%{__cmake_build_dir}" --output-on-failure --force-new-ctest-process %{?_smp_mflags}

%files
%license LICENSE
%doc ThirdPartyNotices.txt
%{_libdir}/libonnx.so
%{_libdir}/libonnx_proto.so
%{_libdir}/libonnxruntime.so.%{version}
%{_libdir}/libonnxruntime_providers_shared.so.%{version}

%files devel
%dir %{_includedir}/onnxruntime/
%{_includedir}/onnxruntime/*
%{_libdir}/cmake
%{_libdir}/*.so*
# %{_libdir}/libgmock.so.*
# %{_libdir}/libgtest.so.*
# %{_libdir}/libonnx_proto.so
# %{_libdir}/libonnx.so
# %{_libdir}/libonnxruntime.so
# %{_libdir}/libonnxruntime_providers_shared.so
%{_libdir}/pkgconfig/libonnxruntime.pc

%files -n python3-onnxruntime
%{_libdir}/python3.11/site-packages/*
%{_bindir}/onnxruntime_test

%files doc
%{_docdir}/%{name}

%changelog
* Sun Jan 28 2024 Binshuo Zu <274620705z@gmail.com> - 1.16.3-1
- Package init