com.github.asus4.onnxruntime 0.3.2 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/Plugins/Android/{onnxruntime-android.aar → onnxruntime.aar} +0 -0
  2. package/Plugins/Linux/x64/libonnxruntime.so +0 -0
  3. package/Plugins/Linux/x64/libonnxruntime.so.meta +17 -37
  4. package/Plugins/Windows/arm64/onnxruntime.dll +0 -0
  5. package/Plugins/Windows/arm64/onnxruntime.dll.meta +65 -0
  6. package/{Editor.meta → Plugins/Windows/arm64.meta} +1 -1
  7. package/Plugins/Windows/x64/onnxruntime.dll +0 -0
  8. package/Plugins/Windows/x64/onnxruntime.dll.meta +15 -35
  9. package/Plugins/Windows/x86/onnxruntime.dll +0 -0
  10. package/Plugins/Windows/x86/onnxruntime.dll.meta +65 -0
  11. package/{Editor/com.github.asus4.onnxruntime.Editor.asmdef.meta → Plugins/Windows/x86.meta} +3 -2
  12. package/Plugins/{iOS~ → iOS}/onnxruntime.xcframework/Info.plist +9 -7
  13. package/Plugins/iOS/onnxruntime.xcframework/ios-arm64/onnxruntime.framework/Headers/coreml_provider_factory.h +90 -0
  14. package/Plugins/{iOS~ → iOS}/onnxruntime.xcframework/ios-arm64/onnxruntime.framework/Headers/onnxruntime_c_api.h +41 -6
  15. package/Plugins/{iOS~/onnxruntime.xcframework/ios-arm64_x86_64-simulator → iOS/onnxruntime.xcframework/ios-arm64}/onnxruntime.framework/Headers/onnxruntime_cxx_api.h +35 -6
  16. package/Plugins/{iOS~/onnxruntime.xcframework/macos-arm64_x86_64/onnxruntime.framework/Versions/A → iOS/onnxruntime.xcframework/ios-arm64/onnxruntime.framework}/Headers/onnxruntime_cxx_inline.h +2 -2
  17. package/Plugins/{iOS~/onnxruntime.xcframework/macos-arm64_x86_64/onnxruntime.framework/Versions/A → iOS/onnxruntime.xcframework/ios-arm64/onnxruntime.framework}/Headers/onnxruntime_session_options_config_keys.h +53 -2
  18. package/Plugins/{iOS~ → iOS}/onnxruntime.xcframework/ios-arm64/onnxruntime.framework/Info.plist +2 -2
  19. package/Plugins/{iOS~ → iOS}/onnxruntime.xcframework/ios-arm64/onnxruntime.framework/onnxruntime +0 -0
  20. package/Plugins/iOS/onnxruntime.xcframework/ios-arm64_x86_64-maccatalyst/onnxruntime.framework/Versions/A/Headers/coreml_provider_factory.h +90 -0
  21. package/Plugins/{iOS~/onnxruntime.xcframework/macos-arm64_x86_64 → iOS/onnxruntime.xcframework/ios-arm64_x86_64-maccatalyst}/onnxruntime.framework/Versions/A/Headers/onnxruntime_c_api.h +41 -6
  22. package/Plugins/{iOS~/onnxruntime.xcframework/ios-arm64/onnxruntime.framework → iOS/onnxruntime.xcframework/ios-arm64_x86_64-maccatalyst/onnxruntime.framework/Versions/A}/Headers/onnxruntime_cxx_api.h +35 -6
  23. package/Plugins/{iOS~/onnxruntime.xcframework/ios-arm64/onnxruntime.framework → iOS/onnxruntime.xcframework/ios-arm64_x86_64-maccatalyst/onnxruntime.framework/Versions/A}/Headers/onnxruntime_cxx_inline.h +2 -2
  24. package/Plugins/{iOS~/onnxruntime.xcframework/ios-arm64/onnxruntime.framework → iOS/onnxruntime.xcframework/ios-arm64_x86_64-maccatalyst/onnxruntime.framework/Versions/A}/Headers/onnxruntime_session_options_config_keys.h +53 -2
  25. package/Plugins/{iOS~/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework → iOS/onnxruntime.xcframework/ios-arm64_x86_64-maccatalyst/onnxruntime.framework/Versions/A/Resources}/Info.plist +2 -2
  26. package/Plugins/{iOS~/onnxruntime.xcframework/macos-arm64_x86_64 → iOS/onnxruntime.xcframework/ios-arm64_x86_64-maccatalyst}/onnxruntime.framework/Versions/A/onnxruntime +0 -0
  27. package/Plugins/iOS/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework/Headers/coreml_provider_factory.h +90 -0
  28. package/Plugins/{iOS~ → iOS}/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework/Headers/onnxruntime_c_api.h +41 -6
  29. package/Plugins/{iOS~/onnxruntime.xcframework/macos-arm64_x86_64/onnxruntime.framework/Versions/A → iOS/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework}/Headers/onnxruntime_cxx_api.h +35 -6
  30. package/Plugins/{iOS~ → iOS}/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework/Headers/onnxruntime_cxx_inline.h +2 -2
  31. package/Plugins/{iOS~ → iOS}/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework/Headers/onnxruntime_session_options_config_keys.h +53 -2
  32. package/Plugins/{iOS~/onnxruntime.xcframework/macos-arm64_x86_64/onnxruntime.framework/Versions/A/Resources → iOS/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework}/Info.plist +2 -2
  33. package/Plugins/{iOS~ → iOS}/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework/onnxruntime +0 -0
  34. package/Plugins/iOS/onnxruntime.xcframework.meta +61 -0
  35. package/Plugins/iOS.meta +8 -0
  36. package/Plugins/macOS/arm64/libonnxruntime.dylib +0 -0
  37. package/Plugins/macOS/{libonnxruntime.dylib.meta → arm64/libonnxruntime.dylib.meta} +20 -40
  38. package/Plugins/macOS/arm64.meta +8 -0
  39. package/Plugins/macOS/{libonnxruntime.dylib → x64/libonnxruntime.dylib} +0 -0
  40. package/Plugins/macOS/x64/libonnxruntime.dylib.meta +61 -0
  41. package/Plugins/macOS/x64.meta +8 -0
  42. package/README.md +9 -10
  43. package/Runtime/NativeMethods.shared.cs +1 -4
  44. package/Runtime/OrtValue.shared.cs +157 -1
  45. package/Runtime/SessionOptions.shared.cs +1 -42
  46. package/Runtime/Training/NativeTrainingMethods.shared.cs +1 -1
  47. package/package.json +1 -1
  48. package/Editor/OrtPostProcessBuild.cs +0 -77
  49. package/Editor/OrtPostProcessBuild.cs.meta +0 -11
  50. package/Editor/com.github.asus4.onnxruntime.Editor.asmdef +0 -16
  51. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64/onnxruntime.framework/Headers/coreml_provider_factory.h +0 -53
  52. package/Plugins/iOS~/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework/Headers/coreml_provider_factory.h +0 -53
  53. package/Plugins/iOS~/onnxruntime.xcframework/macos-arm64_x86_64/onnxruntime.framework/Versions/A/Headers/coreml_provider_factory.h +0 -53
  54. /package/Plugins/Android/{onnxruntime-android.aar.meta → onnxruntime.aar.meta} +0 -0
  55. /package/Plugins/{iOS~ → iOS}/onnxruntime.xcframework/ios-arm64/onnxruntime.framework/Headers/cpu_provider_factory.h +0 -0
  56. /package/Plugins/{iOS~ → iOS}/onnxruntime.xcframework/ios-arm64/onnxruntime.framework/Headers/onnxruntime_float16.h +0 -0
  57. /package/Plugins/{iOS~ → iOS}/onnxruntime.xcframework/ios-arm64/onnxruntime.framework/Headers/onnxruntime_lite_custom_op.h +0 -0
  58. /package/Plugins/{iOS~ → iOS}/onnxruntime.xcframework/ios-arm64/onnxruntime.framework/Headers/onnxruntime_run_options_config_keys.h +0 -0
  59. /package/Plugins/{iOS~/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework → iOS/onnxruntime.xcframework/ios-arm64_x86_64-maccatalyst/onnxruntime.framework/Versions/A}/Headers/cpu_provider_factory.h +0 -0
  60. /package/Plugins/{iOS~/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework → iOS/onnxruntime.xcframework/ios-arm64_x86_64-maccatalyst/onnxruntime.framework/Versions/A}/Headers/onnxruntime_float16.h +0 -0
  61. /package/Plugins/{iOS~/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework → iOS/onnxruntime.xcframework/ios-arm64_x86_64-maccatalyst/onnxruntime.framework/Versions/A}/Headers/onnxruntime_lite_custom_op.h +0 -0
  62. /package/Plugins/{iOS~/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework → iOS/onnxruntime.xcframework/ios-arm64_x86_64-maccatalyst/onnxruntime.framework/Versions/A}/Headers/onnxruntime_run_options_config_keys.h +0 -0
  63. /package/Plugins/{iOS~/onnxruntime.xcframework/macos-arm64_x86_64/onnxruntime.framework/Versions/A → iOS/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework}/Headers/cpu_provider_factory.h +0 -0
  64. /package/Plugins/{iOS~/onnxruntime.xcframework/macos-arm64_x86_64/onnxruntime.framework/Versions/A → iOS/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework}/Headers/onnxruntime_float16.h +0 -0
  65. /package/Plugins/{iOS~/onnxruntime.xcframework/macos-arm64_x86_64/onnxruntime.framework/Versions/A → iOS/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework}/Headers/onnxruntime_lite_custom_op.h +0 -0
  66. /package/Plugins/{iOS~/onnxruntime.xcframework/macos-arm64_x86_64/onnxruntime.framework/Versions/A → iOS/onnxruntime.xcframework/ios-arm64_x86_64-simulator/onnxruntime.framework}/Headers/onnxruntime_run_options_config_keys.h +0 -0
@@ -1,8 +1,8 @@
1
1
  fileFormatVersion: 2
2
- guid: 9891fef016ccb440487274bca11a0cc2
2
+ guid: bc9b82ac0eaaf452da6dfff039f45b96
3
3
  PluginImporter:
4
4
  externalObjects: {}
5
- serializedVersion: 2
5
+ serializedVersion: 3
6
6
  iconMap: {}
7
7
  executionOrder: {}
8
8
  defineConstraints: []
@@ -11,9 +11,13 @@ PluginImporter:
11
11
  isExplicitlyReferenced: 0
12
12
  validateReferences: 1
13
13
  platformData:
14
- - first:
15
- : Any
16
- second:
14
+ Android:
15
+ enabled: 0
16
+ settings:
17
+ AndroidLibraryDependee: UnityLibrary
18
+ AndroidSharedLibraryType: Executable
19
+ CPU: ARMv7
20
+ Any:
17
21
  enabled: 0
18
22
  settings:
19
23
  Exclude Android: 1
@@ -23,53 +27,29 @@ PluginImporter:
23
27
  Exclude Win: 1
24
28
  Exclude Win64: 1
25
29
  Exclude iOS: 1
26
- - first:
27
- Android: Android
28
- second:
29
- enabled: 0
30
- settings:
31
- AndroidSharedLibraryType: Executable
32
- CPU: ARMv7
33
- - first:
34
- Any:
35
- second:
36
- enabled: 0
37
- settings: {}
38
- - first:
39
- Editor: Editor
40
- second:
30
+ Editor:
41
31
  enabled: 1
42
32
  settings:
43
- CPU: AnyCPU
33
+ CPU: ARM64
44
34
  DefaultValueInitialized: true
45
35
  OS: OSX
46
- - first:
47
- Standalone: Linux64
48
- second:
36
+ Linux64:
49
37
  enabled: 0
50
38
  settings:
51
- CPU: AnyCPU
52
- - first:
53
- Standalone: OSXUniversal
54
- second:
39
+ CPU: x86_64
40
+ OSXUniversal:
55
41
  enabled: 1
56
42
  settings:
57
- CPU: AnyCPU
58
- - first:
59
- Standalone: Win
60
- second:
43
+ CPU: ARM64
44
+ Win:
61
45
  enabled: 0
62
46
  settings:
63
- CPU: AnyCPU
64
- - first:
65
- Standalone: Win64
66
- second:
47
+ CPU: x86
48
+ Win64:
67
49
  enabled: 0
68
50
  settings:
69
- CPU: AnyCPU
70
- - first:
71
- iPhone: iOS
72
- second:
51
+ CPU: None
52
+ iOS:
73
53
  enabled: 0
74
54
  settings:
75
55
  AddToEmbeddedBinaries: false
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: 7f9a00c2679f24a40aa0d7b0b9c88a59
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
@@ -0,0 +1,61 @@
1
+ fileFormatVersion: 2
2
+ guid: 031e15b7a7fca47fd9956b825b614de5
3
+ PluginImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 3
6
+ iconMap: {}
7
+ executionOrder: {}
8
+ defineConstraints: []
9
+ isPreloaded: 1
10
+ isOverridable: 1
11
+ isExplicitlyReferenced: 0
12
+ validateReferences: 1
13
+ platformData:
14
+ Android:
15
+ enabled: 0
16
+ settings:
17
+ AndroidLibraryDependee: UnityLibrary
18
+ AndroidSharedLibraryType: Executable
19
+ CPU: ARMv7
20
+ Any:
21
+ enabled: 0
22
+ settings:
23
+ Exclude Android: 1
24
+ Exclude Editor: 0
25
+ Exclude Linux64: 1
26
+ Exclude OSXUniversal: 0
27
+ Exclude Win: 1
28
+ Exclude Win64: 1
29
+ Exclude iOS: 1
30
+ Editor:
31
+ enabled: 1
32
+ settings:
33
+ CPU: x86_64
34
+ DefaultValueInitialized: true
35
+ OS: OSX
36
+ Linux64:
37
+ enabled: 0
38
+ settings:
39
+ CPU: x86_64
40
+ OSXUniversal:
41
+ enabled: 1
42
+ settings:
43
+ CPU: x86_64
44
+ Win:
45
+ enabled: 0
46
+ settings:
47
+ CPU: x86
48
+ Win64:
49
+ enabled: 0
50
+ settings:
51
+ CPU: None
52
+ iOS:
53
+ enabled: 0
54
+ settings:
55
+ AddToEmbeddedBinaries: false
56
+ CPU: AnyCPU
57
+ CompileFlags:
58
+ FrameworkDependencies:
59
+ userData:
60
+ assetBundleName:
61
+ assetBundleVariant:
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: 517737511da0e4498b34b189ae4a6d44
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
package/README.md CHANGED
@@ -8,7 +8,7 @@ Pre-built ONNX Runtime libraries for Unity.
8
8
 
9
9
  [https://github.com/asus4/onnxruntime-unity-examples](https://github.com/asus4/onnxruntime-unity-examples)
10
10
 
11
- **Yolox-Nano**
11
+ **Yolox-Nano**
12
12
 
13
13
  <https://github.com/asus4/onnxruntime-unity-examples/assets/357497/96ed9913-41b7-401d-a634-f0e2de4fc3c7>
14
14
 
@@ -16,16 +16,15 @@ Pre-built ONNX Runtime libraries for Unity.
16
16
 
17
17
  <https://github.com/asus4/onnxruntime-unity-examples/assets/357497/5e2b8712-87cc-4a3a-82b7-f217087a0ed1>
18
18
 
19
- **Yolo11 Seg**
19
+ **Yolo11 Seg**
20
20
 
21
21
  <https://github.com/user-attachments/assets/93c3dccd-569c-4a93-826b-0c9b5b60ebe9>
22
22
 
23
-
24
23
  ## Tested environment
25
24
 
26
- - Unity: 2022.3.20f1 (LTS)
27
- - ONNX Runtime: [1.20.0](https://github.com/microsoft/onnxruntime/releases/tag/v1.20.0)
28
- - ONNX Runtime Extensions: [0.12.0](https://github.com/microsoft/onnxruntime-extensions/releases/tag/v0.12.0)
25
+ - Unity: 6000.0.43f1 (LTS)
26
+ - ONNX Runtime: [1.21.0](https://github.com/microsoft/onnxruntime/releases/tag/v1.21.0)
27
+ - ONNX Runtime Extensions: [0.14.0](https://github.com/microsoft/onnxruntime-extensions/releases/tag/v0.14.0)
29
28
 
30
29
  ### Execution Providers & Extensions
31
30
 
@@ -71,10 +70,10 @@ Pre-built libraries are available on [NPM](https://www.npmjs.com/package/com.git
71
70
  }
72
71
  ]
73
72
  "dependencies": {
74
- "com.github.asus4.onnxruntime": "0.3.2",
75
- "com.github.asus4.onnxruntime.unity": "0.3.2",
76
- "com.github.asus4.onnxruntime.win-x64-gpu": "0.3.2",
77
- "com.github.asus4.onnxruntime-extensions": "0.3.2",
73
+ "com.github.asus4.onnxruntime": "0.3.4",
74
+ "com.github.asus4.onnxruntime.unity": "0.3.4",
75
+ "com.github.asus4.onnxruntime.win-x64-gpu": "0.3.4",
76
+ "com.github.asus4.onnxruntime-extensions": "0.3.4",
78
77
  ... other dependencies
79
78
  }
80
79
  ```
@@ -1154,9 +1154,6 @@ namespace Microsoft.ML.OnnxRuntime
1154
1154
 
1155
1155
  [DllImport(NativeLib.DllName, CharSet = CharSet.Ansi)]
1156
1156
  public static extern IntPtr /*(OrtStatus*)*/ OrtSessionOptionsAppendExecutionProvider_MIGraphX(IntPtr /*(OrtSessionOptions*)*/ options, int device_id);
1157
-
1158
- [DllImport(NativeLib.DllName, CharSet = CharSet.Ansi)]
1159
- public static extern IntPtr /*(OrtStatus*)*/ OrtSessionOptionsAppendExecutionProvider_Tvm(IntPtr /*(OrtSessionOptions*) */ options, byte[] /*(char char*)*/ settings);
1160
1157
  #endif
1161
1158
  /// <summary>
1162
1159
  /// Append a TensorRT EP instance (configured based on given provider options) to the native OrtSessionOptions instance
@@ -1284,7 +1281,7 @@ namespace Microsoft.ML.OnnxRuntime
1284
1281
  /// <summary>
1285
1282
  /// Append an execution provider instance to the native OrtSessionOptions instance.
1286
1283
  ///
1287
- /// 'SNPE' and 'XNNPACK' are currently supported as providerName values.
1284
+ /// 'SNPE', 'XNNPACK' and 'CoreML' are currently supported as providerName values.
1288
1285
  ///
1289
1286
  /// The number of providerOptionsKeys must match the number of providerOptionsValues and equal numKeys.
1290
1287
  /// </summary>
@@ -1,4 +1,8 @@
1
- // Copyright (c) Microsoft Corporation. All rights reserved.
1
+ #if UNITY_6000_0_OR_NEWER
2
+ // #define NET8_0_OR_GREATER
3
+ #endif // UNITY_6000_0_OR_NEWER
4
+
5
+ // Copyright (c) Microsoft Corporation. All rights reserved.
2
6
  // Licensed under the MIT License.
3
7
 
4
8
  using Microsoft.ML.OnnxRuntime.Tensors;
@@ -9,6 +13,14 @@ using System.Diagnostics;
9
13
  using System.Runtime.InteropServices;
10
14
  using System.Text;
11
15
 
16
+ #if NET8_0_OR_GREATER
17
+ using System.Diagnostics.CodeAnalysis;
18
+ using System.Reflection;
19
+ using System.Runtime.CompilerServices;
20
+ using SystemNumericsTensors = System.Numerics.Tensors;
21
+ using TensorPrimitives = System.Numerics.Tensors.TensorPrimitives;
22
+ #endif
23
+
12
24
  namespace Microsoft.ML.OnnxRuntime
13
25
  {
14
26
  /// <summary>
@@ -205,6 +217,33 @@ namespace Microsoft.ML.OnnxRuntime
205
217
  return MemoryMarshal.Cast<byte, T>(byteSpan);
206
218
  }
207
219
 
220
+ #if NET8_0_OR_GREATER
221
+ /// <summary>
222
+ /// Returns a ReadOnlyTensorSpan<typeparamref name="T"/> over tensor native buffer that
223
+ /// provides a read-only view.
224
+ ///
225
+ /// Note, that the memory may be device allocated and, therefore, not accessible from the CPU.
226
+ /// To get memory descriptor use GetTensorMemoryInfo().
227
+ ///
228
+ /// OrtValue must contain a non-string tensor.
229
+ /// The span is valid as long as the OrtValue instance is alive (not disposed).
230
+ /// </summary>
231
+ /// <typeparam name="T"></typeparam>
232
+ /// <returns>ReadOnlySpan<typeparamref name="T"/></returns>
233
+ /// <exception cref="OnnxRuntimeException"></exception>
234
+ [Experimental("SYSLIB5001")]
235
+ public SystemNumericsTensors.ReadOnlyTensorSpan<T> GetTensorDataAsTensorSpan<T>() where T : unmanaged
236
+ {
237
+ var byteSpan = GetTensorBufferRawData(typeof(T));
238
+
239
+ var typeSpan = MemoryMarshal.Cast<byte, T>(byteSpan);
240
+ var shape = GetTypeInfo().TensorTypeAndShapeInfo.Shape;
241
+ nint[] nArray = Array.ConvertAll(shape, new Converter<long, nint>(x => (nint)x));
242
+
243
+ return new SystemNumericsTensors.ReadOnlyTensorSpan<T>(typeSpan, nArray, []);
244
+ }
245
+ #endif
246
+
208
247
  /// <summary>
209
248
  /// Returns a Span<typeparamref name="T"/> over tensor native buffer.
210
249
  /// This enables you to safely and efficiently modify the underlying
@@ -225,6 +264,32 @@ namespace Microsoft.ML.OnnxRuntime
225
264
  return MemoryMarshal.Cast<byte, T>(byteSpan);
226
265
  }
227
266
 
267
+ #if NET8_0_OR_GREATER
268
+ /// <summary>
269
+ /// Returns a TensorSpan<typeparamref name="T"/> over tensor native buffer.
270
+ ///
271
+ /// Note, that the memory may be device allocated and, therefore, not accessible from the CPU.
272
+ /// To get memory descriptor use GetTensorMemoryInfo().
273
+ ///
274
+ /// OrtValue must contain a non-string tensor.
275
+ /// The span is valid as long as the OrtValue instance is alive (not disposed).
276
+ /// </summary>
277
+ /// <typeparam name="T"></typeparam>
278
+ /// <returns>ReadOnlySpan<typeparamref name="T"/></returns>
279
+ /// <exception cref="OnnxRuntimeException"></exception>
280
+ [Experimental("SYSLIB5001")]
281
+ public SystemNumericsTensors.TensorSpan<T> GetTensorMutableDataAsTensorSpan<T>() where T : unmanaged
282
+ {
283
+ var byteSpan = GetTensorBufferRawData(typeof(T));
284
+
285
+ var typeSpan = MemoryMarshal.Cast<byte, T>(byteSpan);
286
+ var shape = GetTypeInfo().TensorTypeAndShapeInfo.Shape;
287
+ nint[] nArray = Array.ConvertAll(shape, new Converter<long, nint>(x => (nint)x));
288
+
289
+ return new SystemNumericsTensors.TensorSpan<T>(typeSpan, nArray, []);
290
+ }
291
+ #endif
292
+
228
293
  /// <summary>
229
294
  /// Provides mutable raw native buffer access.
230
295
  /// </summary>
@@ -234,6 +299,23 @@ namespace Microsoft.ML.OnnxRuntime
234
299
  return GetTensorBufferRawData(typeof(byte));
235
300
  }
236
301
 
302
+ #if NET8_0_OR_GREATER
303
+ /// <summary>
304
+ /// Provides mutable raw native buffer access.
305
+ /// </summary>
306
+ /// <returns>TensorSpan over the native buffer bytes</returns>
307
+ [Experimental("SYSLIB5001")]
308
+ public SystemNumericsTensors.TensorSpan<byte> GetTensorSpanMutableRawData<T>() where T : unmanaged
309
+ {
310
+ var byteSpan = GetTensorBufferRawData(typeof(T));
311
+
312
+ var shape = GetTypeInfo().TensorTypeAndShapeInfo.Shape;
313
+ nint[] nArray = Array.ConvertAll(shape, new Converter<long, nint>(x => (nint)x));
314
+
315
+ return new SystemNumericsTensors.TensorSpan<byte>(byteSpan, nArray, []);
316
+ }
317
+ #endif
318
+
237
319
  /// <summary>
238
320
  /// Fetch string tensor element buffer pointer at the specified index,
239
321
  /// convert/copy to UTF-16 char[] and return a ReadOnlyMemory{char} instance.
@@ -605,6 +687,80 @@ namespace Microsoft.ML.OnnxRuntime
605
687
  return OrtValue.CreateTensorValueFromMemory(OrtMemoryInfo.DefaultInstance, new Memory<T>(data), shape);
606
688
  }
607
689
 
690
+ #if NET8_0_OR_GREATER
691
+ /// <summary>
692
+ /// This is a factory method creates a native Onnxruntime OrtValue containing a tensor on top of the existing tensor managed memory.
693
+ /// The method will attempt to pin managed memory so no copying occurs when data is passed down
694
+ /// to native code.
695
+ /// </summary>
696
+ /// <param name="value">Tensor object</param>
697
+ /// <param name="elementType">discovered tensor element type</param>
698
+ /// <returns>And instance of OrtValue constructed on top of the object</returns>
699
+ [Experimental("SYSLIB5001")]
700
+ public static OrtValue CreateTensorValueFromSystemNumericsTensorObject<T>(SystemNumericsTensors.Tensor<T> tensor) where T : unmanaged
701
+ {
702
+ if (!IsContiguousAndDense(tensor))
703
+ {
704
+ var newTensor = SystemNumericsTensors.Tensor.Create<T>(tensor.Lengths);
705
+ tensor.CopyTo(newTensor);
706
+ tensor = newTensor;
707
+ }
708
+ unsafe
709
+ {
710
+ var backingData = (T[])tensor.GetType().GetField("_values", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(tensor);
711
+ GCHandle handle = GCHandle.Alloc(backingData, GCHandleType.Pinned);
712
+ var memHandle = new MemoryHandle(Unsafe.AsPointer(ref tensor.GetPinnableReference()), handle);
713
+
714
+ try
715
+ {
716
+ IntPtr dataBufferPointer = IntPtr.Zero;
717
+ unsafe
718
+ {
719
+ dataBufferPointer = (IntPtr)memHandle.Pointer;
720
+ }
721
+
722
+ var bufferLengthInBytes = tensor.FlattenedLength * sizeof(T);
723
+ long[] shape = Array.ConvertAll(tensor.Lengths.ToArray(), new Converter<nint, long>(x => (long)x));
724
+
725
+ var typeInfo = TensorBase.GetTypeInfo(typeof(T)) ??
726
+ throw new OnnxRuntimeException(ErrorCode.InvalidArgument, $"Tensor of type: {typeof(T)} is not supported");
727
+
728
+ NativeApiStatus.VerifySuccess(NativeMethods.OrtCreateTensorWithDataAsOrtValue(
729
+ OrtMemoryInfo.DefaultInstance.Pointer,
730
+ dataBufferPointer,
731
+ (UIntPtr)(bufferLengthInBytes),
732
+ shape,
733
+ (UIntPtr)tensor.Rank,
734
+ typeInfo.ElementType,
735
+ out IntPtr nativeValue));
736
+
737
+ return new OrtValue(nativeValue, memHandle);
738
+ }
739
+ catch (Exception)
740
+ {
741
+ memHandle.Dispose();
742
+ throw;
743
+ }
744
+ }
745
+ }
746
+
747
+ [Experimental("SYSLIB5001")]
748
+ private static bool IsContiguousAndDense<T>(SystemNumericsTensors.Tensor<T> tensor) where T : unmanaged
749
+ {
750
+ // Right most dimension must be 1 for a dense tensor.
751
+ if (tensor.Strides[^1] != 1)
752
+ return false;
753
+
754
+ // For other dimensions, the stride must be equal to the product of the dimensions to the right.
755
+ for (int i = tensor.Rank - 2; i >= 0; i--)
756
+ {
757
+ if (tensor.Strides[i] != TensorPrimitives.Product(tensor.Lengths.Slice(i + 1, tensor.Lengths.Length - i - 1)))
758
+ return false;
759
+ }
760
+ return true;
761
+ }
762
+ #endif
763
+
608
764
  /// <summary>
609
765
  /// The factory API creates an OrtValue with memory allocated using the given allocator
610
766
  /// according to the specified shape and element type. The memory will be released when OrtValue
@@ -158,27 +158,6 @@ namespace Microsoft.ML.OnnxRuntime
158
158
  }
159
159
  }
160
160
 
161
- /// <summary>
162
- /// A helper method to construct a SessionOptions object for TVM execution.
163
- /// Use only if you have the onnxruntime package specific to this Execution Provider.
164
- /// </summary>
165
- /// <param name="settings">settings string, comprises of comma separated key:value pairs. default is empty</param>
166
- /// <returns>A SessionsOptions() object configured for execution with TVM</returns>
167
- public static SessionOptions MakeSessionOptionWithTvmProvider(String settings = "")
168
- {
169
- SessionOptions options = new SessionOptions();
170
- try
171
- {
172
- options.AppendExecutionProvider_Tvm(settings);
173
- return options;
174
- }
175
- catch (Exception)
176
- {
177
- options.Dispose();
178
- throw;
179
- }
180
- }
181
-
182
161
  /// <summary>
183
162
  /// A helper method to construct a SessionOptions object for ROCM execution.
184
163
  /// Use only if ROCM is installed and you have the onnxruntime package specific to this Execution Provider.
@@ -409,20 +388,6 @@ namespace Microsoft.ML.OnnxRuntime
409
388
  #endif
410
389
  }
411
390
 
412
- /// <summary>
413
- /// Use only if you have the onnxruntime package specific to this Execution Provider.
414
- /// </summary>
415
- /// <param name="settings">string with TVM specific settings</param>
416
- public void AppendExecutionProvider_Tvm(string settings = "")
417
- {
418
- #if __MOBILE__
419
- throw new NotSupportedException("The TVM Execution Provider is not supported in this build");
420
- #else
421
- var utf8 = NativeOnnxValueHelper.StringToZeroTerminatedUtf8(settings);
422
- NativeApiStatus.VerifySuccess(NativeMethods.OrtSessionOptionsAppendExecutionProvider_Tvm(handle, utf8));
423
- #endif
424
- }
425
-
426
391
  private class ExecutionProviderAppender
427
392
  {
428
393
  private byte[] _utf8ProviderName;
@@ -442,16 +407,10 @@ namespace Microsoft.ML.OnnxRuntime
442
407
  /// <summary>
443
408
  /// Append QNN, SNPE or XNNPACK execution provider
444
409
  /// </summary>
445
- /// <param name="providerName">Execution provider to add. 'QNN', 'SNPE' or 'XNNPACK' are currently supported.</param>
410
+ /// <param name="providerName">Execution provider to add. 'QNN', 'SNPE' 'XNNPACK', 'CoreML and 'AZURE are currently supported.</param>
446
411
  /// <param name="providerOptions">Optional key/value pairs to specify execution provider options.</param>
447
412
  public void AppendExecutionProvider(string providerName, Dictionary<string, string> providerOptions = null)
448
413
  {
449
- if (providerName != "SNPE" && providerName != "XNNPACK" && providerName != "QNN" && providerName != "AZURE")
450
- {
451
- throw new NotSupportedException(
452
- "Only QNN, SNPE, XNNPACK and AZURE execution providers can be enabled by this method.");
453
- }
454
-
455
414
  if (providerOptions == null)
456
415
  {
457
416
  providerOptions = new Dictionary<string, string>();
@@ -76,7 +76,7 @@ namespace Microsoft.ML.OnnxRuntime
76
76
  DOrtGetApi OrtGetApi = (DOrtGetApi)Marshal.GetDelegateForFunctionPointer(NativeMethods.OrtGetApiBase().GetApi, typeof(DOrtGetApi));
77
77
  #endif
78
78
 
79
- const uint ORT_API_VERSION = 20;
79
+ const uint ORT_API_VERSION = 21;
80
80
  #if NETSTANDARD2_0
81
81
  IntPtr ortApiPtr = OrtGetApi(ORT_API_VERSION);
82
82
  api_ = (OrtApi)Marshal.PtrToStructure(ortApiPtr, typeof(OrtApi));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.github.asus4.onnxruntime",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "displayName": "ONNX Runtime",
5
5
  "description": "ONNX Runtime Plugin for Unity",
6
6
  "keywords": [
@@ -1,77 +0,0 @@
1
- using System.IO;
2
- using UnityEngine;
3
- using UnityEngine.Assertions;
4
- using UnityEditor;
5
- using UnityEditor.Build;
6
- using UnityEditor.Build.Reporting;
7
- #if UNITY_IOS
8
- using UnityEditor.iOS.Xcode;
9
- #endif // UNITY_IOS
10
-
11
- namespace Microsoft.ML.OnnxRuntime.Editor
12
- {
13
- /// <summary>
14
- /// Custom post-process build for ONNX Runtime
15
- /// </summary>
16
- public class OrtPostProcessBuild : IPostprocessBuildWithReport
17
- {
18
- private const string PACKAGE_PATH = "Packages/com.github.asus4.onnxruntime";
19
- private const string FRAMEWORK_SRC = "Plugins/iOS~/onnxruntime.xcframework";
20
- private const string FRAMEWORK_DST = "Libraries/onnxruntime.xcframework";
21
-
22
- public int callbackOrder => 0;
23
-
24
- public void OnPostprocessBuild(BuildReport report)
25
- {
26
- switch (report.summary.platform)
27
- {
28
- case BuildTarget.iOS:
29
- PostprocessBuildIOS(report);
30
- break;
31
- case BuildTarget.Android:
32
- // Nothing to do
33
- break;
34
- // TODO: Add support for other platforms
35
- default:
36
- Debug.Log("OnnxPostProcessBuild.OnPostprocessBuild for target " + report.summary.platform + " is not supported");
37
- break;
38
- }
39
- }
40
-
41
- private static void PostprocessBuildIOS(BuildReport report)
42
- {
43
- #if UNITY_IOS
44
- string pbxProjectPath = PBXProject.GetPBXProjectPath(report.summary.outputPath);
45
- PBXProject pbxProject = new();
46
- pbxProject.ReadFromFile(pbxProjectPath);
47
-
48
- // Copy XCFramework to the Xcode project folder
49
- string frameworkSrcPath = Path.Combine(PACKAGE_PATH, FRAMEWORK_SRC);
50
- string frameworkDstAbsPath = Path.Combine(report.summary.outputPath, FRAMEWORK_DST);
51
- CopyDir(frameworkSrcPath, frameworkDstAbsPath);
52
-
53
- // Then add to Xcode project
54
- string frameworkGuid = pbxProject.AddFile(frameworkDstAbsPath, FRAMEWORK_DST, PBXSourceTree.Source);
55
- string targetGuid = pbxProject.GetUnityFrameworkTargetGuid();
56
- // Note: onnxruntime.xcframework should be linked in build section. Embed framework didn't work.
57
- // pbxProject.AddFileToEmbedFrameworks(targetGuid, frameworkGuid);
58
- string targetBuildPhaseGuid = pbxProject.AddFrameworksBuildPhase(targetGuid);
59
- pbxProject.AddFileToBuildSection(targetGuid, targetBuildPhaseGuid, frameworkGuid);
60
-
61
- pbxProject.WriteToFile(pbxProjectPath);
62
- #endif // UNITY_IOS
63
- }
64
-
65
- private static void CopyDir(string srcPath, string dstPath)
66
- {
67
- srcPath = FileUtil.GetPhysicalPath(srcPath);
68
- Assert.IsTrue(Directory.Exists(srcPath), $"Framework not found at {srcPath}");
69
-
70
- if (Directory.Exists(dstPath))
71
- {
72
- FileUtil.DeleteFileOrDirectory(dstPath);
73
- }
74
- FileUtil.CopyFileOrDirectory(srcPath, dstPath);
75
- }
76
- }
77
- }
@@ -1,11 +0,0 @@
1
- fileFormatVersion: 2
2
- guid: e487cab40ce8f4fce81e6f71b6185d49
3
- MonoImporter:
4
- externalObjects: {}
5
- serializedVersion: 2
6
- defaultReferences: []
7
- executionOrder: 0
8
- icon: {instanceID: 0}
9
- userData:
10
- assetBundleName:
11
- assetBundleVariant:
@@ -1,16 +0,0 @@
1
- {
2
- "name": "com.github.asus4.onnxruntime.Editor",
3
- "rootNamespace": "",
4
- "references": [],
5
- "includePlatforms": [
6
- "Editor"
7
- ],
8
- "excludePlatforms": [],
9
- "allowUnsafeCode": false,
10
- "overrideReferences": false,
11
- "precompiledReferences": [],
12
- "autoReferenced": true,
13
- "defineConstraints": [],
14
- "versionDefines": [],
15
- "noEngineReferences": false
16
- }