ONE - On-device Neural Engine
Loading...
Searching...
No Matches
caffeimport::ReLUBuilder Class Referencefinal

#include <ReLU.h>

Collaboration diagram for caffeimport::ReLUBuilder:

Public Member Functions

void build (const ::caffe::LayerParameter &layer, GraphBuilderContext *context) const override
 
- Public Member Functions inherited from caffeimport::GraphBuilder
virtual ~GraphBuilder ()
 

Detailed Description

Definition at line 27 of file ReLU.h.

Member Function Documentation

◆ build()

void caffeimport::ReLUBuilder::build ( const ::caffe::LayerParameter &  layer,
GraphBuilderContext context 
) const
overridevirtual

Implements caffeimport::GraphBuilder.

Definition at line 32 of file ReLU.cpp.

33{
34 coco::Module *module = context->module();
35 coco::Block *blk = context->block();
36 std::map<std::string, tensor::Shape> &shape_ctx = context->shape_ctx();
37 std::map<std::string, coco::Bag *> &bag_ctx = context->bag_ctx();
38
39 assert(layer.bottom().size() == 1);
40 assert(layer.top().size() == 1);
41
42 // PReLU is not supported, yet
43 // TODO Support PReLU
44 assert(!layer.has_relu_param());
45
46 // NOTE The current implementation treats ReLU as Feature op
47 // TODO Support ReLU over general tensor
48 const auto ifm_name = layer.bottom(0);
49 const auto ifm_shape = shape_ctx.at(ifm_name);
50 auto ifm_bag = bag_ctx.at(ifm_name);
51 auto ifm_obj = module->entity()->object()->create<coco::FeatureObject>();
52
53 ifm_obj->bag(ifm_bag);
54 ifm_obj->layout(coco::FeatureLayouts::BCHW::create(as_feature_shape(ifm_shape)));
55
56 const auto ofm_name = layer.top(0);
57 const auto ofm_shape = ifm_shape;
58 auto ofm_bag = module->entity()->bag()->create(num_elements(ofm_shape));
59 auto ofm_obj = module->entity()->object()->create<coco::FeatureObject>();
60
61 ofm_obj->bag(ofm_bag);
62 ofm_obj->layout(coco::FeatureLayouts::BCHW::create(as_feature_shape(ofm_shape)));
63
64 // Create a Load Op
65 auto load = op_builder(module).load(ifm_obj).pop();
66
67 // Create a ReLU op
68 auto op = module->entity()->op()->create<coco::ReLU>();
69
70 op->arg(load);
71
72 // Create a Eval instruction
73 auto ins = instr_builder(module).eval(ofm_obj, op);
74
75 // Append the instruction to the block
76 blk->instr()->append(ins);
77
78 // Update bag and shape context
79 bag_ctx[ofm_name] = ofm_bag;
80 shape_ctx[ofm_name] = ofm_shape;
81}
OpBuilder op_builder(coco::Module *m)
Definition IRBuilder.h:144
InstrBuilder instr_builder(coco::Module *m)
Definition IRBuilder.h:174
coco::Eval * eval(coco::Object *out, coco::Op *op) const
Create "Eval" instruction with a given "Object" and "Op".
Definition IRBuilder.h:162
OpBuilder & load(coco::Object *obj)
Create "Load" op and push it onto the internal stack.
Definition IRBuilder.h:70
coco::Op * pop(void)
Pop op from the internal stack.
Definition IRBuilder.h:116
A unit of (grouped) instructions.
Definition Block.h:40
static std::unique_ptr< BCHW > create(const nncc::core::ADT::feature::Shape &shape)
Top-level element of coco IR which represents a neural network.
Definition Module.h:34
nncc::core::ADT::feature::Shape as_feature_shape(const nncc::core::ADT::tensor::Shape &)
Definition caffe.cpp:54
TensorSignatures load(const char *info_path)
Function to create TensorSignatures defined in info file.
virtual Op * arg(uint32_t n) const =0
Return N-th argument.

References coco::Op::arg(), morph::caffe::as_feature_shape(), caffeimport::GraphBuilderContext::bag_ctx(), caffeimport::GraphBuilderContext::block(), coco::FeatureLayouts::BCHW::create(), InstrBuilder::eval(), instr_builder(), OpBuilder::load(), op_builder(), OpBuilder::pop(), and caffeimport::GraphBuilderContext::shape_ctx().


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