forked from Samsung/ONE
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Draft][Onert] Add Fill operator to cpu backend (Samsung#791)
This pull request add "fill" operator to cpu backend. Signed-off-by: Leehansol <[email protected]>
- Loading branch information
Showing
22 changed files
with
385 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved | ||
* Copyright 2018 The TensorFlow Authors. 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 __NNFW_CKER_FILL_H__ | ||
#define __NNFW_CKER_FILL_H__ | ||
|
||
#include "cker/Shape.h" | ||
|
||
namespace nnfw | ||
{ | ||
namespace cker | ||
{ | ||
template <typename T> | ||
inline void Fill(const Shape &input_shape, int *input_data, const T value_data, | ||
const Shape &output_shape, T output_data) | ||
{ | ||
int input_size = input_shape.FlatSize(); | ||
int output_size = 1; | ||
for (int i = 0; i < input_size; i++) | ||
{ | ||
output_size *= input_data[i]; | ||
} | ||
|
||
if (output_size == output_shape.FlatSize()) | ||
{ | ||
for (int i = 0; i < output_size; i++) | ||
{ | ||
output_data[i] = *value_data; | ||
} | ||
} | ||
} | ||
|
||
} // namespace cker | ||
} // namespace nnfw | ||
|
||
#endif // __NNFW_CKER_FILL_H__ |
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,76 @@ | ||
/* | ||
* Copyright (c) 2020 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 "FillLayer.h" | ||
|
||
#include "OperationUtils.h" | ||
|
||
#include <cker/operation/Fill.h> | ||
|
||
namespace onert | ||
{ | ||
namespace backend | ||
{ | ||
namespace cpu | ||
{ | ||
namespace kernel | ||
{ | ||
|
||
FillLayer::FillLayer() : _input(nullptr), _value(nullptr), _output(nullptr) | ||
{ | ||
// DO NOTHING | ||
} | ||
|
||
void FillLayer::configure(const operand::Tensor *input, const operand::Tensor *value, | ||
operand::Tensor *output) | ||
{ | ||
_input = input; | ||
_value = value; | ||
_output = output; | ||
} | ||
|
||
void FillLayer::run() | ||
{ | ||
switch (_output->data_type()) | ||
{ | ||
case OperandType::FLOAT32: | ||
nnfw::cker::Fill<float *>( | ||
convertTensorToCkerShape(_input), reinterpret_cast<int *>(_input->buffer()), | ||
reinterpret_cast<float *>(_value->buffer()), convertTensorToCkerShape(_output), | ||
reinterpret_cast<float *>(_output->buffer())); | ||
break; | ||
case OperandType::INT32: | ||
nnfw::cker::Fill<int32_t *>( | ||
convertTensorToCkerShape(_input), reinterpret_cast<int *>(_input->buffer()), | ||
reinterpret_cast<int32_t *>(_value->buffer()), convertTensorToCkerShape(_output), | ||
reinterpret_cast<int32_t *>(_output->buffer())); | ||
break; | ||
case OperandType::UINT32: | ||
nnfw::cker::Fill<uint32_t *>( | ||
convertTensorToCkerShape(_input), reinterpret_cast<int *>(_input->buffer()), | ||
reinterpret_cast<uint32_t *>(_value->buffer()), convertTensorToCkerShape(_output), | ||
reinterpret_cast<uint32_t *>(_output->buffer())); | ||
break; | ||
default: | ||
throw std::runtime_error{"Fill: unsupported data type"}; | ||
break; | ||
} | ||
} | ||
|
||
} // namespace kernel | ||
} // 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,60 @@ | ||
/* | ||
* Copyright (c) 2020 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 riting, 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_KERNEL_FILLLAYER_H__ | ||
#define __ONERT_BACKEND_CPU_KERNEL_FILLLAYER_H__ | ||
|
||
#include "../operand/Tensor.h" | ||
|
||
#include <exec/IFunction.h> | ||
|
||
namespace onert | ||
{ | ||
namespace backend | ||
{ | ||
namespace cpu | ||
{ | ||
namespace kernel | ||
{ | ||
|
||
class FillLayer : public ::onert::exec::IFunction | ||
{ | ||
public: | ||
FillLayer(); | ||
|
||
void configure(const operand::Tensor *input, const operand::Tensor *value, | ||
operand::Tensor *output); | ||
|
||
void run(); | ||
void runSync() | ||
{ | ||
// this abstract method is used just for profiling and called for | ||
// backend::acl_common::AclFunction | ||
run(); | ||
} | ||
|
||
private: | ||
const operand::Tensor *_input; | ||
const operand::Tensor *_value; | ||
operand::Tensor *_output; | ||
}; | ||
|
||
} // namespace kernel | ||
} // namespace cpu | ||
} // namespace backend | ||
} // namespace onert | ||
|
||
#endif // __ONERT_BACKEND_CPU_KERNEL_FILLLAYER_H__ |
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,50 @@ | ||
/* | ||
* Copyright (c) 2020 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_OPERATION_FILL_H__ | ||
#define __ONERT_IR_OPERATION_FILL_H__ | ||
|
||
#include "ir/Operation.h" | ||
|
||
namespace onert | ||
{ | ||
namespace ir | ||
{ | ||
namespace operation | ||
{ | ||
|
||
class Fill : public Operation | ||
{ | ||
public: | ||
enum Input | ||
{ | ||
INPUT = 0, | ||
VALUE, | ||
}; | ||
|
||
public: | ||
Fill(const OperandIndexSequence &inputs, const OperandIndexSequence &outputs); | ||
|
||
public: | ||
void accept(OperationVisitor &v) const override; | ||
OpCode opcode() const final { return OpCode::Fill; } | ||
}; | ||
|
||
} // namespace operation | ||
} // namespace ir | ||
} // namespace onert | ||
|
||
#endif // __ONERT_IR_OPERATION_FILL_H__ |
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,39 @@ | ||
/* | ||
* Copyright (c) 2020 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/operation/Fill.h" | ||
|
||
#include <cassert> | ||
|
||
#include "ir/OperationVisitor.h" | ||
|
||
namespace onert | ||
{ | ||
namespace ir | ||
{ | ||
namespace operation | ||
{ | ||
|
||
void Fill::accept(OperationVisitor &v) const { v.visit(*this); } | ||
|
||
Fill::Fill(const OperandIndexSequence &inputs, const OperandIndexSequence &outputs) | ||
: Operation{OperandConstraint::createExact(1u), inputs, outputs} | ||
{ | ||
} | ||
|
||
} // namespace operation | ||
} // namespace ir | ||
} // namespace onert |
Oops, something went wrong.