From c101827542c4dbd22679083d682a3ead39e14281 Mon Sep 17 00:00:00 2001 From: Yongseop Kim Date: Thu, 25 Jan 2024 15:23:30 +0900 Subject: [PATCH] [onert/train] Introduce Pad operation (#12524) This commit introduces Pad operation in train. ONE-DCO-1.0-Signed-off-by: Yongseop Kim --- .../include/ir/train/Operations.Include.h | 1 + .../core/include/ir/train/Operations.lst | 1 + .../core/include/ir/train/operation/Pad.h | 51 +++++++++++++++++++ .../onert/core/src/ir/train/operation/Pad.cc | 46 +++++++++++++++++ 4 files changed, 99 insertions(+) create mode 100644 runtime/onert/core/include/ir/train/operation/Pad.h create mode 100644 runtime/onert/core/src/ir/train/operation/Pad.cc diff --git a/runtime/onert/core/include/ir/train/Operations.Include.h b/runtime/onert/core/include/ir/train/Operations.Include.h index ab4366de716..697c6b91637 100644 --- a/runtime/onert/core/include/ir/train/Operations.Include.h +++ b/runtime/onert/core/include/ir/train/Operations.Include.h @@ -23,6 +23,7 @@ #include "ir/train/operation/ElementwiseActivation.h" #include "ir/train/operation/FullyConnected.h" #include "ir/train/operation/Loss.h" +#include "ir/train/operation/Pad.h" #include "ir/train/operation/Permute.h" #include "ir/train/operation/Pool2D.h" #include "ir/train/operation/Reduce.h" diff --git a/runtime/onert/core/include/ir/train/Operations.lst b/runtime/onert/core/include/ir/train/Operations.lst index 4abca04be9b..4b07980313b 100644 --- a/runtime/onert/core/include/ir/train/Operations.lst +++ b/runtime/onert/core/include/ir/train/Operations.lst @@ -24,6 +24,7 @@ OP(DepthwiseConv2D) OP(ElementwiseActivation) OP(FullyConnected) OP(Loss) +OP(Pad) OP(Permute) OP(Pool2D) OP(Reduce) diff --git a/runtime/onert/core/include/ir/train/operation/Pad.h b/runtime/onert/core/include/ir/train/operation/Pad.h new file mode 100644 index 00000000000..452a171cdd0 --- /dev/null +++ b/runtime/onert/core/include/ir/train/operation/Pad.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_PAD_H__ +#define __ONERT_IR_TRAIN_OPERATION_PAD_H__ + +#include "ir/operation/Pad.h" +#include "ir/train/ITrainableOperation.h" + +namespace onert +{ +namespace ir +{ +namespace train +{ +namespace operation +{ + +class Pad : public ir::operation::Pad, public ITrainableOperation +{ +private: + using OperationType = ir::operation::Pad; + +public: + Pad(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_PAD_H__ diff --git a/runtime/onert/core/src/ir/train/operation/Pad.cc b/runtime/onert/core/src/ir/train/operation/Pad.cc new file mode 100644 index 00000000000..56394f5ef5b --- /dev/null +++ b/runtime/onert/core/src/ir/train/operation/Pad.cc @@ -0,0 +1,46 @@ +/* + * 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/Pad.h" + +#include "ir/OperationVisitor.h" +#include "ir/train/TrainableOperationVisitor.h" + +namespace onert +{ +namespace ir +{ +namespace train +{ +namespace operation +{ + +std::unique_ptr Pad::clone() const { return std::make_unique(*this); } + +void Pad::accept(OperationVisitor &v) const { v.visit(*this); } + +void Pad::accept(TrainableOperationVisitor &v) const { v.visit(*this); } + +Pad::Pad(const OperationType &operation) + : OperationType{operation.getInputs(), operation.getOutputs()} +{ + // DO NOTHING +} + +} // namespace operation +} // namespace train +} // namespace ir +} // namespace onert