-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #179 from yuzawa-san/iobinding2
Add support for simple IoBinding
- Loading branch information
Showing
12 changed files
with
397 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...e-benchmark/src/main/java/com/jyuzawa/onnxruntime_benchmark/OnnxruntimeJavaIoBinding.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) 2022 James Yuzawa (https://www.jyuzawa.com/) | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
package com.jyuzawa.onnxruntime_benchmark; | ||
|
||
import com.jyuzawa.onnxruntime.IoBinding; | ||
import java.io.IOException; | ||
import java.nio.LongBuffer; | ||
|
||
final class OnnxruntimeJavaIoBinding extends OnnxruntimeJava { | ||
|
||
private final IoBinding ioBinding; | ||
private final LongBuffer inputBuf; | ||
private final LongBuffer outputBuf; | ||
|
||
OnnxruntimeJavaIoBinding(byte[] bytes, boolean arena, int size) throws IOException { | ||
super(bytes, arena, size); | ||
this.ioBinding = session.newIoBinding().bindInput(0).bindOutput(0).build(); | ||
this.inputBuf = ioBinding.getInputs().get(0).asTensor().getLongBuffer(); | ||
this.outputBuf = ioBinding.getOutputs().get(0).asTensor().getLongBuffer(); | ||
} | ||
|
||
@Override | ||
public void close() throws Exception { | ||
ioBinding.close(); | ||
super.close(); | ||
} | ||
|
||
@Override | ||
public long[] evaluate(long[] input) { | ||
inputBuf.clear().put(input); | ||
ioBinding.run(); | ||
outputBuf.rewind().get(out); | ||
return out; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright (c) 2022 James Yuzawa (https://www.jyuzawa.com/) | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
package com.jyuzawa.onnxruntime; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* A representation of a model evaluation. Capable of reuse in repetitive runs. More efficient than {@link Transaction}. Only supports tensors. Input and outputs are pre-allocated and must be of fixed size. This class is NOT thread-safe. | ||
* | ||
* @since 1.4.0 | ||
*/ | ||
public interface IoBinding extends AutoCloseable { | ||
|
||
/** | ||
* Set the severity for logging for this specific transaction. | ||
* Can override the environment's or session's logger's severity. | ||
* @param level | ||
* @return this | ||
*/ | ||
IoBinding setLogSeverityLevel(OnnxRuntimeLoggingLevel level); | ||
|
||
/** | ||
* Set the verbosity for logging for this specific transaction. | ||
* Can override the environment's or session's logger's verbosity. | ||
* @param level | ||
* @return this | ||
*/ | ||
IoBinding setLogVerbosityLevel(int level); | ||
|
||
/** | ||
* Set the run tag (which is the logger id) | ||
* @param runTag | ||
* @return this | ||
*/ | ||
IoBinding setRunTag(String runTag); | ||
|
||
NamedCollection<OnnxValue> getInputs(); | ||
|
||
NamedCollection<OnnxValue> getOutputs(); | ||
|
||
/** | ||
* Run the model evaluation. | ||
*/ | ||
void run(); | ||
|
||
/** | ||
* Frees the native resources (typically buffers) associated with this transaction. | ||
*/ | ||
@Override | ||
void close(); | ||
|
||
/** | ||
* A builder of a {@link IoBinding}. Should NOT be reused. This class is NOT thread-safe. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
public interface Builder { | ||
/** | ||
* Add an input and get an OnnxValue to populate. | ||
* @param name | ||
* @return the value to be populated | ||
*/ | ||
Builder bindInput(String name); | ||
|
||
/** | ||
* Add an input and get an OnnxValue to populate. | ||
* @param index | ||
* @return the value to be populated | ||
*/ | ||
Builder bindInput(int index); | ||
|
||
/** | ||
* Request a specific output to be produced. | ||
* @param name | ||
*/ | ||
Builder bindOutput(String name); | ||
|
||
/** | ||
* Request a specific output to be produced. | ||
* @param index | ||
*/ | ||
Builder bindOutput(int index); | ||
|
||
/** | ||
* Set custom parameters for this transaction. | ||
* @param config | ||
* @return the builder | ||
*/ | ||
Builder setConfigMap(Map<String, String> config); | ||
|
||
/** | ||
* Construct a {@link IoBinding}. | ||
* | ||
* @return a new instance | ||
*/ | ||
IoBinding build(); | ||
} | ||
} |
Oops, something went wrong.