From 77727bd4ae023761197c5e2040c2a642eef0b2e2 Mon Sep 17 00:00:00 2001 From: YongHyun An Date: Thu, 18 Jan 2024 14:50:27 +0900 Subject: [PATCH 1/2] [onert] Introduce BinaryArithmetic trainable operation This commit introduces BinaryArithmetic train IR. Signed-off-by: YongHyun An --- .../include/ir/train/Operations.Include.h | 1 + .../core/include/ir/train/Operations.lst | 1 + .../ir/train/operation/BinaryArithmetic.h | 51 +++++++++++++++++++ .../train/TrainableOperationConverter.cc | 5 ++ .../train/TrainableOperationConverter.h | 1 + .../ir/train/operation/BinaryArithmetic.cc | 49 ++++++++++++++++++ 6 files changed, 108 insertions(+) create mode 100644 runtime/onert/core/include/ir/train/operation/BinaryArithmetic.h create mode 100644 runtime/onert/core/src/ir/train/operation/BinaryArithmetic.cc diff --git a/runtime/onert/core/include/ir/train/Operations.Include.h b/runtime/onert/core/include/ir/train/Operations.Include.h index e9b73bce51d..ab4366de716 100644 --- a/runtime/onert/core/include/ir/train/Operations.Include.h +++ b/runtime/onert/core/include/ir/train/Operations.Include.h @@ -17,6 +17,7 @@ #ifndef __ONERT_IR_TRAIN_OPERATIONS_OPERATION_INCLUDE_H__ #define __ONERT_IR_TRAIN_OPERATIONS_OPERATION_INCLUDE_H__ +#include "ir/train/operation/BinaryArithmetic.h" #include "ir/train/operation/Conv2D.h" #include "ir/train/operation/DepthwiseConv2D.h" #include "ir/train/operation/ElementwiseActivation.h" diff --git a/runtime/onert/core/include/ir/train/Operations.lst b/runtime/onert/core/include/ir/train/Operations.lst index 61443de1b4b..4abca04be9b 100644 --- a/runtime/onert/core/include/ir/train/Operations.lst +++ b/runtime/onert/core/include/ir/train/Operations.lst @@ -18,6 +18,7 @@ #error Define OP before including this file #endif +OP(BinaryArithmetic) OP(Conv2D) OP(DepthwiseConv2D) OP(ElementwiseActivation) diff --git a/runtime/onert/core/include/ir/train/operation/BinaryArithmetic.h b/runtime/onert/core/include/ir/train/operation/BinaryArithmetic.h new file mode 100644 index 00000000000..ee5d7767f43 --- /dev/null +++ b/runtime/onert/core/include/ir/train/operation/BinaryArithmetic.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 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 __ONERT_IR_TRAIN_OPERATION_BinaryArithmetic_H__ +#define __ONERT_IR_TRAIN_OPERATION_BinaryArithmetic_H__ + +#include "ir/operation/BinaryArithmetic.h" +#include "ir/train/ITrainableOperation.h" + +namespace onert +{ +namespace ir +{ +namespace train +{ +namespace operation +{ + +class BinaryArithmetic : public ir::operation::BinaryArithmetic, public ITrainableOperation +{ +private: + using OperationType = ir::operation::BinaryArithmetic; + +public: + BinaryArithmetic(const OperationType &operation); + +public: + std::unique_ptr clone() const override; + void accept(OperationVisitor &v) const override; + void accept(TrainableOperationVisitor &v) const override; +}; + +} // namespace operation +} // namespace train +} // namespace ir +} // namespace onert + +#endif // __ONERT_IR_TRAIN_OPERATION_BinaryArithmetic_H__ diff --git a/runtime/onert/core/src/compiler/train/TrainableOperationConverter.cc b/runtime/onert/core/src/compiler/train/TrainableOperationConverter.cc index 924b1663d47..e08ed7d9a90 100644 --- a/runtime/onert/core/src/compiler/train/TrainableOperationConverter.cc +++ b/runtime/onert/core/src/compiler/train/TrainableOperationConverter.cc @@ -34,6 +34,11 @@ TrainableOperationConverter::TrainableOperationConverter( UNUSED_RELEASE(_training_info); } +void TrainableOperationConverter::visit(const ir::operation::BinaryArithmetic &node) +{ + _return_op = std::make_unique(node); +} + void TrainableOperationConverter::visit(const ir::operation::Conv2D &node) { _return_op = std::make_unique(node); diff --git a/runtime/onert/core/src/compiler/train/TrainableOperationConverter.h b/runtime/onert/core/src/compiler/train/TrainableOperationConverter.h index 1d035c135d5..992185e51b0 100644 --- a/runtime/onert/core/src/compiler/train/TrainableOperationConverter.h +++ b/runtime/onert/core/src/compiler/train/TrainableOperationConverter.h @@ -37,6 +37,7 @@ class TrainableOperationConverter : public UntrainableOperationConverter using UntrainableOperationConverter::operator(); private: + void visit(const ir::operation::BinaryArithmetic &) override; void visit(const ir::operation::Conv2D &) override; void visit(const ir::operation::DepthwiseConv2D &) override; void visit(const ir::operation::ElementwiseActivation &) override; diff --git a/runtime/onert/core/src/ir/train/operation/BinaryArithmetic.cc b/runtime/onert/core/src/ir/train/operation/BinaryArithmetic.cc new file mode 100644 index 00000000000..473d3873569 --- /dev/null +++ b/runtime/onert/core/src/ir/train/operation/BinaryArithmetic.cc @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2024 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 "ir/train/operation/BinaryArithmetic.h" + +#include "ir/OperationVisitor.h" +#include "ir/train/TrainableOperationVisitor.h" + +namespace onert +{ +namespace ir +{ +namespace train +{ +namespace operation +{ + +std::unique_ptr BinaryArithmetic::clone() const +{ + return std::make_unique(*this); +} + +void BinaryArithmetic::accept(OperationVisitor &v) const { v.visit(*this); } + +void BinaryArithmetic::accept(TrainableOperationVisitor &v) const { v.visit(*this); } + +BinaryArithmetic::BinaryArithmetic(const OperationType &operation) + : OperationType{operation.getInputs(), operation.getOutputs(), operation.param()} +{ + // DO NOTHING +} + +} // namespace operation +} // namespace train +} // namespace ir +} // namespace onert From 3836e94ef3b0b0761fdb096f4cafaa5f94a29b0e Mon Sep 17 00:00:00 2001 From: Aeren <58352696+Aeren1564@users.noreply.github.com> Date: Mon, 22 Jan 2024 12:25:02 +0900 Subject: [PATCH 2/2] Update runtime/onert/core/include/ir/train/operation/BinaryArithmetic.h Co-authored-by: Jiyoung Giuliana Yun --- .../core/include/ir/train/operation/BinaryArithmetic.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/onert/core/include/ir/train/operation/BinaryArithmetic.h b/runtime/onert/core/include/ir/train/operation/BinaryArithmetic.h index ee5d7767f43..e24fd012828 100644 --- a/runtime/onert/core/include/ir/train/operation/BinaryArithmetic.h +++ b/runtime/onert/core/include/ir/train/operation/BinaryArithmetic.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __ONERT_IR_TRAIN_OPERATION_BinaryArithmetic_H__ -#define __ONERT_IR_TRAIN_OPERATION_BinaryArithmetic_H__ +#ifndef __ONERT_IR_TRAIN_OPERATION_BINARY_ARITHMETIC_H__ +#define __ONERT_IR_TRAIN_OPERATION_BINARY_ARITHMETIC_H__ #include "ir/operation/BinaryArithmetic.h" #include "ir/train/ITrainableOperation.h" @@ -48,4 +48,4 @@ class BinaryArithmetic : public ir::operation::BinaryArithmetic, public ITrainab } // namespace ir } // namespace onert -#endif // __ONERT_IR_TRAIN_OPERATION_BinaryArithmetic_H__ +#endif // __ONERT_IR_TRAIN_OPERATION_BINARY_ARITHMETIC_H__