gotvm

package
v2.9.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 23, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package gotvm is TVM runtime interface definition for golang.

Application need to import this package to access the c_runtime_api exposed by TVM.

Index

Constants

This section is empty.

Variables

View Source
var DLPackVersion = int(C.DLPACK_VERSION)

DLPackVersion is the dlpack version of tvm runtime.

View Source
var KArrayHandle = int32(C.kTVMDLTensorHandle)

KArrayHandle is golang type code for TVM kTVMDLTensorHandle.

View Source
var KBytes = int32(C.kTVMBytes)

KBytes is golang type code for TVM kTVMBytes.

View Source
var KDLCPU = int32(C.kDLCPU)

KDLCPU is golang enum correspond to TVM device type kDLCPU.

View Source
var KDLDevice = int32(C.kDLDevice)

KDLDevice is golang type code for TVM kDLDevice.

View Source
var KDLFloat = int32(C.kDLFloat)

KDLFloat is golang type code for TVM kDLFloat.

View Source
var KDLInt = int32(C.kDLInt)

KDLInt is golang type code for TVM kDLInt.

View Source
var KDLMetal = int32(C.kDLMetal)

KDLMetal is golang enum correspond to TVM device type kDLMetal.

View Source
var KDLOpenCL = int32(C.kDLOpenCL)

KDLOpenCL is golang enum correspond to TVM device type kDLOpenCL.

View Source
var KDLROCM = int32(C.kDLROCM)

KDLROCM is golang enum correspond to TVM device type kDLROCM.

View Source
var KDLSDAccel = int32(C.kDLSDAccel)

KDLSDAccel is golang enum correspond to TVM device type kDLSDAccel.

View Source
var KDLUInt = int32(C.kDLUInt)

KDLUInt is golang type code for TVM kDLUInt.

View Source
var KDLVPI = int32(C.kDLVPI)

KDLVPI is golang enum correspond to TVM device type kDLVPI.

View Source
var KDLVulkan = int32(C.kDLVulkan)

KDLVulkan is golang enum correspond to TVM device type kDLVulkan.

View Source
var KExtBegin = int32(C.kTVMExtBegin)

KExtBegin is golang enum corresponding to TVM kTVMExtBegin.

View Source
var KExtDev = int32(C.kDLExtDev)

KExtDev is golang enum correspond to TVM device type kDLExtDev.

View Source
var KExtEnd = int32(C.kTVMExtEnd)

KExtEnd is golang enum corresponding to TVM kExtEnd.

View Source
var KExtReserveEnd = int32(C.kTVMExtReserveEnd)

KExtReserveEnd is golang enum corresponding to TVM kExtReserveEnd.

KFuncHandle is gonalg type code for TVM kTVMPackedFuncHandle.

KHandle is golang type code for TVM enum kTVMOpaqueHandle.

View Source
var KModuleHandle = int32(C.kTVMModuleHandle)

KModuleHandle is gonag type code for TVM kTVMModuleHandle.

View Source
var KNDArrayContainer = int32(C.kTVMNDArrayHandle)

KNDArrayContainer is golang typecode for kTVMNDArrayHandle.

View Source
var KNNVMFirst = int32(C.kTVMNNVMFirst)

KNNVMFirst is golang enum corresponding to TVM kNNVMFirst.

View Source
var KNNVMLast = int32(C.kTVMNNVMLast)

KNNVMLast is golang enum corresponding to TVM kNNVMLast.

KNull is golang type code for TVM kTVMNullptr.

View Source
var KObjectHandle = int32(C.kTVMObjectHandle)

KObjectHandle is golang type code for TVM kTVMObjectHandle.

View Source
var KOpenGL = int32(C.kOpenGL)

KOpenGL is golang enum correspond to TVM device type kOpenGL.

View Source
var KStr = int32(C.kTVMStr)

KStr is golang type code for TVM kTVMStr.

View Source
var KTVMType = int32(C.kTVMDataType)

KTVMType is golang type code for TVM kTVMDataType.

View Source
var TVMVersion = getTVMVersion()

TVMVersion is the TVM runtime version.

Functions

func FuncListGlobalNames

func FuncListGlobalNames() (retVal []string, err error)

FuncListGlobalNames is used to query global callable packed function names from TVM.

returns slice of string holding function names and error if any.

func RegisterFunction

func RegisterFunction(args ...interface{}) (err error)

RegisterFunction registers the golang func in TVM runtime global space.

`args[0]` function pointer for a type ```func (args ...interface{}) (interface{})```

`args[1]` Optional argument of function name with which it will be registered.

If not passed we use function name from reflection.

Returns err indicating native error if any.

Types

type Array

type Array uintptr

Array type in golang hold pointer for the TVMArray object from dlpack.

Array initialization happen through Empty api

func Empty

func Empty(shape []int64, args ...interface{}) (parray *Array, err error)

Empty is used to allocate TVM empty array of given epecification.

`shape` is int64 slice holding shape of the Array

`args` is variadic args for

`args[0]` is string for data type. Default value is 'float32'

`args[1]` is Device. Default value is '{KDLCPU, 0}'

returns pointer to Array on successful execution and error if any.

func (Array) AsSlice

func (parray Array) AsSlice() (retVal interface{}, err error)

AsSlice returns the unitptr of for the data inside Array.

returns the slice of array inside Array and err of any. TOD: Use reflections for better handling

func (Array) CopyFrom

func (parray Array) CopyFrom(val interface{}) (err error)

CopyFrom copies given golang data slice into Array.

`val` is interface homding a slice of Array data type.

returns err is any. TOD: Use reflections for better handling

func (Array) GetDType

func (parray Array) GetDType() (retVal string)

GetDType returns the number of dimentions in Array

func (Array) GetDevice

func (parray Array) GetDevice() (retVal Device)

GetDevice returns the number of dimentions in Array

func (Array) GetNdim

func (parray Array) GetNdim() (retVal int32)

GetNdim returns the number of dimentions in Array

func (Array) GetShape

func (parray Array) GetShape() (retVal []int64)

GetShape returns the number of dimentions in Array

type ByteArray

type ByteArray uintptr

ByteArray type wraps the TVMByteArray of C runtime API.

This can be used to hold raw data like params of a model.

type Device

type Device struct {
	DeviceType int32
	DeviceID   int32
}

Device dtype corresponding to Device aka DLDevice

func CPU

func CPU(index int32) Device

CPU returns the Device object for CPU target on given index

func CUDA

func CUDA(index int32) Device

CUDA returns the Device object for CUDA target on given index

func CUDAHost

func CUDAHost(index int32) Device

CUDAHost returns the Device object for CUDAHost target on given index

func Metal

func Metal(index int32) Device

Metal returns the Device object for Metal target on given index

func OpenCL

func OpenCL(index int32) Device

OpenCL returns the Device object for OpenCL target on given index

func OpenGL

func OpenGL(index int32) Device

OpenGL returns the Device object for OpenGL target on given index

func ROCM

func ROCM(index int32) Device

ROCM returns the Device object for ROCM target on given index

func SDAccel

func SDAccel(index int32) Device

SDAccel returns the Device object for SDAccel target on given index

func VPI

func VPI(index int32) Device

VPI returns the Device object for VPI target on given index

func Vulkan

func Vulkan(index int32) Device

Vulkan returns the Device object for Vulkan target on given index

type Function

type Function uintptr

Function type in golang hold pointer for the TVMFunction handle.

func ConvertFunction

func ConvertFunction(args ...interface{}) (retVal *Function, err error)

ConvertFunction converts given golang function to TVM packed function.

`args[0]` function pointer for a type ```func (args ...interface{}) (interface{})```

Returns Function handle and err if any.

func GetGlobalFunction

func GetGlobalFunction(funcname string) (retVal *Function, err error)

GetGlobalFunction is to get handle to the given global function name.

`funcname` is the name of global packed function.

returns a function closure with signature

func (args ...interface{}) (interface{}, error) and  error if any.

The closure function can be used to call Function with arguments directly.

Variadic arguments can be any type which can be embed into Value.

func (*Function) Invoke

func (tvmfunction *Function) Invoke(args ...interface{}) (retVal *Value, err error)

Invoke calls the TVM packed function referred by the handle with given arguments.

type Module

type Module uintptr

Module type in golang hold pointer for the TVMModule handle.

Module initialization happen through TVMModLoadFromFile api in TVM runtime.

func LoadModuleFromFile

func LoadModuleFromFile(modpath string, args ...interface{}) (retVal *Module, err error)

LoadModuleFromFile loads the given module in TVM runtime.

`modpath` is the path to tvm module.

`args` is an optional arguments of ["dll", "dylib", "dso", "so"] with default value "so"

returns pointer to Module and err or if any.

func (*Module) GetFunction

func (tvmmodule *Module) GetFunction(
	funcname string, args ...interface{}) (
	retVal *Function, err error)

GetFunction returns the function pointer from the module for given function name.

`tvmmodule` is handle for Module

`funcname` function name in module.

`args` variadic args of `queryImport`

returns function closure with signature

func (args ...interface{}) (interface{}, error) and error if any.

The closure function can be used to call Function with arguments directly.

Variadic arguments can be any type which can be embed into Value.

type Value

type Value struct {
	// contains filtered or unexported fields
}

Value Typemap for union exposed by TVM runtime API.

gotvm maps it to a uintptr and then dynamically allocates memory by newTVMValue method.

func (*Value) AsBytes

func (tvmval *Value) AsBytes() (retVal []byte)

AsBytes returns the byte slice value inside the Value.

func (*Value) AsFloat64

func (tvmval *Value) AsFloat64() (retVal float64)

AsFloat64 returns the Float64 value inside the Value.

func (*Value) AsFunction

func (tvmval *Value) AsFunction() (retVal *Function)

AsFunction returns the Function inside the Value.

func (*Value) AsInt64

func (tvmval *Value) AsInt64() (retVal int64)

AsInt64 returns the int64 value inside the Value.

func (*Value) AsModule

func (tvmval *Value) AsModule() (retVal *Module)

AsModule returns the Module inside the Value.

func (*Value) AsStr

func (tvmval *Value) AsStr() (retVal string)

AsStr returns the golang string in the Value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL