summaryrefslogtreecommitdiff
path: root/sci-libs/onnxruntime/onnxruntime-1.29.0.ebuild
blob: f1ddaf4b193741d9002974f3f42fc49209576e56 (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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# Copyright 1999-2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

PYTHON_COMPAT=( python3_{13..14} )

inherit cmake edo flag-o-matic python-r1

EIGEN_COMMIT="1d8b82b0740839c0de7f1242a3585e3390ff5f33"

DESCRIPTION="Cross-platform, high performance ML inferencing and training accelerator"
HOMEPAGE="
	https://onnxruntime.ai
	https://github.com/microsoft/onnxruntime
"
SRC_URI="
	https://github.com/microsoft/onnxruntime/archive/refs/tags/v${PV}.tar.gz -> ${P}.tar.gz
	https://gitlab.com/libeigen/eigen/-/archive/${EIGEN_COMMIT}/eigen-${EIGEN_COMMIT}.tar.bz2 ->
		eigen-3.4.0_p20250216.tar.bz2
"

LICENSE="MIT"
SLOT="0"
KEYWORDS="~amd64"
IUSE="python test"
REQUIRED_USE="${PYTHON_REQUIRED_USE}"
RESTRICT="!test? ( test )"

RDEPEND="
	dev-cpp/abseil-cpp:=
	dev-libs/cpuinfo
	dev-libs/protobuf:=
	dev-libs/re2:=
	sci-ml/onnx[disableStaticReg]

	python? (
		${PYTHON_DEPS}
		dev-python/coloredlogs[${PYTHON_USEDEP}]
		dev-python/flatbuffers[${PYTHON_USEDEP}]
		>=dev-python/numpy-2[${PYTHON_USEDEP}]
		dev-python/packaging[${PYTHON_USEDEP}]
		dev-python/protobuf[${PYTHON_USEDEP}]
		dev-python/sympy[${PYTHON_USEDEP}]
		sci-ml/onnx[${PYTHON_USEDEP}]
	)
"
DEPEND="
	${RDEPEND}
	dev-cpp/ms-gsl
	dev-cpp/nlohmann_json
	dev-cpp/safeint
	dev-libs/boost
	dev-libs/date
	dev-libs/flatbuffers

	python? (
		dev-python/pybind11[${PYTHON_USEDEP}]
		sci-libs/dlpack
	)
"
BDEPEND="
	${PYTHON_DEPS}

	test? (
		dev-cpp/gtest
		$(python_gen_any_dep 'sci-ml/onnx[${PYTHON_USEDEP}]')

		python? ( dev-python/pytest[${PYTHON_USEDEP}] )
	)
"

PATCHES=(
	"${FILESDIR}/${PN}-1.22.2-relax-the-dependency-on-flatbuffers.patch"
	"${FILESDIR}/${PN}-1.24.4-no-werror.patch"
	"${FILESDIR}/${PN}-1.26.0-r1-prevent-generation-of-PIE.patch"
	"${FILESDIR}/${PN}-1.28.0-use-system-libraries.patch"
)

CMAKE_USE_DIR="${S}/cmake"

# The `$(python_get_sitedir)/onnx/onnx-ml.proto` file is used during tests
python_check_deps() {
	! use test && return 0
	python_has_version "sci-ml/onnx[${PYTHON_USEDEP}]"
}

src_configure() {
	# Python is used at build time unconditionally
	python_setup

	local mycmakeargs=(
		-Donnxruntime_BUILD_SHARED_LIB=on
		-Donnxruntime_USE_TELEMETRY=OFF

		-Donnxruntime_BUILD_UNIT_TESTS=$(usex test)
		-Donnxruntime_ENABLE_PYTHON=$(usex python)

		# This is required until a newer version of Eigen3 comes out
		-DFETCHCONTENT_SOURCE_DIR_EIGEN3="${WORKDIR}/eigen-${EIGEN_COMMIT}"

		# This makes it possible for `find_path` to find the `onnx-ml.proto` file
		-DCMAKE_INCLUDE_PATH="$(python_get_sitedir)"

		-Wno-dev
	)

	append-ldflags -Wl,-z,noexecstack

	if use python; then
		python_foreach_impl cmake_src_configure
	else
		cmake_src_configure
	fi
}

src_compile() {
	if use python; then
		python_foreach_impl cmake_src_compile
	else
		cmake_src_compile
	fi
}

# Adapted from `run_onnxruntime_tests` in `tools/ci_build/build.py`
python_test() {
	cd "${BUILD_DIR}" || die
	epytest --pyargs \
		onnxruntime_test_python.py \
		onnxruntime_test_python_backend.py \
		onnxruntime_test_python_mlops.py \
		onnxruntime_test_python_sparse_matmul.py
}

src_test() {
	# https://bugs.gentoo.org/975584
	local GTEST_SKIP_TESTS=(
		"ActivationOpNoInfTest.Softsign"
		"ConvTransposeTest.ConvTranspose_InvalidKernelShape"
		"GraphTransformationTests.GatherToSliceFusion"
		"LabelEncoder.RejectsInMemoryExternalDataInKeysTensorOpset4"
		"MLOpTest.TreeEnsembleRegressorRejectsInMemoryExternalDataInTensorAttribute"
		"MLOpTest.TreeEnsembleRejectsInMemoryExternalDataInTensorAttribute"
		"NhwcTransformerTests.ConvFloat_UsesNhwcOnlyWithKleidi"
		"Random.MultinomialDefaultDType"
		"Random.MultinomialGoodCase"
		"SamplingTest.Gpt2Sampling_CPU"
		"SignalOpsTest.DFT17_2D_complex_onesided_inverse"
		"SignalOpsTest.DFT17_IRFFT_naive"
		"SignalOpsTest.DFT17_IRFFT_radix2"
		"SignalOpsTest.DFT17_RFFT_IRFFT_roundtrip"
		"SignalOpsTest.DFT20_2D_complex_onesided_inverse"
		"SignalOpsTest.DFT20_IRFFT_naive"
		"SignalOpsTest.DFT20_IRFFT_radix2"
		"SignalOpsTest.DFT20_IRFFT_underprovided_spectrum_prime"
		"SignalOpsTest.DFT20_RFFT_IRFFT_roundtrip"
	)
	local -x GTEST_FILTER="*:-$(IFS=':'; echo "${GTEST_SKIP_TESTS[*]}")"

	if use python; then
		python_foreach_impl cmake_src_test
		python_foreach_impl python_test
	else
		cmake_src_test
	fi
}

# There is some custom logic in `setup.py`
python_install() {
	cd "${BUILD_DIR}" || die
	edo "${EPYTHON}" ../setup.py install \
		--prefix="${EPREFIX}/usr" \
		--root="${D}"

	rm -rf "${D}/$(python_get_sitedir)"/*.egg-info || die
	python_optimize
}

src_install() {
	if use python; then
		python_foreach_impl cmake_src_install
		python_foreach_impl python_install
	else
		cmake_src_install
	fi

	einstalldocs
}