ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Validation.h File Reference
#include "OperationType.h"
#include "Model.h"
#include "Request.h"
#include "NeuralNetworks.h"

Go to the source code of this file.

Functions

int validateOperationType (const OperationType &)
 
int validateOperandType (const ANeuralNetworksOperandType &type, const char *tag, bool allowPartial)
 
int validateOperandList (uint32_t count, const uint32_t *list, uint32_t operandCount, const char *tag)
 
bool validateModel (const Model &model)
 
bool validateRequest (const Request &request, const Model &model)
 

Function Documentation

◆ validateModel()

bool validateModel ( const Model model)

Definition at line 181 of file Validation.cpp.

182{
183 const size_t operandCount = model.operands.size();
184 return (validOperands(model.operands, model.operandValues) &&
185 validOperations(model.operations, operandCount) &&
186 validOperandIndexes(model.inputIndexes, operandCount) &&
187 validOperandIndexes(model.outputIndexes, operandCount));
188}

Referenced by ModelBuilder::finish().

◆ validateOperandList()

int validateOperandList ( uint32_t  count,
const uint32_t *  list,
uint32_t  operandCount,
const char *  tag 
)

Definition at line 81 of file Validation.cpp.

83{
84 for (uint32_t i = 0; i < count; i++)
85 {
86 if (list[i] >= operandCount)
87 {
88 LOG(ERROR) << tag << " invalid operand index at " << i << " = " << list[i]
89 << ", operandCount " << operandCount;
91 }
92 }
94}
#define LOG(...)
Definition Logging.h:36
@ ANEURALNETWORKS_BAD_DATA
@ ANEURALNETWORKS_NO_ERROR

References ANEURALNETWORKS_BAD_DATA, ANEURALNETWORKS_NO_ERROR, and LOG.

Referenced by ModelBuilder::addOperation(), and ModelBuilder::identifyInputsAndOutputs().

◆ validateOperandType()

int validateOperandType ( const ANeuralNetworksOperandType type,
const char *  tag,
bool  allowPartial 
)

Definition at line 33 of file Validation.cpp.

34{
35 if (!allowPartial)
36 {
37 for (uint32_t i = 0; i < type.dimensionCount; i++)
38 {
39 if (type.dimensions[i] == 0)
40 {
41 LOG(ERROR) << tag << " OperandType invalid dimensions[" << i
42 << "] = " << type.dimensions[i];
44 }
45 }
46 }
47 if (!validCode(kNumberOfDataTypes, type.type))
48 {
49 LOG(ERROR) << tag << " OperandType invalid type " << type.type;
51 }
53 {
54 if (type.zeroPoint < 0 || type.zeroPoint > 255)
55 {
56 LOG(ERROR) << tag << " OperandType invalid zeroPoint " << type.zeroPoint;
58 }
59 if (type.scale < 0.f)
60 {
61 LOG(ERROR) << tag << " OperandType invalid scale " << type.scale;
63 }
64 }
65
66 // TODO-NNRT : add 'type.type == ANEURALNETWORKS_OEM_SCALAR' later.
67 // OEM operaters are not supported now.
70 {
71 if (type.dimensionCount != 0 || type.dimensions != nullptr)
72 {
73 LOG(ERROR) << tag << " Invalid dimensions for scalar type";
75 }
76 }
77
79}
const int kNumberOfDataTypes
Definition OperandType.h:34
@ ANEURALNETWORKS_TENSOR_QUANT8_ASYMM
@ ANEURALNETWORKS_FLOAT32
@ ANEURALNETWORKS_INT32
@ ANEURALNETWORKS_UINT32
type
Definition infer.py:18

References ANEURALNETWORKS_BAD_DATA, ANEURALNETWORKS_FLOAT32, ANEURALNETWORKS_INT32, ANEURALNETWORKS_NO_ERROR, ANEURALNETWORKS_TENSOR_QUANT8_ASYMM, ANEURALNETWORKS_UINT32, kNumberOfDataTypes, and LOG.

Referenced by ModelBuilder::addOperand(), ExecutionBuilder::setInput(), and ExecutionBuilder::setOutput().

◆ validateOperationType()

int validateOperationType ( const OperationType type)

Definition at line 27 of file Validation.cpp.

28{
29 return validCode(kNumberOfOperationTypes, static_cast<uint32_t>(type));
30}
const int kNumberOfOperationTypes

References kNumberOfOperationTypes.

Referenced by ModelBuilder::addOperation().

◆ validateRequest()

bool validateRequest ( const Request request,
const Model model 
)

Definition at line 254 of file Validation.cpp.

255{
256 //const size_t poolCount = request.pools.size();
257 const size_t poolCount = 0;
258 return (validRequestArguments(request.inputs, model.inputIndexes, model.operands, poolCount,
259 "input") &&
260 validRequestArguments(request.outputs, model.outputIndexes, model.operands, poolCount,
261 "output"));
262}
bool validRequestArguments(const std::vector< RequestArgument > &arguments, const std::vector< uint32_t > &operandIndexes, const std::vector< Operand > &operands, size_t poolCount, const char *type)
std::vector< RequestArgument > outputs
Definition Request.h:32
std::vector< RequestArgument > inputs
Definition Request.h:31

References Request::inputs, Request::outputs, and validRequestArguments().