-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[onert] Implement RoPELayer in backend cpu
This commit implements RoPE Layer in backend cpu ONE-DCO-1.0-Signed-off-by: youngsik kim <[email protected]>
- Loading branch information
Showing
6 changed files
with
202 additions
and
0 deletions.
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
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,92 @@ | ||
/* | ||
* 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 "RoPELayer.h" | ||
|
||
#include <cker/operation/RoPE.h> | ||
|
||
namespace onert | ||
{ | ||
namespace backend | ||
{ | ||
namespace cpu | ||
{ | ||
namespace ops | ||
{ | ||
|
||
RoPELayer::RoPELayer() | ||
: _input(nullptr), _sin(nullptr), _cos(nullptr), _mode(nnfw::cker::RoPEMode::kGptNeox), | ||
_output(nullptr) | ||
{ | ||
// DO NOTHING | ||
} | ||
|
||
RoPELayer::~RoPELayer() = default; | ||
|
||
void RoPELayer::configure(const IPortableTensor *input, const IPortableTensor *sin, | ||
const IPortableTensor *cos, nnfw::cker::RoPEMode mode, | ||
IPortableTensor *output) | ||
{ | ||
assert(input != nullptr); | ||
assert(sin != nullptr); | ||
assert(cos != nullptr); | ||
assert(output != nullptr); | ||
|
||
_input = input; | ||
_sin = sin; | ||
_cos = cos; | ||
_mode = mode; | ||
_output = output; | ||
} | ||
|
||
template <typename T> void RoPELayer::rope() | ||
{ | ||
auto input_shape = _input->getShape(); | ||
assert(input_shape.rank() == 4); | ||
|
||
nnfw::cker::RoPE(_mode, getShape(_input), getBuffer<T>(_input), getShape(_sin), | ||
getBuffer<T>(_sin), getShape(_cos), getBuffer<T>(_cos), getShape(_output), | ||
getBuffer<T>(_output)); | ||
} | ||
|
||
void RoPELayer::run() | ||
{ | ||
switch (_input->data_type()) | ||
{ | ||
case OperandType::FLOAT32: | ||
rope<float>(); | ||
break; | ||
case OperandType::INT32: | ||
rope<int32_t>(); | ||
break; | ||
case OperandType::INT64: | ||
rope<int64_t>(); | ||
break; | ||
case OperandType::QUANT_UINT8_ASYMM: | ||
rope<uint8_t>(); | ||
break; | ||
case OperandType::QUANT_INT8_ASYMM: | ||
rope<int8_t>(); | ||
break; | ||
default: | ||
throw std::runtime_error("RoPE: unsupported data type"); | ||
} | ||
} | ||
|
||
} // namespace ops | ||
} // namespace cpu | ||
} // 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,71 @@ | ||
/* | ||
* 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_CPU_OPS_ROPE_LAYER_H__ | ||
#define __ONERT_BACKEND_CPU_OPS_ROPE_LAYER_H__ | ||
|
||
#include <backend/IPortableTensor.h> | ||
#include "OperationUtils.h" | ||
|
||
#include <exec/IFunction.h> | ||
|
||
namespace nnfw | ||
{ | ||
namespace cker | ||
{ | ||
class RoPE; | ||
} | ||
} // namespace nnfw | ||
|
||
namespace onert | ||
{ | ||
namespace backend | ||
{ | ||
namespace cpu | ||
{ | ||
namespace ops | ||
{ | ||
|
||
class RoPELayer : public ::onert::exec::IFunction | ||
{ | ||
public: | ||
RoPELayer(); | ||
~RoPELayer(); | ||
|
||
public: | ||
template <typename T> void rope(); | ||
|
||
void configure(const IPortableTensor *input, const IPortableTensor *sin, | ||
const IPortableTensor *cos, const nnfw::cker::RoPEMode mode, | ||
IPortableTensor *output); | ||
|
||
void run() override; | ||
|
||
private: | ||
const IPortableTensor *_input; | ||
const IPortableTensor *_sin; | ||
const IPortableTensor *_cos; | ||
|
||
nnfw::cker::RoPEMode _mode; | ||
IPortableTensor *_output; | ||
}; | ||
|
||
} // namespace ops | ||
} // namespace cpu | ||
} // namespace backend | ||
} // namespace onert | ||
|
||
#endif // __ONERT_BACKEND_CPU_OPS_ROPE_LAYER_H__ |