nnapi

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package nnapi provides Go bindings for Android Neural Networks API (NNAPI).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ANeuralNetworksCompilation_getPreferredMemoryAlignmentForInput

func ANeuralNetworksCompilation_getPreferredMemoryAlignmentForInput(compilation *Compilation, index uint32, alignment *uint32) int32

ANeuralNetworksCompilation_getPreferredMemoryAlignmentForInput calls the underlying C function.

func ANeuralNetworksCompilation_getPreferredMemoryAlignmentForOutput

func ANeuralNetworksCompilation_getPreferredMemoryAlignmentForOutput(compilation *Compilation, index uint32, alignment *uint32) int32

ANeuralNetworksCompilation_getPreferredMemoryAlignmentForOutput calls the underlying C function.

func ANeuralNetworksCompilation_getPreferredMemoryPaddingForInput

func ANeuralNetworksCompilation_getPreferredMemoryPaddingForInput(compilation *Compilation, index uint32, padding *uint32) int32

ANeuralNetworksCompilation_getPreferredMemoryPaddingForInput calls the underlying C function.

func ANeuralNetworksCompilation_getPreferredMemoryPaddingForOutput

func ANeuralNetworksCompilation_getPreferredMemoryPaddingForOutput(compilation *Compilation, index uint32, padding *uint32) int32

ANeuralNetworksCompilation_getPreferredMemoryPaddingForOutput calls the underlying C function.

func ANeuralNetworksDevice_wait

func ANeuralNetworksDevice_wait(device *Device) int32

ANeuralNetworksDevice_wait calls the underlying C function.

func ANeuralNetworksEvent_getSyncFenceFd

func ANeuralNetworksEvent_getSyncFenceFd(event *Event, sync_fence_fd *int32) int32

ANeuralNetworksEvent_getSyncFenceFd calls the underlying C function.

func ANeuralNetworksExecution_burstCompute

func ANeuralNetworksExecution_burstCompute(execution *Execution, burst *Burst) int32

ANeuralNetworksExecution_burstCompute calls the underlying C function.

func ANeuralNetworksExecution_enableInputAndOutputPadding

func ANeuralNetworksExecution_enableInputAndOutputPadding(execution *Execution, enable bool) int32

ANeuralNetworksExecution_enableInputAndOutputPadding calls the underlying C function.

func ANeuralNetworksExecution_getOutputOperandDimensions

func ANeuralNetworksExecution_getOutputOperandDimensions(execution *Execution, index int32, dimensions *uint32) int32

ANeuralNetworksExecution_getOutputOperandDimensions calls the underlying C function.

func ANeuralNetworksExecution_getOutputOperandRank

func ANeuralNetworksExecution_getOutputOperandRank(execution *Execution, index int32, rank *uint32) int32

ANeuralNetworksExecution_getOutputOperandRank calls the underlying C function.

func ANeuralNetworksExecution_setLoopTimeout

func ANeuralNetworksExecution_setLoopTimeout(execution *Execution, duration uint64) int32

ANeuralNetworksExecution_setLoopTimeout calls the underlying C function.

func ANeuralNetworksExecution_setReusable

func ANeuralNetworksExecution_setReusable(execution *Execution, reusable bool) int32

ANeuralNetworksExecution_setReusable calls the underlying C function.

func ANeuralNetworksMemoryDesc_addInputRole

func ANeuralNetworksMemoryDesc_addInputRole(desc *ANeuralNetworksMemoryDesc, compilation *Compilation, index uint32, frequency float32) int32

ANeuralNetworksMemoryDesc_addInputRole calls the underlying C function.

func ANeuralNetworksMemoryDesc_addOutputRole

func ANeuralNetworksMemoryDesc_addOutputRole(desc *ANeuralNetworksMemoryDesc, compilation *Compilation, index uint32, frequency float32) int32

ANeuralNetworksMemoryDesc_addOutputRole calls the underlying C function.

func ANeuralNetworksMemoryDesc_finish

func ANeuralNetworksMemoryDesc_finish(desc *ANeuralNetworksMemoryDesc) int32

ANeuralNetworksMemoryDesc_finish calls the underlying C function.

func ANeuralNetworksMemoryDesc_free

func ANeuralNetworksMemoryDesc_free(desc *ANeuralNetworksMemoryDesc)

ANeuralNetworksMemoryDesc_free calls the underlying C function.

func ANeuralNetworksMemoryDesc_setDimensions

func ANeuralNetworksMemoryDesc_setDimensions(desc *ANeuralNetworksMemoryDesc, rank uint32, dimensions *uint32) int32

ANeuralNetworksMemoryDesc_setDimensions calls the underlying C function.

func ANeuralNetworksMemory_copy

func ANeuralNetworksMemory_copy(src *Memory, dst *Memory) int32

ANeuralNetworksMemory_copy calls the underlying C function.

func ANeuralNetworksModel_setOperandSymmPerChannelQuantParams

func ANeuralNetworksModel_setOperandSymmPerChannelQuantParams(model *Model, index int32, channelQuant *ANeuralNetworksSymmPerChannelQuantParams) int32

ANeuralNetworksModel_setOperandSymmPerChannelQuantParams calls the underlying C function.

func ANeuralNetworksModel_setOperandValueFromMemory

func ANeuralNetworksModel_setOperandValueFromMemory(model *Model, index int32, memory *Memory, offset uint64, length uint64) int32

ANeuralNetworksModel_setOperandValueFromMemory calls the underlying C function.

func ANeuralNetworksModel_setOperandValueFromModel

func ANeuralNetworksModel_setOperandValueFromModel(model *Model, index int32, value *Model) int32

ANeuralNetworksModel_setOperandValueFromModel calls the underlying C function.

func ANeuralNetworks_getDefaultLoopTimeout

func ANeuralNetworks_getDefaultLoopTimeout() uint64

ANeuralNetworks_getDefaultLoopTimeout calls the underlying C function.

func ANeuralNetworks_getMaximumLoopTimeout

func ANeuralNetworks_getMaximumLoopTimeout() uint64

ANeuralNetworks_getMaximumLoopTimeout calls the underlying C function.

func ANeuralNetworks_getRuntimeFeatureLevel

func ANeuralNetworks_getRuntimeFeatureLevel() int64

ANeuralNetworks_getRuntimeFeatureLevel calls the underlying C function.

Types

type AHardwareBuffer

type AHardwareBuffer = capi.AHardwareBuffer

type ANeuralNetworksMemoryDesc

type ANeuralNetworksMemoryDesc = capi.ANeuralNetworksMemoryDesc

type ANeuralNetworksOperationType

type ANeuralNetworksOperationType = capi.ANeuralNetworksOperationType

type ANeuralNetworksSymmPerChannelQuantParams

type ANeuralNetworksSymmPerChannelQuantParams = capi.ANeuralNetworksSymmPerChannelQuantParams

type Burst

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

Burst wraps the NDK ANeuralNetworksBurst handle.

func NewBurstFromPointer

func NewBurstFromPointer(ptr unsafe.Pointer) *Burst

NewBurstFromPointer wraps a raw ANeuralNetworksBurst pointer.

func (*Burst) Pointer

func (h *Burst) Pointer() unsafe.Pointer

Pointer returns the underlying pointer as unsafe.Pointer.

type Compilation

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

Compilation wraps the NDK ANeuralNetworksCompilation handle.

func NewCompilationFromPointer

func NewCompilationFromPointer(ptr unsafe.Pointer) *Compilation

NewCompilationFromPointer wraps a raw ANeuralNetworksCompilation pointer.

func (*Compilation) Close

func (h *Compilation) Close() error

Close releases the underlying NDK handle.

func (*Compilation) Finish

func (h *Compilation) Finish() error

Finish calls the underlying NDK function.

func (*Compilation) NewBurst

func (h *Compilation) NewBurst() (*Burst, error)

NewBurst creates a new Burst from this Compilation.

func (*Compilation) NewExecution

func (h *Compilation) NewExecution() (*Execution, error)

NewExecution creates a new Execution from this Compilation.

func (*Compilation) Pointer

func (h *Compilation) Pointer() unsafe.Pointer

Pointer returns the underlying pointer as unsafe.Pointer.

func (*Compilation) SetCaching

func (h *Compilation) SetCaching(cacheDir string, token *uint8) error

SetCaching calls the underlying NDK function.

func (*Compilation) SetPreference

func (h *Compilation) SetPreference(preference Preference) error

SetPreference calls the underlying NDK function.

func (*Compilation) SetPriority

func (h *Compilation) SetPriority(priority int32) error

SetPriority calls the underlying NDK function.

func (*Compilation) SetTimeout

func (h *Compilation) SetTimeout(duration uint64) error

SetTimeout calls the underlying NDK function.

type Device

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

Device wraps the NDK ANeuralNetworksDevice handle.

func NewDeviceFromPointer

func NewDeviceFromPointer(ptr unsafe.Pointer) *Device

NewDeviceFromPointer wraps a raw ANeuralNetworksDevice pointer.

func (*Device) Pointer

func (h *Device) Pointer() unsafe.Pointer

Pointer returns the underlying pointer as unsafe.Pointer.

type Error

type Error int32

Error represents an NDK error code.

const (
	ErrOutOfMemory                 Error = 1
	ErrIncomplete                  Error = 2
	ErrUnexpectedNull              Error = 3
	ErrBadData                     Error = 4
	ErrOpFailed                    Error = 5
	ErrBadState                    Error = 6
	ErrUnmappable                  Error = 7
	ErrOutputInsufficientSize      Error = 8
	ErrUnavailableDevice           Error = 9
	ErrMissedDeadlineTransient     Error = 10
	ErrMissedDeadlinePersistent    Error = 11
	ErrResourceExhaustedTransient  Error = 12
	ErrResourceExhaustedPersistent Error = 13
	ErrDeadObject                  Error = 14
)

func (Error) Error

func (e Error) Error() string

type Event

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

Event wraps the NDK ANeuralNetworksEvent handle.

func NewEventFromPointer

func NewEventFromPointer(ptr unsafe.Pointer) *Event

NewEventFromPointer wraps a raw ANeuralNetworksEvent pointer.

func (*Event) Pointer

func (h *Event) Pointer() unsafe.Pointer

Pointer returns the underlying pointer as unsafe.Pointer.

func (*Event) Wait

func (h *Event) Wait() error

Wait calls the underlying NDK function.

type Execution

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

Execution wraps the NDK ANeuralNetworksExecution handle.

func NewExecutionFromPointer

func NewExecutionFromPointer(ptr unsafe.Pointer) *Execution

NewExecutionFromPointer wraps a raw ANeuralNetworksExecution pointer.

func (*Execution) Compute

func (h *Execution) Compute() error

Compute calls the underlying NDK function.

func (*Execution) GetDuration

func (h *Execution) GetDuration(durationCode int32, duration *uint64) error

GetDuration calls the underlying NDK function.

func (*Execution) Pointer

func (h *Execution) Pointer() unsafe.Pointer

Pointer returns the underlying pointer as unsafe.Pointer.

func (*Execution) SetMeasureTiming

func (h *Execution) SetMeasureTiming(measure bool) error

SetMeasureTiming calls the underlying NDK function.

func (*Execution) SetTimeout

func (h *Execution) SetTimeout(duration uint64) error

SetTimeout calls the underlying NDK function.

func (*Execution) StartCompute

func (h *Execution) StartCompute() (*Event, error)

StartCompute creates a new Event from this Execution.

type FuseCode

type FuseCode int32
const (
	FusedNone  FuseCode = 0
	FusedRelu  FuseCode = 1
	FusedRelu1 FuseCode = 2
	FusedRelu6 FuseCode = 3
)

type Memory

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

Memory wraps the NDK ANeuralNetworksMemory handle.

func NewMemoryFromPointer

func NewMemoryFromPointer(ptr unsafe.Pointer) *Memory

NewMemoryFromPointer wraps a raw ANeuralNetworksMemory pointer.

func (*Memory) Pointer

func (h *Memory) Pointer() unsafe.Pointer

Pointer returns the underlying pointer as unsafe.Pointer.

type Model

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

Model wraps the NDK ANeuralNetworksModel handle.

func NewModel

func NewModel() (*Model, error)

NewModel creates a new empty neural network model.

func NewModelFromPointer

func NewModelFromPointer(ptr unsafe.Pointer) *Model

NewModelFromPointer wraps a raw ANeuralNetworksModel pointer.

func (*Model) AddOperand

func (h *Model) AddOperand(desc OperandTypeDesc) error

AddOperand adds an operand to the model with the given type descriptor.

func (*Model) AddOperation

func (h *Model) AddOperation(_type ANeuralNetworksOperationType, inputCount uint32, inputs *uint32, outputCount uint32, outputs *uint32) error

AddOperation calls the underlying NDK function.

func (*Model) Close

func (h *Model) Close() error

Close releases the underlying NDK handle.

func (*Model) Finish

func (h *Model) Finish() error

Finish calls the underlying NDK function.

func (*Model) IdentifyInputsAndOutputs

func (h *Model) IdentifyInputsAndOutputs(inputCount uint32, inputs *uint32, outputCount uint32, outputs *uint32) error

IdentifyInputsAndOutputs calls the underlying NDK function.

func (*Model) NewCompilation

func (h *Model) NewCompilation() (*Compilation, error)

NewCompilation creates a new Compilation from this Model.

func (*Model) Pointer

func (h *Model) Pointer() unsafe.Pointer

Pointer returns the underlying pointer as unsafe.Pointer.

func (*Model) RelaxFloat32toFloat16

func (h *Model) RelaxFloat32toFloat16(allow bool) error

RelaxFloat32toFloat16 calls the underlying NDK function.

func (*Model) SetOperandValue

func (h *Model) SetOperandValue(index int32, buffer unsafe.Pointer, length uint64) error

SetOperandValue calls the underlying NDK function.

type OperandType

type OperandType int32
const (
	Float32                    OperandType = 0
	Int32                      OperandType = 1
	Uint32                     OperandType = 2
	TensorFloat32              OperandType = 3
	TensorInt32                OperandType = 4
	TensorQuant8Asymm          OperandType = 5
	Bool                       OperandType = 6
	TensorQuant16Symm          OperandType = 7
	TensorFloat16              OperandType = 8
	TensorBool8                OperandType = 9
	Float16                    OperandType = 10
	TensorQuant8SymmPerChannel OperandType = 11
	TensorQuant16Asymm         OperandType = 12
	TensorQuant8Symm           OperandType = 13
	TensorQuant8AsymmSigned    OperandType = 14
)

type OperandTypeDesc

type OperandTypeDesc struct {
	Type      OperandType
	Dims      []uint32
	Scale     float32
	ZeroPoint int32
}

OperandTypeDesc describes the type of an operand for AddOperand. It mirrors the C struct ANeuralNetworksOperandType.

type OperationType

type OperationType int32
const (
	Add             OperationType = 0
	Mul             OperationType = 18
	Relu            OperationType = 19
	Softmax         OperationType = 25
	FullyConnected  OperationType = 9
	Conv2d          OperationType = 3
	DepthwiseConv2d OperationType = 4
	AveragePool2d   OperationType = 1
	MaxPool2d       OperationType = 17
	Reshape         OperationType = 22
	Concatenation   OperationType = 2
)

type Preference

type Preference int32
const (
	LowPower         Preference = 0
	FastSingleAnswer Preference = 1
	SustainedSpeed   Preference = 2
)

Jump to

Keyboard shortcuts

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