struct ITensorBuilder
{
virtual ~ITensorBuilder(void) = default;
- virtual void mark(const ::internal::tflite::operand::Index &ind) = 0;
+ virtual void mark(const ::neurun::graph::operand::Index &ind) = 0;
virtual void markFromCommon(const ::internal::tflite::op::Node &op, int32_t ind) = 0;
virtual void markToCommon(const ::internal::tflite::op::Node &op, int32_t ind) = 0;
virtual void insertTensorConvertNodes(::internal::tflite::op::Sequence &operations) = 0;
Initializer
InitializerGenerator::generateWeight(const ::internal::tflite::op::Conv2D::implicit::Node &node)
{
- const ::internal::tflite::operand::Index ker_index{node.param().ker_index};
+ const ::neurun::graph::operand::Index ker_index{node.param().ker_index};
const auto ker_shape = _ctx.at(ker_index).shape().asKernel();
auto ker_base = _ctx.at(ker_index).data().base();
Initializer
InitializerGenerator::generateWeight(const ::internal::tflite::op::FullyConnected::Node &node)
{
- const ::internal::tflite::operand::Index weight_index{node.param().weight_index};
- const ::internal::tflite::operand::Index input_index{node.param().input_index};
+ const ::neurun::graph::operand::Index weight_index{node.param().weight_index};
+ const ::neurun::graph::operand::Index input_index{node.param().input_index};
const auto num_output = _ctx.at(weight_index).shape().dim(0);
auto weight_base = _ctx.at(weight_index).data().base();
{
// TODO Refactor so we can reuse the common code
- const ::internal::tflite::operand::Index bias_index{node.param().bias_index};
+ const ::neurun::graph::operand::Index bias_index{node.param().bias_index};
auto bias_base = _ctx.at(bias_index).data().base();
const auto bias_size = _ctx.at(bias_index).shape().asVector();
Initializer
InitializerGenerator::generateBias(const ::internal::tflite::op::FullyConnected::Node &node)
{
- const ::internal::tflite::operand::Index bias_index{node.param().bias_index};
+ const ::neurun::graph::operand::Index bias_index{node.param().bias_index};
auto bias_base = _ctx.at(bias_index).data().base();
const auto bias_size = _ctx.at(bias_index).shape().asVector();
#include "internal/Padding.h"
#include "internal/Model.h"
+#include "graph/operand/Index.h"
+
#include "logging.h"
#include "NeuralNetworks.h"
Stage StageGenerator::generate(const ::internal::tflite::op::Conv2D::implicit::Node &node)
{
- const ::internal::tflite::operand::Index ofm_index{node.param().ofm_index};
- const ::internal::tflite::operand::Index ifm_index{node.param().ifm_index};
- const ::internal::tflite::operand::Index ker_index{node.param().ker_index};
- const ::internal::tflite::operand::Index bias_index{node.param().bias_index};
+ const ::neurun::graph::operand::Index ofm_index{node.param().ofm_index};
+ const ::neurun::graph::operand::Index ifm_index{node.param().ifm_index};
+ const ::neurun::graph::operand::Index ker_index{node.param().ker_index};
+ const ::neurun::graph::operand::Index bias_index{node.param().bias_index};
- const ::internal::tflite::operand::Index vstride_index{node.param().vstride_index};
- const ::internal::tflite::operand::Index hstride_index{node.param().hstride_index};
+ const ::neurun::graph::operand::Index vstride_index{node.param().vstride_index};
+ const ::neurun::graph::operand::Index hstride_index{node.param().hstride_index};
- const ::internal::tflite::operand::Index padding_index{node.param().padding_index};
- const ::internal::tflite::operand::Index activation_index{node.param().activation_index};
+ const ::neurun::graph::operand::Index padding_index{node.param().padding_index};
+ const ::neurun::graph::operand::Index activation_index{node.param().activation_index};
const auto ofm_shape = _ctx.at(ofm_index).shape().asFeature();
const auto ifm_shape = _ctx.at(ifm_index).shape().asFeature();
auto tensors = _tensor_builder;
return [tensors, param](IExecutionBuilder &builder) {
- auto ofm_alloc = tensors->at(::internal::tflite::operand::Index{param.ofm_index}).get();
- auto ifm_alloc = tensors->at(::internal::tflite::operand::Index{param.ifm_index}).get();
- auto ker_alloc = tensors->at(::internal::tflite::operand::Index{param.ker_index}).get();
- auto bias_alloc = tensors->at(::internal::tflite::operand::Index{param.bias_index}).get();
+ auto ofm_alloc = tensors->at(::neurun::graph::operand::Index{param.ofm_index}).get();
+ auto ifm_alloc = tensors->at(::neurun::graph::operand::Index{param.ifm_index}).get();
+ auto ker_alloc = tensors->at(::neurun::graph::operand::Index{param.ker_index}).get();
+ auto bias_alloc = tensors->at(::neurun::graph::operand::Index{param.bias_index}).get();
const auto conv_info = asPadStringInfo(param.padding, param.stride);
Stage StageGenerator::generate(const ::internal::tflite::op::MaxPool2D::implicit::Node &node)
{
- const ::internal::tflite::operand::Index ofm_index{node.param().ofm_index};
- const ::internal::tflite::operand::Index ifm_index{node.param().ifm_index};
+ const ::neurun::graph::operand::Index ofm_index{node.param().ofm_index};
+ const ::neurun::graph::operand::Index ifm_index{node.param().ifm_index};
- const ::internal::tflite::operand::Index kh_index{node.param().kh_index};
- const ::internal::tflite::operand::Index kw_index{node.param().kw_index};
+ const ::neurun::graph::operand::Index kh_index{node.param().kh_index};
+ const ::neurun::graph::operand::Index kw_index{node.param().kw_index};
- const ::internal::tflite::operand::Index vstride_index{node.param().vstride_index};
- const ::internal::tflite::operand::Index hstride_index{node.param().hstride_index};
+ const ::neurun::graph::operand::Index vstride_index{node.param().vstride_index};
+ const ::neurun::graph::operand::Index hstride_index{node.param().hstride_index};
- const ::internal::tflite::operand::Index padding_index{node.param().padding_index};
+ const ::neurun::graph::operand::Index padding_index{node.param().padding_index};
const auto ofm_shape = _ctx.at(ofm_index).shape().asFeature();
const auto ifm_shape = _ctx.at(ifm_index).shape().asFeature();
auto tensors = _tensor_builder;
return [tensors, param](IExecutionBuilder &builder) {
- auto ofm_alloc = tensors->at(::internal::tflite::operand::Index{param.ofm_index}).get();
- auto ifm_alloc = tensors->at(::internal::tflite::operand::Index{param.ifm_index}).get();
+ auto ofm_alloc = tensors->at(::neurun::graph::operand::Index{param.ofm_index}).get();
+ auto ifm_alloc = tensors->at(::neurun::graph::operand::Index{param.ifm_index}).get();
::arm_compute::PoolingLayerInfo info{::arm_compute::PoolingType::MAX,
::arm_compute::Size2D{param.kw, param.kh},
Stage StageGenerator::generate(const ::internal::tflite::op::AvgPool2D::implicit::Node &node)
{
- const ::internal::tflite::operand::Index ofm_index{node.param().ofm_index};
- const ::internal::tflite::operand::Index ifm_index{node.param().ifm_index};
+ const ::neurun::graph::operand::Index ofm_index{node.param().ofm_index};
+ const ::neurun::graph::operand::Index ifm_index{node.param().ifm_index};
- const ::internal::tflite::operand::Index kh_index{node.param().kh_index};
- const ::internal::tflite::operand::Index kw_index{node.param().kw_index};
+ const ::neurun::graph::operand::Index kh_index{node.param().kh_index};
+ const ::neurun::graph::operand::Index kw_index{node.param().kw_index};
- const ::internal::tflite::operand::Index vstride_index{node.param().vstride_index};
- const ::internal::tflite::operand::Index hstride_index{node.param().hstride_index};
+ const ::neurun::graph::operand::Index vstride_index{node.param().vstride_index};
+ const ::neurun::graph::operand::Index hstride_index{node.param().hstride_index};
- const ::internal::tflite::operand::Index padding_index{node.param().padding_index};
+ const ::neurun::graph::operand::Index padding_index{node.param().padding_index};
const auto ofm_shape = _ctx.at(ofm_index).shape().asFeature();
const auto ifm_shape = _ctx.at(ifm_index).shape().asFeature();
auto tensors = _tensor_builder;
return [tensors, param](IExecutionBuilder &builder) {
- auto ofm_alloc = tensors->at(::internal::tflite::operand::Index{param.ofm_index}).get();
- auto ifm_alloc = tensors->at(::internal::tflite::operand::Index{param.ifm_index}).get();
+ auto ofm_alloc = tensors->at(::neurun::graph::operand::Index{param.ofm_index}).get();
+ auto ifm_alloc = tensors->at(::neurun::graph::operand::Index{param.ifm_index}).get();
::arm_compute::PoolingLayerInfo info{
::arm_compute::PoolingType::AVG, ::arm_compute::Size2D{param.kw, param.kh},
Stage StageGenerator::generate(const ::internal::tflite::op::Concat::Node &node)
{
- const ::internal::tflite::operand::Index ofm_index{node.param().ofm_index};
- const ::internal::tflite::operand::Index axis_index{node.param().axis_index};
+ const ::neurun::graph::operand::Index ofm_index{node.param().ofm_index};
+ const ::neurun::graph::operand::Index axis_index{node.param().axis_index};
struct Param
{
auto tensors = _tensor_builder;
return [tensors, param](IExecutionBuilder &builder) {
- auto output_alloc = tensors->at(::internal::tflite::operand::Index{param.output_index}).get();
+ auto output_alloc = tensors->at(::neurun::graph::operand::Index{param.output_index}).get();
std::vector<::arm_compute::ICLTensor *> input_allocs;
for (auto ifm_ind : param.input_indexes)
{
- input_allocs.emplace_back(tensors->at(::internal::tflite::operand::Index{ifm_ind}).get());
+ input_allocs.emplace_back(tensors->at(::neurun::graph::operand::Index{ifm_ind}).get());
}
std::unique_ptr<::neurun::kernel::acl_cl::ConcatLayer> fn{
Stage StageGenerator::generate(const ::internal::tflite::op::FullyConnected::Node &node)
{
- const ::internal::tflite::operand::Index output_index{node.param().output_index};
- const ::internal::tflite::operand::Index input_index{node.param().input_index};
- const ::internal::tflite::operand::Index weight_index{node.param().weight_index};
- const ::internal::tflite::operand::Index bias_index{node.param().bias_index};
- const ::internal::tflite::operand::Index activation_index{node.param().activation_index};
+ const ::neurun::graph::operand::Index output_index{node.param().output_index};
+ const ::neurun::graph::operand::Index input_index{node.param().input_index};
+ const ::neurun::graph::operand::Index weight_index{node.param().weight_index};
+ const ::neurun::graph::operand::Index bias_index{node.param().bias_index};
+ const ::neurun::graph::operand::Index activation_index{node.param().activation_index};
// Construct operation parameters
struct Param
auto tensors = _tensor_builder;
return [tensors, param](IExecutionBuilder &builder) {
- auto output_alloc = tensors->at(::internal::tflite::operand::Index{param.output_index}).get();
- auto input_alloc = tensors->at(::internal::tflite::operand::Index{param.input_index}).get();
- auto weight_alloc = tensors->at(::internal::tflite::operand::Index{param.weight_index}).get();
- auto bias_alloc = tensors->at(::internal::tflite::operand::Index{param.bias_index}).get();
+ auto output_alloc = tensors->at(::neurun::graph::operand::Index{param.output_index}).get();
+ auto input_alloc = tensors->at(::neurun::graph::operand::Index{param.input_index}).get();
+ auto weight_alloc = tensors->at(::neurun::graph::operand::Index{param.weight_index}).get();
+ auto bias_alloc = tensors->at(::neurun::graph::operand::Index{param.bias_index}).get();
auto fn = make_layer<::arm_compute::CLFullyConnectedLayer>();
Stage StageGenerator::generate(const ::internal::tflite::op::Reshape::Node &node)
{
- const ::internal::tflite::operand::Index output_index{node.param().output_index};
- const ::internal::tflite::operand::Index input_index{node.param().input_index};
+ const ::neurun::graph::operand::Index output_index{node.param().output_index};
+ const ::neurun::graph::operand::Index input_index{node.param().input_index};
struct Param
{
auto tensors = _tensor_builder;
return [tensors, param](IExecutionBuilder &builder) {
- auto output_alloc = tensors->at(::internal::tflite::operand::Index{param.output_index}).get();
- auto input_alloc = tensors->at(::internal::tflite::operand::Index{param.input_index}).get();
+ auto output_alloc = tensors->at(::neurun::graph::operand::Index{param.output_index}).get();
+ auto input_alloc = tensors->at(::neurun::graph::operand::Index{param.input_index}).get();
auto fn = make_layer<::arm_compute::CLReshapeLayer>();
Stage StageGenerator::generate(const ::internal::tflite::op::Softmax::Node &node)
{
- const ::internal::tflite::operand::Index output_index{node.param().output_index};
- const ::internal::tflite::operand::Index input_index{node.param().input_index};
+ const ::neurun::graph::operand::Index output_index{node.param().output_index};
+ const ::neurun::graph::operand::Index input_index{node.param().input_index};
struct Param
{
auto tensors = _tensor_builder;
return [tensors, param](IExecutionBuilder &builder) {
- auto output_alloc = tensors->at(::internal::tflite::operand::Index{param.output_index}).get();
- auto input_alloc = tensors->at(::internal::tflite::operand::Index{param.input_index}).get();
+ auto output_alloc = tensors->at(::neurun::graph::operand::Index{param.output_index}).get();
+ auto input_alloc = tensors->at(::neurun::graph::operand::Index{param.input_index}).get();
auto fn = make_layer<::arm_compute::CLSoftmaxLayer>();
Stage StageGenerator::generate(
const ::internal::tflite::op::TensorConvert::AclFromCommon::Node &node)
{
- const ::internal::tflite::operand::Index ifm_index{node.param().ifm_index};
+ const ::neurun::graph::operand::Index ifm_index{node.param().ifm_index};
struct Param
{
auto common_tensor_builder = _common_tensor_builder;
return [tensors, common_tensor_builder, param](IExecutionBuilder &builder) {
- const ::internal::tflite::operand::Index ifm_index{param.ifm_index};
+ const ::neurun::graph::operand::Index ifm_index{param.ifm_index};
auto input_alloc = tensors->at(ifm_index).get();
auto common_tensor = common_tensor_builder->at(ifm_index);
Stage StageGenerator::generate(const ::internal::tflite::op::TensorConvert::AclToCommon::Node &node)
{
- const ::internal::tflite::operand::Index ofm_index{node.param().ofm_index};
+ const ::neurun::graph::operand::Index ofm_index{node.param().ofm_index};
struct Param
{
auto common_tensor_builder = _common_tensor_builder;
return [tensors, common_tensor_builder, param](IExecutionBuilder &builder) {
- const ::internal::tflite::operand::Index ofm_index{param.ofm_index};
+ const ::neurun::graph::operand::Index ofm_index{param.ofm_index};
auto output_alloc = tensors->at(ofm_index).get();
auto common_tensor = common_tensor_builder->at(ofm_index);
// DO NOTHING
}
-void TensorBuilder::mark(const ::internal::tflite::operand::Index &ind)
+void TensorBuilder::mark(const ::neurun::graph::operand::Index &ind)
{
assert(_tensors.size() == 0);
for (auto ind_int : _inds)
{
- ::internal::tflite::operand::Index ind{ind_int};
+ ::neurun::graph::operand::Index ind{ind_int};
auto tensor = std::make_shared<::arm_compute::CLTensor>();
tensor->allocator()->init(tensor_info_ctx.at(ind.asInt()));
_plan.operands().set(ind, std::make_shared<operand::Object>(tensor));
}
std::shared_ptr<::arm_compute::CLTensor>
-TensorBuilder::at(const ::internal::tflite::operand::Index &ind)
+TensorBuilder::at(const ::neurun::graph::operand::Index &ind)
{
return _tensors.at(ind.asInt());
}
public:
TensorBuilder(::internal::Plan &plan);
- virtual void mark(const ::internal::tflite::operand::Index &ind) override;
+ virtual void mark(const ::neurun::graph::operand::Index &ind) override;
virtual void markFromCommon(const ::internal::tflite::op::Node &op, int32_t ind) override;
virtual void markToCommon(const ::internal::tflite::op::Node &op, int32_t ind) override;
virtual void insertTensorConvertNodes(::internal::tflite::op::Sequence &operations) override;
virtual void prepare(const std::map<int, ::arm_compute::TensorInfo> &tensor_info_ctx) override;
virtual void allocate(void) override;
- std::shared_ptr<::arm_compute::CLTensor> at(const ::internal::tflite::operand::Index &ind);
+ std::shared_ptr<::arm_compute::CLTensor> at(const ::neurun::graph::operand::Index &ind);
private:
::internal::Plan &_plan;
Initializer
InitializerGenerator::generateWeight(const ::internal::tflite::op::Conv2D::implicit::Node &node)
{
- const ::internal::tflite::operand::Index ker_index{node.param().ker_index};
+ const ::neurun::graph::operand::Index ker_index{node.param().ker_index};
const auto ker_shape = _ctx.at(ker_index).shape().asKernel();
auto ker_base = _ctx.at(ker_index).data().base();
Initializer
InitializerGenerator::generateWeight(const ::internal::tflite::op::FullyConnected::Node &node)
{
- const ::internal::tflite::operand::Index weight_index{node.param().weight_index};
- const ::internal::tflite::operand::Index input_index{node.param().input_index};
+ const ::neurun::graph::operand::Index weight_index{node.param().weight_index};
+ const ::neurun::graph::operand::Index input_index{node.param().input_index};
const auto num_output = _ctx.at(weight_index).shape().dim(0);
auto weight_base = _ctx.at(weight_index).data().base();
{
// TODO Refactor so we can reuse the common code
- const ::internal::tflite::operand::Index bias_index{node.param().bias_index};
+ const ::neurun::graph::operand::Index bias_index{node.param().bias_index};
auto bias_base = _ctx.at(bias_index).data().base();
const auto bias_size = _ctx.at(bias_index).shape().asVector();
Initializer
InitializerGenerator::generateBias(const ::internal::tflite::op::FullyConnected::Node &node)
{
- const ::internal::tflite::operand::Index bias_index{node.param().bias_index};
+ const ::neurun::graph::operand::Index bias_index{node.param().bias_index};
auto bias_base = _ctx.at(bias_index).data().base();
auto bias_type = _ctx.at(bias_index).shape().type();
Stage StageGenerator::generate(const ::internal::tflite::op::Conv2D::implicit::Node &node)
{
- const ::internal::tflite::operand::Index ofm_index{node.param().ofm_index};
- const ::internal::tflite::operand::Index ifm_index{node.param().ifm_index};
- const ::internal::tflite::operand::Index ker_index{node.param().ker_index};
- const ::internal::tflite::operand::Index bias_index{node.param().bias_index};
+ const ::neurun::graph::operand::Index ofm_index{node.param().ofm_index};
+ const ::neurun::graph::operand::Index ifm_index{node.param().ifm_index};
+ const ::neurun::graph::operand::Index ker_index{node.param().ker_index};
+ const ::neurun::graph::operand::Index bias_index{node.param().bias_index};
- const ::internal::tflite::operand::Index vstride_index{node.param().vstride_index};
- const ::internal::tflite::operand::Index hstride_index{node.param().hstride_index};
+ const ::neurun::graph::operand::Index vstride_index{node.param().vstride_index};
+ const ::neurun::graph::operand::Index hstride_index{node.param().hstride_index};
- const ::internal::tflite::operand::Index padding_index{node.param().padding_index};
- const ::internal::tflite::operand::Index activation_index{node.param().activation_index};
+ const ::neurun::graph::operand::Index padding_index{node.param().padding_index};
+ const ::neurun::graph::operand::Index activation_index{node.param().activation_index};
const PaddingCode padding_type =
static_cast<PaddingCode>(_ctx.at(padding_index).asScalar<int32_t>());
auto tensors = _tensor_builder;
return [tensors, param](IExecutionBuilder &builder) {
- auto ofm_alloc = tensors->at(::internal::tflite::operand::Index{param.ofm_index});
- auto ifm_alloc = tensors->at(::internal::tflite::operand::Index{param.ifm_index});
- auto ker_alloc = tensors->at(::internal::tflite::operand::Index{param.ker_index});
- auto bias_alloc = tensors->at(::internal::tflite::operand::Index{param.bias_index});
+ auto ofm_alloc = tensors->at(::neurun::graph::operand::Index{param.ofm_index});
+ auto ifm_alloc = tensors->at(::neurun::graph::operand::Index{param.ifm_index});
+ auto ker_alloc = tensors->at(::neurun::graph::operand::Index{param.ker_index});
+ auto bias_alloc = tensors->at(::neurun::graph::operand::Index{param.bias_index});
std::unique_ptr<::neurun::kernel::cpu::ConvolutionLayer> fn{
new ::neurun::kernel::cpu::ConvolutionLayer};
{
VERBOSE(MaxPool2D) << "generate CPU MaxPool2D" << std::endl;
- const ::internal::tflite::operand::Index ofm_index{node.param().ofm_index};
- const ::internal::tflite::operand::Index ifm_index{node.param().ifm_index};
+ const ::neurun::graph::operand::Index ofm_index{node.param().ofm_index};
+ const ::neurun::graph::operand::Index ifm_index{node.param().ifm_index};
- const ::internal::tflite::operand::Index kh_index{node.param().kh_index};
- const ::internal::tflite::operand::Index kw_index{node.param().kw_index};
+ const ::neurun::graph::operand::Index kh_index{node.param().kh_index};
+ const ::neurun::graph::operand::Index kw_index{node.param().kw_index};
- const ::internal::tflite::operand::Index vstride_index{node.param().vstride_index};
- const ::internal::tflite::operand::Index hstride_index{node.param().hstride_index};
+ const ::neurun::graph::operand::Index vstride_index{node.param().vstride_index};
+ const ::neurun::graph::operand::Index hstride_index{node.param().hstride_index};
- const ::internal::tflite::operand::Index padding_index{node.param().padding_index};
- const ::internal::tflite::operand::Index activation_index{node.param().activation_index};
+ const ::neurun::graph::operand::Index padding_index{node.param().padding_index};
+ const ::neurun::graph::operand::Index activation_index{node.param().activation_index};
const int32_t kh = _ctx.at(kh_index).asScalar<int32_t>();
const int32_t kw = _ctx.at(kw_index).asScalar<int32_t>();
auto tensors = _tensor_builder;
return [tensors, param](IExecutionBuilder &builder) {
- auto ofm_alloc = tensors->at(::internal::tflite::operand::Index{param.ofm_index}).get();
- auto ifm_alloc = tensors->at(::internal::tflite::operand::Index{param.ifm_index}).get();
+ auto ofm_alloc = tensors->at(::neurun::graph::operand::Index{param.ofm_index}).get();
+ auto ifm_alloc = tensors->at(::neurun::graph::operand::Index{param.ifm_index}).get();
std::unique_ptr<::neurun::kernel::cpu::MaxPoolLayer> fn{
new ::neurun::kernel::cpu::MaxPoolLayer};
{
VERBOSE(AvgPool2D) << "generate CPU AvgPool2D" << std::endl;
- const ::internal::tflite::operand::Index ofm_index{node.param().ofm_index};
- const ::internal::tflite::operand::Index ifm_index{node.param().ifm_index};
+ const ::neurun::graph::operand::Index ofm_index{node.param().ofm_index};
+ const ::neurun::graph::operand::Index ifm_index{node.param().ifm_index};
- const ::internal::tflite::operand::Index kh_index{node.param().kh_index};
- const ::internal::tflite::operand::Index kw_index{node.param().kw_index};
+ const ::neurun::graph::operand::Index kh_index{node.param().kh_index};
+ const ::neurun::graph::operand::Index kw_index{node.param().kw_index};
- const ::internal::tflite::operand::Index vstride_index{node.param().vstride_index};
- const ::internal::tflite::operand::Index hstride_index{node.param().hstride_index};
+ const ::neurun::graph::operand::Index vstride_index{node.param().vstride_index};
+ const ::neurun::graph::operand::Index hstride_index{node.param().hstride_index};
- const ::internal::tflite::operand::Index padding_index{node.param().padding_index};
- const ::internal::tflite::operand::Index activation_index{node.param().activation_index};
+ const ::neurun::graph::operand::Index padding_index{node.param().padding_index};
+ const ::neurun::graph::operand::Index activation_index{node.param().activation_index};
const int32_t kh = _ctx.at(kh_index).asScalar<int32_t>();
const int32_t kw = _ctx.at(kw_index).asScalar<int32_t>();
auto tensors = _tensor_builder;
return [tensors, param](IExecutionBuilder &builder) {
- auto ofm_alloc = tensors->at(::internal::tflite::operand::Index{param.ofm_index}).get();
- auto ifm_alloc = tensors->at(::internal::tflite::operand::Index{param.ifm_index}).get();
+ auto ofm_alloc = tensors->at(::neurun::graph::operand::Index{param.ofm_index}).get();
+ auto ifm_alloc = tensors->at(::neurun::graph::operand::Index{param.ifm_index}).get();
std::unique_ptr<::neurun::kernel::cpu::AvgPoolLayer> fn{
new ::neurun::kernel::cpu::AvgPoolLayer};
{
VERBOSE(Concat) << "generate CPU Concat" << std::endl;
- const ::internal::tflite::operand::Index ofm_index{node.param().ofm_index};
- const ::internal::tflite::operand::Index axis_index{node.param().axis_index};
+ const ::neurun::graph::operand::Index ofm_index{node.param().ofm_index};
+ const ::neurun::graph::operand::Index axis_index{node.param().axis_index};
struct Param
{
for (auto ifm_ind : node.param().ifm_indexes)
{
- const ::internal::tflite::operand::Index ifm_index{ifm_ind};
+ const ::neurun::graph::operand::Index ifm_index{ifm_ind};
param.ifm_shapes.emplace_back(_ctx.at(ifm_index).shape());
}
auto tensors = _tensor_builder;
return [tensors, param](IExecutionBuilder &builder) {
- auto output_alloc = tensors->at(::internal::tflite::operand::Index{param.output_index}).get();
+ auto output_alloc = tensors->at(::neurun::graph::operand::Index{param.output_index}).get();
std::vector<const uint8_t *> input_buffers;
for (auto ifm_ind : param.input_indexes)
{
input_buffers.emplace_back(
- tensors->at(::internal::tflite::operand::Index{ifm_ind}).get()->buffer());
+ tensors->at(::neurun::graph::operand::Index{ifm_ind}).get()->buffer());
}
std::unique_ptr<::neurun::kernel::cpu::ConcatLayer> fn{new ::neurun::kernel::cpu::ConcatLayer};
{
VERBOSE(FullyConnected) << "generate CPU FullyConnected" << std::endl;
- const ::internal::tflite::operand::Index output_index{node.param().output_index};
- const ::internal::tflite::operand::Index input_index{node.param().input_index};
- const ::internal::tflite::operand::Index weight_index{node.param().weight_index};
- const ::internal::tflite::operand::Index bias_index{node.param().bias_index};
- const ::internal::tflite::operand::Index activation_index{node.param().activation_index};
+ const ::neurun::graph::operand::Index output_index{node.param().output_index};
+ const ::neurun::graph::operand::Index input_index{node.param().input_index};
+ const ::neurun::graph::operand::Index weight_index{node.param().weight_index};
+ const ::neurun::graph::operand::Index bias_index{node.param().bias_index};
+ const ::neurun::graph::operand::Index activation_index{node.param().activation_index};
// Construct operation parameters
struct Param
auto tensors = _tensor_builder;
return [tensors, param](IExecutionBuilder &builder) {
- auto output_alloc = tensors->at(::internal::tflite::operand::Index{param.output_index}).get();
- auto input_alloc = tensors->at(::internal::tflite::operand::Index{param.input_index}).get();
- auto weight_alloc = tensors->at(::internal::tflite::operand::Index{param.weight_index}).get();
- auto bias_alloc = tensors->at(::internal::tflite::operand::Index{param.bias_index}).get();
+ auto output_alloc = tensors->at(::neurun::graph::operand::Index{param.output_index}).get();
+ auto input_alloc = tensors->at(::neurun::graph::operand::Index{param.input_index}).get();
+ auto weight_alloc = tensors->at(::neurun::graph::operand::Index{param.weight_index}).get();
+ auto bias_alloc = tensors->at(::neurun::graph::operand::Index{param.bias_index}).get();
std::unique_ptr<::neurun::kernel::cpu::FullyConnectedLayer> fn{
new ::neurun::kernel::cpu::FullyConnectedLayer};
Stage StageGenerator::generate(const ::internal::tflite::op::Reshape::Node &node)
{
- const ::internal::tflite::operand::Index output_index{node.param().output_index};
- const ::internal::tflite::operand::Index input_index{node.param().input_index};
+ const ::neurun::graph::operand::Index output_index{node.param().output_index};
+ const ::neurun::graph::operand::Index input_index{node.param().input_index};
struct Param
{
auto tensors = _tensor_builder;
return [tensors, param](IExecutionBuilder &builder) {
- auto output_alloc = tensors->at(::internal::tflite::operand::Index{param.output_index}).get();
- auto input_alloc = tensors->at(::internal::tflite::operand::Index{param.input_index}).get();
+ auto output_alloc = tensors->at(::neurun::graph::operand::Index{param.output_index}).get();
+ auto input_alloc = tensors->at(::neurun::graph::operand::Index{param.input_index}).get();
std::unique_ptr<::neurun::kernel::cpu::ReshapeLayer> fn{
new ::neurun::kernel::cpu::ReshapeLayer};
{
VERBOSE(Softmax) << "generate CPU Softmax" << std::endl;
- const ::internal::tflite::operand::Index output_index{node.param().output_index};
- const ::internal::tflite::operand::Index input_index{node.param().input_index};
- const ::internal::tflite::operand::Index scale_index{node.param().scale_index};
+ const ::neurun::graph::operand::Index output_index{node.param().output_index};
+ const ::neurun::graph::operand::Index input_index{node.param().input_index};
+ const ::neurun::graph::operand::Index scale_index{node.param().scale_index};
struct Param
{
auto tensors = _tensor_builder;
return [tensors, param](IExecutionBuilder &builder) {
- auto output_alloc = tensors->at(::internal::tflite::operand::Index{param.output_index}).get();
- auto input_alloc = tensors->at(::internal::tflite::operand::Index{param.input_index}).get();
+ auto output_alloc = tensors->at(::neurun::graph::operand::Index{param.output_index}).get();
+ auto input_alloc = tensors->at(::neurun::graph::operand::Index{param.input_index}).get();
std::unique_ptr<::neurun::kernel::cpu::SoftMaxLayer> fn{
new ::neurun::kernel::cpu::SoftMaxLayer};
Stage StageGenerator::generate(
const ::internal::tflite::op::TensorConvert::CpuFromCommon::Node &node)
{
- const ::internal::tflite::operand::Index ifm_index{node.param().ifm_index};
+ const ::neurun::graph::operand::Index ifm_index{node.param().ifm_index};
struct Param
{
auto common_tensor_builder = _common_tensor_builder;
return [tensors, common_tensor_builder, param](IExecutionBuilder &builder) {
- const ::internal::tflite::operand::Index ifm_index{param.ifm_index};
+ const ::neurun::graph::operand::Index ifm_index{param.ifm_index};
auto input_alloc = tensors->at(ifm_index).get();
auto common_tensor = common_tensor_builder->at(ifm_index);
Stage StageGenerator::generate(const ::internal::tflite::op::TensorConvert::CpuToCommon::Node &node)
{
- const ::internal::tflite::operand::Index ofm_index{node.param().ofm_index};
+ const ::neurun::graph::operand::Index ofm_index{node.param().ofm_index};
struct Param
{
auto common_tensor_builder = _common_tensor_builder;
return [tensors, common_tensor_builder, param](IExecutionBuilder &builder) {
- const ::internal::tflite::operand::Index ofm_index{param.ofm_index};
+ const ::neurun::graph::operand::Index ofm_index{param.ofm_index};
auto output_alloc = tensors->at(ofm_index).get();
auto common_tensor = common_tensor_builder->at(ofm_index);
// DO NOTHING
}
-void TensorBuilder::mark(const ::internal::tflite::operand::Index &ind)
+void TensorBuilder::mark(const ::neurun::graph::operand::Index &ind)
{
assert(_tensors.size() == 0);
for (auto ind_int : _inds)
{
- ::internal::tflite::operand::Index ind{ind_int};
+ ::neurun::graph::operand::Index ind{ind_int};
auto tensor = std::make_shared<::internal::cpu::Tensor>(tensor_info_ctx.at(ind.asInt()));
// TODO Fix allocation here. When Tensor object is created the memory for tensor is also
// allocated, and this must be fixed.
}
std::shared_ptr<::internal::cpu::Tensor>
-TensorBuilder::at(const ::internal::tflite::operand::Index &ind)
+TensorBuilder::at(const ::neurun::graph::operand::Index &ind)
{
return _tensors.at(ind.asInt());
}
public:
TensorBuilder(::internal::Plan &plan);
- virtual void mark(const ::internal::tflite::operand::Index &ind) override;
+ virtual void mark(const ::neurun::graph::operand::Index &ind) override;
virtual void markFromCommon(const ::internal::tflite::op::Node &op, int32_t ind) override;
virtual void markToCommon(const ::internal::tflite::op::Node &op, int32_t ind) override;
virtual void insertTensorConvertNodes(::internal::tflite::op::Sequence &operations) override;
virtual void prepare(const std::map<int, ::arm_compute::TensorInfo> &tensor_info_ctx) override;
virtual void allocate(void) override;
- std::shared_ptr<::internal::cpu::Tensor> at(const ::internal::tflite::operand::Index &ind);
+ std::shared_ptr<::internal::cpu::Tensor> at(const ::neurun::graph::operand::Index &ind);
private:
::internal::Plan &_plan;
{
virtual ~IPlanBuilder() = default;
- virtual void addShapeConstr(const ::internal::tflite::operand::Index &ind,
+ virtual void addShapeConstr(const ::neurun::graph::operand::Index &ind,
const ::arm_compute::TensorInfo &info) = 0;
- virtual void addInitializer(const ::internal::tflite::operand::Index &ind,
+ virtual void addInitializer(const ::neurun::graph::operand::Index &ind,
const Initializer &initializer) = 0;
virtual void addStage(const Stage &) = 0;
};
namespace codegen
{
-void PlanBuilder::addShapeConstr(const ::internal::tflite::operand::Index &ind,
+void PlanBuilder::addShapeConstr(const ::neurun::graph::operand::Index &ind,
const ::arm_compute::TensorInfo &info)
{
_tensor_info_ctx[ind.asInt()] = info;
}
-void PlanBuilder::addInitializer(const ::internal::tflite::operand::Index &ind,
+void PlanBuilder::addInitializer(const ::neurun::graph::operand::Index &ind,
const Initializer &initializer)
{
_initializer_ctx[ind.asInt()] = initializer;
// Fill weight/bias
for (auto it = _initializer_ctx.begin(); it != _initializer_ctx.end(); ++it)
{
- const ::internal::tflite::operand::Index operand_index{it->first};
+ const ::neurun::graph::operand::Index operand_index{it->first};
auto objects = _plan.operands().at(operand_index);
for (auto object : objects)
}
public:
- void addShapeConstr(const ::internal::tflite::operand::Index &ind,
+ void addShapeConstr(const ::neurun::graph::operand::Index &ind,
const ::arm_compute::TensorInfo &info) override;
public:
- void addInitializer(const ::internal::tflite::operand::Index &ind,
+ void addInitializer(const ::neurun::graph::operand::Index &ind,
const Initializer &initializer) override;
public:
void Planner::visit(const ::internal::tflite::op::Conv2D::implicit::Node &node)
{
- const ::internal::tflite::operand::Index ofm_index{node.param().ofm_index};
+ const ::neurun::graph::operand::Index ofm_index{node.param().ofm_index};
- const ::internal::tflite::operand::Index ifm_index{node.param().ifm_index};
- const ::internal::tflite::operand::Index ker_index{node.param().ker_index};
- const ::internal::tflite::operand::Index bias_index{node.param().bias_index};
+ const ::neurun::graph::operand::Index ifm_index{node.param().ifm_index};
+ const ::neurun::graph::operand::Index ker_index{node.param().ker_index};
+ const ::neurun::graph::operand::Index bias_index{node.param().bias_index};
const auto ofm_shape = _ctx.at(ofm_index).shape().asFeature();
const auto ifm_shape = _ctx.at(ifm_index).shape().asFeature();
void Planner::visit(const ::internal::tflite::op::MaxPool2D::implicit::Node &node)
{
- const ::internal::tflite::operand::Index ofm_index{node.param().ofm_index};
- const ::internal::tflite::operand::Index ifm_index{node.param().ifm_index};
+ const ::neurun::graph::operand::Index ofm_index{node.param().ofm_index};
+ const ::neurun::graph::operand::Index ifm_index{node.param().ifm_index};
const auto ofm_shape = _ctx.at(ofm_index).shape().asFeature();
const auto ifm_shape = _ctx.at(ifm_index).shape().asFeature();
void Planner::visit(const ::internal::tflite::op::AvgPool2D::implicit::Node &node)
{
- const ::internal::tflite::operand::Index ofm_index{node.param().ofm_index};
- const ::internal::tflite::operand::Index ifm_index{node.param().ifm_index};
+ const ::neurun::graph::operand::Index ofm_index{node.param().ofm_index};
+ const ::neurun::graph::operand::Index ifm_index{node.param().ifm_index};
const auto ofm_shape = _ctx.at(ofm_index).shape().asFeature();
const auto ifm_shape = _ctx.at(ifm_index).shape().asFeature();
void Planner::visit(const ::internal::tflite::op::Concat::Node &node)
{
- const ::internal::tflite::operand::Index ofm_index{node.param().ofm_index};
+ const ::neurun::graph::operand::Index ofm_index{node.param().ofm_index};
// NOTE This implementation assumes that inputs and output are a feature
// TODO Remove this assumption
// NOTE This implementation assumes concat over feature depth
// TODO Remove this assumption
- assert(_ctx.at(::internal::tflite::operand::Index{node.param().axis_index}).asScalar<int32_t>() ==
+ assert(_ctx.at(::neurun::graph::operand::Index{node.param().axis_index}).asScalar<int32_t>() ==
3);
// Set Shape Constraints (for output)
for (const auto &index : node.param().ifm_indexes)
{
- const ::internal::tflite::operand::Index ifm_index{index};
+ const ::neurun::graph::operand::Index ifm_index{index};
const auto ifm_shape = _ctx.at(ifm_index).shape().asFeature();
_builder.addShapeConstr(ifm_index, ::internal::asTensorInfo(ifm_shape));
}
{
VERBOSE(FullyConnected) << "Configure FULLY_CONNECTED operation" << std::endl;
- const ::internal::tflite::operand::Index output_index{node.param().output_index};
+ const ::neurun::graph::operand::Index output_index{node.param().output_index};
- const ::internal::tflite::operand::Index input_index{node.param().input_index};
- const ::internal::tflite::operand::Index weight_index{node.param().weight_index};
- const ::internal::tflite::operand::Index bias_index{node.param().bias_index};
+ const ::neurun::graph::operand::Index input_index{node.param().input_index};
+ const ::neurun::graph::operand::Index weight_index{node.param().weight_index};
+ const ::neurun::graph::operand::Index bias_index{node.param().bias_index};
- const ::internal::tflite::operand::Index activation_index{node.param().activation_index};
+ const ::neurun::graph::operand::Index activation_index{node.param().activation_index};
assert(_ctx.at(output_index).shape().rank() == 2);
const auto output_size = _ctx.at(output_index).shape().dim(1);
void Planner::visit(const ::internal::tflite::op::Reshape::Node &node)
{
- const ::internal::tflite::operand::Index output_index{node.param().output_index};
- const ::internal::tflite::operand::Index input_index{node.param().input_index};
+ const ::neurun::graph::operand::Index output_index{node.param().output_index};
+ const ::neurun::graph::operand::Index input_index{node.param().input_index};
// NOTE The content of a tensor specified by shape_index should be aligned with
// output tensor shape
{
VERBOSE(Softmax) << "Configure SOFTMAX operation" << std::endl;
- const ::internal::tflite::operand::Index output_index{node.param().output_index};
- const ::internal::tflite::operand::Index input_index{node.param().input_index};
+ const ::neurun::graph::operand::Index output_index{node.param().output_index};
+ const ::neurun::graph::operand::Index input_index{node.param().input_index};
assert(_ctx.at(output_index).shape().rank() == _ctx.at(input_index).shape().rank());
void visit(const ::internal::tflite::op::TensorConvert::AclToCommon::Node &node) override;
private:
- void mark(int32_t ind) { _tensor_builder.mark(::internal::tflite::operand::Index{ind}); }
+ void mark(int32_t ind) { _tensor_builder.mark(::neurun::graph::operand::Index{ind}); }
void markFromCommon(const ::internal::tflite::op::Node &op, int32_t ind)
{
_tensor_builder.markFromCommon(op, ind);
neurun::graph::operand::IO::Index input_index{n};
- ::internal::tflite::operand::Index index{model.inputs().at(input_index).asInt()};
+ ::neurun::graph::operand::Index index{model.inputs().at(input_index)};
auto objects = plan.operands().at(index);
for (auto object : objects)
neurun::graph::operand::IO::Index output_index{n};
- ::internal::tflite::operand::Index index{model.outputs().at(output_index).asInt()};
+ ::neurun::graph::operand::Index index{model.outputs().at(output_index)};
auto objects = plan.operands().at(index);
for (auto object : objects)
for (uint32_t i = 0; i < outputCount; i++)
{
- // NOTE ::internal::tflite::operand::Index uses int as its underlying type as various NNAPI
+ // NOTE ::neurun::graph::operand::Index uses int as its underlying type as various NNAPI
// functions such as ANeuralNetworksModel_setOperandValue use int to represent operand
// index
//
// index.
//
// Below, static_cast<int>(...) is introduced to eliminate compiler warning.
- const internal::tflite::operand::Index ind{static_cast<int>(outputs[i])};
+ const ::neurun::graph::operand::Index ind{static_cast<int>(outputs[i])};
auto &obj = model->deref().operands().at(ind);
if (!obj.setAsOperationOutput())
for (uint32_t i = 0; i < outputCount; i++)
{
- // NOTE ::internal::tflite::operand::Index uses int as its underlying type as various NNAPI
+ // NOTE ::neurun::graph::operand::Index uses int as its underlying type as various NNAPI
// functions such as ANeuralNetworksModel_setOperandValue use int to represent operand
// index
//
// index.
//
// Below, static_cast<int>(...) is introduced to eliminate compiler warning.
- const internal::tflite::operand::Index ind{static_cast<int>(outputs[i])};
+ const ::neurun::graph::operand::Index ind{static_cast<int>(outputs[i])};
auto &obj = model->deref().operands().at(ind);
if (!obj.setAsOperationOutput())
return ANEURALNETWORKS_BAD_STATE;
}
- // NOTE ::internal::tflite::operand::Index uses int as its underlying type as various NNAPI
+ // NOTE ::neurun::graph::operand::Index uses int as its underlying type as various NNAPI
// functions such as ANeuralNetworksModel_setOperandValue use int to represent operand index
//
// ANeuralNetworksModel_identifyInputsAndOutputs, however, uses uint32_t to represent operand
#include "graph/operand/Index.h"
-namespace internal
-{
-namespace tflite
-{
-namespace operand
-{
-
-class Index
-{
-public:
- explicit Index(int value) : _value{value}
- {
- // DO NOTHING
- }
-
- // NOTE Temporary casting operator for legacy code compatibility
-public:
- operator neurun::graph::operand::Index() const { return neurun::graph::operand::Index{_value}; }
-
-public:
- int asInt(void) const { return _value; }
-
-private:
- int _value;
-};
-
-} // namespace operand
-} // namespace tflite
-} // namespace internal
-
#include <vector>
#include <cstdint>
namespace operand
{
-Context &Context::set(const ::internal::tflite::operand::Index &id,
+Context &Context::set(const ::neurun::graph::operand::Index &id,
const std::shared_ptr<neurun::backend::operand::IObject> &object)
{
_objects[id.asInt()].emplace_back(object);
class Context
{
public:
- Context &set(const ::internal::tflite::operand::Index &ind,
+ Context &set(const ::neurun::graph::operand::Index &ind,
const std::shared_ptr<neurun::backend::operand::IObject> &object);
public:
- bool exist(const ::internal::tflite::operand::Index &ind) const
+ bool exist(const ::neurun::graph::operand::Index &ind) const
{
return _objects.find(ind.asInt()) != _objects.end();
}
public:
const std::vector<std::shared_ptr<neurun::backend::operand::IObject>> &
- at(const ::internal::tflite::operand::Index &ind) const
+ at(const ::neurun::graph::operand::Index &ind) const
{
return _objects.at(ind.asInt());
}
std::vector<std::shared_ptr<neurun::backend::operand::IObject>> &
- at(const ::internal::tflite::operand::Index &ind)
+ at(const ::neurun::graph::operand::Index &ind)
{
return _objects.at(ind.asInt());
}
// DO NOTHING
}
-void TensorBuilder::mark(const ::internal::tflite::operand::Index &ind)
+void TensorBuilder::mark(const ::neurun::graph::operand::Index &ind)
{
assert(_tensors.size() == 0);
for (auto ind_int : _inds)
{
- ::internal::tflite::operand::Index ind{ind_int};
+ ::neurun::graph::operand::Index ind{ind_int};
auto tensor = std::make_shared<::internal::common::Tensor>(tensor_info_ctx.at(ind.asInt()));
_plan.common_operands().set(ind, std::make_shared<::internal::common::Object>(tensor));
_tensors[ind.asInt()] = tensor;
}
std::shared_ptr<::internal::common::Tensor>
-TensorBuilder::at(const ::internal::tflite::operand::Index &ind)
+TensorBuilder::at(const ::neurun::graph::operand::Index &ind)
{
return _tensors.at(ind.asInt());
}
public:
TensorBuilder(::internal::Plan &plan);
- virtual void mark(const ::internal::tflite::operand::Index &ind) override;
+ virtual void mark(const ::neurun::graph::operand::Index &ind) override;
virtual void markFromCommon(const ::internal::tflite::op::Node &op, int32_t ind) override;
virtual void markToCommon(const ::internal::tflite::op::Node &op, int32_t ind) override;
virtual void insertTensorConvertNodes(::internal::tflite::op::Sequence &operations) override;
virtual void prepare(const std::map<int, ::arm_compute::TensorInfo> &tensor_info_ctx) override;
virtual void allocate(void) override;
- std::shared_ptr<::internal::common::Tensor> at(const ::internal::tflite::operand::Index &ind);
+ std::shared_ptr<::internal::common::Tensor> at(const ::neurun::graph::operand::Index &ind);
private:
::internal::Plan &_plan;