summaryrefslogtreecommitdiff
blob: 2bbde3bd85f258df57b38f2e0c545fb6456f860e (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
# Copyright 2021 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
# Distributed under the terms of the GNU General Public License v2

EAPI=7

inherit cmake

CPUINFO_COMMIT=5916273f79a21551890fd3d56fc5375a78d1598d
ONNX_COMMIT=1f63dcb7fcc3a8bf5c3c8e326867ecd6f5c43f35
MP11_COMMIT=21cace4e574180ba64d9307a5e4ea9e5e94d3e8d
OPTIONAL_LITE_COMMIT=4acf4553baa886e10e6613fe1452b706b0250e78
SAFEINT_COMMIT=a104e0cf23be4fe848f7ef1f3e8996fe429b06bb
FLATBUFFERS_PV=1.12.0

DESCRIPTION="cross-platform, high performance ML inferencing and training accelerator"
HOMEPAGE="https://github.com/microsoft/onnxruntime"
SRC_URI="
	https://github.com/microsoft/${PN}/archive/refs/tags/v${PV}.tar.gz -> ${P}.tar.gz
	https://github.com/pytorch/cpuinfo/archive/${CPUINFO_COMMIT}.tar.gz -> pytorch-cpuinfo-${CPUINFO_COMMIT:0:10}.tar.gz
	https://github.com/onnx/onnx/archive/${ONNX_COMMIT}.tar.gz -> onnx-${ONNX_COMMIT:0:10}.tar.gz
	https://github.com/boostorg/mp11/archive/${MP11_COMMIT}.tar.gz -> boost_mp11-${MP11_COMMIT:0:11}.tar.gz
	https://github.com/google/flatbuffers/archive/v${FLATBUFFERS_PV}.tar.gz -> flatbuffers-${FLATBUFFERS_PV}.tar.gz
	https://github.com/martinmoene/optional-lite/archive/${OPTIONAL_LITE_COMMIT}.tar.gz -> optional-lite-${OPTIONAL_LITE_COMMIT:0:10}.tar.gz
	https://github.com/dcleblanc/SafeInt/archive/${SAFEINT_COMMIT}.tar.gz -> SafeInt-${SAFEINT_COMMIT:0:10}.tar.gz
"
LICENSE="MIT"
SLOT="0"
KEYWORDS="~amd64"
IUSE="benchmark test"

# libonnxruntime_framework.so: undefined reference to `onnx::AttributeProto_AttributeType_Name[abi:cxx11](onnx::AttributeProto_AttributeType)'
RESTRICT="test"

S="${WORKDIR}/${P}/cmake"

# Needs https://gitlab.com/libeigen/eigen/-/commit/d0e3791b1a0e2db9edd5f1d1befdb2ac5a40efe0.patch on eigen-3.4.0
RDEPEND="
	dev-python/numpy
	dev-libs/date:=
	>=dev-libs/boost-1.66:=
	dev-libs/protobuf:=
	dev-libs/re2:=
	dev-libs/flatbuffers:=
	dev-cpp/nlohmann_json:=
	dev-libs/nsync
	dev-cpp/eigen:3
	benchmark? ( dev-cpp/benchmark )
"
DEPEND="
	${RDEPEND}
	test? ( dev-cpp/gtest )
"

PATCHES=(
	"${FILESDIR}/${P}-system_libs.patch"
)

src_unpack() {
	if [[ -n ${A} ]]; then
	      	 unpack ${A}
	fi
	eapply "${FILESDIR}/${P}-fix-RepeatedIterator-compile-error.patch"
}

src_prepare() {
	cmake_src_prepare

	rm -r "${S}/external/pytorch_cpuinfo" || die
	mv "${WORKDIR}/cpuinfo-${CPUINFO_COMMIT}" "${S}/external/pytorch_cpuinfo" || die

	rm -r "${S}/external/onnx" || die
	mv "${WORKDIR}/onnx-${ONNX_COMMIT}" "${S}/external/onnx" || die

	rm -r "${S}/external/mp11" || die
	mv "${WORKDIR}/mp11-${MP11_COMMIT}" "${S}/external/mp11" || die

	rm -r "${S}/external/flatbuffers" || die
	mv "${WORKDIR}/flatbuffers-${FLATBUFFERS_PV}" "${S}/external/flatbuffers" || die

	rm -r "${S}/external/optional-lite" || die
	mv "${WORKDIR}/optional-lite-${OPTIONAL_LITE_COMMIT}" "${S}/external/optional-lite" || die

	rm -r "${S}/external/SafeInt/safeint" || die
	mv "${WORKDIR}/SafeInt-${SAFEINT_COMMIT}" "${S}/external/SafeInt/safeint" || die
}

src_configure() {
	append-cppflags "-I/usr/include/eigen3"

	local mycmakeargs=(
		-Donnxruntime_PREFER_SYSTEM_LIB=ON
		-Donnxruntime_BUILD_BENCHMARKS=$(usex benchmark)
		-Donnxruntime_BUILD_UNIT_TESTS=$(usex test)
	)

	cmake_src_configure
}