-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.go
More file actions
80 lines (65 loc) · 2.79 KB
/
model.go
File metadata and controls
80 lines (65 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Code generated by idiomgen. DO NOT EDIT.
package nnapi
import (
"unsafe"
capi "github.com/AndroidGoLab/ndk/capi/neuralnetworks"
)
// Model wraps the NDK ANeuralNetworksModel handle.
type Model struct {
ptr *capi.ANeuralNetworksModel
}
// cptr returns the underlying C pointer, or nil if h is nil.
// This allows passing optional (nullable) handle parameters to capi functions.
func (h *Model) cptr() *capi.ANeuralNetworksModel {
if h == nil {
return nil
}
return h.ptr
}
// NewModelFromPointer wraps a raw ANeuralNetworksModel pointer.
func NewModelFromPointer(ptr unsafe.Pointer) *Model {
return &Model{ptr: (*capi.ANeuralNetworksModel)(ptr)}
}
// Pointer returns the underlying pointer as unsafe.Pointer.
func (h *Model) Pointer() unsafe.Pointer {
return unsafe.Pointer(h.ptr)
}
// UintPtr returns the underlying pointer as a uintptr.
// This is useful for interop with gomobile bind, golang.org/x/mobile,
// gioui.org, and other packages that represent native handles as uintptr.
func (h *Model) UintPtr() uintptr {
return uintptr(unsafe.Pointer(h.ptr))
}
// NewModelFromUintPtr wraps a uintptr as a Model.
// The caller must ensure ptr points to a valid ANeuralNetworksModel.
func NewModelFromUintPtr(ptr uintptr) *Model {
return &Model{ptr: (*capi.ANeuralNetworksModel)(unsafe.Pointer(ptr))}
}
// NewCompilation creates a new Compilation from this Model.
func (h *Model) NewCompilation() (*Compilation, error) {
var ptr *capi.ANeuralNetworksCompilation
if err := result(capi.ANeuralNetworksCompilation_create(h.ptr, &ptr)); err != nil {
return nil, err
}
return &Compilation{ptr: ptr}, nil
}
// AddOperation calls the underlying NDK function.
func (h *Model) AddOperation(_type ANeuralNetworksOperationType, inputCount uint32, inputs *uint32, outputCount uint32, outputs *uint32) error {
return result(capi.ANeuralNetworksModel_addOperation(h.ptr, capi.ANeuralNetworksOperationType(_type), inputCount, inputs, outputCount, outputs))
}
// Finish calls the underlying NDK function.
func (h *Model) Finish() error {
return result(capi.ANeuralNetworksModel_finish(h.ptr))
}
// IdentifyInputsAndOutputs calls the underlying NDK function.
func (h *Model) IdentifyInputsAndOutputs(inputCount uint32, inputs *uint32, outputCount uint32, outputs *uint32) error {
return result(capi.ANeuralNetworksModel_identifyInputsAndOutputs(h.ptr, inputCount, inputs, outputCount, outputs))
}
// RelaxFloat32toFloat16 calls the underlying NDK function.
func (h *Model) RelaxFloat32toFloat16(allow bool) error {
return result(capi.ANeuralNetworksModel_relaxComputationFloat32toFloat16(h.ptr, allow))
}
// SetOperandValue calls the underlying NDK function.
func (h *Model) SetOperandValue(index int32, buffer unsafe.Pointer, length uint64) error {
return result(capi.ANeuralNetworksModel_setOperandValue(h.ptr, index, buffer, length))
}