-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[onert/train] Add PadLayer op to train backend #12535
Merged
chunseoklee
merged 4 commits into
Samsung:master
from
YongseopKim:pr/backend/train/ops/PadLayer
Jan 29, 2024
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* 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 "PadLayer.h" | ||
|
||
#include <cker/train/operation/Pad.h> | ||
|
||
namespace onert | ||
{ | ||
namespace backend | ||
{ | ||
namespace train | ||
{ | ||
namespace ops | ||
{ | ||
|
||
PadLayer::PadLayer() : cpu::ops::PadLayer(), _back_prop_input{nullptr}, _back_prop_output{nullptr} | ||
{ | ||
// DO NOTHING | ||
} | ||
|
||
template <typename T> void PadLayer::depad() | ||
{ | ||
nnfw::cker::train::Depad<T>(_padData, _padRank, getShape(_back_prop_output), | ||
getBuffer<T>(_back_prop_output), getShape(_back_prop_input), | ||
getBuffer<T>(_back_prop_input)); | ||
} | ||
|
||
void PadLayer::configure(const IPortableTensor *input, IPortableTensor *output, | ||
const int32_t *padData, int32_t padRank, const void *constantValueData, | ||
IPortableTensor *back_prop_input, const IPortableTensor *back_prop_output) | ||
{ | ||
cpu::ops::PadLayer::configure(input, output, padData, padRank, constantValueData); | ||
_back_prop_input = back_prop_input; | ||
_back_prop_output = back_prop_output; | ||
} | ||
|
||
void PadLayer::forward(bool) { cpu::ops::PadLayer::run(); } | ||
|
||
void PadLayer::backward() | ||
YongseopKim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
switch (_back_prop_output->data_type()) | ||
{ | ||
case OperandType::FLOAT32: | ||
depad<float>(); | ||
break; | ||
case OperandType::QUANT_UINT8_ASYMM: | ||
depad<uint8_t>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
break; | ||
case OperandType::QUANT_INT8_ASYMM: | ||
depad<int8_t>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto. 👍 |
||
break; | ||
default: | ||
throw std::runtime_error{"Pad: unsupported data type"}; | ||
} | ||
} | ||
|
||
} // namespace ops | ||
} // namespace train | ||
} // namespace backend | ||
} // namespace onert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* 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_BACKEND_TRAIN_OPS_PADLAYER_H__ | ||
#define __ONERT_BACKEND_TRAIN_OPS_PADLAYER_H__ | ||
|
||
#include <ops/PadLayer.h> | ||
#include <backend/IPortableTensor.h> | ||
#include "OperationUtils.h" | ||
|
||
#include <exec/train/ITrainableFunction.h> | ||
|
||
namespace onert | ||
{ | ||
namespace backend | ||
{ | ||
namespace train | ||
{ | ||
namespace ops | ||
{ | ||
|
||
// Note, this is pad with mode=`CONSTANT`: it doesn't support `REFLECT` and | ||
// `SYMMETRIC` | ||
class PadLayer : public ::onert::exec::train::ITrainableFunction, public cpu::ops::PadLayer | ||
{ | ||
public: | ||
PadLayer(); | ||
|
||
public: | ||
template <typename T> void depad(); | ||
|
||
void configure(const IPortableTensor *input, IPortableTensor *output, const int32_t *padData, | ||
int32_t padRank, const void *constantValueData, IPortableTensor *back_prop_input, | ||
const IPortableTensor *back_prop_output); | ||
void forward(bool training) override; | ||
void backward() override; | ||
|
||
private: | ||
IPortableTensor *_back_prop_input; | ||
const IPortableTensor *_back_prop_output; | ||
}; | ||
|
||
} // namespace ops | ||
} // namespace train | ||
} // namespace backend | ||
} // namespace onert | ||
|
||
#endif // __ONERT_BACKEND_TRAIN_OPS_PADLAYER_H__ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. You're right. I'll fix it.