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,
|
2018-11-20 00:48:22 +00:00
|
|
|
ulong inputCount, /* TODO: size_t, make it portable for x86 arm */
|
|
|
|
|
string[] outputNames,
|
|
|
|
|
ulong outputCount, /* TODO: size_t, make it portable for x86 and arm */
|
|
|
|
|
|
|
|
|
|
[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,
|
2018-11-20 00:48:22 +00:00
|
|
|
out ulong /* TODO: size_t */ count);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[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,
|
2018-11-20 00:48:22 +00:00
|
|
|
out ulong /*TODO: size_t port*/ count);
|
|
|
|
|
|
|
|
|
|
[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,
|
2018-11-20 00:48:22 +00:00
|
|
|
ulong index, //TODO: port size_t
|
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,
|
2018-11-20 00:48:22 +00:00
|
|
|
ulong index, //TODO: port size_t
|
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,
|
2018-11-23 04:56:43 +00:00
|
|
|
ulong index, //TODO: port for size_t
|
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,
|
2018-11-23 04:56:43 +00:00
|
|
|
ulong index, //TODO: port for size_t
|
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)]
|
2018-12-14 22:54:23 +00:00
|
|
|
public static extern IntPtr /*OrtSessionOptions* */ OrtCreateSessionOptions();
|
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)]
|
2018-12-14 22:54:23 +00:00
|
|
|
public static extern IntPtr /*(OrtSessionOptions*)*/OrtCloneSessionOptions(IntPtr /*(OrtSessionOptions*)*/ sessionOptions);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-14 22:54:23 +00:00
|
|
|
public static extern void OrtEnableSequentialExecution(IntPtr /*(OrtSessionOptions*)*/ options);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-14 22:54:23 +00:00
|
|
|
public static extern void OrtDisableSequentialExecution(IntPtr /*(OrtSessionOptions*)*/ options);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-14 22:54:23 +00:00
|
|
|
public static extern void OrtEnableProfiling(IntPtr /* OrtSessionOptions* */ options, string profilePathPrefix);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-14 22:54:23 +00:00
|
|
|
public static extern void OrtDisableProfiling(IntPtr /* OrtSessionOptions* */ options);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-14 22:54:23 +00:00
|
|
|
public static extern void OrtEnableMemPattern(IntPtr /* OrtSessionOptions* */ options);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-14 22:54:23 +00:00
|
|
|
public static extern void OrtDisableMemPattern(IntPtr /* OrtSessionOptions* */ options);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-14 22:54:23 +00:00
|
|
|
public static extern void OrtEnableCpuMemArena(IntPtr /* OrtSessionOptions* */ options);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-14 22:54:23 +00:00
|
|
|
public static extern void OrtDisableCpuMemArena(IntPtr /* OrtSessionOptions* */ options);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-14 22:54:23 +00:00
|
|
|
public static extern void OrtSetSessionLogId(IntPtr /* OrtSessionOptions* */ options, string logId);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-14 22:54:23 +00:00
|
|
|
public static extern void OrtSetSessionLogVerbosityLevel(IntPtr /* OrtSessionOptions* */ options, LogLevel sessionLogVerbosityLevel);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-14 22:54:23 +00:00
|
|
|
public static extern int OrtSetSessionThreadPoolSize(IntPtr /* OrtSessionOptions* */ options, int sessionThreadPoolSize);
|
2018-11-20 00:48:22 +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
|
|
|
|
|
|
|
|
#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)]
|
2018-12-14 22:54:23 +00:00
|
|
|
public static extern void OrtAllocatorFree(IntPtr allocator, IntPtr memory);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-14 22:54:23 +00:00
|
|
|
public static extern IntPtr /*(const struct OrtAllocatorInfo*)*/ OrtAllocatorGetInfo(IntPtr /*(const OrtAllocator*)*/ ptr);
|
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)]
|
|
|
|
|
public static extern OnnxValueType /*Onnxtype*/ OrtGetValueType(IntPtr /*(OrtValue*)*/ value);
|
|
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
|
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtGetValueCount(IntPtr /*(OrtValue*)*/ value, out IntPtr /*(size_t*)*/ count);
|
|
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
|
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtGetTypeInfo(IntPtr /*(OrtValue*)*/ value, out IntPtr /*(OrtValue**)*/ typeInfo);
|
|
|
|
|
|
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,
|
|
|
|
|
ulong dataLength, //size_t, TODO: make it portable for x86, arm
|
|
|
|
|
ulong[] shape, //size_t* or size_t[], TODO: make it portable for x86, arm
|
|
|
|
|
ulong shapeLength, //size_t, TODO: make it portable for x86, arm
|
|
|
|
|
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-03-06 00:00:40 +00:00
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
|
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtGetStringTensorContent(
|
|
|
|
|
IntPtr /*(OrtValue*)*/ value,
|
|
|
|
|
IntPtr /*(void*)*/ dst_buffer,
|
|
|
|
|
ulong dst_buffer_len, //size_t, TODO: make it portable for x86, arm
|
|
|
|
|
IntPtr offsets,
|
|
|
|
|
ulong offsets_len); //size_t, TODO: make it portable for x86, arm
|
|
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
|
|
|
|
public static extern IntPtr /*(OrtStatus*)*/ OrtGetStringTensorDataLength(IntPtr /*(OrtValue*)*/ value, out ulong /*(size_t*)*/ len);
|
|
|
|
|
|
2018-11-23 04:56:43 +00:00
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-14 22:54:23 +00:00
|
|
|
public static extern IntPtr /*(const struct OrtTensorTypeAndShapeInfo*)*/
|
|
|
|
|
OrtCastTypeInfoToTensorInfo(IntPtr /*(struct OrtTypeInfo*)*/ typeInfo);
|
2018-11-23 04:56:43 +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 IntPtr /*(OrtStatus*)*/ OrtGetTensorShapeAndType(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)]
|
2018-12-14 22:54:23 +00:00
|
|
|
public static extern TensorElementType OrtGetTensorElementType(IntPtr /*(const struct OrtTensorTypeAndShapeInfo*)*/ typeAndShapeInfo);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-14 22:54:23 +00:00
|
|
|
public static extern ulong /*TODO: port for size_t */OrtGetNumOfDimensions(IntPtr /*(const struct OrtTensorTypeAndShapeInfo*)*/ typeAndShapeInfo);
|
2018-11-20 00:48:22 +00:00
|
|
|
|
|
|
|
|
[DllImport(nativeLib, CharSet = charSet)]
|
2018-12-14 22:54:23 +00:00
|
|
|
public static extern void OrtGetDimensions(
|
2019-03-06 00:00:40 +00:00
|
|
|
IntPtr /*(const struct OrtTensorTypeAndShapeInfo*)*/ typeAndShapeInfo,
|
|
|
|
|
long[] dim_values,
|
2018-11-20 00:48:22 +00:00
|
|
|
ulong dim_values_length);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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)]
|
2018-12-14 22:54:23 +00:00
|
|
|
public static extern long OrtGetTensorShapeElementCount(IntPtr /*(const struct OrtTensorTypeAndShapeInfo*)*/ typeAndShapeInfo);
|
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
|