diff options
Diffstat (limited to 'compiler/luci-interpreter/src/loader')
77 files changed, 207 insertions, 220 deletions
diff --git a/compiler/luci-interpreter/src/loader/GraphLoader.cpp b/compiler/luci-interpreter/src/loader/GraphLoader.cpp index dba39050c..40207090b 100644 --- a/compiler/luci-interpreter/src/loader/GraphLoader.cpp +++ b/compiler/luci-interpreter/src/loader/GraphLoader.cpp @@ -187,7 +187,7 @@ void GraphLoader::loadTensors() const auto *node = loco::must_cast<const luci::CircleNode *>(_graph->nodes()->at(i)); if (node->opcode() == luci::CircleOpcode::CUSTOM && !isSupportedCustomNode(node)) - throw std::runtime_error("Unknown Custom Node, yet."); + throw std::runtime_error("Unsupported Custom operator. " + node->name()); if (!isTensorProducingNode(node)) continue; diff --git a/compiler/luci-interpreter/src/loader/nodes/Add.cpp b/compiler/luci-interpreter/src/loader/nodes/Add.cpp index decccaa1d..501e84752 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Add.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Add.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleAdd(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleAdd *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleAdd *>(circle_node); assert(node->arity() == 2); const Tensor *input1 = helper.getInputTensor(node->x()); diff --git a/compiler/luci-interpreter/src/loader/nodes/ArgMax.cpp b/compiler/luci-interpreter/src/loader/nodes/ArgMax.cpp index 0ee367748..f3ca55744 100644 --- a/compiler/luci-interpreter/src/loader/nodes/ArgMax.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/ArgMax.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleArgMax(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleArgMax *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleArgMax *>(circle_node); assert(node->arity() == 2); const Tensor *input = helper.getInputTensor(node->input()); const Tensor *axis = helper.getInputTensor(node->dimension()); diff --git a/compiler/luci-interpreter/src/loader/nodes/AveragePool2D.cpp b/compiler/luci-interpreter/src/loader/nodes/AveragePool2D.cpp index efb011257..a8135706f 100644 --- a/compiler/luci-interpreter/src/loader/nodes/AveragePool2D.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/AveragePool2D.cpp @@ -25,9 +25,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleAveragePool2D(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleAveragePool2D *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleAveragePool2D *>(circle_node); assert(node->arity() == 1); const Tensor *input = helper.getInputTensor(node->value()); diff --git a/compiler/luci-interpreter/src/loader/nodes/BatchMatMul.cpp b/compiler/luci-interpreter/src/loader/nodes/BatchMatMul.cpp index aae3dbab1..9da2f6d93 100644 --- a/compiler/luci-interpreter/src/loader/nodes/BatchMatMul.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/BatchMatMul.cpp @@ -25,9 +25,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleBatchMatMul(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleBatchMatMul *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleBatchMatMul *>(circle_node); assert(node->arity() == 2); const Tensor *lhs = helper.getInputTensor(node->x()); diff --git a/compiler/luci-interpreter/src/loader/nodes/BatchToSpaceND.cpp b/compiler/luci-interpreter/src/loader/nodes/BatchToSpaceND.cpp index 33d0e2db6..ac6ebb30f 100644 --- a/compiler/luci-interpreter/src/loader/nodes/BatchToSpaceND.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/BatchToSpaceND.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleBatchToSpaceND(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleBatchToSpaceND *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleBatchToSpaceND *>(circle_node); assert(node->arity() == 3); const Tensor *input = helper.getInputTensor(node->input()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Cast.cpp b/compiler/luci-interpreter/src/loader/nodes/Cast.cpp index 21ea5ceab..a16354c96 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Cast.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Cast.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleCast(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleCast *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleCast *>(circle_node); assert(node->arity() == 1); diff --git a/compiler/luci-interpreter/src/loader/nodes/Concatenation.cpp b/compiler/luci-interpreter/src/loader/nodes/Concatenation.cpp index 7823a9967..ba2564ea2 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Concatenation.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Concatenation.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleConcatenation(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleConcatenation *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleConcatenation *>(circle_node); std::vector<const Tensor *> inputs(node->numValues()); for (uint32_t i = 0; i < node->numValues(); ++i) { diff --git a/compiler/luci-interpreter/src/loader/nodes/Conv2D.cpp b/compiler/luci-interpreter/src/loader/nodes/Conv2D.cpp index b48d97d19..218165e20 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Conv2D.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Conv2D.cpp @@ -25,9 +25,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleConv2D(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleConv2D *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleConv2D *>(circle_node); assert(node->arity() == 3); const Tensor *input = helper.getInputTensor(node->input()); diff --git a/compiler/luci-interpreter/src/loader/nodes/DepthToSpace.cpp b/compiler/luci-interpreter/src/loader/nodes/DepthToSpace.cpp index 0310fb23f..174946367 100644 --- a/compiler/luci-interpreter/src/loader/nodes/DepthToSpace.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/DepthToSpace.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleDepthToSpace(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleDepthToSpace *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleDepthToSpace *>(circle_node); assert(node->arity() == 1); const Tensor *input = helper.getInputTensor(node->input()); diff --git a/compiler/luci-interpreter/src/loader/nodes/DepthwiseConv2D.cpp b/compiler/luci-interpreter/src/loader/nodes/DepthwiseConv2D.cpp index db26ecf2e..8af1e3b58 100644 --- a/compiler/luci-interpreter/src/loader/nodes/DepthwiseConv2D.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/DepthwiseConv2D.cpp @@ -25,9 +25,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleDepthwiseConv2D(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleDepthwiseConv2D *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleDepthwiseConv2D *>(circle_node); assert(node->arity() == 3); const Tensor *input = helper.getInputTensor(node->input()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Dequantize.cpp b/compiler/luci-interpreter/src/loader/nodes/Dequantize.cpp index 4aae56469..787322e9b 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Dequantize.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Dequantize.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleDequantize(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleDequantize *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleDequantize *>(circle_node); const Tensor *input = helper.getInputTensor(node->input()); Tensor *output = helper.getOutputTensor(node); diff --git a/compiler/luci-interpreter/src/loader/nodes/Div.cpp b/compiler/luci-interpreter/src/loader/nodes/Div.cpp index 56c2e98f2..0611dfdab 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Div.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Div.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleDiv(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleDiv *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleDiv *>(circle_node); assert(node->arity() == 2); const Tensor *input1 = helper.getInputTensor(node->x()); const Tensor *input2 = helper.getInputTensor(node->y()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Elu.cpp b/compiler/luci-interpreter/src/loader/nodes/Elu.cpp index 98ee78be7..a79985e3b 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Elu.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Elu.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleElu(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleElu *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleElu *>(circle_node); assert(node->arity() == 1); const Tensor *input = helper.getInputTensor(node->features()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Equal.cpp b/compiler/luci-interpreter/src/loader/nodes/Equal.cpp index 649d9bfe9..59692883f 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Equal.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Equal.cpp @@ -25,9 +25,7 @@ std::unique_ptr<Kernel> build_kernel_CircleEqual(const luci::CircleNode *circle_ KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleEqual *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleEqual *>(circle_node); assert(node->arity() == 2); const Tensor *x = helper.getInputTensor(node->x()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Exp.cpp b/compiler/luci-interpreter/src/loader/nodes/Exp.cpp index 411d142c3..30d11cb89 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Exp.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Exp.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleExp(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleExp *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleExp *>(circle_node); assert(node->arity() == 1); const Tensor *input = helper.getInputTensor(node->x()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Fill.cpp b/compiler/luci-interpreter/src/loader/nodes/Fill.cpp new file mode 100644 index 000000000..3aefdf1c5 --- /dev/null +++ b/compiler/luci-interpreter/src/loader/nodes/Fill.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022 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 "Builders.h" + +#include "kernels/Fill.h" + +namespace luci_interpreter +{ + +std::unique_ptr<Kernel> build_kernel_CircleFill(const luci::CircleNode *circle_node, + KernelBuilderHelper &helper) +{ + const auto *node = loco::must_cast<const luci::CircleFill *>(circle_node); + assert(node->arity() == 2); + + const auto dims = helper.getInputTensor(node->dims()); + const auto value = helper.getInputTensor(node->value()); + auto output = helper.getOutputTensor(node); + + return std::make_unique<kernels::Fill>(dims, value, output); +} + +} // namespace luci_interpreter diff --git a/compiler/luci-interpreter/src/loader/nodes/Floor.cpp b/compiler/luci-interpreter/src/loader/nodes/Floor.cpp index 6d8435f6c..e0a223116 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Floor.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Floor.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleFloor(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleFloor *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleFloor *>(circle_node); assert(node->arity() == 1); const Tensor *input = helper.getInputTensor(node->x()); diff --git a/compiler/luci-interpreter/src/loader/nodes/FloorDiv.cpp b/compiler/luci-interpreter/src/loader/nodes/FloorDiv.cpp index cae2e186e..a45d89e38 100644 --- a/compiler/luci-interpreter/src/loader/nodes/FloorDiv.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/FloorDiv.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleFloorDiv(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleFloorDiv *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleFloorDiv *>(circle_node); assert(node->arity() == 2); const Tensor *x = helper.getInputTensor(node->x()); diff --git a/compiler/luci-interpreter/src/loader/nodes/FullyConnected.cpp b/compiler/luci-interpreter/src/loader/nodes/FullyConnected.cpp index 0b8ac44bd..b7b742b8a 100644 --- a/compiler/luci-interpreter/src/loader/nodes/FullyConnected.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/FullyConnected.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleFullyConnected(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleFullyConnected *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleFullyConnected *>(circle_node); assert(node->arity() == 3); const Tensor *input = helper.getInputTensor(node->input()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Gather.cpp b/compiler/luci-interpreter/src/loader/nodes/Gather.cpp index 9df9775c5..2ee2906e0 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Gather.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Gather.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleGather(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleGather *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleGather *>(circle_node); assert(node->arity() == 2); const Tensor *params = helper.getInputTensor(node->params()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Greater.cpp b/compiler/luci-interpreter/src/loader/nodes/Greater.cpp index 3db11b840..80aa63cf0 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Greater.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Greater.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleGreater(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleGreater *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleGreater *>(circle_node); assert(node->arity() == 2); const Tensor *x = helper.getInputTensor(node->x()); diff --git a/compiler/luci-interpreter/src/loader/nodes/GreaterEqual.cpp b/compiler/luci-interpreter/src/loader/nodes/GreaterEqual.cpp index dbe051d67..272f2843b 100644 --- a/compiler/luci-interpreter/src/loader/nodes/GreaterEqual.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/GreaterEqual.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleGreaterEqual(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleGreaterEqual *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleGreaterEqual *>(circle_node); assert(node->arity() == 2); const Tensor *x = helper.getInputTensor(node->x()); diff --git a/compiler/luci-interpreter/src/loader/nodes/If.cpp b/compiler/luci-interpreter/src/loader/nodes/If.cpp index 5983f4d3b..3ac7d4941 100644 --- a/compiler/luci-interpreter/src/loader/nodes/If.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/If.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleIf(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleIf *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleIf *>(circle_node); auto output_nodes = collectOutputNodes<luci::CircleIfOut>(node); assert(node->arity() == 1 + node->input_count()); assert(output_nodes.size() == static_cast<size_t>(node->output_count())); diff --git a/compiler/luci-interpreter/src/loader/nodes/InstanceNorm.cpp b/compiler/luci-interpreter/src/loader/nodes/InstanceNorm.cpp index 0a8fb85e2..06031e5bc 100644 --- a/compiler/luci-interpreter/src/loader/nodes/InstanceNorm.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/InstanceNorm.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleInstanceNorm(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleInstanceNorm *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleInstanceNorm *>(circle_node); assert(node->arity() == 3); const Tensor *input = helper.getInputTensor(node->input()); diff --git a/compiler/luci-interpreter/src/loader/nodes/L2Normalize.cpp b/compiler/luci-interpreter/src/loader/nodes/L2Normalize.cpp index 05f920266..6e22e6d4e 100644 --- a/compiler/luci-interpreter/src/loader/nodes/L2Normalize.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/L2Normalize.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleL2Normalize(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleL2Normalize *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleL2Normalize *>(circle_node); assert(node->arity() == 1); const Tensor *input = helper.getInputTensor(node->x()); diff --git a/compiler/luci-interpreter/src/loader/nodes/L2Pool2D.cpp b/compiler/luci-interpreter/src/loader/nodes/L2Pool2D.cpp index 0e70afafa..95b55896f 100644 --- a/compiler/luci-interpreter/src/loader/nodes/L2Pool2D.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/L2Pool2D.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleL2Pool2D(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleL2Pool2D *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleL2Pool2D *>(circle_node); assert(node->arity() == 1); const Tensor *input = helper.getInputTensor(node->value()); diff --git a/compiler/luci-interpreter/src/loader/nodes/LeakyRelu.cpp b/compiler/luci-interpreter/src/loader/nodes/LeakyRelu.cpp index 7b229ad0e..bbf5067b1 100644 --- a/compiler/luci-interpreter/src/loader/nodes/LeakyRelu.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/LeakyRelu.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleLeakyRelu(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleLeakyRelu *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleLeakyRelu *>(circle_node); assert(node->arity() == 1); const Tensor *input = helper.getInputTensor(node->features()); Tensor *output = helper.getOutputTensor(node); diff --git a/compiler/luci-interpreter/src/loader/nodes/Less.cpp b/compiler/luci-interpreter/src/loader/nodes/Less.cpp index 81156f275..ae914ecc9 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Less.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Less.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleLess(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleLess *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleLess *>(circle_node); assert(node->arity() == 2); const Tensor *x = helper.getInputTensor(node->x()); diff --git a/compiler/luci-interpreter/src/loader/nodes/LessEqual.cpp b/compiler/luci-interpreter/src/loader/nodes/LessEqual.cpp index 82141e5ae..f1b424b55 100644 --- a/compiler/luci-interpreter/src/loader/nodes/LessEqual.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/LessEqual.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleLessEqual(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleLessEqual *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleLessEqual *>(circle_node); assert(node->arity() == 2); const Tensor *x = helper.getInputTensor(node->x()); diff --git a/compiler/luci-interpreter/src/loader/nodes/LocalResponseNormalization.cpp b/compiler/luci-interpreter/src/loader/nodes/LocalResponseNormalization.cpp index a12dce0a0..962ca2d7c 100644 --- a/compiler/luci-interpreter/src/loader/nodes/LocalResponseNormalization.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/LocalResponseNormalization.cpp @@ -25,9 +25,7 @@ std::unique_ptr<Kernel> build_kernel_CircleLocalResponseNormalization(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleLocalResponseNormalization *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleLocalResponseNormalization *>(circle_node); assert(node->arity() == 1); const Tensor *input = helper.getInputTensor(node->input()); Tensor *output = helper.getOutputTensor(node); diff --git a/compiler/luci-interpreter/src/loader/nodes/LogSoftmax.cpp b/compiler/luci-interpreter/src/loader/nodes/LogSoftmax.cpp index 6cf547aae..432204115 100644 --- a/compiler/luci-interpreter/src/loader/nodes/LogSoftmax.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/LogSoftmax.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleLogSoftmax(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleLogSoftmax *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleLogSoftmax *>(circle_node); assert(node->arity() == 1); const Tensor *input = helper.getInputTensor(node->logits()); diff --git a/compiler/luci-interpreter/src/loader/nodes/LogicalAnd.cpp b/compiler/luci-interpreter/src/loader/nodes/LogicalAnd.cpp index 2c9549f71..bf3cb671a 100644 --- a/compiler/luci-interpreter/src/loader/nodes/LogicalAnd.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/LogicalAnd.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleLogicalAnd(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleLogicalAnd *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleLogicalAnd *>(circle_node); assert(node->arity() == 2); const Tensor *input1 = helper.getInputTensor(node->x()); diff --git a/compiler/luci-interpreter/src/loader/nodes/LogicalNot.cpp b/compiler/luci-interpreter/src/loader/nodes/LogicalNot.cpp index 3d327d6c4..fefcd9a06 100644 --- a/compiler/luci-interpreter/src/loader/nodes/LogicalNot.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/LogicalNot.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleLogicalNot(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleLogicalNot *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleLogicalNot *>(circle_node); assert(node->arity() == 1); const Tensor *input = helper.getInputTensor(node->x()); diff --git a/compiler/luci-interpreter/src/loader/nodes/LogicalOr.cpp b/compiler/luci-interpreter/src/loader/nodes/LogicalOr.cpp index 50566bb30..a416cb401 100644 --- a/compiler/luci-interpreter/src/loader/nodes/LogicalOr.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/LogicalOr.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleLogicalOr(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleLogicalOr *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleLogicalOr *>(circle_node); assert(node->arity() == 2); const Tensor *input1 = helper.getInputTensor(node->x()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Logistic.cpp b/compiler/luci-interpreter/src/loader/nodes/Logistic.cpp index e4160edb3..4a69deef1 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Logistic.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Logistic.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleLogistic(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleLogistic *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleLogistic *>(circle_node); assert(node->arity() == 1); const Tensor *input = helper.getInputTensor(node->x()); diff --git a/compiler/luci-interpreter/src/loader/nodes/MaxPool2D.cpp b/compiler/luci-interpreter/src/loader/nodes/MaxPool2D.cpp index 914f22838..f66a206ca 100644 --- a/compiler/luci-interpreter/src/loader/nodes/MaxPool2D.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/MaxPool2D.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleMaxPool2D(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleMaxPool2D *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleMaxPool2D *>(circle_node); assert(node->arity() == 1); const Tensor *input = helper.getInputTensor(node->value()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Maximum.cpp b/compiler/luci-interpreter/src/loader/nodes/Maximum.cpp index dc50d6773..d0bff776a 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Maximum.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Maximum.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleMaximum(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleMaximum *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleMaximum *>(circle_node); assert(node->arity() == 2); const Tensor *input1 = helper.getInputTensor(node->x()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Mean.cpp b/compiler/luci-interpreter/src/loader/nodes/Mean.cpp index 97d91207f..0dec63e79 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Mean.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Mean.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleMean(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleMean *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleMean *>(circle_node); assert(node->arity() == 2); const Tensor *input = helper.getInputTensor(node->input()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Minimum.cpp b/compiler/luci-interpreter/src/loader/nodes/Minimum.cpp index ff659524a..1a49c1090 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Minimum.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Minimum.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleMinimum(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleMinimum *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleMinimum *>(circle_node); assert(node->arity() == 2); const Tensor *input1 = helper.getInputTensor(node->x()); diff --git a/compiler/luci-interpreter/src/loader/nodes/MirrorPad.cpp b/compiler/luci-interpreter/src/loader/nodes/MirrorPad.cpp index ebf294583..b221b4574 100644 --- a/compiler/luci-interpreter/src/loader/nodes/MirrorPad.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/MirrorPad.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleMirrorPad(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleMirrorPad *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleMirrorPad *>(circle_node); assert(node->arity() == 2); const Tensor *input = helper.getInputTensor(node->input()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Mul.cpp b/compiler/luci-interpreter/src/loader/nodes/Mul.cpp index 4f9da967d..f9984853a 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Mul.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Mul.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleMul(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleMul *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleMul *>(circle_node); assert(node->arity() == 2); const Tensor *input1 = helper.getInputTensor(node->x()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Neg.cpp b/compiler/luci-interpreter/src/loader/nodes/Neg.cpp index 23c00537b..9a9ecf991 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Neg.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Neg.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleNeg(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleNeg *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleNeg *>(circle_node); assert(node->arity() == 1); const Tensor *input = helper.getInputTensor(node->x()); diff --git a/compiler/luci-interpreter/src/loader/nodes/NotEqual.cpp b/compiler/luci-interpreter/src/loader/nodes/NotEqual.cpp index 8e5711fc1..3916a5854 100644 --- a/compiler/luci-interpreter/src/loader/nodes/NotEqual.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/NotEqual.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleNotEqual(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleNotEqual *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleNotEqual *>(circle_node); assert(node->arity() == 2); const Tensor *x = helper.getInputTensor(node->x()); diff --git a/compiler/luci-interpreter/src/loader/nodes/PRelu.cpp b/compiler/luci-interpreter/src/loader/nodes/PRelu.cpp index e31601bf6..f3d700c95 100644 --- a/compiler/luci-interpreter/src/loader/nodes/PRelu.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/PRelu.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CirclePRelu(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CirclePRelu *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CirclePRelu *>(circle_node); assert(node->arity() == 2); const Tensor *input = helper.getInputTensor(node->input()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Pack.cpp b/compiler/luci-interpreter/src/loader/nodes/Pack.cpp index 699472081..efc5850e0 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Pack.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Pack.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CirclePack(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CirclePack *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CirclePack *>(circle_node); assert(node->arity() == node->values_count()); std::vector<const Tensor *> inputs(node->values_count()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Pad.cpp b/compiler/luci-interpreter/src/loader/nodes/Pad.cpp index 770549295..67ce997a7 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Pad.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Pad.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CirclePad(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CirclePad *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CirclePad *>(circle_node); assert(node->arity() == 2); const Tensor *input = helper.getInputTensor(node->input()); diff --git a/compiler/luci-interpreter/src/loader/nodes/PadV2.cpp b/compiler/luci-interpreter/src/loader/nodes/PadV2.cpp index 12deb15f0..e378a972a 100644 --- a/compiler/luci-interpreter/src/loader/nodes/PadV2.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/PadV2.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CirclePadV2(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CirclePadV2 *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CirclePadV2 *>(circle_node); assert(node->arity() == 3); const Tensor *input = helper.getInputTensor(node->input()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Pow.cpp b/compiler/luci-interpreter/src/loader/nodes/Pow.cpp index b430bc94f..d32fc3dbb 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Pow.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Pow.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CirclePow(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CirclePow *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CirclePow *>(circle_node); assert(node->arity() == 2); const Tensor *input1 = helper.getInputTensor(node->x()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Quantize.cpp b/compiler/luci-interpreter/src/loader/nodes/Quantize.cpp index fd9836345..cb36fb6da 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Quantize.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Quantize.cpp @@ -24,9 +24,8 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleQuantize(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleQuantize *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleQuantize *>(circle_node); + assert(node->arity() == 1); const Tensor *input = helper.getInputTensor(node->input()); Tensor *output = helper.getOutputTensor(node); diff --git a/compiler/luci-interpreter/src/loader/nodes/ReduceMax.cpp b/compiler/luci-interpreter/src/loader/nodes/ReduceMax.cpp new file mode 100644 index 000000000..1a8522dd6 --- /dev/null +++ b/compiler/luci-interpreter/src/loader/nodes/ReduceMax.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2022 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 "Builders.h" + +#include "kernels/ReduceMax.h" + +namespace luci_interpreter +{ + +std::unique_ptr<Kernel> build_kernel_CircleReduceMax(const luci::CircleNode *circle_node, + KernelBuilderHelper &helper) +{ + const auto *node = loco::must_cast<const luci::CircleReduceMax *>(circle_node); + assert(node->arity() == 2); + + const Tensor *input = helper.getInputTensor(node->input()); + const Tensor *axes = helper.getInputTensor(node->reduction_indices()); + Tensor *output = helper.getOutputTensor(node); + + auto temp_index_unique = + std::make_unique<Tensor>(DataType::S32, Shape({}), AffineQuantization{}, ""); + temp_index_unique->set_observable(false); + temp_index_unique->set_data_buffer(nullptr); + Tensor *temp_index = + helper.getRuntimeGraph(node->graph())->addTensor(std::move(temp_index_unique)); + + auto resolved_axes_unique = + std::make_unique<Tensor>(DataType::S32, Shape({}), AffineQuantization{}, ""); + resolved_axes_unique->set_observable(false); + resolved_axes_unique->set_data_buffer(nullptr); + Tensor *resolved_axes = + helper.getRuntimeGraph(node->graph())->addTensor(std::move(resolved_axes_unique)); + + ReducerParams params{}; + params.keep_dims = node->keep_dims(); + + return std::make_unique<kernels::ReduceMax>(input, axes, output, temp_index, resolved_axes, + params); +} + +} // namespace luci_interpreter diff --git a/compiler/luci-interpreter/src/loader/nodes/Relu.cpp b/compiler/luci-interpreter/src/loader/nodes/Relu.cpp index d53a66a06..1d64c1c4e 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Relu.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Relu.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleRelu(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleRelu *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleRelu *>(circle_node); assert(node->arity() == 1); const Tensor *input = helper.getInputTensor(node->features()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Relu6.cpp b/compiler/luci-interpreter/src/loader/nodes/Relu6.cpp index f1b5d219b..e50cd2545 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Relu6.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Relu6.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleRelu6(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleRelu6 *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleRelu6 *>(circle_node); assert(node->arity() == 1); const Tensor *input = helper.getInputTensor(node->features()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Reshape.cpp b/compiler/luci-interpreter/src/loader/nodes/Reshape.cpp index 89e3ecebf..76ddd88a3 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Reshape.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Reshape.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleReshape(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleReshape *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleReshape *>(circle_node); assert(node->arity() == 2); const Tensor *input = helper.getInputTensor(node->tensor()); diff --git a/compiler/luci-interpreter/src/loader/nodes/ResizeBilinear.cpp b/compiler/luci-interpreter/src/loader/nodes/ResizeBilinear.cpp index dca56588d..dc2b88ad3 100644 --- a/compiler/luci-interpreter/src/loader/nodes/ResizeBilinear.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/ResizeBilinear.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleResizeBilinear(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleResizeBilinear *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleResizeBilinear *>(circle_node); assert(node->arity() == 2); const Tensor *input = helper.getInputTensor(node->input()); diff --git a/compiler/luci-interpreter/src/loader/nodes/ResizeNearestNeighbor.cpp b/compiler/luci-interpreter/src/loader/nodes/ResizeNearestNeighbor.cpp index d1ea19c0f..c7058ae78 100644 --- a/compiler/luci-interpreter/src/loader/nodes/ResizeNearestNeighbor.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/ResizeNearestNeighbor.cpp @@ -25,9 +25,7 @@ std::unique_ptr<Kernel> build_kernel_CircleResizeNearestNeighbor(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleResizeNearestNeighbor *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleResizeNearestNeighbor *>(circle_node); assert(node->arity() == 2); const Tensor *input = helper.getInputTensor(node->input()); diff --git a/compiler/luci-interpreter/src/loader/nodes/ReverseV2.cpp b/compiler/luci-interpreter/src/loader/nodes/ReverseV2.cpp index ea00f5408..c1a7f5350 100644 --- a/compiler/luci-interpreter/src/loader/nodes/ReverseV2.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/ReverseV2.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleReverseV2(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleReverseV2 *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleReverseV2 *>(circle_node); assert(node->arity() == 2); const Tensor *input = helper.getInputTensor(node->tensor()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Rsqrt.cpp b/compiler/luci-interpreter/src/loader/nodes/Rsqrt.cpp index ff87f435c..0714a5dba 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Rsqrt.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Rsqrt.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleRsqrt(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleRsqrt *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleRsqrt *>(circle_node); assert(node->arity() == 1); const Tensor *input = helper.getInputTensor(node->x()); diff --git a/compiler/luci-interpreter/src/loader/nodes/SVDF.cpp b/compiler/luci-interpreter/src/loader/nodes/SVDF.cpp index 89528d5ee..d172ef438 100644 --- a/compiler/luci-interpreter/src/loader/nodes/SVDF.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/SVDF.cpp @@ -24,9 +24,8 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleSVDF(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleSVDF *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleSVDF *>(circle_node); + assert(node->arity() == 5); const Tensor *input = helper.getInputTensor(node->input()); const Tensor *feature = helper.getInputTensor(node->weight_feature()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Shape.cpp b/compiler/luci-interpreter/src/loader/nodes/Shape.cpp new file mode 100644 index 000000000..d1edbc794 --- /dev/null +++ b/compiler/luci-interpreter/src/loader/nodes/Shape.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2022 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 "Builders.h" + +#include "kernels/Shape.h" + +namespace luci_interpreter +{ + +std::unique_ptr<Kernel> build_kernel_CircleShape(const luci::CircleNode *circle_node, + KernelBuilderHelper &helper) +{ + const auto *node = loco::must_cast<const luci::CircleShape *>(circle_node); + assert(node->arity() == 1); + + const auto input = helper.getInputTensor(node->input()); + auto output = helper.getOutputTensor(node); + + ShapeParams shape_params{}; + shape_params.out_type = node->out_type(); + + return std::make_unique<kernels::ShapeKernel>(input, output, shape_params); +} + +} // namespace luci_interpreter diff --git a/compiler/luci-interpreter/src/loader/nodes/Slice.cpp b/compiler/luci-interpreter/src/loader/nodes/Slice.cpp index 741cd0806..60ac6417c 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Slice.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Slice.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleSlice(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleSlice *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleSlice *>(circle_node); assert(node->arity() == 3); const Tensor *input = helper.getInputTensor(node->input()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Softmax.cpp b/compiler/luci-interpreter/src/loader/nodes/Softmax.cpp index b15e4b6f3..f41f63f6f 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Softmax.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Softmax.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleSoftmax(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleSoftmax *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleSoftmax *>(circle_node); assert(node->arity() == 1); const Tensor *input = helper.getInputTensor(node->logits()); diff --git a/compiler/luci-interpreter/src/loader/nodes/SpaceToBatchND.cpp b/compiler/luci-interpreter/src/loader/nodes/SpaceToBatchND.cpp index 91c237aa5..b6e6cf516 100644 --- a/compiler/luci-interpreter/src/loader/nodes/SpaceToBatchND.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/SpaceToBatchND.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleSpaceToBatchND(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleSpaceToBatchND *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleSpaceToBatchND *>(circle_node); assert(node->arity() == 3); const Tensor *input = helper.getInputTensor(node->input()); diff --git a/compiler/luci-interpreter/src/loader/nodes/SpaceToDepth.cpp b/compiler/luci-interpreter/src/loader/nodes/SpaceToDepth.cpp index 3cbbd9718..63fdb95ec 100644 --- a/compiler/luci-interpreter/src/loader/nodes/SpaceToDepth.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/SpaceToDepth.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleSpaceToDepth(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleSpaceToDepth *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleSpaceToDepth *>(circle_node); assert(node->arity() == 1); const Tensor *input = helper.getInputTensor(node->input()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Split.cpp b/compiler/luci-interpreter/src/loader/nodes/Split.cpp index 32553ad5e..3f6d4a7df 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Split.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Split.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleSplit(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleSplit *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleSplit *>(circle_node); auto output_nodes = collectOutputNodes<luci::CircleSplitOut>(node); assert(node->arity() == 2); assert(output_nodes.size() == static_cast<size_t>(node->num_split())); diff --git a/compiler/luci-interpreter/src/loader/nodes/SplitV.cpp b/compiler/luci-interpreter/src/loader/nodes/SplitV.cpp index d78816447..0788822ca 100644 --- a/compiler/luci-interpreter/src/loader/nodes/SplitV.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/SplitV.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleSplitV(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleSplitV *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleSplitV *>(circle_node); auto output_nodes = collectOutputNodes<luci::CircleSplitVOut>(node); assert(node->arity() == 3); assert(output_nodes.size() == static_cast<size_t>(node->num_split())); diff --git a/compiler/luci-interpreter/src/loader/nodes/Sqrt.cpp b/compiler/luci-interpreter/src/loader/nodes/Sqrt.cpp index 56dd986f1..b9843fe0b 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Sqrt.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Sqrt.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleSqrt(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleSqrt *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleSqrt *>(circle_node); assert(node->arity() == 1); const Tensor *input = helper.getInputTensor(node->x()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Square.cpp b/compiler/luci-interpreter/src/loader/nodes/Square.cpp index 43aadb969..0ad7c1772 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Square.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Square.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleSquare(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleSquare *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleSquare *>(circle_node); assert(node->arity() == 1); const Tensor *input = helper.getInputTensor(node->x()); diff --git a/compiler/luci-interpreter/src/loader/nodes/SquaredDifference.cpp b/compiler/luci-interpreter/src/loader/nodes/SquaredDifference.cpp index 6a2717aa2..e4c6fd851 100644 --- a/compiler/luci-interpreter/src/loader/nodes/SquaredDifference.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/SquaredDifference.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleSquaredDifference(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleSquaredDifference *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleSquaredDifference *>(circle_node); assert(node->arity() == 2); const Tensor *input1 = helper.getInputTensor(node->x()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Squeeze.cpp b/compiler/luci-interpreter/src/loader/nodes/Squeeze.cpp index 583ff9314..6885f8077 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Squeeze.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Squeeze.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleSqueeze(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleSqueeze *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleSqueeze *>(circle_node); assert(node->arity() == 1); const Tensor *input = helper.getInputTensor(node->input()); diff --git a/compiler/luci-interpreter/src/loader/nodes/StridedSlice.cpp b/compiler/luci-interpreter/src/loader/nodes/StridedSlice.cpp index fe5fa7707..359b4e3e9 100644 --- a/compiler/luci-interpreter/src/loader/nodes/StridedSlice.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/StridedSlice.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleStridedSlice(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleStridedSlice *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleStridedSlice *>(circle_node); assert(node->arity() == 4); const Tensor *input = helper.getInputTensor(node->input()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Sub.cpp b/compiler/luci-interpreter/src/loader/nodes/Sub.cpp index bad4fbb13..a6252cb53 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Sub.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Sub.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleSub(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleSub *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleSub *>(circle_node); assert(node->arity() == 2); const Tensor *input1 = helper.getInputTensor(node->x()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Tanh.cpp b/compiler/luci-interpreter/src/loader/nodes/Tanh.cpp index f4255291b..a58ef60a8 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Tanh.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Tanh.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleTanh(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleTanh *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleTanh *>(circle_node); assert(node->arity() == 1); const Tensor *input = helper.getInputTensor(node->x()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Transpose.cpp b/compiler/luci-interpreter/src/loader/nodes/Transpose.cpp index 4e095fbbc..ea17d8311 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Transpose.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Transpose.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleTranspose(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleTranspose *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleTranspose *>(circle_node); assert(node->arity() == 2); const Tensor *input = helper.getInputTensor(node->a()); diff --git a/compiler/luci-interpreter/src/loader/nodes/TransposeConv.cpp b/compiler/luci-interpreter/src/loader/nodes/TransposeConv.cpp index 1b954c35c..d773e301e 100644 --- a/compiler/luci-interpreter/src/loader/nodes/TransposeConv.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/TransposeConv.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleTransposeConv(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleTransposeConv *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleTransposeConv *>(circle_node); assert(node->arity() == 4); const Tensor *input_sizes = helper.getInputTensor(node->inputSizes()); diff --git a/compiler/luci-interpreter/src/loader/nodes/Unpack.cpp b/compiler/luci-interpreter/src/loader/nodes/Unpack.cpp index 978c738c6..a1c0d323a 100644 --- a/compiler/luci-interpreter/src/loader/nodes/Unpack.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/Unpack.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleUnpack(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleUnpack *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleUnpack *>(circle_node); auto output_nodes = collectOutputNodes<luci::CircleUnpackOut>(node); assert(node->arity() == 1); assert(output_nodes.size() == static_cast<size_t>(node->num())); diff --git a/compiler/luci-interpreter/src/loader/nodes/While.cpp b/compiler/luci-interpreter/src/loader/nodes/While.cpp index 284dc0c68..8fde6ec8a 100644 --- a/compiler/luci-interpreter/src/loader/nodes/While.cpp +++ b/compiler/luci-interpreter/src/loader/nodes/While.cpp @@ -24,9 +24,7 @@ namespace luci_interpreter std::unique_ptr<Kernel> build_kernel_CircleWhile(const luci::CircleNode *circle_node, KernelBuilderHelper &helper) { - const auto *node = dynamic_cast<const luci::CircleWhile *>(circle_node); - if (node == nullptr) - throw std::runtime_error("wrong builder for operation"); + const auto *node = loco::must_cast<const luci::CircleWhile *>(circle_node); auto output_nodes = collectOutputNodes<luci::CircleWhileOut>(node); assert(node->arity() == node->input_count()); |