forked from microsoft/onnxruntime
-
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.
[java] Sparse tensor support (microsoft#10653)
**Description**: Adds support for creating and receiving sparse tensors in the ORT Java API. CSRC and COO tensors as inputs are tested, but there is no op which accepts a block sparse tensor to test. COO tensors are tested as outputs, but there is no op which emits a CSRC or block sparse tensor to test. **Motivation and Context** - Why is this change required? What problem does it solve? Request to expose ORT sparse tensor support in Java. cc @yuslepukhin
- Loading branch information
Showing
13 changed files
with
2,218 additions
and
106 deletions.
There are no files selected for viewing
920 changes: 920 additions & 0 deletions
920
java/src/main/java/ai/onnxruntime/OnnxSparseTensor.java
Large diffs are not rendered by default.
Oops, something went wrong.
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,59 @@ | ||
/* | ||
* Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
package ai.onnxruntime; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Currently implemented by {@link OnnxTensor}, {@link OnnxSparseTensor}. Will be sealed to these | ||
* types one day. | ||
*/ | ||
public abstract class OnnxTensorLike implements OnnxValue { | ||
static { | ||
try { | ||
OnnxRuntime.init(); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Failed to load onnx-runtime library", e); | ||
} | ||
} | ||
|
||
protected final long nativeHandle; | ||
|
||
protected final long allocatorHandle; | ||
|
||
protected final TensorInfo info; | ||
|
||
/** | ||
* Constructs a tensor-like (the base class of OnnxTensor and OnnxSparseTensor). | ||
* | ||
* @param nativeHandle The pointer to the tensor. | ||
* @param allocatorHandle The pointer to the memory allocator. | ||
* @param info The tensor info. | ||
*/ | ||
OnnxTensorLike(long nativeHandle, long allocatorHandle, TensorInfo info) { | ||
this.nativeHandle = nativeHandle; | ||
this.allocatorHandle = allocatorHandle; | ||
this.info = info; | ||
} | ||
|
||
/** | ||
* Returns the native pointer. | ||
* | ||
* @return The native pointer. | ||
*/ | ||
long getNativeHandle() { | ||
return nativeHandle; | ||
} | ||
|
||
/** | ||
* Returns a {@link TensorInfo} for this tensor. | ||
* | ||
* @return The tensor info. | ||
*/ | ||
@Override | ||
public TensorInfo getInfo() { | ||
return info; | ||
} | ||
} |
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
Oops, something went wrong.