ONE - On-device Neural Engine
Loading...
Searching...
No Matches
enco::SubnetStructBuilder Class Reference

#include <Subnet.h>

Public Member Functions

std::unique_ptr< SubnetStructbuild (const ANNBinder *binder) const
 
void expr (const ann::Operand *oper, const std::string &base, const std::string &size)
 

Detailed Description

Definition at line 47 of file Subnet.h.

Member Function Documentation

◆ build()

std::unique_ptr< SubnetStruct > enco::SubnetStructBuilder::build ( const ANNBinder binder) const

Definition at line 320 of file Subnet.cpp.

321{
322 auto res = make_unique<SubnetStructImpl>();
323
324 auto mname = res->model();
325 auto cname = res->compilation();
326
327 res->def()->append("ANeuralNetworksModel *", mname, ";");
328 res->def()->append("ANeuralNetworksCompilation *", cname, ";");
329
330 res->ctor()->append("ANeuralNetworksModel_create(&", mname, ");");
331 res->dtor()->append("ANeuralNetworksModel_free(", mname, ");");
332
333 binder->module()->operand()->each([&](const ann::OperandID &id, const ann::Operand *info) {
334 // TODO Remove dynamic cast
335 if (auto scalar = dynamic_cast<const ann::ScalarOperand *>(info))
336 {
337 res->ctor() << ScalarOperandDecl{mname, scalar->dtype()};
338 }
339 else if (auto tensor = dynamic_cast<const ann::TensorOperand *>(info))
340 {
341 res->ctor() << TensorOperandDecl{mname, tensor->dtype(), tensor->shape()};
342 }
343 else
344 {
345 throw std::runtime_error{"Unsupported"};
346 }
347
348 if (_weighted.find(info) != _weighted.end())
349 {
350 const auto &base_exp = _base_exprs.at(info);
351 const auto &size_exp = _size_exprs.at(info);
352
353 res->ctor() << WeightDecl{mname, id, base_exp, size_exp};
354 }
355 });
356
357 for (unsigned n = 0; n < binder->module()->operation()->count(); ++n)
358 {
359 auto op = binder->module()->operation()->at(n);
360 res->ctor() << OperationDecl{mname, op};
361 }
362
363 // Emit ANeuralNetworksModel_identifyInputsAndOutputs call
364 res->ctor() << ArgumentDecl{mname, binder};
365
366 // Emit ANeuralNetworksModel_finish call
367 res->ctor()->append("ANeuralNetworksModel_finish(", mname, ");");
368
369 // Create compilation
370 res->ctor()->append("ANeuralNetworksCompilation_create(", mname, ", &", cname, ");");
371 res->dtor()->append("ANeuralNetworksCompilation_free(", cname, ");");
372
373 // Finalize compilation
374 res->ctor()->append("ANeuralNetworksCompilation_finish(", cname, ");");
375
376 return res;
377}
const ann::Module * module(void) const
Definition Binder.h:45
OperationInventory * operation(void)
Definition Module.h:41
OperandInventory * operand(void)
Definition Module.h:38
void each(Callable &&cb) const
const Operation * at(uint32_t n) const
uint32_t count(void) const
volatile const char info[]
Plain (non-qunatized) Tensor Operand.
Definition Operand.h:66

References ann::OperandInventory::each(), info, ANNBinder::module(), and ann::Module::operand().

Referenced by enco::CppCode::dump().

◆ expr()

void enco::SubnetStructBuilder::expr ( const ann::Operand oper,
const std::string &  base,
const std::string &  size 
)
inline

Definition at line 53 of file Subnet.h.

54 {
55 _weighted.insert(oper);
56 _base_exprs[oper] = base;
57 _size_exprs[oper] = size;
58 }
int32_t size[5]
Definition Slice.cpp:35

References size.

Referenced by enco::CppCode::dump().


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