Created
April 19, 2020 08:40
-
-
Save jmorrill/0f65876c2a9b8b7c335e008393cbddbc to your computer and use it in GitHub Desktop.
tvm c#
This file contains hidden or 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
using System; | |
namespace LibNative | |
{ | |
using System.Runtime.InteropServices; | |
public static partial class libnative | |
{ | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief The type code options DLDataType. | |
/// </remarks> | |
public enum DLDataTypeCode : int | |
{ | |
kDLInt = unchecked((int)0U), | |
kDLUInt = unchecked((int)1U), | |
kDLFloat = unchecked((int)2U), | |
} | |
public const libnative.DLDataTypeCode kDLInt = DLDataTypeCode.kDLInt; | |
public const libnative.DLDataTypeCode kDLUInt = DLDataTypeCode.kDLUInt; | |
public const libnative.DLDataTypeCode kDLFloat = DLDataTypeCode.kDLFloat; | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief Extension device types in TVM | |
/// </remarks> | |
public enum TVMDeviceExtType : int | |
{ | |
kDLAOCL = unchecked((int)5), | |
kDLSDAccel = unchecked((int)6), | |
kOpenGL = unchecked((int)11), | |
kDLMicroDev = unchecked((int)13), | |
kDLHexagon = unchecked((int)14), | |
} | |
public const libnative.TVMDeviceExtType kDLAOCL = TVMDeviceExtType.kDLAOCL; | |
public const libnative.TVMDeviceExtType kDLSDAccel = TVMDeviceExtType.kDLSDAccel; | |
public const libnative.TVMDeviceExtType kOpenGL = TVMDeviceExtType.kOpenGL; | |
public const libnative.TVMDeviceExtType kDLMicroDev = TVMDeviceExtType.kDLMicroDev; | |
public const libnative.TVMDeviceExtType kDLHexagon = TVMDeviceExtType.kDLHexagon; | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief The type code in used in the TVM FFI. | |
/// </remarks> | |
public enum TVMTypeCode : int | |
{ | |
/// <summary> | |
/// The type code of other types are compatible with DLPack. | |
/// The next few fields are extension types | |
/// that is used by TVM API calls. | |
/// </summary> | |
kTVMOpaqueHandle = unchecked((int)3U), | |
/// <summary> | |
/// The type code of other types are compatible with DLPack. | |
/// The next few fields are extension types | |
/// that is used by TVM API calls. | |
/// </summary> | |
kTVMNullptr = unchecked((int)4U), | |
/// <summary> | |
/// The type code of other types are compatible with DLPack. | |
/// The next few fields are extension types | |
/// that is used by TVM API calls. | |
/// </summary> | |
kTVMDataType = unchecked((int)5U), | |
/// <summary> | |
/// The type code of other types are compatible with DLPack. | |
/// The next few fields are extension types | |
/// that is used by TVM API calls. | |
/// </summary> | |
kTVMContext = unchecked((int)6U), | |
/// <summary> | |
/// The type code of other types are compatible with DLPack. | |
/// The next few fields are extension types | |
/// that is used by TVM API calls. | |
/// </summary> | |
kTVMDLTensorHandle = unchecked((int)7U), | |
/// <summary> | |
/// The type code of other types are compatible with DLPack. | |
/// The next few fields are extension types | |
/// that is used by TVM API calls. | |
/// </summary> | |
kTVMObjectHandle = unchecked((int)8U), | |
/// <summary> | |
/// The type code of other types are compatible with DLPack. | |
/// The next few fields are extension types | |
/// that is used by TVM API calls. | |
/// </summary> | |
kTVMModuleHandle = unchecked((int)9U), | |
/// <summary> | |
/// The type code of other types are compatible with DLPack. | |
/// The next few fields are extension types | |
/// that is used by TVM API calls. | |
/// </summary> | |
kTVMPackedFuncHandle = unchecked((int)10U), | |
/// <summary> | |
/// The type code of other types are compatible with DLPack. | |
/// The next few fields are extension types | |
/// that is used by TVM API calls. | |
/// </summary> | |
kTVMStr = unchecked((int)11U), | |
/// <summary> | |
/// The type code of other types are compatible with DLPack. | |
/// The next few fields are extension types | |
/// that is used by TVM API calls. | |
/// </summary> | |
kTVMBytes = unchecked((int)12U), | |
/// <summary> | |
/// The type code of other types are compatible with DLPack. | |
/// The next few fields are extension types | |
/// that is used by TVM API calls. | |
/// </summary> | |
kTVMNDArrayHandle = unchecked((int)13U), | |
/// <summary> | |
/// The type code of other types are compatible with DLPack. | |
/// The next few fields are extension types | |
/// that is used by TVM API calls. | |
/// </summary> | |
kTVMObjectRValueRefArg = unchecked((int)14U), | |
/// <summary> | |
/// Extension codes for other frameworks to integrate TVM PackedFunc. | |
/// To make sure each framework's id do not conflict, use first and | |
/// last sections to mark ranges. | |
/// Open an issue at the repo if you need a section of code. | |
/// </summary> | |
kTVMExtBegin = unchecked((int)15U), | |
/// <summary> | |
/// Extension codes for other frameworks to integrate TVM PackedFunc. | |
/// To make sure each framework's id do not conflict, use first and | |
/// last sections to mark ranges. | |
/// Open an issue at the repo if you need a section of code. | |
/// </summary> | |
kTVMNNVMFirst = unchecked((int)16U), | |
/// <summary> | |
/// Extension codes for other frameworks to integrate TVM PackedFunc. | |
/// To make sure each framework's id do not conflict, use first and | |
/// last sections to mark ranges. | |
/// Open an issue at the repo if you need a section of code. | |
/// </summary> | |
kTVMNNVMLast = unchecked((int)20U), | |
/// <summary> | |
/// The following section of code is used for non-reserved types. | |
/// </summary> | |
kTVMExtReserveEnd = unchecked((int)64U), | |
/// <summary> | |
/// The following section of code is used for non-reserved types. | |
/// </summary> | |
kTVMExtEnd = unchecked((int)128U), | |
/// <summary> | |
/// The rest of the space is used for custom, user-supplied datatypes | |
/// </summary> | |
kTVMCustomBegin = unchecked((int)129U), | |
} | |
/// <summary> | |
/// The type code of other types are compatible with DLPack. | |
/// The next few fields are extension types | |
/// that is used by TVM API calls. | |
/// </summary> | |
public const libnative.TVMTypeCode kTVMOpaqueHandle = TVMTypeCode.kTVMOpaqueHandle; | |
/// <summary> | |
/// The type code of other types are compatible with DLPack. | |
/// The next few fields are extension types | |
/// that is used by TVM API calls. | |
/// </summary> | |
public const libnative.TVMTypeCode kTVMNullptr = TVMTypeCode.kTVMNullptr; | |
/// <summary> | |
/// The type code of other types are compatible with DLPack. | |
/// The next few fields are extension types | |
/// that is used by TVM API calls. | |
/// </summary> | |
public const libnative.TVMTypeCode kTVMDataType = TVMTypeCode.kTVMDataType; | |
/// <summary> | |
/// The type code of other types are compatible with DLPack. | |
/// The next few fields are extension types | |
/// that is used by TVM API calls. | |
/// </summary> | |
public const libnative.TVMTypeCode kTVMContext = TVMTypeCode.kTVMContext; | |
/// <summary> | |
/// The type code of other types are compatible with DLPack. | |
/// The next few fields are extension types | |
/// that is used by TVM API calls. | |
/// </summary> | |
public const libnative.TVMTypeCode kTVMDLTensorHandle = TVMTypeCode.kTVMDLTensorHandle; | |
/// <summary> | |
/// The type code of other types are compatible with DLPack. | |
/// The next few fields are extension types | |
/// that is used by TVM API calls. | |
/// </summary> | |
public const libnative.TVMTypeCode kTVMObjectHandle = TVMTypeCode.kTVMObjectHandle; | |
/// <summary> | |
/// The type code of other types are compatible with DLPack. | |
/// The next few fields are extension types | |
/// that is used by TVM API calls. | |
/// </summary> | |
public const libnative.TVMTypeCode kTVMModuleHandle = TVMTypeCode.kTVMModuleHandle; | |
/// <summary> | |
/// The type code of other types are compatible with DLPack. | |
/// The next few fields are extension types | |
/// that is used by TVM API calls. | |
/// </summary> | |
public const libnative.TVMTypeCode kTVMPackedFuncHandle = TVMTypeCode.kTVMPackedFuncHandle; | |
/// <summary> | |
/// The type code of other types are compatible with DLPack. | |
/// The next few fields are extension types | |
/// that is used by TVM API calls. | |
/// </summary> | |
public const libnative.TVMTypeCode kTVMStr = TVMTypeCode.kTVMStr; | |
/// <summary> | |
/// The type code of other types are compatible with DLPack. | |
/// The next few fields are extension types | |
/// that is used by TVM API calls. | |
/// </summary> | |
public const libnative.TVMTypeCode kTVMBytes = TVMTypeCode.kTVMBytes; | |
/// <summary> | |
/// The type code of other types are compatible with DLPack. | |
/// The next few fields are extension types | |
/// that is used by TVM API calls. | |
/// </summary> | |
public const libnative.TVMTypeCode kTVMNDArrayHandle = TVMTypeCode.kTVMNDArrayHandle; | |
/// <summary> | |
/// The type code of other types are compatible with DLPack. | |
/// The next few fields are extension types | |
/// that is used by TVM API calls. | |
/// </summary> | |
public const libnative.TVMTypeCode kTVMObjectRValueRefArg = TVMTypeCode.kTVMObjectRValueRefArg; | |
/// <summary> | |
/// Extension codes for other frameworks to integrate TVM PackedFunc. | |
/// To make sure each framework's id do not conflict, use first and | |
/// last sections to mark ranges. | |
/// Open an issue at the repo if you need a section of code. | |
/// </summary> | |
public const libnative.TVMTypeCode kTVMExtBegin = TVMTypeCode.kTVMExtBegin; | |
/// <summary> | |
/// Extension codes for other frameworks to integrate TVM PackedFunc. | |
/// To make sure each framework's id do not conflict, use first and | |
/// last sections to mark ranges. | |
/// Open an issue at the repo if you need a section of code. | |
/// </summary> | |
public const libnative.TVMTypeCode kTVMNNVMFirst = TVMTypeCode.kTVMNNVMFirst; | |
/// <summary> | |
/// Extension codes for other frameworks to integrate TVM PackedFunc. | |
/// To make sure each framework's id do not conflict, use first and | |
/// last sections to mark ranges. | |
/// Open an issue at the repo if you need a section of code. | |
/// </summary> | |
public const libnative.TVMTypeCode kTVMNNVMLast = TVMTypeCode.kTVMNNVMLast; | |
/// <summary> | |
/// The following section of code is used for non-reserved types. | |
/// </summary> | |
public const libnative.TVMTypeCode kTVMExtReserveEnd = TVMTypeCode.kTVMExtReserveEnd; | |
/// <summary> | |
/// The following section of code is used for non-reserved types. | |
/// </summary> | |
public const libnative.TVMTypeCode kTVMExtEnd = TVMTypeCode.kTVMExtEnd; | |
/// <summary> | |
/// The rest of the space is used for custom, user-supplied datatypes | |
/// </summary> | |
public const libnative.TVMTypeCode kTVMCustomBegin = TVMTypeCode.kTVMCustomBegin; | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief The device type in DLContext. | |
/// </remarks> | |
public enum DLDeviceType : int | |
{ | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief CPU device | |
/// </remarks> | |
kDLCPU = unchecked((int)1), | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief CUDA GPU device | |
/// </remarks> | |
kDLGPU = unchecked((int)2), | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief Pinned CUDA GPU device by cudaMallocHost@note kDLCPUPinned = kDLCPU | kDLGPU | |
/// </remarks> | |
kDLCPUPinned = unchecked((int)3), | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief OpenCL devices. | |
/// </remarks> | |
kDLOpenCL = unchecked((int)4), | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief Vulkan buffer for next generation graphics. | |
/// </remarks> | |
kDLVulkan = unchecked((int)7), | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief Metal for Apple GPU. | |
/// </remarks> | |
kDLMetal = unchecked((int)8), | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief Verilog simulator buffer | |
/// </remarks> | |
kDLVPI = unchecked((int)9), | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief ROCm GPUs for AMD GPUs | |
/// </remarks> | |
kDLROCM = unchecked((int)10), | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief Reserved extension device type, | |
/// used for quickly test extension device | |
/// The semantics can differ depending on the implementation. | |
/// </remarks> | |
kDLExtDev = unchecked((int)12), | |
} | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief CPU device | |
/// </remarks> | |
public const libnative.DLDeviceType kDLCPU = DLDeviceType.kDLCPU; | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief CUDA GPU device | |
/// </remarks> | |
public const libnative.DLDeviceType kDLGPU = DLDeviceType.kDLGPU; | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief Pinned CUDA GPU device by cudaMallocHost@note kDLCPUPinned = kDLCPU | kDLGPU | |
/// </remarks> | |
public const libnative.DLDeviceType kDLCPUPinned = DLDeviceType.kDLCPUPinned; | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief OpenCL devices. | |
/// </remarks> | |
public const libnative.DLDeviceType kDLOpenCL = DLDeviceType.kDLOpenCL; | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief Vulkan buffer for next generation graphics. | |
/// </remarks> | |
public const libnative.DLDeviceType kDLVulkan = DLDeviceType.kDLVulkan; | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief Metal for Apple GPU. | |
/// </remarks> | |
public const libnative.DLDeviceType kDLMetal = DLDeviceType.kDLMetal; | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief Verilog simulator buffer | |
/// </remarks> | |
public const libnative.DLDeviceType kDLVPI = DLDeviceType.kDLVPI; | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief ROCm GPUs for AMD GPUs | |
/// </remarks> | |
public const libnative.DLDeviceType kDLROCM = DLDeviceType.kDLROCM; | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief Reserved extension device type, | |
/// used for quickly test extension device | |
/// The semantics can differ depending on the implementation. | |
/// </remarks> | |
public const libnative.DLDeviceType kDLExtDev = DLDeviceType.kDLExtDev; | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief A Device context for Tensor and operator. | |
/// </remarks> | |
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] | |
public partial struct DLContext | |
{ | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief The device type used in the device. | |
/// </remarks> | |
public libnative.DLDeviceType device_type; | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief The device index | |
/// </remarks> | |
public int device_id; | |
} | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief The data type the tensor can hold.Examples | |
/// - float: type_code = 2, bits = 32, lanes=1 | |
/// - float4(vectorized 4 float): type_code = 2, bits = 32, lanes=4 | |
/// - int8: type_code = 0, bits = 8, lanes=1 | |
/// </remarks> | |
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] | |
public partial struct DLDataType | |
{ | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief Type code of base types. | |
/// We keep it uint8_t instead of DLDataTypeCode for minimal memory | |
/// footprint, but the value should be one of DLDataTypeCode enum values. | |
/// </remarks> | |
public byte code; | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief Number of bits, common choices are 8, 16, 32. | |
/// </remarks> | |
public byte bits; | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief Number of lanes in the type, used for vector types. | |
/// </remarks> | |
public ushort lanes; | |
} | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief Plain C Tensor object, does not manage memory. | |
/// </remarks> | |
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] | |
public partial struct DLTensor | |
{ | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief The opaque data pointer points to the allocated data. This will be | |
/// CUDA device pointer or cl_mem handle in OpenCL. This pointer is always | |
/// aligns to 256 bytes as in CUDA.For given DLTensor, the size of memory required to store the contents of | |
/// data is calculated as follows:@code {.c} | |
/// static inline size_t GetDataSize(const DLTensor* t) { | |
/// size_t size = 1; | |
/// for (tvm_index_t i = 0; i < t->ndim; ++i) { | |
/// size *= t->shape[i]; | |
/// } | |
/// size *= (t->dtype.bits * t->dtype.lanes + 7) / 8; | |
/// return size; | |
/// } | |
/// @endcode | |
/// </remarks> | |
public IntPtr data; | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief The device context of the tensor | |
/// </remarks> | |
public libnative.DLContext ctx; | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief Number of dimensions | |
/// </remarks> | |
public int ndim; | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief The data type of the pointer | |
/// </remarks> | |
public libnative.DLDataType dtype; | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief The shape of the tensor | |
/// </remarks> | |
public IntPtr shape; | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief strides of the tensor, | |
/// can be NULL, indicating tensor is compact. | |
/// </remarks> | |
public IntPtr strides; | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief The offset in bytes to the beginning pointer to data | |
/// </remarks> | |
public ulong byte_offset; | |
} | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief C Tensor object, manage memory of DLTensor. This data structure is | |
/// intended to faciliate the borrowing of DLTensor by another framework. It is | |
/// not meant to transfer the tensor. When the borrowing framework doesn't need | |
/// the tensor, it should call the deleter to notify the host that the resource | |
/// is no longer needed. | |
/// </remarks> | |
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] | |
public partial struct DLManagedTensor | |
{ | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief DLTensor which is being memory managed | |
/// </remarks> | |
public libnative.DLTensor dl_tensor; | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief the context of the original host framework of DLManagedTensor in | |
/// which DLManagedTensor is used in the framework. It can also be NULL. | |
/// </remarks> | |
public IntPtr manager_ctx; | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief Destructor signature void (*)(void*) - this should be called | |
/// to destruct manager_ctx which holds the DLManagedTensor. It can be NULL | |
/// if there is no way for the caller to provide a reasonable destructor. | |
/// </remarks> | |
public libnative.DLManagedTensor.deleter_delegate deleter; | |
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | |
public delegate void deleter_delegate(ref libnative.DLManagedTensor self); | |
} | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief Union type of values | |
/// being passed through API and function calls. | |
/// </remarks> | |
[StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi)] | |
public partial struct TVMValue | |
{ | |
[FieldOffset(0)] | |
public long v_int64; | |
[FieldOffset(0)] | |
public double v_float64; | |
[FieldOffset(0)] | |
public IntPtr v_handle; | |
[FieldOffset(0)] | |
[MarshalAs(UnmanagedType.LPStr)] | |
public string v_str; | |
[FieldOffset(0)] | |
public libnative.DLDataType v_type; | |
[FieldOffset(0)] | |
public libnative.TVMContext v_ctx; | |
} | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief The Device information, abstract away common device types. | |
/// </remarks> | |
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] | |
public readonly partial struct TVMContext : IEquatable<TVMContext> | |
{ | |
public TVMContext(libnative.DLContext value) => this.Value = value; | |
public readonly libnative.DLContext Value; | |
public bool Equals(TVMContext other) => Value.Equals(other.Value); | |
public override bool Equals(object obj) => obj is TVMContext other && Equals(other); | |
public override int GetHashCode() => Value.GetHashCode(); | |
public override string ToString() => Value.ToString(); | |
public static implicit operator libnative.DLContext(TVMContext from) => from.Value; | |
public static implicit operator TVMContext(libnative.DLContext from) => new TVMContext(from); | |
public static bool operator ==(TVMContext left, TVMContext right) => left.Equals(right); | |
public static bool operator !=(TVMContext left, TVMContext right) => !left.Equals(right); | |
} | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief Byte array type used to pass in byte array | |
/// When kTVMBytes is used as data type. | |
/// </remarks> | |
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] | |
public partial struct TVMByteArray | |
{ | |
[MarshalAs(UnmanagedType.LPStr)] | |
public string data; | |
public libnative.size_t size; | |
} | |
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] | |
public readonly partial struct size_t : IEquatable<size_t> | |
{ | |
public size_t(IntPtr value) => this.Value = value; | |
public readonly IntPtr Value; | |
public bool Equals(size_t other) => Value.Equals(other.Value); | |
public override bool Equals(object obj) => obj is size_t other && Equals(other); | |
public override int GetHashCode() => Value.GetHashCode(); | |
public override string ToString() => Value.ToString(); | |
public static implicit operator IntPtr(size_t from) => from.Value; | |
public static implicit operator size_t(IntPtr from) => new size_t(from); | |
public static bool operator ==(size_t left, size_t right) => left.Equals(right); | |
public static bool operator !=(size_t left, size_t right) => !left.Equals(right); | |
} | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief type of array index. | |
/// </remarks> | |
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] | |
public readonly partial struct tvm_index_t : IEquatable<tvm_index_t> | |
{ | |
public tvm_index_t(long value) => this.Value = value; | |
public readonly long Value; | |
public bool Equals(tvm_index_t other) => Value.Equals(other.Value); | |
public override bool Equals(object obj) => obj is tvm_index_t other && Equals(other); | |
public override int GetHashCode() => Value.GetHashCode(); | |
public override string ToString() => Value.ToString(); | |
public static implicit operator long(tvm_index_t from) => from.Value; | |
public static implicit operator tvm_index_t(long from) => new tvm_index_t(from); | |
public static bool operator ==(tvm_index_t left, tvm_index_t right) => left.Equals(right); | |
public static bool operator !=(tvm_index_t left, tvm_index_t right) => !left.Equals(right); | |
} | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief the array handle | |
/// </remarks> | |
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] | |
public readonly partial struct TVMArrayHandle : IEquatable<TVMArrayHandle> | |
{ | |
public TVMArrayHandle(IntPtr value) => this.Value = value; | |
public readonly IntPtr Value; | |
public bool Equals(TVMArrayHandle other) => Value.Equals(other.Value); | |
public override bool Equals(object obj) => obj is TVMArrayHandle other && Equals(other); | |
public override int GetHashCode() => Value.GetHashCode(); | |
public override string ToString() => Value.ToString(); | |
public static implicit operator IntPtr(TVMArrayHandle from) => from.Value; | |
public static implicit operator TVMArrayHandle(IntPtr from) => new TVMArrayHandle(from); | |
public static bool operator ==(TVMArrayHandle left, TVMArrayHandle right) => left.Equals(right); | |
public static bool operator !=(TVMArrayHandle left, TVMArrayHandle right) => !left.Equals(right); | |
} | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief Handle to TVM runtime modules. | |
/// </remarks> | |
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] | |
public readonly partial struct TVMModuleHandle : IEquatable<TVMModuleHandle> | |
{ | |
public TVMModuleHandle(IntPtr value) => this.Value = value; | |
public readonly IntPtr Value; | |
public bool Equals(TVMModuleHandle other) => Value.Equals(other.Value); | |
public override bool Equals(object obj) => obj is TVMModuleHandle other && Equals(other); | |
public override int GetHashCode() => Value.GetHashCode(); | |
public override string ToString() => Value.ToString(); | |
public static implicit operator IntPtr(TVMModuleHandle from) => from.Value; | |
public static implicit operator TVMModuleHandle(IntPtr from) => new TVMModuleHandle(from); | |
public static bool operator ==(TVMModuleHandle left, TVMModuleHandle right) => left.Equals(right); | |
public static bool operator !=(TVMModuleHandle left, TVMModuleHandle right) => !left.Equals(right); | |
} | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief Handle to packed function handle. | |
/// </remarks> | |
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] | |
public readonly partial struct TVMFunctionHandle : IEquatable<TVMFunctionHandle> | |
{ | |
public TVMFunctionHandle(IntPtr value) => this.Value = value; | |
public readonly IntPtr Value; | |
public bool Equals(TVMFunctionHandle other) => Value.Equals(other.Value); | |
public override bool Equals(object obj) => obj is TVMFunctionHandle other && Equals(other); | |
public override int GetHashCode() => Value.GetHashCode(); | |
public override string ToString() => Value.ToString(); | |
public static implicit operator IntPtr(TVMFunctionHandle from) => from.Value; | |
public static implicit operator TVMFunctionHandle(IntPtr from) => new TVMFunctionHandle(from); | |
public static bool operator ==(TVMFunctionHandle left, TVMFunctionHandle right) => left.Equals(right); | |
public static bool operator !=(TVMFunctionHandle left, TVMFunctionHandle right) => !left.Equals(right); | |
} | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief Handle to hold return value. | |
/// </remarks> | |
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] | |
public readonly partial struct TVMRetValueHandle : IEquatable<TVMRetValueHandle> | |
{ | |
public TVMRetValueHandle(IntPtr value) => this.Value = value; | |
public readonly IntPtr Value; | |
public bool Equals(TVMRetValueHandle other) => Value.Equals(other.Value); | |
public override bool Equals(object obj) => obj is TVMRetValueHandle other && Equals(other); | |
public override int GetHashCode() => Value.GetHashCode(); | |
public override string ToString() => Value.ToString(); | |
public static implicit operator IntPtr(TVMRetValueHandle from) => from.Value; | |
public static implicit operator TVMRetValueHandle(IntPtr from) => new TVMRetValueHandle(from); | |
public static bool operator ==(TVMRetValueHandle left, TVMRetValueHandle right) => left.Equals(right); | |
public static bool operator !=(TVMRetValueHandle left, TVMRetValueHandle right) => !left.Equals(right); | |
} | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief The stream that is specific to device | |
/// can be NULL, which indicates the default one. | |
/// </remarks> | |
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] | |
public readonly partial struct TVMStreamHandle : IEquatable<TVMStreamHandle> | |
{ | |
public TVMStreamHandle(IntPtr value) => this.Value = value; | |
public readonly IntPtr Value; | |
public bool Equals(TVMStreamHandle other) => Value.Equals(other.Value); | |
public override bool Equals(object obj) => obj is TVMStreamHandle other && Equals(other); | |
public override int GetHashCode() => Value.GetHashCode(); | |
public override string ToString() => Value.ToString(); | |
public static implicit operator IntPtr(TVMStreamHandle from) => from.Value; | |
public static implicit operator TVMStreamHandle(IntPtr from) => new TVMStreamHandle(from); | |
public static bool operator ==(TVMStreamHandle left, TVMStreamHandle right) => left.Equals(right); | |
public static bool operator !=(TVMStreamHandle left, TVMStreamHandle right) => !left.Equals(right); | |
} | |
/// <summary> | |
/// | |
/// </summary> | |
/// <remarks> | |
/// @brief Handle to Object. | |
/// </remarks> | |
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] | |
public readonly partial struct TVMObjectHandle : IEquatable<TVMObjectHandle> | |
{ | |
public TVMObjectHandle(IntPtr value) => this.Value = value; | |
public readonly IntPtr Value; | |
public bool Equals(TVMObjectHandle other) => Value.Equals(other.Value); | |
public override bool Equals(object obj) => obj is TVMObjectHandle other && Equals(other); | |
public override int GetHashCode() => Value.GetHashCode(); | |
public override string ToString() => Value.ToString(); | |
public static implicit operator IntPtr(TVMObjectHandle from) => from.Value; | |
public static implicit operator TVMObjectHandle(IntPtr from) => new TVMObjectHandle(from); | |
public static bool operator ==(TVMObjectHandle left, TVMObjectHandle right) => left.Equals(right); | |
public static bool operator !=(TVMObjectHandle left, TVMObjectHandle right) => !left.Equals(right); | |
} | |
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | |
public delegate int TVMPackedCFunc(ref libnative.TVMValue args, ref int type_codes, int num_args, libnative.TVMRetValueHandle ret, IntPtr resource_handle); | |
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | |
public delegate void TVMPackedCFuncFinalizer(IntPtr resource_handle); | |
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] | |
public delegate int TVMExtensionFuncDeclarer(libnative.TVMFunctionHandle register_func_handle); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="msg">The error message to be set.</param> | |
/// <remarks> | |
/// @brief Used for implementing C API function. | |
/// Set last error message before return. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern void TVMAPISetLastError([MarshalAs(UnmanagedType.LPStr)] string msg); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <returns>error info</returns> | |
/// <remarks> | |
/// @brief return str message of the last error | |
/// all function in this file will return 0 when success | |
/// and -1 when an error occurred, | |
/// TVMGetLastError can be called to retrieve the errorthis function is threadsafe and can be called by different thread | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
[return:MarshalAs(UnmanagedType.LPStr)] | |
public static extern string TVMGetLastError(); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="file_name">The file name to load the module from.</param> | |
/// <param name="format">The format of the module.</param> | |
/// <param name="out">The result module</param> | |
/// <returns>0 when success, -1 when failure happens</returns> | |
/// <remarks> | |
/// @brief Load module from file.@note The resulting module do not contain import relation. | |
/// It can be reconstructed by TVMModImport. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int TVMModLoadFromFile([MarshalAs(UnmanagedType.LPStr)] string file_name, [MarshalAs(UnmanagedType.LPStr)] string format, ref libnative.TVMModuleHandle @out); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="mod">The module handle.</param> | |
/// <param name="dep">The dependent module to be imported.</param> | |
/// <returns>0 when success, -1 when failure happens</returns> | |
/// <remarks> | |
/// @brief Add dep to mod's dependency. | |
/// This allows functions in this module to use modules. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int TVMModImport(libnative.TVMModuleHandle mod, libnative.TVMModuleHandle dep); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="mod">The module handle.</param> | |
/// <param name="func_name">The name of the function.</param> | |
/// <param name="query_imports">Whether to query imported modules</param> | |
/// <param name="out">The result function, can be NULL if it is not available.</param> | |
/// <returns>0 when no error is thrown, -1 when failure happens</returns> | |
/// <remarks> | |
/// @brief Get function from the module. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int TVMModGetFunction(libnative.TVMModuleHandle mod, [MarshalAs(UnmanagedType.LPStr)] string func_name, int query_imports, ref libnative.TVMFunctionHandle @out); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="mod">The module to be freed.</param> | |
/// <returns>0 when success, -1 when failure happens</returns> | |
/// <remarks> | |
/// @brief Free the Module@note This may not free up the module's resources. | |
/// If there is active TVMFunctionHandle uses the module | |
/// Or if this module is imported by another active module.The all functions remains valid until TVMFuncFree is called. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int TVMModFree(libnative.TVMModuleHandle mod); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="func">The function handle</param> | |
/// <returns>0 when success, -1 when failure happens</returns> | |
/// <remarks> | |
/// @brief Free the function when it is no longer needed. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int TVMFuncFree(libnative.TVMFunctionHandle func); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="func">node handle of the function.</param> | |
/// <param name="arg_values">The arguments</param> | |
/// <param name="type_codes">The type codes of the arguments</param> | |
/// <param name="num_args">Number of arguments.</param> | |
/// <param name="ret_val">The return value.</param> | |
/// <param name="ret_type_code">the type code of return value.</param> | |
/// <returns>0 when success, -1 when failure happens</returns> | |
/// <remarks> | |
/// @brief Call a Packed TVM Function.@note TVM calls always exchanges with type bits=64, lanes=1@note API calls always exchanges with type bits=64, lanes=1 | |
/// If API call returns container handles (e.g. FunctionHandle) | |
/// these handles should be managed by the front-end. | |
/// The front-end need to call free function (e.g. TVMFuncFree) | |
/// to free these handles. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int TVMFuncCall(libnative.TVMFunctionHandle func, ref libnative.TVMValue arg_values, ref int type_codes, int num_args, ref libnative.TVMValue ret_val, ref int ret_type_code); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="ret">The return value handle, pass by ret in TVMPackedCFunc</param> | |
/// <param name="value">The value to be returned.</param> | |
/// <param name="type_code">The type of the value to be returned.</param> | |
/// <param name="num_ret">Number of return values, for now only 1 is supported.</param> | |
/// <remarks> | |
/// @brief Set the return value of TVMPackedCFunc.This function is called by TVMPackedCFunc to set the return value. | |
/// When this function is not called, the function returns null by default. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int TVMCFuncSetReturn(libnative.TVMRetValueHandle ret, ref libnative.TVMValue value, ref int type_code, int num_ret); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="value">The value to be translated.</param> | |
/// <param name="code">The type code to be translated.</param> | |
/// <returns>0 when success, -1 when failure happens.</returns> | |
/// <remarks> | |
/// @brief Inplace translate callback argument value to return value. | |
/// This is only needed for non-POD arguments.@note This function will do a shallow copy when necessary. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int TVMCbArgToReturn(ref libnative.TVMValue value, ref int code); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="func">The packed C function.</param> | |
/// <param name="resource_handle">The resource handle from front-end, can be NULL.</param> | |
/// <param name="fin">The finalizer on resource handle when the FunctionHandle get freed, can be NULL</param> | |
/// <param name="out">the result function handle.</param> | |
/// <returns>0 when success, -1 when failure happens</returns> | |
/// <remarks> | |
/// @brief Wrap a TVMPackedCFunc to become a FunctionHandle.The resource_handle will be managed by TVM API, until the function is no longer used. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int TVMFuncCreateFromCFunc(libnative.TVMPackedCFunc func, IntPtr resource_handle, libnative.TVMPackedCFuncFinalizer fin, ref libnative.TVMFunctionHandle @out); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="name">The name of the function.</param> | |
/// <param name="f">The function to be registered.</param> | |
/// <param name="override">Whether allow override already registered function.</param> | |
/// <remarks> | |
/// @brief Register the function to runtime's global table.The registered function then can be pulled by the backend by the name. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int TVMFuncRegisterGlobal([MarshalAs(UnmanagedType.LPStr)] string name, libnative.TVMFunctionHandle f, int @override); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="name">The name of the function.</param> | |
/// <param name="out">the result function pointer, NULL if it does not exist.</param> | |
/// <remarks> | |
/// @brief Get a global function.@note The function handle of global function is managed by TVM runtime, | |
/// So TVMFuncFree is should not be called when it get deleted. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int TVMFuncGetGlobal([MarshalAs(UnmanagedType.LPStr)] string name, ref libnative.TVMFunctionHandle @out); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="out_size">The number of functions</param> | |
/// <param name="out_array">The array of function names.</param> | |
/// <returns>0 when success, -1 when failure happens</returns> | |
/// <remarks> | |
/// @brief List all the globally registered function name | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int TVMFuncListGlobalNames(ref int out_size, out IntPtr out_array); | |
/// <summary> | |
/// Array related apis for quick proptyping | |
/// </summary> | |
/// <param name="shape">The shape of the array, the data content will be copied to out</param> | |
/// <param name="ndim">The number of dimension of the array.</param> | |
/// <param name="dtype_code">The type code of the dtype</param> | |
/// <param name="dtype_bits">The number of bits of dtype</param> | |
/// <param name="dtype_lanes">The number of lanes in the dtype.</param> | |
/// <param name="device_type">The device type of context</param> | |
/// <param name="device_id">The device id of context.</param> | |
/// <param name="out">The output handle.</param> | |
/// <returns>0 when success, -1 when failure happens</returns> | |
/// <remarks> | |
/// @brief Allocate a nd-array's memory, | |
/// including space of shape, of given spec. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int TVMArrayAlloc(ref libnative.tvm_index_t shape, int ndim, int dtype_code, int dtype_bits, int dtype_lanes, int device_type, int device_id, ref libnative.TVMArrayHandle @out); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="handle">The array handle to be freed.</param> | |
/// <returns>0 when success, -1 when failure happens</returns> | |
/// <remarks> | |
/// @brief Free the TVM Array. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int TVMArrayFree(libnative.TVMArrayHandle handle); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="handle">The array handle.</param> | |
/// <param name="data">the data pointer</param> | |
/// <param name="nbytes">The number of bytes to copy.</param> | |
/// <returns>0 when success, -1 when failure happens</returns> | |
/// <remarks> | |
/// @brief Copy array data from CPU byte array. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int TVMArrayCopyFromBytes(libnative.TVMArrayHandle handle, IntPtr data, libnative.size_t nbytes); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="handle">The array handle.</param> | |
/// <param name="data">the data pointer</param> | |
/// <param name="nbytes">The number of bytes to copy.</param> | |
/// <returns>0 when success, -1 when failure happens</returns> | |
/// <remarks> | |
/// @brief Copy array data to CPU byte array. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int TVMArrayCopyToBytes(libnative.TVMArrayHandle handle, IntPtr data, libnative.size_t nbytes); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="from">The array to be copied from.</param> | |
/// <param name="to">The target space.</param> | |
/// <param name="stream">The stream where the copy happens, can be NULL.</param> | |
/// <returns>0 when success, -1 when failure happens</returns> | |
/// <remarks> | |
/// @brief Copy the array, both from and to must be valid during the copy. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int TVMArrayCopyFromTo(libnative.TVMArrayHandle from, libnative.TVMArrayHandle to, libnative.TVMStreamHandle stream); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="from">The source DLManagedTensor.</param> | |
/// <param name="out">The output array handle.</param> | |
/// <returns>0 when success, -1 when failure happens</returns> | |
/// <remarks> | |
/// @brief Produce an array from the DLManagedTensor that shares data memory | |
/// with the DLManagedTensor. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int TVMArrayFromDLPack(ref libnative.DLManagedTensor from, ref libnative.TVMArrayHandle @out); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="from">The source array.</param> | |
/// <param name="out">The DLManagedTensor handle.</param> | |
/// <returns>0 when success, -1 when failure happens</returns> | |
/// <remarks> | |
/// @brief Produce a DLMangedTensor from the array that shares data memory with | |
/// the array. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int TVMArrayToDLPack(libnative.TVMArrayHandle from, out IntPtr @out); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="dltensor">Pointer to the DLManagedTensor.</param> | |
/// <remarks> | |
/// @brief Delete (free) a DLManagedTensor's data. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern void TVMDLManagedTensorCallDeleter(ref libnative.DLManagedTensor dltensor); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="device_type">The device type of context</param> | |
/// <param name="device_id">The device id of context</param> | |
/// <param name="out">The new stream handle</param> | |
/// <returns>0 when success, -1 when failure happens</returns> | |
/// <remarks> | |
/// @brief Create a new runtime stream. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int TVMStreamCreate(int device_type, int device_id, ref libnative.TVMStreamHandle @out); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="device_type">The device type of context</param> | |
/// <param name="device_id">The device id of context</param> | |
/// <param name="stream">The stream to be freed</param> | |
/// <returns>0 when success, -1 when failure happens</returns> | |
/// <remarks> | |
/// @brief Free a created stream handle. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int TVMStreamFree(int device_type, int device_id, libnative.TVMStreamHandle stream); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="device_type">The device type of context</param> | |
/// <param name="device_id">The device id of context.</param> | |
/// <param name="handle">The stream handle.</param> | |
/// <returns>0 when success, -1 when failure happens</returns> | |
/// <remarks> | |
/// @brief Set the runtime stream of current thread to be stream. | |
/// The subsequent calls to the same device_type | |
/// will use the setted stream handle. | |
/// The specific type of stream is runtime device dependent. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int TVMSetStream(int device_type, int device_id, libnative.TVMStreamHandle handle); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="device_type">The device type of context</param> | |
/// <param name="device_id">The device id of context.</param> | |
/// <param name="stream">The stream to be synchronized.</param> | |
/// <returns>0 when success, -1 when failure happens</returns> | |
/// <remarks> | |
/// @brief Wait until all computations on stream completes. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int TVMSynchronize(int device_type, int device_id, libnative.TVMStreamHandle stream); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="device_type">The device type of context</param> | |
/// <param name="device_id">The device id of context</param> | |
/// <param name="src">The source stream to synchronize.</param> | |
/// <param name="dst">The destination stream to synchronize.</param> | |
/// <returns>0 when success, -1 when failure happens</returns> | |
/// <remarks> | |
/// @brief Synchronize two streams of execution. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int TVMStreamStreamSynchronize(int device_type, int device_id, libnative.TVMStreamHandle src, libnative.TVMStreamHandle dst); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="obj">The object handle.</param> | |
/// <param name="out_tindex">the output type index.</param> | |
/// <returns>0 when success, -1 when failure happens</returns> | |
/// <remarks> | |
/// @brief Get the type_index from an object. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int TVMObjectGetTypeIndex(libnative.TVMObjectHandle obj, ref uint out_tindex); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="type_key">The key of the type.</param> | |
/// <param name="out_tindex">the corresponding type index.</param> | |
/// <returns>0 when success, -1 when failure happens</returns> | |
/// <remarks> | |
/// @brief Convert type key to type index. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int TVMObjectTypeKey2Index([MarshalAs(UnmanagedType.LPStr)] string type_key, ref uint out_tindex); | |
/// <summary> | |
/// | |
/// </summary> | |
/// <param name="obj">The object handle.</param> | |
/// <returns>0 when success, -1 when failure happens</returns> | |
/// <remarks> | |
/// @brief Free the object.@note Internally we decrease the reference counter of the object. | |
/// The object will be freed when every reference to the object are removed. | |
/// </remarks> | |
[DllImport("tvm_runtime", CallingConvention = CallingConvention.Cdecl)] | |
public static extern int TVMObjectFree(libnative.TVMObjectHandle obj); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment