From cbef5e5484a901374d7cb81f9d38a7ad605c1506 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=9E=A5=EC=A7=80=EC=84=AD/On-Device=20Lab=28SR=29/Enginee?= =?utf8?q?r/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Thu, 18 Jul 2019 17:32:44 +0900 Subject: [PATCH] Introduce ConstantInitializer into acl cl backend (#5692) This commit introduces ConstantInitializer into acl cl backend. Signed-off-by: jiseob.jang --- .../neurun/backend/acl_cl/ConstantInitializer.cc | 619 +++++++++++++++++++++ .../neurun/backend/acl_cl/ConstantInitializer.h | 106 ++++ 2 files changed, 725 insertions(+) create mode 100644 runtimes/neurun/backend/acl_cl/ConstantInitializer.cc create mode 100644 runtimes/neurun/backend/acl_cl/ConstantInitializer.h diff --git a/runtimes/neurun/backend/acl_cl/ConstantInitializer.cc b/runtimes/neurun/backend/acl_cl/ConstantInitializer.cc new file mode 100644 index 0000000..255340a --- /dev/null +++ b/runtimes/neurun/backend/acl_cl/ConstantInitializer.cc @@ -0,0 +1,619 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ConstantInitializer.h" + +namespace neurun +{ +namespace backend +{ +namespace acl_cl +{ + +ConstantInitializer::ConstantInitializer(const model::Operands &operands, + const std::shared_ptr &tensor_builder) + : _operands{operands}, _tensor_builder{tensor_builder} +{ + // DO NOTHING +} + +void ConstantInitializer::run() +{ + for (const auto &it : _init_map) + { + const auto &ind = it.first; + const auto &fn = it.second; + + const auto &model_obj = _operands.at(ind); + auto tensor_obj = _tensor_builder->wrapTensor(ind); + fn(model_obj, *tensor_obj); + } +} + +void ConstantInitializer::visit(const model::operation::AbsNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::AbsNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::AddNode &node) +{ + const auto &lhs_index = node.getInputs().at(model::operation::AddNode::LHS); + const auto &lhs_obj = _operands.at(lhs_index); + registerPermuteInitializer(lhs_index, lhs_obj); + + const auto &rhs_index = node.getInputs().at(model::operation::AddNode::RHS); + const auto &rhs_obj = _operands.at(rhs_index); + registerPermuteInitializer(rhs_index, rhs_obj); +} + +void ConstantInitializer::visit(const model::operation::ArgMaxNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::ArgMaxNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::AvgPool2DNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::AvgPool2DNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::CastNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::CastNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::ComparisonNode &node) +{ + const auto &input0_index = node.getInputs().at(model::operation::ComparisonNode::INPUT0); + const auto &input0_obj = _operands.at(input0_index); + registerPermuteInitializer(input0_index, input0_obj); + + const auto &input1_index = node.getInputs().at(model::operation::ComparisonNode::INPUT1); + const auto &input1_obj = _operands.at(input1_index); + registerPermuteInitializer(input1_index, input1_obj); +} + +void ConstantInitializer::visit(const model::operation::ConcatNode &node) +{ + const auto inputs = node.getInputs(); + for (const auto &input_index : inputs) + { + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); + } +} + +void ConstantInitializer::visit(const model::operation::Conv2DNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::Conv2DNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); + + const auto &kernel_index = node.getInputs().at(model::operation::Conv2DNode::KERNEL); + const auto &kernel_obj = _operands.at(kernel_index); + registerPermuteInitializer(kernel_index, kernel_obj); + + const auto &bias_index = node.getInputs().at(model::operation::Conv2DNode::BIAS); + const auto &bias_obj = _operands.at(bias_index); + registerDefaultInitializer(bias_index, bias_obj); +} + +void ConstantInitializer::visit(const model::operation::DepthToSpaceNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::DepthToSpaceNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::DepthwiseConv2DNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::DepthwiseConv2DNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); + + const auto &kernel_index = node.getInputs().at(model::operation::DepthwiseConv2DNode::KERNEL); + const auto &kernel_obj = _operands.at(kernel_index); + registerPermuteInitializer(kernel_index, kernel_obj); + + const auto &bias_index = node.getInputs().at(model::operation::DepthwiseConv2DNode::BIAS); + const auto &bias_obj = _operands.at(bias_index); + registerDefaultInitializer(bias_index, bias_obj); +} + +void ConstantInitializer::visit(const model::operation::DequantizeNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::DequantizeNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::DivNode &node) +{ + const auto &lhs_index = node.getInputs().at(model::operation::DivNode::LHS); + const auto &lhs_obj = _operands.at(lhs_index); + registerPermuteInitializer(lhs_index, lhs_obj); + + const auto &rhs_index = node.getInputs().at(model::operation::DivNode::RHS); + const auto &rhs_obj = _operands.at(rhs_index); + registerPermuteInitializer(rhs_index, rhs_obj); +} + +void ConstantInitializer::visit(const model::operation::EmbeddingLookupNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::EmbeddingLookupNode::VALUES); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); + + const auto &lookups_index = node.getInputs().at(model::operation::EmbeddingLookupNode::LOOKUPS); + const auto &lookups_obj = _operands.at(lookups_index); + registerDefaultInitializer(lookups_index, lookups_obj); +} + +void ConstantInitializer::visit(const model::operation::ExpNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::ExpNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::FloorNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::FloorNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::FullyConnectedNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::FullyConnectedNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); + + const auto &weight_index = node.getInputs().at(model::operation::FullyConnectedNode::WEIGHT); + const auto &weight_obj = _operands.at(weight_index); + registerDefaultInitializer(weight_index, weight_obj); + + const auto &bias_index = node.getInputs().at(model::operation::FullyConnectedNode::BIAS); + const auto &bias_obj = _operands.at(bias_index); + registerDefaultInitializer(bias_index, bias_obj); +} + +void ConstantInitializer::visit(const model::operation::GatherNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::GatherNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); + + const auto &indices_index = node.getInputs().at(model::operation::GatherNode::INDICES); + const auto &indices_obj = _operands.at(indices_index); + registerDefaultInitializer(indices_index, indices_obj); +} + +void ConstantInitializer::visit(const model::operation::HashtableLookupNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::HashtableLookupNode::VALUES); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); + + const auto &lookups_index = node.getInputs().at(model::operation::HashtableLookupNode::LOOKUPS); + const auto &lookups_obj = _operands.at(lookups_index); + registerDefaultInitializer(lookups_index, lookups_obj); + + const auto &keys_index = node.getInputs().at(model::operation::HashtableLookupNode::KEYS); + const auto &keys_obj = _operands.at(keys_index); + registerDefaultInitializer(keys_index, keys_obj); +} + +void ConstantInitializer::visit(const model::operation::L2NormalizationNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::L2NormalizationNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::L2Pool2DNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::L2Pool2DNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::LocalResponseNormalizationNode &node) +{ + const auto &input_index = + node.getInputs().at(model::operation::LocalResponseNormalizationNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::LogicalAndNode &node) +{ + const auto &input0_index = node.getInputs().at(model::operation::LogicalAndNode::INPUT0); + const auto &input0_obj = _operands.at(input0_index); + registerPermuteInitializer(input0_index, input0_obj); + + const auto &input1_index = node.getInputs().at(model::operation::LogicalAndNode::INPUT1); + const auto &input1_obj = _operands.at(input1_index); + registerPermuteInitializer(input1_index, input1_obj); +} + +void ConstantInitializer::visit(const model::operation::LogicalNotNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::LogicalNotNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::LogicalOrNode &node) +{ + const auto &input0_index = node.getInputs().at(model::operation::LogicalOrNode::INPUT0); + const auto &input0_obj = _operands.at(input0_index); + registerPermuteInitializer(input0_index, input0_obj); + + const auto &input1_index = node.getInputs().at(model::operation::LogicalOrNode::INPUT1); + const auto &input1_obj = _operands.at(input1_index); + registerPermuteInitializer(input1_index, input1_obj); +} + +void ConstantInitializer::visit(const model::operation::LogisticNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::LogisticNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::LSTMNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::LSTMNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); + + const auto &output_state_in_index = + node.getInputs().at(model::operation::LSTMNode::OUTPUT_STATE_IN); + const auto &output_state_in_obj = _operands.at(output_state_in_index); + registerPermuteInitializer(output_state_in_index, output_state_in_obj); + + const auto &cell_state_in_index = node.getInputs().at(model::operation::LSTMNode::CELL_STATE_IN); + const auto &cell_state_in_obj = _operands.at(cell_state_in_index); + registerPermuteInitializer(cell_state_in_index, cell_state_in_obj); + + const auto &input_to_input_weights_index = + node.getInputs().at(model::operation::LSTMNode::INPUT_TO_INPUT_WEIGHTS); + const auto &input_to_input_weights_obj = _operands.at(input_to_input_weights_index); + registerDefaultInitializer(input_to_input_weights_index, input_to_input_weights_obj); + + const auto &input_to_forget_weights_index = + node.getInputs().at(model::operation::LSTMNode::INPUT_TO_FORGET_WEIGHTS); + const auto &input_to_forget_weights_obj = _operands.at(input_to_forget_weights_index); + registerDefaultInitializer(input_to_forget_weights_index, input_to_forget_weights_obj); + + const auto &input_to_cell_weights_index = + node.getInputs().at(model::operation::LSTMNode::INPUT_TO_CELL_WEIGHTS); + const auto &input_to_cell_weights_obj = _operands.at(input_to_cell_weights_index); + registerDefaultInitializer(input_to_cell_weights_index, input_to_cell_weights_obj); + + const auto &input_to_output_weights_index = + node.getInputs().at(model::operation::LSTMNode::INPUT_TO_OUTPUT_WEIGHTS); + const auto &input_to_output_weights_obj = _operands.at(input_to_output_weights_index); + registerDefaultInitializer(input_to_output_weights_index, input_to_output_weights_obj); + + const auto &recurrent_to_input_weights_index = + node.getInputs().at(model::operation::LSTMNode::RECURRENT_TO_INPUT_WEIGHTS); + const auto &recurrent_to_input_weights_obj = _operands.at(recurrent_to_input_weights_index); + registerDefaultInitializer(recurrent_to_input_weights_index, recurrent_to_input_weights_obj); + + const auto &recurrent_to_forget_weights_index = + node.getInputs().at(model::operation::LSTMNode::RECURRENT_TO_FORGET_WEIGHTS); + const auto &recurrent_to_forget_weights_obj = _operands.at(recurrent_to_forget_weights_index); + registerDefaultInitializer(recurrent_to_forget_weights_index, recurrent_to_forget_weights_obj); + + const auto &recurrent_to_cell_weights_index = + node.getInputs().at(model::operation::LSTMNode::RECURRENT_TO_CELL_WEIGHTS); + const auto &recurrent_to_cell_weights_obj = _operands.at(recurrent_to_cell_weights_index); + registerDefaultInitializer(recurrent_to_cell_weights_index, recurrent_to_cell_weights_obj); + + const auto &recurrent_to_output_weights_index = + node.getInputs().at(model::operation::LSTMNode::RECURRENT_TO_OUTPUT_WEIGHTS); + const auto &recurrent_to_output_weights_obj = _operands.at(recurrent_to_output_weights_index); + registerDefaultInitializer(recurrent_to_output_weights_index, recurrent_to_output_weights_obj); + + const auto &cell_to_input_weights_index = + node.getInputs().at(model::operation::LSTMNode::CELL_TO_INPUT_WEIGHTS); + const auto &cell_to_input_weights_obj = _operands.at(cell_to_input_weights_index); + registerDefaultInitializer(cell_to_input_weights_index, cell_to_input_weights_obj); + + const auto &cell_to_forget_weights_index = + node.getInputs().at(model::operation::LSTMNode::CELL_TO_FORGET_WEIGHTS); + const auto &cell_to_forget_weights_obj = _operands.at(cell_to_forget_weights_index); + registerDefaultInitializer(cell_to_forget_weights_index, cell_to_forget_weights_obj); + + const auto &cell_to_output_weights_index = + node.getInputs().at(model::operation::LSTMNode::CELL_TO_OUTPUT_WEIGHTS); + const auto &cell_to_output_weights_obj = _operands.at(cell_to_output_weights_index); + registerDefaultInitializer(cell_to_output_weights_index, cell_to_output_weights_obj); + + const auto &input_gate_bias_index = + node.getInputs().at(model::operation::LSTMNode::INPUT_GATE_BIAS); + const auto &input_gate_bias_obj = _operands.at(input_gate_bias_index); + registerDefaultInitializer(input_gate_bias_index, input_gate_bias_obj); + + const auto &forget_gate_bias_index = + node.getInputs().at(model::operation::LSTMNode::FORGET_GATE_BIAS); + const auto &forget_gate_bias_obj = _operands.at(forget_gate_bias_index); + registerDefaultInitializer(forget_gate_bias_index, forget_gate_bias_obj); + + const auto &output_gate_bias_index = + node.getInputs().at(model::operation::LSTMNode::OUTPUT_GATE_BIAS); + const auto &output_gate_bias_obj = _operands.at(output_gate_bias_index); + registerDefaultInitializer(output_gate_bias_index, output_gate_bias_obj); + + const auto &projection_weights_index = + node.getInputs().at(model::operation::LSTMNode::PROJECTION_WEIGHTS); + const auto &projection_weights_obj = _operands.at(projection_weights_index); + registerDefaultInitializer(projection_weights_index, projection_weights_obj); + + const auto &projection_bias_index = + node.getInputs().at(model::operation::LSTMNode::PROJECTION_BIAS); + const auto &projection_bias_obj = _operands.at(projection_bias_index); + registerDefaultInitializer(projection_bias_index, projection_bias_obj); +} + +void ConstantInitializer::visit(const model::operation::MaxPool2DNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::MaxPool2DNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::MeanNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::MeanNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::MulNode &node) +{ + const auto &lhs_index = node.getInputs().at(model::operation::MulNode::LHS); + const auto &lhs_obj = _operands.at(lhs_index); + registerPermuteInitializer(lhs_index, lhs_obj); + + const auto &rhs_index = node.getInputs().at(model::operation::MulNode::RHS); + const auto &rhs_obj = _operands.at(rhs_index); + registerPermuteInitializer(rhs_index, rhs_obj); +} + +void ConstantInitializer::visit(const model::operation::NegNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::NegNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::PadNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::PadNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::PReLUNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::PReLUNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); + + const auto &alpha_index = node.getInputs().at(model::operation::PReLUNode::ALPHA); + const auto &alpha_obj = _operands.at(alpha_index); + registerPermuteInitializer(alpha_index, alpha_obj); +} + +void ConstantInitializer::visit(const model::operation::ReduceMaxNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::ReduceMaxNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::ReduceMinNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::ReduceMinNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::ReduceSumNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::ReduceSumNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::ReLUNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::ReLUNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::ReLU1Node &node) +{ + const auto &input_index = node.getInputs().at(model::operation::ReLU1Node::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::ReLU6Node &node) +{ + const auto &input_index = node.getInputs().at(model::operation::ReLU6Node::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::ReshapeNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::ReshapeNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::ResizeBilinearNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::ResizeBilinearNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::RNNNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::RNNNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); + + const auto &weights_index = node.getInputs().at(model::operation::RNNNode::WEIGHTS); + const auto &weights_obj = _operands.at(weights_index); + registerDefaultInitializer(weights_index, weights_obj); + + const auto &recurrent_weights_index = + node.getInputs().at(model::operation::RNNNode::RECURRENT_WEIGHTS); + const auto &recurrent_weights_obj = _operands.at(recurrent_weights_index); + registerDefaultInitializer(recurrent_weights_index, recurrent_weights_obj); + + const auto &bias_index = node.getInputs().at(model::operation::RNNNode::BIAS); + const auto &bias_obj = _operands.at(bias_index); + registerDefaultInitializer(bias_index, bias_obj); +} + +void ConstantInitializer::visit(const model::operation::RSQRTNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::RSQRTNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::SoftmaxNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::SoftmaxNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::SpaceToDepthNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::SpaceToDepthNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::SplitNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::SplitNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::SQRTNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::SQRTNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::SquaredDifferenceNode &node) +{ + const auto &lhs_index = node.getInputs().at(model::operation::SquaredDifferenceNode::LHS); + const auto &lhs_obj = _operands.at(lhs_index); + registerPermuteInitializer(lhs_index, lhs_obj); + + const auto &rhs_index = node.getInputs().at(model::operation::SquaredDifferenceNode::RHS); + const auto &rhs_obj = _operands.at(rhs_index); + registerPermuteInitializer(rhs_index, rhs_obj); +} + +void ConstantInitializer::visit(const model::operation::SqueezeNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::SqueezeNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::StridedSliceNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::StridedSliceNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::SubNode &node) +{ + const auto &lhs_index = node.getInputs().at(model::operation::SubNode::LHS); + const auto &lhs_obj = _operands.at(lhs_index); + registerPermuteInitializer(lhs_index, lhs_obj); + + const auto &rhs_index = node.getInputs().at(model::operation::SubNode::RHS); + const auto &rhs_obj = _operands.at(rhs_index); + registerPermuteInitializer(rhs_index, rhs_obj); +} + +void ConstantInitializer::visit(const model::operation::TanhNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::TanhNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::TopKV2Node &node) +{ + const auto &input_index = node.getInputs().at(model::operation::TopKV2Node::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::TransposeConvNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::TransposeConvNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); + + const auto &kernel_index = node.getInputs().at(model::operation::TransposeConvNode::KERNEL); + const auto &kernel_obj = _operands.at(kernel_index); + registerDefaultInitializer(kernel_index, kernel_obj); +} + +void ConstantInitializer::visit(const model::operation::TransposeNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::TransposeNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +void ConstantInitializer::visit(const model::operation::UnpackNode &node) +{ + const auto &input_index = node.getInputs().at(model::operation::UnpackNode::INPUT); + const auto &input_obj = _operands.at(input_index); + registerPermuteInitializer(input_index, input_obj); +} + +} // namespace acl_cl +} // namespace backend +} // namespace neurun diff --git a/runtimes/neurun/backend/acl_cl/ConstantInitializer.h b/runtimes/neurun/backend/acl_cl/ConstantInitializer.h new file mode 100644 index 0000000..f1d243d --- /dev/null +++ b/runtimes/neurun/backend/acl_cl/ConstantInitializer.h @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __NEURUN_COMPILER_ACL_CL_CONSTANT_INITIALIZER_H__ +#define __NEURUN_COMPILER_ACL_CL_CONSTANT_INITIALIZER_H__ + +#include +#include +#include "TensorBuilder.h" + +namespace neurun +{ +namespace backend +{ +namespace acl_cl +{ + +class ConstantInitializer : public IConstantInitializer +{ +public: + ConstantInitializer(const model::Operands &operands, + const std::shared_ptr &tensor_builder); + +public: + void run() override; + +public: + void visit(const model::operation::AbsNode &) override; + void visit(const model::operation::AddNode &) override; + void visit(const model::operation::ArgMaxNode &) override; + void visit(const model::operation::AvgPool2DNode &) override; + void visit(const model::operation::CastNode &) override; + void visit(const model::operation::ComparisonNode &) override; + void visit(const model::operation::ConcatNode &) override; + void visit(const model::operation::Conv2DNode &) override; + void visit(const model::operation::DepthToSpaceNode &) override; + void visit(const model::operation::DepthwiseConv2DNode &) override; + void visit(const model::operation::DequantizeNode &) override; + void visit(const model::operation::DivNode &) override; + void visit(const model::operation::EmbeddingLookupNode &) override; + void visit(const model::operation::ExpNode &) override; + void visit(const model::operation::FloorNode &) override; + void visit(const model::operation::FullyConnectedNode &) override; + void visit(const model::operation::GatherNode &) override; + void visit(const model::operation::HashtableLookupNode &) override; + void visit(const model::operation::L2NormalizationNode &) override; + void visit(const model::operation::L2Pool2DNode &) override; + void visit(const model::operation::LocalResponseNormalizationNode &) override; + void visit(const model::operation::LogicalAndNode &) override; + void visit(const model::operation::LogicalNotNode &) override; + void visit(const model::operation::LogicalOrNode &) override; + void visit(const model::operation::LogisticNode &) override; + void visit(const model::operation::LSTMNode &) override; + void visit(const model::operation::MaxPool2DNode &) override; + void visit(const model::operation::MeanNode &) override; + void visit(const model::operation::MulNode &) override; + void visit(const model::operation::NegNode &) override; + void visit(const model::operation::PadNode &) override; + void visit(const model::operation::PReLUNode &) override; + void visit(const model::operation::ReduceMaxNode &) override; + void visit(const model::operation::ReduceMinNode &) override; + void visit(const model::operation::ReduceSumNode &) override; + void visit(const model::operation::ReLUNode &) override; + void visit(const model::operation::ReLU1Node &) override; + void visit(const model::operation::ReLU6Node &) override; + void visit(const model::operation::ReshapeNode &node) override; + void visit(const model::operation::ResizeBilinearNode &) override; + void visit(const model::operation::RNNNode &) override; + void visit(const model::operation::RSQRTNode &) override; + void visit(const model::operation::SoftmaxNode &node) override; + void visit(const model::operation::SpaceToDepthNode &) override; + void visit(const model::operation::SplitNode &) override; + void visit(const model::operation::SQRTNode &) override; + void visit(const model::operation::SquaredDifferenceNode &) override; + void visit(const model::operation::SqueezeNode &) override; + void visit(const model::operation::StridedSliceNode &) override; + void visit(const model::operation::SubNode &) override; + void visit(const model::operation::TanhNode &) override; + void visit(const model::operation::TopKV2Node &) override; + void visit(const model::operation::TransposeConvNode &) override; + void visit(const model::operation::TransposeNode &) override; + void visit(const model::operation::UnpackNode &) override; + +private: + const model::Operands &_operands; + std::shared_ptr _tensor_builder; +}; + +} // namespace acl_cl +} // namespace backend +} // namespace neurun + +#endif // __NEURUN_COMPILER_ACL_CL_CONSTANT_INITIALIZER_H__ -- 2.7.4