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

Generate C++ code that invokes Android NN subnet. More...

#include <Subnet.h>

Public Member Functions

 SubnetBlockCompiler (const enco::MemoryContext &mem)
 
void bind (const ANNBinder *binder, const std::string &exp)
 Specify how to access ANeuralNetworksCompilation value (C expression)
 
std::unique_ptr< pp::MultiLineTextcompile (const ANNBinder *binder) const
 

Detailed Description

Generate C++ code that invokes Android NN subnet.

Definition at line 69 of file Subnet.h.

Constructor & Destructor Documentation

◆ SubnetBlockCompiler()

enco::SubnetBlockCompiler::SubnetBlockCompiler ( const enco::MemoryContext mem)
inline

Definition at line 72 of file Subnet.h.

72 : _mem(mem)
73 {
74 // DO NOTHING
75 }

Member Function Documentation

◆ bind()

void enco::SubnetBlockCompiler::bind ( const ANNBinder binder,
const std::string &  exp 
)
inline

Specify how to access ANeuralNetworksCompilation value (C expression)

Definition at line 79 of file Subnet.h.

79{ _compilation_ctx[binder] = exp; }

◆ compile()

std::unique_ptr< pp::MultiLineText > enco::SubnetBlockCompiler::compile ( const ANNBinder binder) const

Definition at line 379 of file Subnet.cpp.

380{
381 auto res = make_unique<pp::LinearDocument>();
382
383 const auto compilation = _compilation_ctx.at(binder);
384
385 res->append("ANeuralNetworksExecution *execution;");
386 res->append("ANeuralNetworksEvent *event;");
387 res->append();
388 res->append("ANeuralNetworksExecution_create(", compilation, ", &execution);");
389
390 // Emit ANeuralNetworksExecution_setInput call(s)
391 for (uint32_t n = 0; n < binder->module()->input()->size(); ++n)
392 {
393 auto bag = binder->input(n);
394 auto base = _mem.base(bag);
395 auto size = _mem.size(bag);
396
397 res->append("ANeuralNetworksExecution_setInput(execution, ", n, ", nullptr, ", base, ", ", size,
398 ");");
399 }
400
401 // Emit ANeuralNetworksExecution_setOutput call(s)
402 for (uint32_t n = 0; n < binder->module()->output()->size(); ++n)
403 {
404 auto bag = binder->output(n);
405 auto base = _mem.base(bag);
406 auto size = _mem.size(bag);
407
408 res->append("ANeuralNetworksExecution_setOutput(execution, ", n, ", nullptr, ", base, ", ",
409 size, ");");
410 }
411
412 res->append("ANeuralNetworksExecution_startCompute(execution, &event);");
413 res->append("ANeuralNetworksEvent_wait(event);");
414 res->append("ANeuralNetworksEvent_free(event);");
415
416 res->append("ANeuralNetworksExecution_free(execution);");
417
418 return res;
419}
const ann::Module * module(void) const
Definition Binder.h:45
coco::Bag * input(uint32_t n) const
Definition Binder.h:187
coco::Bag * output(uint32_t n) const
Definition Binder.h:188
void size(const coco::Bag *bag, const std::string &exp)
void base(const coco::Bag *bag, const std::string &exp)
int32_t size[5]
Definition Slice.cpp:35

References ANNBinder::input(), ANNBinder::module(), ANNBinder::output(), coco::Bag::size(), and size.


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