2018-11-20 00:48:22 +00:00
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
|
// Licensed under the MIT License.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.ML.OnnxRuntime
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// NamedOnnxValue type, must match the native enum
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
|
|
internal static class NativeMethods
|
|
|
|
|
{
|
2019-01-04 03:52:21 +00:00
|
|
|
private const string nativeLib = "onnxruntime";
|
2018-11-20 00:48:22 +00:00
|
|
|
internal const CharSet charSet = CharSet.Ansi;
|
|
|
|
|
|
|
|
|
|
#region Runtime/Environment API
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-01-29 23:03:18 +00:00
|
|
|
public static extern IntPtr /* OrtStatus* */OrtCreateEnv(
|
2018-11-20 00:48:22 +00:00
|
|
|
LogLevel default_warning_level,
|
|
|
|
|
string logId,
|
2018-12-18 19:39:46 +00:00
|
|
|
out IntPtr /*(OrtEnv*)*/ env);
|
|
|
|
|
// OrtReleaseEnv should not be used
|
2018-11-20 00:48:22 +00:00
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-18 19:39:46 +00:00
|
|
|
public static extern void OrtReleaseEnv(IntPtr /*(OrtEnv*)*/ env);
|
2018-11-20 00:48:22 +00:00
|
|
|
#endregion Runtime/Environment API
|
|
|
|
|
|
|
|
|
|
#region Status API
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-18 19:39:46 +00:00
|
|
|
public static extern ErrorCode OrtGetErrorCode(IntPtr /*(OrtStatus*)*/status);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
2019-03-06 00:00:40 +00:00
|
|
|
// returns char*, need to convert to string by the caller.
|
|
|
|
|
// does not free the underlying OrtStatus*
|
2018-11-20 00:48:22 +00:00
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-18 19:39:46 +00:00
|
|
|
public static extern IntPtr /* char* */OrtGetErrorMessage(IntPtr /* (OrtStatus*) */status);
|
2019-03-06 00:00:40 +00:00
|
|
|
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-18 19:39:46 +00:00
|
|
|
public static extern void OrtReleaseStatus(IntPtr /*(OrtStatus*)*/ statusPtr);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
#endregion Status API
|
|
|
|
|
|
|
|
|
|
#region InferenceSession API
|
|
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-28 22:53:19 +00:00
|
|
|
public static extern IntPtr /* OrtStatus* */OrtCreateSession(
|
2019-01-15 09:41:32 +00:00
|
|
|
IntPtr /* (OrtEnv*) */ environment,
|
|
|
|
|
//[MarshalAs(UnmanagedType.LPStr)]string modelPath
|
|
|
|
|
byte[] modelPath,
|
|
|
|
|
IntPtr /* (OrtSessionOptions*) */sessopnOptions,
|
|
|
|
|
out IntPtr /**/ session);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-28 22:53:19 +00:00
|
|
|
public static extern IntPtr /*(ONNStatus*)*/ OrtRun(
|
2018-12-18 19:39:46 +00:00
|
|
|
IntPtr /*(OrtSession*)*/ session,
|
|
|
|
|
IntPtr /*(OrtSessionRunOptions*)*/ runOptions, // can be null to use the default options
|
2018-11-20 00:48:22 +00:00
|
|
|
string[] inputNames,
|
2018-12-18 19:39:46 +00:00
|
|
|
IntPtr[] /* (OrtValue*[])*/ inputValues,
|
2019-05-20 22:48:14 +00:00
|
|
|
UIntPtr inputCount,
|
2018-11-20 00:48:22 +00:00
|
|
|
string[] outputNames,
|
2019-05-20 22:48:14 +00:00
|
|
|
UIntPtr outputCount,
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 5 /*index of outputCount*/)][In, Out]
|
|
|
|
|
IntPtr[] outputValues /* An array of output value pointers. Array must be allocated by the caller */
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-28 22:53:19 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtSessionGetInputCount(
|
2019-03-06 00:00:40 +00:00
|
|
|
IntPtr /*(OrtSession*)*/ session,
|
2019-05-20 22:48:14 +00:00
|
|
|
out UIntPtr count);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-28 22:53:19 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtSessionGetOutputCount(
|
2018-12-18 19:39:46 +00:00
|
|
|
IntPtr /*(OrtSession*)*/ session,
|
2019-05-20 22:48:14 +00:00
|
|
|
out UIntPtr count);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-28 22:53:19 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/OrtSessionGetInputName(
|
2018-12-18 19:39:46 +00:00
|
|
|
IntPtr /*(OrtSession*)*/ session,
|
2019-05-20 22:48:14 +00:00
|
|
|
UIntPtr index,
|
2019-03-06 00:00:40 +00:00
|
|
|
IntPtr /*(OrtAllocator*)*/ allocator,
|
2018-11-20 00:48:22 +00:00
|
|
|
out IntPtr /*(char**)*/name);
|
|
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-28 22:53:19 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/OrtSessionGetOutputName(
|
2018-12-18 19:39:46 +00:00
|
|
|
IntPtr /*(OrtSession*)*/ session,
|
2019-07-30 01:35:28 +00:00
|
|
|
UIntPtr index,
|
2018-12-14 22:54:23 +00:00
|
|
|
IntPtr /*(OrtAllocator*)*/ allocator,
|
2018-11-20 00:48:22 +00:00
|
|
|
out IntPtr /*(char**)*/name);
|
|
|
|
|
|
2019-01-26 03:41:10 +00:00
|
|
|
// release the typeinfo using OrtReleaseTypeInfo
|
2018-11-23 04:56:43 +00:00
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-28 22:53:19 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/OrtSessionGetInputTypeInfo(
|
2019-03-06 00:00:40 +00:00
|
|
|
IntPtr /*(const OrtSession*)*/ session,
|
2019-05-20 22:48:14 +00:00
|
|
|
UIntPtr index,
|
2018-12-14 22:54:23 +00:00
|
|
|
out IntPtr /*(struct OrtTypeInfo**)*/ typeInfo);
|
2018-11-23 04:56:43 +00:00
|
|
|
|
2019-01-26 03:41:10 +00:00
|
|
|
// release the typeinfo using OrtReleaseTypeInfo
|
2018-11-23 04:56:43 +00:00
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-28 22:53:19 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/OrtSessionGetOutputTypeInfo(
|
2019-03-06 00:00:40 +00:00
|
|
|
IntPtr /*(const OrtSession*)*/ session,
|
2019-05-20 22:48:14 +00:00
|
|
|
UIntPtr index,
|
2018-12-14 22:54:23 +00:00
|
|
|
out IntPtr /* (struct OrtTypeInfo**)*/ typeInfo);
|
2018-11-23 04:56:43 +00:00
|
|
|
|
2019-01-26 03:41:10 +00:00
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
|
|
|
|
public static extern void OrtReleaseTypeInfo(IntPtr /*(OrtTypeInfo*)*/session);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-18 19:39:46 +00:00
|
|
|
public static extern void OrtReleaseSession(IntPtr /*(OrtSession*)*/session);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
#endregion InferenceSession API
|
|
|
|
|
|
|
|
|
|
#region SessionOptions API
|
2018-11-23 04:56:43 +00:00
|
|
|
|
2018-11-20 00:48:22 +00:00
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-06-06 20:24:24 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtCreateSessionOptions(out IntPtr /*(OrtSessionOptions**)*/ sessionOptions);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
2019-01-26 03:41:10 +00:00
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
|
|
|
|
public static extern void OrtReleaseSessionOptions(IntPtr /*(OrtSessionOptions*)*/session);
|
|
|
|
|
|
2018-11-20 00:48:22 +00:00
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-06-06 20:24:24 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtCloneSessionOptions(IntPtr /*(OrtSessionOptions*)*/ sessionOptions, out IntPtr /*(OrtSessionOptions**)*/ output);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-06-06 20:24:24 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtEnableSequentialExecution(IntPtr /*(OrtSessionOptions*)*/ options);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-06-06 20:24:24 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtDisableSequentialExecution(IntPtr /*(OrtSessionOptions*)*/ options);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
2019-08-13 01:43:40 +00:00
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
|
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtSetOptimizedModelFilePath(IntPtr /* OrtSessionOptions* */ options, [MarshalAs(UnmanagedType.LPWStr)]string optimizedModelFilepath);
|
|
|
|
|
|
2018-11-20 00:48:22 +00:00
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-06-06 20:24:24 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtEnableProfiling(IntPtr /* OrtSessionOptions* */ options, string profilePathPrefix);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-06-06 20:24:24 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtDisableProfiling(IntPtr /* OrtSessionOptions* */ options);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-06-06 20:24:24 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtEnableMemPattern(IntPtr /* OrtSessionOptions* */ options);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-06-06 20:24:24 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtDisableMemPattern(IntPtr /* OrtSessionOptions* */ options);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-06-06 20:24:24 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtEnableCpuMemArena(IntPtr /* OrtSessionOptions* */ options);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-06-06 20:24:24 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtDisableCpuMemArena(IntPtr /* OrtSessionOptions* */ options);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-06-06 20:24:24 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtSetSessionLogId(IntPtr /* OrtSessionOptions* */ options, string logId);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-06-06 20:24:24 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtSetSessionLogVerbosityLevel(IntPtr /* OrtSessionOptions* */ options, LogLevel sessionLogVerbosityLevel);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-06-06 20:24:24 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtSetSessionThreadPoolSize(IntPtr /* OrtSessionOptions* */ options, int sessionThreadPoolSize);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
2019-04-03 00:23:14 +00:00
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-08-15 00:12:08 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtSetSessionGraphOptimizationLevel(IntPtr /* OrtSessionOptions* */ options, GraphOptimizationLevel graphOptimizationLevel);
|
2019-04-03 00:23:14 +00:00
|
|
|
|
2019-01-26 03:41:10 +00:00
|
|
|
|
2018-11-23 04:56:43 +00:00
|
|
|
///**
|
|
|
|
|
// * The order of invocation indicates the preference order as well. In other words call this method
|
|
|
|
|
// * on your most preferred execution provider first followed by the less preferred ones.
|
|
|
|
|
// * Calling this API is optional in which case onnxruntime will use its internal CPU execution provider.
|
|
|
|
|
// */
|
2018-11-20 00:48:22 +00:00
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-01-26 03:41:10 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtSessionOptionsAppendExecutionProvider_CPU(IntPtr /*(OrtSessionOptions*) */ options, int use_arena);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-01-26 03:41:10 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtSessionOptionsAppendExecutionProvider_Mkldnn(IntPtr /*(OrtSessionOptions*) */ options, int use_arena);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-01-26 03:41:10 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtSessionOptionsAppendExecutionProvider_CUDA(IntPtr /*(OrtSessionOptions*) */ options, int device_id);
|
2018-11-23 04:56:43 +00:00
|
|
|
|
2019-01-17 00:53:06 +00:00
|
|
|
//[DllImport(nativeLib, CharSet = charSet)]
|
|
|
|
|
//public static extern IntPtr /*(OrtStatus*)*/ OrtCreateNupharExecutionProviderFactory(int device_id, string target_str, out IntPtr /*(OrtProviderFactoryPtr**)*/ factory);
|
2018-11-23 04:56:43 +00:00
|
|
|
|
2019-01-17 00:53:06 +00:00
|
|
|
//[DllImport(nativeLib, CharSet = charSet)]
|
|
|
|
|
//public static extern void OrtAddCustomOp(IntPtr /*(OrtSessionOptions*)*/ options, string custom_op_path);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
2019-08-14 19:02:02 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region RunOptions API
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
|
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtCreateRunOptions( out IntPtr /* OrtRunOptions** */ runOptions);
|
|
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
|
|
|
|
public static extern void OrtReleaseRunOptions(IntPtr /*(OrtRunOptions*)*/options);
|
|
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
|
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtRunOptionsSetRunLogVerbosityLevel(IntPtr /* OrtRunOptions* */ options, LogLevel value);
|
|
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
|
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtRunOptionsSetRunTag(IntPtr /* OrtRunOptions* */ options, string /* const char* */ runTag);
|
|
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
|
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtRunOptionsGetRunLogVerbosityLevel(IntPtr /* OrtRunOptions* */ options, out LogLevel verbosityLevel);
|
|
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
|
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtRunOptionsGetRunTag(IntPtr /* const OrtRunOptions* */options, out IntPtr /* const char** */ runtag);
|
|
|
|
|
|
|
|
|
|
// Set a flag so that any running OrtRun* calls that are using this instance of OrtRunOptions
|
|
|
|
|
// will exit as soon as possible if the flag is true.
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
|
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtRunOptionsEnableTerminate(IntPtr /* OrtRunOptions* */ options);
|
|
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
|
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtRunOptionsDisableTerminate(IntPtr /* OrtRunOptions* */ options);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-20 00:48:22 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Allocator/AllocatorInfo API
|
|
|
|
|
|
|
|
|
|
//TODO: consider exposing them publicly, when allocator API is exposed
|
|
|
|
|
public enum AllocatorType
|
|
|
|
|
{
|
|
|
|
|
DeviceAllocator = 0,
|
|
|
|
|
ArenaAllocator = 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//TODO: consider exposing them publicly when allocator API is exposed
|
|
|
|
|
public enum MemoryType
|
|
|
|
|
{
|
|
|
|
|
CpuInput = -2, // Any CPU memory used by non-CPU execution provider
|
|
|
|
|
CpuOutput = -1, // CPU accessible memory outputted by non-CPU execution provider, i.e. CUDA_PINNED
|
|
|
|
|
Cpu = CpuOutput, // temporary CPU accessible memory allocated by non-CPU execution provider, i.e. CUDA_PINNED
|
|
|
|
|
Default = 0, // the default allocator for execution provider
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-18 19:39:46 +00:00
|
|
|
public static extern IntPtr /* (OrtStatus*)*/ OrtCreateAllocatorInfo(
|
2018-11-20 00:48:22 +00:00
|
|
|
IntPtr /*(const char*) */name,
|
|
|
|
|
AllocatorType allocatorType,
|
|
|
|
|
int identifier,
|
|
|
|
|
MemoryType memType,
|
2018-12-14 22:54:23 +00:00
|
|
|
out IntPtr /*(OrtAllocatorInfo*)*/ allocatorInfo // memory ownership transfered to caller
|
2018-11-20 00:48:22 +00:00
|
|
|
);
|
|
|
|
|
|
2018-12-18 19:39:46 +00:00
|
|
|
//ORT_API_STATUS(OrtCreateCpuAllocatorInfo, enum OrtAllocatorType type, enum OrtMemType mem_type1, _Out_ OrtAllocatorInfo** out)
|
2018-11-20 00:48:22 +00:00
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-18 19:39:46 +00:00
|
|
|
public static extern IntPtr /* (OrtStatus*)*/ OrtCreateCpuAllocatorInfo(
|
2018-11-20 00:48:22 +00:00
|
|
|
AllocatorType allocatorType,
|
|
|
|
|
MemoryType memoryType,
|
2018-12-14 22:54:23 +00:00
|
|
|
out IntPtr /*(OrtAllocatorInfo*)*/ allocatorInfo
|
2018-11-20 00:48:22 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-01-17 00:53:06 +00:00
|
|
|
public static extern void OrtReleaseAllocatorInfo(IntPtr /*(OrtAllocatorInfo*)*/ allocatorInfo);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-18 19:39:46 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/OrtCreateDefaultAllocator(out IntPtr /*(OrtAllocator**)*/ allocator);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-01-26 03:41:10 +00:00
|
|
|
public static extern void OrtReleaseAllocator(IntPtr /*(OrtAllocator*)*/ allocator);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Release any object allocated by an allocator
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="allocator"></param>
|
|
|
|
|
/// <param name="memory"></param>
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-06-11 01:36:04 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/OrtAllocatorFree(IntPtr allocator, IntPtr memory);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-06-11 01:36:04 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/OrtAllocatorGetInfo(IntPtr /*(const OrtAllocator*)*/ ptr, out IntPtr /*(const struct OrtAllocatorInfo**)*/info);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
#endregion Allocator/AllocatorInfo API
|
|
|
|
|
|
|
|
|
|
#region Tensor/OnnxValue API
|
|
|
|
|
|
2019-03-06 00:00:40 +00:00
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
|
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtGetValue(IntPtr /*(OrtValue*)*/ value,
|
|
|
|
|
int index,
|
|
|
|
|
IntPtr /*(OrtAllocator*)*/ allocator,
|
|
|
|
|
out IntPtr /*(OrtValue**)*/ outputValue);
|
|
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-06-11 01:36:04 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtGetValueType(IntPtr /*(OrtValue*)*/ value, IntPtr /*(OnnxValueType*)*/ onnxtype);
|
2019-03-06 00:00:40 +00:00
|
|
|
|
2019-03-12 17:11:14 +00:00
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-07-30 01:35:28 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtGetOnnxTypeFromTypeInfo(IntPtr /*(OrtTypeInfo*)*/ typeinfo, IntPtr /*(OnnxValueType*)*/ onnxtype);
|
2019-03-12 17:11:14 +00:00
|
|
|
|
2019-03-06 00:00:40 +00:00
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
|
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtGetValueCount(IntPtr /*(OrtValue*)*/ value, out IntPtr /*(size_t*)*/ count);
|
|
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-06-11 01:36:04 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtGetTypeInfo(IntPtr /*(OrtValue*)*/ value, IntPtr /*(OrtValue**)*/ typeInfo);
|
2019-03-06 00:00:40 +00:00
|
|
|
|
2019-08-22 17:14:50 +00:00
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
|
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtCreateTensorAsOrtValue(
|
|
|
|
|
IntPtr /*_Inout_ OrtAllocator* */ allocator,
|
|
|
|
|
long[] /*_In_ const int64_t* */ shape,
|
|
|
|
|
UIntPtr /*size_t*/ shape_len,
|
|
|
|
|
TensorElementType type,
|
|
|
|
|
out IntPtr /* OrtValue** */ outputValue);
|
|
|
|
|
|
2018-11-20 00:48:22 +00:00
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-18 19:39:46 +00:00
|
|
|
public static extern IntPtr /* OrtStatus */ OrtCreateTensorWithDataAsOrtValue(
|
2018-12-14 22:54:23 +00:00
|
|
|
IntPtr /* (const OrtAllocatorInfo*) */ allocatorInfo,
|
2018-11-20 00:48:22 +00:00
|
|
|
IntPtr /* (void*) */dataBufferHandle,
|
2019-05-20 22:48:14 +00:00
|
|
|
UIntPtr dataLength,
|
|
|
|
|
long[] shape,
|
|
|
|
|
UIntPtr shapeLength,
|
2018-11-20 00:48:22 +00:00
|
|
|
TensorElementType type,
|
2018-12-18 19:39:46 +00:00
|
|
|
out IntPtr /* OrtValue** */ outputValue);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
/// This function doesn't work with string tensor
|
2018-12-18 19:39:46 +00:00
|
|
|
/// this is a no-copy method whose pointer is only valid until the backing OrtValue* is free'd.
|
2018-11-20 00:48:22 +00:00
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-18 19:39:46 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtGetTensorMutableData(IntPtr /*(OrtValue*)*/ value, out IntPtr /* (void**)*/ dataBufferHandle);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
2019-08-22 17:14:50 +00:00
|
|
|
|
|
|
|
|
/// \param value A tensor created from OrtCreateTensor... function.
|
|
|
|
|
/// \param len total data length, not including the trailing '\0' chars.
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
|
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtFillStringTensor(
|
|
|
|
|
IntPtr /* OrtValue */ value,
|
|
|
|
|
string[] /* const char* const* */s,
|
|
|
|
|
UIntPtr /* size_t */ s_len);
|
|
|
|
|
|
2019-03-06 00:00:40 +00:00
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
|
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtGetStringTensorContent(
|
|
|
|
|
IntPtr /*(OrtValue*)*/ value,
|
|
|
|
|
IntPtr /*(void*)*/ dst_buffer,
|
2019-05-20 22:48:14 +00:00
|
|
|
UIntPtr dst_buffer_len,
|
2019-03-06 00:00:40 +00:00
|
|
|
IntPtr offsets,
|
2019-05-20 22:48:14 +00:00
|
|
|
UIntPtr offsets_len);
|
2019-03-06 00:00:40 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-05-20 22:48:14 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtGetStringTensorDataLength(IntPtr /*(OrtValue*)*/ value,
|
|
|
|
|
out UIntPtr /*(size_t*)*/ len);
|
2019-03-06 00:00:40 +00:00
|
|
|
|
2018-11-23 04:56:43 +00:00
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-06-11 01:36:04 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/
|
|
|
|
|
OrtCastTypeInfoToTensorInfo(IntPtr /*(struct OrtTypeInfo*)*/ typeInfo, out IntPtr /*(const struct OrtTensorTypeAndShapeInfo**)*/ typeAndShapeInfo);
|
2018-11-23 04:56:43 +00:00
|
|
|
|
2018-11-20 00:48:22 +00:00
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-05-20 21:57:43 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtGetTensorTypeAndShape(IntPtr /*(OrtValue*)*/ value, out IntPtr /*(struct OrtTensorTypeAndShapeInfo*)*/ typeAndShapeInfo);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
2019-01-26 03:41:10 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
|
|
|
|
public static extern void OrtReleaseTensorTypeAndShapeInfo(IntPtr /*(OrtTensorTypeAndShapeInfo*)*/ value);
|
|
|
|
|
|
2018-11-20 00:48:22 +00:00
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-06-11 01:36:04 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtGetTensorElementType(IntPtr /*(const struct OrtTensorTypeAndShapeInfo*)*/ typeAndShapeInfo, IntPtr /*(TensorElementType*)*/ output);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-06-11 01:36:04 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtGetDimensionsCount(IntPtr /*(const struct OrtTensorTypeAndShapeInfo*)*/ typeAndShapeInfo, out UIntPtr output);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-06-11 01:36:04 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtGetDimensions(
|
2019-03-06 00:00:40 +00:00
|
|
|
IntPtr /*(const struct OrtTensorTypeAndShapeInfo*)*/ typeAndShapeInfo,
|
|
|
|
|
long[] dim_values,
|
2019-05-20 22:48:14 +00:00
|
|
|
UIntPtr dim_values_length);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* How many elements does this tensor have.
|
|
|
|
|
* May return a negative value
|
|
|
|
|
* e.g.
|
|
|
|
|
* [] -> 1
|
|
|
|
|
* [1,3,4] -> 12
|
|
|
|
|
* [2,0,4] -> 0
|
|
|
|
|
* [-1,3,4] -> -1
|
|
|
|
|
*/
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2019-06-11 01:36:04 +00:00
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtGetTensorShapeElementCount(IntPtr /*(const struct OrtTensorTypeAndShapeInfo*)*/ typeAndShapeInfo, IntPtr /*(long*)*/ output);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-18 19:39:46 +00:00
|
|
|
public static extern void OrtReleaseValue(IntPtr /*(OrtValue*)*/ value);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
} //class NativeMethods
|
|
|
|
|
} //namespace
|