2022-08-21 13:32:41 +00:00
|
|
|
{ stdenv
|
|
|
|
, lib
|
|
|
|
, fetchFromGitHub
|
|
|
|
, fetchpatch
|
|
|
|
, fetchurl
|
|
|
|
, pkg-config
|
|
|
|
, cmake
|
2022-09-30 11:47:45 +00:00
|
|
|
, python3Packages
|
2022-08-21 13:32:41 +00:00
|
|
|
, libpng
|
|
|
|
, zlib
|
|
|
|
, eigen
|
|
|
|
, protobuf
|
|
|
|
, howard-hinnant-date
|
|
|
|
, nlohmann_json
|
|
|
|
, boost
|
|
|
|
, oneDNN
|
2023-01-11 07:51:40 +00:00
|
|
|
, abseil-cpp_202111
|
2022-08-21 13:32:41 +00:00
|
|
|
, gtest
|
2022-10-06 18:32:54 +00:00
|
|
|
, pythonSupport ? false
|
2022-09-30 11:47:45 +00:00
|
|
|
, nsync
|
|
|
|
, flatbuffers
|
2022-08-21 13:32:41 +00:00
|
|
|
}:
|
|
|
|
|
2022-10-06 18:32:54 +00:00
|
|
|
# Python Support
|
|
|
|
#
|
|
|
|
# When enabling Python support a wheel is made and stored in a `dist` output.
|
|
|
|
# This wheel is then installed in a separate derivation.
|
|
|
|
|
|
|
|
assert pythonSupport -> lib.versionOlder protobuf.version "3.20";
|
|
|
|
|
2022-08-21 13:32:41 +00:00
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
pname = "onnxruntime";
|
2023-01-11 07:51:40 +00:00
|
|
|
version = "1.13.1";
|
2022-08-21 13:32:41 +00:00
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "microsoft";
|
|
|
|
repo = "onnxruntime";
|
|
|
|
rev = "v${version}";
|
2023-01-11 07:51:40 +00:00
|
|
|
sha256 = "sha256-paaeq6QeiOzwiibbz0GkYZxEI/V80lvYNYTm6AuyAXQ=";
|
2022-08-21 13:32:41 +00:00
|
|
|
fetchSubmodules = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
patches = [
|
|
|
|
# Use dnnl from nixpkgs instead of submodules
|
|
|
|
(fetchpatch {
|
|
|
|
name = "system-dnnl.patch";
|
2023-01-11 07:51:40 +00:00
|
|
|
url = "https://aur.archlinux.org/cgit/aur.git/plain/system-dnnl.diff?h=python-onnxruntime&id=9c392fb542979981fe0026e0fe3cc361a5f00a36";
|
|
|
|
sha256 = "sha256-+kedzJHLFU1vMbKO9cn8fr+9A5+IxIuiqzOfR2AfJ0k=";
|
2022-08-21 13:32:41 +00:00
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
|
|
|
cmake
|
|
|
|
pkg-config
|
2022-09-30 11:47:45 +00:00
|
|
|
python3Packages.python
|
2022-08-21 13:32:41 +00:00
|
|
|
gtest
|
2022-09-30 11:47:45 +00:00
|
|
|
] ++ lib.optionals pythonSupport (with python3Packages; [
|
|
|
|
setuptools
|
|
|
|
wheel
|
|
|
|
pip
|
2022-10-06 18:32:54 +00:00
|
|
|
pythonOutputDistHook
|
2022-09-30 11:47:45 +00:00
|
|
|
]);
|
2022-08-21 13:32:41 +00:00
|
|
|
|
|
|
|
buildInputs = [
|
|
|
|
libpng
|
|
|
|
zlib
|
|
|
|
howard-hinnant-date
|
|
|
|
nlohmann_json
|
|
|
|
boost
|
|
|
|
oneDNN
|
2022-10-06 18:32:54 +00:00
|
|
|
protobuf
|
|
|
|
] ++ lib.optionals pythonSupport [
|
2022-09-30 11:47:45 +00:00
|
|
|
nsync
|
2022-10-06 18:32:54 +00:00
|
|
|
python3Packages.numpy
|
|
|
|
python3Packages.pybind11
|
2023-01-11 07:51:40 +00:00
|
|
|
python3Packages.packaging
|
2022-10-06 18:32:54 +00:00
|
|
|
];
|
2022-08-21 13:32:41 +00:00
|
|
|
|
|
|
|
# TODO: build server, and move .so's to lib output
|
2022-10-06 18:32:54 +00:00
|
|
|
# Python's wheel is stored in a separate dist output
|
|
|
|
outputs = [ "out" "dev" ] ++ lib.optionals pythonSupport [ "dist" ];
|
2022-08-21 13:32:41 +00:00
|
|
|
|
|
|
|
enableParallelBuilding = true;
|
|
|
|
|
|
|
|
cmakeDir = "../cmake";
|
|
|
|
|
|
|
|
cmakeFlags = [
|
|
|
|
"-Donnxruntime_PREFER_SYSTEM_LIB=ON"
|
|
|
|
"-Donnxruntime_BUILD_SHARED_LIB=ON"
|
|
|
|
"-Donnxruntime_ENABLE_LTO=ON"
|
|
|
|
"-Donnxruntime_BUILD_UNIT_TESTS=ON"
|
|
|
|
"-Donnxruntime_USE_PREINSTALLED_EIGEN=ON"
|
|
|
|
"-Donnxruntime_USE_MPI=ON"
|
|
|
|
"-Deigen_SOURCE_PATH=${eigen.src}"
|
2023-01-11 07:51:40 +00:00
|
|
|
"-DFETCHCONTENT_SOURCE_DIR_ABSEIL_CPP=${abseil-cpp_202111.src}"
|
2022-08-21 13:32:41 +00:00
|
|
|
"-Donnxruntime_USE_DNNL=YES"
|
2022-09-30 11:47:45 +00:00
|
|
|
] ++ lib.optionals pythonSupport [
|
|
|
|
"-Donnxruntime_ENABLE_PYTHON=ON"
|
2022-08-21 13:32:41 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
doCheck = true;
|
|
|
|
|
|
|
|
postPatch = ''
|
2022-09-30 11:47:45 +00:00
|
|
|
substituteInPlace cmake/libonnxruntime.pc.cmake.in \
|
|
|
|
--replace '$'{prefix}/@CMAKE_INSTALL_ @CMAKE_INSTALL_
|
|
|
|
'';
|
|
|
|
|
|
|
|
postBuild = lib.optionalString pythonSupport ''
|
2023-01-11 07:51:40 +00:00
|
|
|
python ../setup.py bdist_wheel
|
2022-08-21 13:32:41 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
postInstall = ''
|
|
|
|
# perform parts of `tools/ci_build/github/linux/copy_strip_binary.sh`
|
|
|
|
install -m644 -Dt $out/include \
|
|
|
|
../include/onnxruntime/core/framework/provider_options.h \
|
|
|
|
../include/onnxruntime/core/providers/cpu/cpu_provider_factory.h \
|
|
|
|
../include/onnxruntime/core/session/onnxruntime_*.h
|
|
|
|
'';
|
|
|
|
|
2022-10-06 18:32:54 +00:00
|
|
|
passthru = {
|
|
|
|
inherit protobuf;
|
|
|
|
tests = lib.optionalAttrs pythonSupport {
|
|
|
|
python = python3Packages.onnxruntime;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-08-21 13:32:41 +00:00
|
|
|
meta = with lib; {
|
|
|
|
description = "Cross-platform, high performance scoring engine for ML models";
|
|
|
|
longDescription = ''
|
|
|
|
ONNX Runtime is a performance-focused complete scoring engine
|
|
|
|
for Open Neural Network Exchange (ONNX) models, with an open
|
|
|
|
extensible architecture to continually address the latest developments
|
|
|
|
in AI and Deep Learning. ONNX Runtime stays up to date with the ONNX
|
|
|
|
standard with complete implementation of all ONNX operators, and
|
|
|
|
supports all ONNX releases (1.2+) with both future and backwards
|
|
|
|
compatibility.
|
|
|
|
'';
|
|
|
|
homepage = "https://github.com/microsoft/onnxruntime";
|
|
|
|
changelog = "https://github.com/microsoft/onnxruntime/releases/tag/v${version}";
|
|
|
|
# https://github.com/microsoft/onnxruntime/blob/master/BUILD.md#architectures
|
|
|
|
platforms = platforms.unix;
|
|
|
|
license = licenses.mit;
|
|
|
|
maintainers = with maintainers; [ jonringer puffnfresh ck3d ];
|
|
|
|
};
|
|
|
|
}
|