diff options
author | Arne Juul <arnej@yahooinc.com> | 2022-12-01 21:35:01 +0000 |
---|---|---|
committer | Arne Juul <arnej@yahooinc.com> | 2022-12-02 14:46:10 +0000 |
commit | 2348208f249f0f56eb73a4c4066422e6c88516d8 (patch) | |
tree | d6e1af4c63e2b993421469aefb31bb47f71d5f2c /container-onnxruntime | |
parent | d9ab932c59cf1d22f22c19b96619024a76aecc32 (diff) |
rename to just "container-onnxruntime"
Diffstat (limited to 'container-onnxruntime')
8 files changed, 162 insertions, 0 deletions
diff --git a/container-onnxruntime/.gitignore b/container-onnxruntime/.gitignore new file mode 100644 index 00000000000..916e17c097a --- /dev/null +++ b/container-onnxruntime/.gitignore @@ -0,0 +1 @@ +dependency-reduced-pom.xml diff --git a/container-onnxruntime/CMakeLists.txt b/container-onnxruntime/CMakeLists.txt new file mode 100644 index 00000000000..4eff1d26e60 --- /dev/null +++ b/container-onnxruntime/CMakeLists.txt @@ -0,0 +1,2 @@ +# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +install_jar(container-onnxruntime.jar) diff --git a/container-onnxruntime/README.md b/container-onnxruntime/README.md new file mode 100644 index 00000000000..ef332b88ba7 --- /dev/null +++ b/container-onnxruntime/README.md @@ -0,0 +1,4 @@ +<!-- Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +# container-onnxruntime + +onnxruntime.ai repackaged as a bundle diff --git a/container-onnxruntime/pom.xml b/container-onnxruntime/pom.xml new file mode 100644 index 00000000000..854a4571028 --- /dev/null +++ b/container-onnxruntime/pom.xml @@ -0,0 +1,86 @@ +<?xml version="1.0"?> +<!-- Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. --> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 + http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <artifactId>container-onnxruntime</artifactId> + <packaging>container-plugin</packaging> + <version>8-SNAPSHOT</version> + <parent> + <groupId>com.yahoo.vespa</groupId> + <artifactId>parent</artifactId> + <version>8-SNAPSHOT</version> + <relativePath>../parent/pom.xml</relativePath> + </parent> + <properties> + <maven.javadoc.skip>true</maven.javadoc.skip> <!-- Javadoc plugin fails because of no source code in module --> + </properties> + <dependencies> + <!-- provided --> + <dependency> + <groupId>com.yahoo.vespa</groupId> + <artifactId>annotations</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <dependency> + <!-- Not directly used in this module, but needed to get Import-Packages for JDK packages it exports. --> + <groupId>com.yahoo.vespa</groupId> + <artifactId>jdisc_core</artifactId> + <version>${project.version}</version> + <scope>provided</scope> + </dependency> + <!-- compile --> + <dependency> + <groupId>com.microsoft.onnxruntime</groupId> + <artifactId>onnxruntime</artifactId> + <scope>compile</scope> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>com.yahoo.vespa</groupId> + <artifactId>bundle-plugin</artifactId> + <extensions>true</extensions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <minimizeJar>false</minimizeJar> + <filters> + <filter> + <artifact>com.microsoft.onnxruntime:*</artifact> + <excludes> + <exclude>ai/onnxruntime/native/**</exclude> + <exclude>META-INF/**</exclude> + </excludes> + </filter> + </filters> + <transformers> + <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> + <manifestEntries> + <Bundle-Activator>ai.vespa.onnxruntime.OnnxBundleActivator</Bundle-Activator> + </manifestEntries> + </transformer> + </transformers> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> diff --git a/container-onnxruntime/src/main/java/ai/onnxruntime/package-info.java b/container-onnxruntime/src/main/java/ai/onnxruntime/package-info.java new file mode 100644 index 00000000000..8b4b7369115 --- /dev/null +++ b/container-onnxruntime/src/main/java/ai/onnxruntime/package-info.java @@ -0,0 +1,8 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +/** + * @author arnej + */ +@ExportPackage +package ai.onnxruntime; + +import com.yahoo.osgi.annotation.ExportPackage; diff --git a/container-onnxruntime/src/main/java/ai/onnxruntime/providers/package-info.java b/container-onnxruntime/src/main/java/ai/onnxruntime/providers/package-info.java new file mode 100644 index 00000000000..af09aa01661 --- /dev/null +++ b/container-onnxruntime/src/main/java/ai/onnxruntime/providers/package-info.java @@ -0,0 +1,8 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +/** + * @author arnej + */ +@ExportPackage +package ai.onnxruntime.providers; + +import com.yahoo.osgi.annotation.ExportPackage; diff --git a/container-onnxruntime/src/main/java/ai/vespa/onnxruntime/OnnxBundleActivator.java b/container-onnxruntime/src/main/java/ai/vespa/onnxruntime/OnnxBundleActivator.java new file mode 100644 index 00000000000..6995c28b124 --- /dev/null +++ b/container-onnxruntime/src/main/java/ai/vespa/onnxruntime/OnnxBundleActivator.java @@ -0,0 +1,52 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package ai.vespa.onnxruntime; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +import java.util.logging.Logger; + +/** + * @author arnej + * Loads native libraries when the bundle is activated. + * Use system properties to ensure onnxruntime won't try + * to load them itself. + **/ +public class OnnxBundleActivator implements BundleActivator { + + private static final String SKIP_PREFIX = "onnxruntime.native."; + private static final String SKIP_SUFFIX = ".skip"; + private static final String SKIP_VALUE = "true"; + private static final String[] LIBRARY_NAMES = { "onnxruntime", "onnxruntime4j_jni" }; + private static final Logger log = Logger.getLogger(OnnxBundleActivator.class.getName()); + + @Override + public void start(BundleContext ctx) { + for (String libName : LIBRARY_NAMES) { + String skipProp = SKIP_PREFIX + libName + SKIP_SUFFIX; + if (SKIP_VALUE.equals(System.getProperty(skipProp))) { + log.info("already loaded native library "+libName+", skipping"); + } else { + System.setProperty(skipProp, SKIP_VALUE); + log.info("loading native library: "+libName); + try { + System.loadLibrary(libName); + log.fine("loaded native library OK: "+libName); + } catch (Exception e) { + log.warning("Could not load native library '"+libName+"' because: "+e.getMessage()); + } + } + } + } + + @Override + public void stop(BundleContext ctx) { + // not sure how to test that loading and unloading multiple times actually works, + // but this should in theory do the necessary thing. + for (String libName : LIBRARY_NAMES) { + String skipProp = SKIP_PREFIX + libName + SKIP_SUFFIX; + System.clearProperty(skipProp); + log.info("will unload native library: "+libName); + } + } +} diff --git a/container-onnxruntime/src/main/javadoc/README b/container-onnxruntime/src/main/javadoc/README new file mode 100644 index 00000000000..97109fa2cc5 --- /dev/null +++ b/container-onnxruntime/src/main/javadoc/README @@ -0,0 +1 @@ +No javadoc available for module |