In https://github.sec.samsung.net/STAR/nnfw/pull/4738#discussion_r156180, we've discussed to group all operations in `::arm_compute::ComparisonOperation`.
This commit introduces `ComparisonNode` that includes operations in `::::arm_compute::ComparisonOperation` and intergrate `Equal` and `NotEqual` to `ComparisonNode`
`ComparisonNode` can be support below.
```
enum class ComparisonType
{
Equal,
NotEqual,
Greater,
GreaterEqual,
Less,
LessEqual
};
```
Signed-off-by: sjsujinkim <sjsujin.kim@samsung.com>
});
}
-void StageGenerator::visit(const model::operation::NotEqualNode &node)
+void StageGenerator::visit(const model::operation::ComparisonNode &node)
{
const auto output_index{node.getOutputs().at(0)};
- const auto input0_index{node.getInputs().at(model::operation::NotEqualNode::Input::INPUT0)};
- const auto input1_index{node.getInputs().at(model::operation::NotEqualNode::Input::INPUT1)};
+ const auto input0_index{node.getInputs().at(model::operation::ComparisonNode::Input::INPUT0)};
+ const auto input1_index{node.getInputs().at(model::operation::ComparisonNode::Input::INPUT1)};
if (!(_ctx.at(input0_index).shape() == _ctx.at(input1_index).shape()))
{
model::operand::Index output_index;
model::operand::Index input0_index;
model::operand::Index input1_index;
+
+ model::operation::ComparisonNode::ComparisonType comparison_type;
};
Param param;
param.input0_index = input0_index;
param.input1_index = input1_index;
+ param.comparison_type = node.param().comparison_type;
+
auto tensors = _tensor_builder;
returnStage([tensors, param](IExecutionBuilder &builder) {
auto l = make_layer<::arm_compute::CLComparison>();
l->configure(input0_alloc->handle(), input1_alloc->handle(), output_alloc->handle(),
- arm_compute::ComparisonOperation::NotEqual);
+ (arm_compute::ComparisonOperation)param.comparison_type);
fn = std::move(l);
});
}
-void StageGenerator::visit(const model::operation::EqualNode &node)
-{
- const auto output_index{node.getOutputs().at(0)};
- const auto input0_index{node.getInputs().at(model::operation::EqualNode::Input::INPUT0)};
- const auto input1_index{node.getInputs().at(model::operation::EqualNode::Input::INPUT1)};
-
- if (!(_ctx.at(input0_index).shape() == _ctx.at(input1_index).shape()))
- {
- const auto broadcast_rank =
- std::max(_ctx.at(input0_index).shape().rank(), _ctx.at(input1_index).shape().rank());
- const_cast<neurun::model::operand::Shape &>(_ctx.at(input0_index).shape())
- .extendRank(broadcast_rank);
- const_cast<neurun::model::operand::Shape &>(_ctx.at(input1_index).shape())
- .extendRank(broadcast_rank);
- }
-
- // Construct operation parameters
- struct Param
- {
- model::operand::Index output_index;
- model::operand::Index input0_index;
- model::operand::Index input1_index;
- };
-
- Param param;
-
- param.output_index = output_index;
- param.input0_index = input0_index;
- param.input1_index = input1_index;
-
- auto tensors = _tensor_builder;
-
- returnStage([tensors, param](IExecutionBuilder &builder) {
- auto output_alloc = tensors->at(param.output_index).get();
- auto input0_alloc = tensors->at(param.input0_index).get();
- auto input1_alloc = tensors->at(param.input1_index).get();
-
- std::unique_ptr<::arm_compute::IFunction> fn;
-
- auto l = make_layer<::arm_compute::CLComparison>();
-
- l->configure(input0_alloc->handle(), input1_alloc->handle(), output_alloc->handle(),
- ::arm_compute::ComparisonOperation::Equal);
-
- fn = std::move(l);
-
- auto acl_fn = make_cl_function(std::move(fn));
-
- builder.append(std::move(acl_fn));
- });
-}
-
void StageGenerator::visit(const model::operation::SquaredDifferenceNode &node)
{
const auto ofm_index{node.getOutputs().at(0)};
virtual void visit(const model::operation::ExpNode &) override;
virtual void visit(const model::operation::LogisticNode &) override;
virtual void visit(const model::operation::ReduceMaxNode &) override;
- virtual void visit(const model::operation::NotEqualNode &) override;
+ virtual void visit(const model::operation::ComparisonNode &) override;
virtual void visit(const model::operation::LogicalAndNode &) override;
virtual void visit(const model::operation::RSQRTNode &) override;
virtual void visit(const model::operation::ReLUNode &) override;
virtual void visit(const model::operation::SQRTNode &) override;
virtual void visit(const model::operation::LogicalOrNode &) override;
virtual void visit(const model::operation::LogicalNotNode &) override;
- virtual void visit(const model::operation::EqualNode &) override;
virtual void visit(const model::operation::SquaredDifferenceNode &) override;
virtual void visit(const model::operation::TopKV2Node &) override;
--- /dev/null
+/*
+ * 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_MODEL_OPERATION_COMPARISON_NODE_H__
+#define __NEURUN_MODEL_OPERATION_COMPARISON_NODE_H__
+
+#include "model/operation/Node.h"
+
+namespace neurun
+{
+namespace model
+{
+namespace operation
+{
+
+class ComparisonNode : public model::operation::Node
+{
+public:
+ enum Input
+ {
+ INPUT0 = 0,
+ INPUT1
+ };
+
+ enum class ComparisonType
+ {
+ Equal,
+ NotEqual,
+ Greater,
+ GreaterEqual,
+ Less,
+ LessEqual
+ };
+
+ struct Param
+ {
+ ComparisonType comparison_type;
+ };
+
+public:
+ ComparisonNode(const operand::IndexSet &inputs, const operand::IndexSet &outputs,
+ const Param ¶m);
+
+public:
+ virtual void accept(NodeVisitor &&) const override;
+ virtual std::string getName() const override { return "Comparison"; }
+
+public:
+ const Param ¶m() const { return _param; }
+
+private:
+ Param _param;
+};
+
+} // namespace operation
+} // namespace model
+} // namespace neurun
+
+#endif // __NEURUN_MODEL_OPERATION_COMPARISON_NODE_H__
+++ /dev/null
-/*
- * 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_MODEL_OPERATION_EQUAL_NODE_H__
-#define __NEURUN_MODEL_OPERATION_EQUAL_NODE_H__
-
-#include "model/operation/Node.h"
-
-namespace neurun
-{
-namespace model
-{
-namespace operation
-{
-
-class EqualNode : public model::operation::Node
-{
-public:
- enum Input
- {
- INPUT0 = 0,
- INPUT1 = 1
- };
-
-public:
- EqualNode(const operand::IndexSet &inputs, const operand::IndexSet &outputs);
-
-public:
- virtual void accept(NodeVisitor &&) const override;
- virtual std::string getName() const override { return "Equal"; }
-};
-
-} // namespace operation
-} // namespace model
-} // namespace neurun
-
-#endif // __NEURUN_MODEL_OPERATION_EQUAL_NODE_H__
#include "DivNode.h"
#include "ExpNode.h"
#include "ReduceMaxNode.h"
-#include "NotEqualNode.h"
-#include "EqualNode.h"
+#include "ComparisonNode.h"
#include "LogicalAndNode.h"
#include "LogicalOrNode.h"
#include "LogicalNotNode.h"
+++ /dev/null
-/*
- * 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_MODEL_OPERATION_NOT_EQUAL_NODE_H__
-#define __NEURUN_MODEL_OPERATION_NOT_EQUAL_NODE_H__
-
-#include "model/operation/Node.h"
-
-namespace neurun
-{
-namespace model
-{
-namespace operation
-{
-
-class NotEqualNode : public model::operation::Node
-{
-public:
- enum Input
- {
- INPUT0 = 0,
- INPUT1 = 1
- };
-
-public:
- NotEqualNode(const operand::IndexSet &inputs, const operand::IndexSet &outputs);
-
-public:
- virtual void accept(NodeVisitor &&) const override;
- virtual std::string getName() const override { return "NotEqual"; }
-};
-
-} // namespace operation
-} // namespace model
-} // namespace neurun
-
-#endif // __NEURUN_MODEL_OPERATION_NOT_EQUAL_NODE_H__
OP(TransposeNode , true)
OP(ExpNode , true)
OP(ReduceMaxNode , true)
-OP(NotEqualNode , true)
+OP(ComparisonNode , true)
OP(LogicalAndNode , true)
OP(LogicalOrNode , true)
OP(LogicalNotNode , true)
OP(PReLUNode , true)
OP(TransposeConvNode , true)
OP(SQRTNode , true)
-OP(EqualNode , true)
OP(SquaredDifferenceNode , true)
OP(TopKV2Node , true)
OP(PermuteNode , false)
--- /dev/null
+/*
+ * 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 "model/operation/ComparisonNode.h"
+
+#include <cassert>
+
+#include "model/operation/NodeVisitor.h"
+
+namespace neurun
+{
+namespace model
+{
+namespace operation
+{
+
+void ComparisonNode::accept(NodeVisitor &&v) const { v.visit(*this); }
+
+ComparisonNode::ComparisonNode(const operand::IndexSet &inputs, const operand::IndexSet &outputs,
+ const Param ¶m)
+ : model::operation::Node{OperandConstraint::createExact(2u), inputs, outputs}, _param{param}
+{
+}
+
+} // namespace operation
+} // namespace model
+} // namespace neurun
+++ /dev/null
-/*
- * 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 "model/operation/EqualNode.h"
-
-#include <cassert>
-
-#include "model/operation/NodeVisitor.h"
-
-namespace neurun
-{
-namespace model
-{
-namespace operation
-{
-
-void EqualNode::accept(NodeVisitor &&v) const { v.visit(*this); }
-
-EqualNode::EqualNode(const operand::IndexSet &inputs, const operand::IndexSet &outputs)
- : model::operation::Node{OperandConstraint::createExact(2u), inputs, outputs}
-{
-}
-
-} // namespace operation
-} // namespace model
-} // namespace neurun
+++ /dev/null
-/*
- * 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 "model/operation/NotEqualNode.h"
-
-#include <cassert>
-
-#include "model/operation/NodeVisitor.h"
-
-namespace neurun
-{
-namespace model
-{
-namespace operation
-{
-
-void NotEqualNode::accept(NodeVisitor &&v) const { v.visit(*this); }
-
-NotEqualNode::NotEqualNode(const operand::IndexSet &inputs, const operand::IndexSet &outputs)
- : model::operation::Node{OperandConstraint::createExact(2u), inputs, outputs}
-{
-}
-
-} // namespace operation
-} // namespace model
-} // namespace neurun
// 1 -> input2 Tensor Index
operand::IndexSet inputs{init_param.inputs[0], init_param.inputs[1]};
- return new operation::NotEqualNode{inputs, outputs};
+ operation::ComparisonNode::Param param;
+ param.comparison_type = operation::ComparisonNode::ComparisonType::NotEqual;
+
+ return new operation::ComparisonNode{inputs, outputs, param};
};
_map[ANEURALNETWORKS_LOGICAL_AND_EX] = [](const OperationFactory::Param &init_param) {
// 1 -> input1 Tensor Index
operand::IndexSet inputs{init_param.inputs[0], init_param.inputs[1]};
- return new operation::EqualNode{inputs, outputs};
+ operation::ComparisonNode::Param param;
+ param.comparison_type = operation::ComparisonNode::ComparisonType::Equal;
+
+ return new operation::ComparisonNode{inputs, outputs, param};
};
_map[ANEURALNETWORKS_SQUARED_DIFFERENCE_EX] = [](const OperationFactory::Param &init_param) {