ONE - On-device Neural Engine
Loading...
Searching...
No Matches
ExecutionBuilder Class Reference

#include <ExecutionBuilder.h>

Public Member Functions

 ExecutionBuilder (const ModelBuilder *)
 
int setInput (uint32_t index, const ANeuralNetworksOperandType *type, const void *buffer, size_t length)
 
int setInputFromMemory (uint32_t index, const ANeuralNetworksOperandType *type, const Memory *memory, size_t offset, size_t length)
 
int setOutput (uint32_t index, const ANeuralNetworksOperandType *type, void *buffer, size_t length)
 
int setOutputFromMemory (uint32_t index, const ANeuralNetworksOperandType *type, const Memory *memory, size_t offset, size_t length)
 
int startCompute (void)
 

Detailed Description

Definition at line 32 of file ExecutionBuilder.h.

Constructor & Destructor Documentation

◆ ExecutionBuilder()

ExecutionBuilder::ExecutionBuilder ( const ModelBuilder model)

Definition at line 59 of file ExecutionBuilder.cpp.

60 : mModel(model), mInputs(mModel->inputCount()), mOutputs(mModel->outputCount())
61{
62 VLOG(EXECUTION) << "ExecutionBuilder::ExecutionBuilder";
63}
uint32_t inputCount() const
uint32_t outputCount() const
#define VLOG(...)
Definition Logging.h:37

References VLOG.

Member Function Documentation

◆ setInput()

int ExecutionBuilder::setInput ( uint32_t  index,
const ANeuralNetworksOperandType type,
const void *  buffer,
size_t  length 
)

Definition at line 65 of file ExecutionBuilder.cpp.

67{
68 uint32_t count = static_cast<uint32_t>(mInputs.size());
69 if (index >= count)
70 {
71 LOG(ERROR) << "ANeuralNetworksExecution_setInput bad index " << index << " " << count;
73 }
74 if (type != nullptr)
75 {
76 int n = validateOperandType(*type, "ANeuralNetworksExecution_setInput", false);
78 {
79 return n;
80 }
81 }
82 if (length > 0xFFFFFFFF)
83 {
84 LOG(ERROR) << "ANeuralNetworksExecution_setInput input exceeds max length " << length;
86 }
87 uint32_t l = static_cast<uint32_t>(length);
88 return mInputs[index].setFromPointer(mModel->getInputOperand(index), type,
89 const_cast<void *>(buffer), l);
90}
int validateOperandType(const ANeuralNetworksOperandType &type, const char *tag, bool allowPartial)
const Operand & getInputOperand(uint32_t i) const
#define LOG(...)
Definition Logging.h:36
@ ANEURALNETWORKS_BAD_DATA
@ ANEURALNETWORKS_NO_ERROR
type
Definition infer.py:18
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54

References ANEURALNETWORKS_BAD_DATA, ANEURALNETWORKS_NO_ERROR, ModelBuilder::getInputOperand(), LOG, and validateOperandType().

◆ setInputFromMemory()

int ExecutionBuilder::setInputFromMemory ( uint32_t  index,
const ANeuralNetworksOperandType type,
const Memory memory,
size_t  offset,
size_t  length 
)

Definition at line 92 of file ExecutionBuilder.cpp.

94{
95 uint32_t count = static_cast<uint32_t>(mInputs.size());
96 if (index >= count)
97 {
98 LOG(ERROR) << "ANeuralNetworksExecution_setInputFromMemory bad index " << index << " " << count;
100 }
101 if (!memory->validateSize(offset, length))
102 {
104 }
105 uint32_t poolIndex = mMemories.add(memory);
106 return mInputs[index].setFromMemory(mModel->getInputOperand(index), type, poolIndex, offset,
107 length);
108}
uint32_t add(const Memory *memory)
__global uchar * offset(const Image *img, int x, int y)
Definition helpers.h:540
virtual bool validateSize(uint32_t offset, uint32_t length) const =0

References MemoryTracker::add(), ANEURALNETWORKS_BAD_DATA, ModelBuilder::getInputOperand(), LOG, offset(), and Memory::validateSize().

◆ setOutput()

int ExecutionBuilder::setOutput ( uint32_t  index,
const ANeuralNetworksOperandType type,
void *  buffer,
size_t  length 
)

Definition at line 110 of file ExecutionBuilder.cpp.

112{
113 uint32_t count = static_cast<uint32_t>(mOutputs.size());
114 if (index >= count)
115 {
116 LOG(ERROR) << "ANeuralNetworksExecution_setOutput bad index " << index << " " << count;
118 }
119 if (type != nullptr)
120 {
121 int n = validateOperandType(*type, "ANeuralNetworksExecution_setOutput", false);
123 {
124 return n;
125 }
126 }
127 if (length > 0xFFFFFFFF)
128 {
129 LOG(ERROR) << "ANeuralNetworksExecution_setOutput input exceeds max length " << length;
131 }
132 uint32_t l = static_cast<uint32_t>(length);
133 return mOutputs[index].setFromPointer(mModel->getOutputOperand(index), type, buffer, l);
134}
const Operand & getOutputOperand(uint32_t i) const

References ANEURALNETWORKS_BAD_DATA, ANEURALNETWORKS_NO_ERROR, ModelBuilder::getOutputOperand(), LOG, and validateOperandType().

◆ setOutputFromMemory()

int ExecutionBuilder::setOutputFromMemory ( uint32_t  index,
const ANeuralNetworksOperandType type,
const Memory memory,
size_t  offset,
size_t  length 
)

Definition at line 136 of file ExecutionBuilder.cpp.

138{
139 // Should be similar to StepExecutor::setInputOrOutputFromTemporaryMemory()
140
141 uint32_t count = static_cast<uint32_t>(mOutputs.size());
142 if (index >= count)
143 {
144 LOG(ERROR) << "ANeuralNetworksExecution_setOutputFromMemory bad index " << index << " "
145 << count;
147 }
148 if (!memory->validateSize(offset, length))
149 {
151 }
152 // TODO validate the rest
153 uint32_t poolIndex = mMemories.add(memory);
154 return mOutputs[index].setFromMemory(mModel->getOutputOperand(index), type, poolIndex, offset,
155 length);
156}

References MemoryTracker::add(), ANEURALNETWORKS_BAD_DATA, ModelBuilder::getOutputOperand(), LOG, offset(), and Memory::validateSize().

◆ startCompute()

int ExecutionBuilder::startCompute ( void  )

Definition at line 158 of file ExecutionBuilder.cpp.

159{
160 Model model;
161 mModel->publish(&model);
162
163 // modelPoolInfo holds the infomation of pre-allocated memory pools during model construction
164 std::vector<RunTimePoolInfo> modelPoolInfos;
165 if (!setRunTimePoolInfosFromMemories(&modelPoolInfos, model.pools))
166 {
168 }
169
170 std::vector<RunTimePoolInfo> requestPoolInfos;
171 uint32_t count = mMemories.size();
172 requestPoolInfos.resize(count);
173 // Create as many pools as there are input / output
174 auto fixPointerArguments = [&requestPoolInfos](std::vector<ModelArgumentInfo> &argumentInfos) {
175 for (ModelArgumentInfo &argumentInfo : argumentInfos)
176 {
177 if (argumentInfo.state == ModelArgumentInfo::POINTER)
178 {
179 RunTimePoolInfo runTimeInfo;
180 runTimeInfo.buffer = static_cast<uint8_t *>(argumentInfo.buffer);
181 argumentInfo.locationAndLength.poolIndex = static_cast<uint32_t>(requestPoolInfos.size());
182 argumentInfo.locationAndLength.offset = 0;
183 requestPoolInfos.push_back(runTimeInfo);
184 }
185 }
186 };
187 fixPointerArguments(mInputs);
188 fixPointerArguments(mOutputs);
189
190 Request request;
191 setRequestArgumentArray(mInputs, &request.inputs);
192 setRequestArgumentArray(mOutputs, &request.outputs);
193
194 Executor executor;
195 return executor.run(model, request, modelPoolInfos, requestPoolInfos);
196}
bool setRunTimePoolInfosFromMemories(std::vector< RunTimePoolInfo > *poolInfos, const std::vector< uint8_t * > &pools)
int run(const Model &model, const Request &request, const std::vector< RunTimePoolInfo > &modelPoolInfos, const std::vector< RunTimePoolInfo > &requestPoolInfos)
Definition Executor.cpp:126
uint32_t size() const
void publish(Model *model) const
@ ANEURALNETWORKS_UNMAPPABLE
Definition Model.h:27
std::vector< RequestArgument > outputs
Definition Request.h:32
std::vector< RequestArgument > inputs
Definition Request.h:31
uint8_t * buffer
Definition Executor.h:70

References ANEURALNETWORKS_UNMAPPABLE, RunTimePoolInfo::buffer, Request::inputs, Request::outputs, ModelArgumentInfo::POINTER, ModelBuilder::publish(), Executor::run(), setRunTimePoolInfosFromMemories(), and MemoryTracker::size().


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