ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ModelArgumentInfo Struct Reference

#include <ModelArgumentInfo.h>

Collaboration diagram for ModelArgumentInfo:

Public Types

enum  { POINTER , MEMORY , HAS_NO_VALUE , UNSPECIFIED }
 

Public Member Functions

int setFromPointer (const Operand &operand, const ANeuralNetworksOperandType *type, void *buffer, uint32_t length)
 
int setFromMemory (const Operand &operand, const ANeuralNetworksOperandType *type, uint32_t poolIndex, uint32_t offset, uint32_t length)
 
int updateDimensionInfo (const Operand &operand, const ANeuralNetworksOperandType *newType)
 

Data Fields

enum ModelArgumentInfo:: { ... }  state = UNSPECIFIED
 
DataLocation locationAndLength
 
std::vector< uint32_t > dimensions
 
void * buffer
 

Detailed Description

Definition at line 27 of file ModelArgumentInfo.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
POINTER 
MEMORY 
HAS_NO_VALUE 
UNSPECIFIED 

Definition at line 38 of file ModelArgumentInfo.h.

Member Function Documentation

◆ setFromMemory()

int ModelArgumentInfo::setFromMemory ( const Operand operand,
const ANeuralNetworksOperandType type,
uint32_t  poolIndex,
uint32_t  offset,
uint32_t  length 
)

Definition at line 59 of file ModelArgumentInfo.cpp.

61{
62 int n = updateDimensionInfo(operand, type);
64 {
65 return n;
66 }
67 uint32_t neededLength = sizeOfData(operand.type, dimensions);
68 if (neededLength != length)
69 {
70 LOG(ERROR) << "Setting argument with invalid length: " << length
71 << ", expected length: " << neededLength;
73 }
74
76 locationAndLength = {.poolIndex = poolIndex, .offset = offset, .length = length};
77 buffer = nullptr;
79}
#define LOG(...)
Definition Logging.h:36
uint32_t sizeOfData(const Operand &operand)
Definition Operand.h:56
@ ANEURALNETWORKS_BAD_DATA
@ ANEURALNETWORKS_NO_ERROR
__global uchar * offset(const Image *img, int x, int y)
Definition helpers.h:540
uint32_t poolIndex
Definition Operand.h:36
int updateDimensionInfo(const Operand &operand, const ANeuralNetworksOperandType *newType)
DataLocation locationAndLength
std::vector< uint32_t > dimensions
OperandType type
Definition Operand.h:42

References ANEURALNETWORKS_BAD_DATA, ANEURALNETWORKS_NO_ERROR, buffer, dimensions, locationAndLength, LOG, MEMORY, offset(), DataLocation::poolIndex, sizeOfData(), state, Operand::type, and updateDimensionInfo().

◆ setFromPointer()

int ModelArgumentInfo::setFromPointer ( const Operand operand,
const ANeuralNetworksOperandType type,
void *  buffer,
uint32_t  length 
)

Definition at line 24 of file ModelArgumentInfo.cpp.

27{
28 if ((data == nullptr) != (length == 0))
29 {
30 LOG(ERROR) << "Data pointer must be nullptr if and only if length is zero (data = " << data
31 << ", length = " << length << ")";
33 }
34 if (data == nullptr)
35 {
37 }
38 else
39 {
40 int n = updateDimensionInfo(operand, type);
42 {
43 return n;
44 }
45 uint32_t neededLength = sizeOfData(operand.type, dimensions);
46 if (neededLength != length)
47 {
48 LOG(ERROR) << "Setting argument with invalid length: " << length
49 << ", expected length: " << neededLength;
51 }
53 }
54 buffer = data;
55 locationAndLength = {.poolIndex = 0, .offset = 0, .length = length};
57}

References ANEURALNETWORKS_BAD_DATA, ANEURALNETWORKS_NO_ERROR, buffer, dimensions, HAS_NO_VALUE, locationAndLength, LOG, POINTER, DataLocation::poolIndex, sizeOfData(), state, Operand::type, and updateDimensionInfo().

◆ updateDimensionInfo()

int ModelArgumentInfo::updateDimensionInfo ( const Operand operand,
const ANeuralNetworksOperandType newType 
)

Definition at line 81 of file ModelArgumentInfo.cpp.

83{
84 ASSERT(dimensions.empty());
85 if (newType == nullptr)
86 {
87 for (auto i : operand.dimensions)
88 {
89 if (i == 0)
90 {
91 LOG(ERROR) << "Setting input/output with unspecified dimensions";
93 }
94 }
95 dimensions = operand.dimensions;
96 }
97 else
98 {
99 uint32_t count = newType->dimensionCount;
100 if (static_cast<OperandType>(newType->type) != operand.type ||
101 count != operand.dimensions.size())
102 {
103 LOG(ERROR) << "Setting input/output with incompatible types";
105 }
106 dimensions = std::vector<uint32_t>(count);
107 for (uint32_t i = 0; i < count; i++)
108 {
109 if (operand.dimensions[i] != 0 && operand.dimensions[i] != newType->dimensions[i])
110 {
111 LOG(ERROR) << "Overriding a fully specified dimension is disallowed";
113 }
114 else
115 {
116 dimensions[i] = newType->dimensions[i];
117 }
118 }
119 }
121}
OperandType
Definition OperandType.h:24
#define ASSERT(v)
Definition Assert.h:24
std::vector< uint32_t > dimensions
Definition Operand.h:46

References ANEURALNETWORKS_BAD_DATA, ANEURALNETWORKS_NO_ERROR, ASSERT, ANeuralNetworksOperandType::dimensionCount, ANeuralNetworksOperandType::dimensions, dimensions, Operand::dimensions, LOG, ANeuralNetworksOperandType::type, and Operand::type.

Referenced by setFromMemory(), and setFromPointer().

Field Documentation

◆ buffer

void* ModelArgumentInfo::buffer

Definition at line 49 of file ModelArgumentInfo.h.

Referenced by setFromMemory(), and setFromPointer().

◆ dimensions

std::vector<uint32_t> ModelArgumentInfo::dimensions

Definition at line 48 of file ModelArgumentInfo.h.

Referenced by setFromMemory(), setFromPointer(), and updateDimensionInfo().

◆ locationAndLength

DataLocation ModelArgumentInfo::locationAndLength

Definition at line 46 of file ModelArgumentInfo.h.

Referenced by setFromMemory(), and setFromPointer().

◆ []

enum { ... } ModelArgumentInfo::state

Referenced by setFromMemory(), and setFromPointer().


The documentation for this struct was generated from the following files: