Skip to content

Commit

Permalink
onnxruntime: add Python support
Browse files Browse the repository at this point in the history
  • Loading branch information
FRidh committed Sep 28, 2022
1 parent ea990dc commit d2356bf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
31 changes: 26 additions & 5 deletions pkgs/development/libraries/onnxruntime/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
, fetchurl
, pkg-config
, cmake
, python3
, python3Packages
, libpng
, zlib
, eigen
Expand All @@ -15,6 +15,9 @@
, boost
, oneDNN
, gtest
, pythonSupport ? true
, nsync
, flatbuffers
}:

let
Expand Down Expand Up @@ -49,9 +52,13 @@ stdenv.mkDerivation rec {
nativeBuildInputs = [
cmake
pkg-config
python3
python3Packages.python
gtest
];
] ++ lib.optionals pythonSupport (with python3Packages; [
setuptools
wheel
pip
]);

buildInputs = [
libpng
Expand All @@ -61,10 +68,16 @@ stdenv.mkDerivation rec {
nlohmann_json
boost
oneDNN
];
] ++ lib.optionals pythonSupport ([
flatbuffers
nsync
] ++ (with python3Packages; [
numpy
pybind11
]));

# TODO: build server, and move .so's to lib output
outputs = [ "out" "dev" ];
outputs = [ "out" "dev" ] ++ lib.optionals pythonSupport [ "python" ];

enableParallelBuilding = true;

Expand All @@ -79,6 +92,8 @@ stdenv.mkDerivation rec {
"-Donnxruntime_USE_MPI=ON"
"-Deigen_SOURCE_PATH=${eigen.src}"
"-Donnxruntime_USE_DNNL=YES"
] ++ lib.optionals pythonSupport [
"-Donnxruntime_ENABLE_PYTHON=ON"
];

doCheck = true;
Expand All @@ -91,12 +106,18 @@ stdenv.mkDerivation rec {
--replace '$'{prefix}/@CMAKE_INSTALL_ @CMAKE_INSTALL_
'';

postBuild = lib.optionalString pythonSupport ''
${python3Packages.python.interpreter} ../setup.py bdist_wheel
'';

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
'' + lib.optionalString pythonSupport ''
pip install dist/*.whl --no-index --no-warn-script-location --prefix="$python" --no-cache --no-deps
'';

meta = with lib; {
Expand Down
5 changes: 5 additions & 0 deletions pkgs/top-level/python-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6388,6 +6388,11 @@ in {

onnx = callPackage ../development/python-modules/onnx { };

onnxruntime = (toPythonModule (pkgs.onnxruntime.override {
python3Packages = self;
pythonSupport = true;
})).python;

onvif-zeep-async = callPackage ../development/python-modules/onvif-zeep-async { };

oocsi = callPackage ../development/python-modules/oocsi { };
Expand Down

0 comments on commit d2356bf

Please sign in to comment.