mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-11-07 07:26:13 -05:00
gnu: Add onnx-optimizer.
* gnu/packages/machine-learning.scm (onnx-optimizer): New variable. * gnu/packages/patches/onnx-optimizer-system-library.patch: New file. * gnu/local.mk (dist_patch_DATA): Add it.
This commit is contained in:
parent
92d99aa5dc
commit
6da2b35b60
3 changed files with 98 additions and 0 deletions
|
@ -1512,6 +1512,7 @@ dist_patch_DATA = \
|
|||
%D%/packages/patches/ocaml-dose3-Install-mli-cmx-etc.patch \
|
||||
%D%/packages/patches/omake-fix-non-determinism.patch \
|
||||
%D%/packages/patches/oneko-remove-nonfree-characters.patch \
|
||||
%D%/packages/patches/onnx-optimizer-system-library.patch \
|
||||
%D%/packages/patches/onnx-use-system-googletest.patch \
|
||||
%D%/packages/patches/onnx-shared-libraries.patch \
|
||||
%D%/packages/patches/onnx-skip-model-downloads.patch \
|
||||
|
|
|
@ -675,6 +675,50 @@ (define-public python-onnx
|
|||
;; headers, hence the name change.
|
||||
(deprecated-package "python-onnx" onnx))
|
||||
|
||||
(define-public onnx-optimizer
|
||||
(package
|
||||
(name "onnx-optimizer")
|
||||
;; Note: 0.2.x is *more* recent than 1.5.0.
|
||||
(version "0.2.6")
|
||||
(home-page "https://github.com/onnx/optimizer")
|
||||
(source (origin
|
||||
(method git-fetch)
|
||||
(uri (git-reference
|
||||
(url home-page)
|
||||
(commit (string-append "v" version))))
|
||||
(sha256
|
||||
(base32
|
||||
"1wkqqdxcxpfbf8zpbdfdd3zz5jkw775g31gyykj11z4y6pp659l6"))
|
||||
(file-name (git-file-name name version))
|
||||
(patches (search-patches "onnx-optimizer-system-library.patch"))
|
||||
(modules '((guix build utils)))
|
||||
(snippet '(delete-file-recursively "third_party"))))
|
||||
(build-system python-build-system)
|
||||
(arguments (package-arguments onnx)) ;reuse build system tweaks
|
||||
(native-inputs
|
||||
`(("cmake" ,cmake)
|
||||
("python-pytest" ,python-pytest)
|
||||
("python-pytest-runner" ,python-pytest-runner)
|
||||
("python-nbval" ,python-nbval)
|
||||
("python-coverage" ,python-coverage)))
|
||||
(inputs
|
||||
`(("onnx" ,onnx)
|
||||
("protobuf" ,protobuf)
|
||||
("pybind11" ,pybind11)))
|
||||
(propagated-inputs
|
||||
`(("python-numpy" ,python-numpy)))
|
||||
(synopsis "Library to optimize ONNX models")
|
||||
(description
|
||||
"This package provides a C++ and Python library for performing arbitrary
|
||||
optimizations on ONNX models, as well as a growing list of prepackaged
|
||||
optimization passes.
|
||||
|
||||
Not all possible optimizations can be directly implemented on ONNX graphs---
|
||||
some will need additional backend-specific information---but many can, and the
|
||||
aim is to provide all such passes along with ONNX so that they can be re-used
|
||||
with a single function call.")
|
||||
(license license:expat)))
|
||||
|
||||
(define-public rxcpp
|
||||
(package
|
||||
(name "rxcpp")
|
||||
|
|
53
gnu/packages/patches/onnx-optimizer-system-library.patch
Normal file
53
gnu/packages/patches/onnx-optimizer-system-library.patch
Normal file
|
@ -0,0 +1,53 @@
|
|||
Arrange so that onnx-optimizer (1) uses our own ONNX build,
|
||||
(2) builds as a shared library, and (3) links against the shared
|
||||
libraries of ONNX.
|
||||
|
||||
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
||||
index c2e48b35..8af51076 100644
|
||||
--- a/CMakeLists.txt
|
||||
+++ b/CMakeLists.txt
|
||||
@@ -9,8 +9,6 @@ endif(NOT MSVC)
|
||||
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
-set(ONNX_ROOT ${PROJECT_SOURCE_DIR}/third_party/onnx)
|
||||
-add_subdirectory(${ONNX_ROOT})
|
||||
|
||||
file(READ "${PROJECT_SOURCE_DIR}/VERSION_NUMBER" ONNX_OPTIMIZER_VERSION)
|
||||
string(STRIP "${ONNX_OPTIMIZER_VERSION}" ONNX_OPTIMIZER_VERSION)
|
||||
@@ -21,14 +19,18 @@ file(GLOB_RECURSE onnx_opt_srcs "onnxoptimizer/*.cc"
|
||||
list(REMOVE_ITEM onnx_opt_srcs "${PROJECT_SOURCE_DIR}/onnxoptimizer/cpp2py_export.cc")
|
||||
|
||||
add_library(onnx_optimizer ${onnx_opt_srcs})
|
||||
-target_link_libraries(onnx_optimizer PUBLIC onnx)
|
||||
+target_link_libraries(onnx_optimizer PUBLIC onnx onnx_proto)
|
||||
target_include_directories(onnx_optimizer PUBLIC
|
||||
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
|
||||
+# These cpp macros must be defined so the ONNX headers behave
|
||||
+# correctly.
|
||||
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DONNX_ML=1 -DONNX_NAMESPACE=onnx")
|
||||
+
|
||||
add_executable(onnx_optimizer_exec examples/onnx_optimizer_exec.cpp)
|
||||
-target_link_libraries(onnx_optimizer_exec onnx_optimizer)
|
||||
+target_link_libraries(onnx_optimizer_exec onnx_optimizer protobuf)
|
||||
|
||||
if(BUILD_ONNX_PYTHON)
|
||||
if("${PY_EXT_SUFFIX}" STREQUAL "")
|
||||
@@ -79,11 +81,10 @@ if(BUILD_ONNX_PYTHON)
|
||||
PRIVATE $<TARGET_OBJECTS:onnx_optimizer>)
|
||||
else()
|
||||
# Assume everything else is like gcc
|
||||
- target_link_libraries(onnx_opt_cpp2py_export
|
||||
- PRIVATE "-Wl,--whole-archive" $<TARGET_FILE:onnx_optimizer>
|
||||
- "-Wl,--no-whole-archive")
|
||||
+ target_link_libraries(onnx_opt_cpp2py_export PRIVATE onnx_optimizer)
|
||||
set_target_properties(onnx_opt_cpp2py_export
|
||||
- PROPERTIES LINK_FLAGS "-Wl,--exclude-libs,ALL")
|
||||
+ PROPERTIES LINK_FLAGS
|
||||
+ "-Wl,-rpath=${CMAKE_INSTALL_PREFIX}/lib")
|
||||
endif()
|
||||
|
||||
target_link_libraries(onnx_opt_cpp2py_export PRIVATE onnx_optimizer)
|
Loading…
Reference in a new issue