-
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.
Merge branch 'master' into comparisons_kernels_onert_micro
- Loading branch information
Showing
48 changed files
with
2,594 additions
and
556 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (c) 2023 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 LUCI_INTERPRETER_PAL_HARDSWISH_H | ||
#define LUCI_INTERPRETER_PAL_HARDSWISH_H | ||
|
||
#include <tensorflow/lite/kernels/internal/optimized/optimized_ops.h> | ||
|
||
namespace luci_interpreter_pal | ||
{ | ||
static inline void HardSwish(const tflite::RuntimeShape &input_shape, const float *input_data, | ||
const tflite::RuntimeShape &output_shape, float *output_data) | ||
{ | ||
tflite::optimized_ops::HardSwish(input_shape, input_data, output_shape, output_data); | ||
} | ||
} // namespace luci_interpreter_pal | ||
|
||
#endif // LUCI_INTERPRETER_PAL_HARDSWISH_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) 2023 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 "kernels/HardSwish.h" | ||
#include "kernels/Utils.h" | ||
|
||
#include "PALHardSwish.h" | ||
|
||
#include <stdexcept> | ||
|
||
namespace luci_interpreter | ||
{ | ||
|
||
namespace kernels | ||
{ | ||
|
||
HardSwish::HardSwish(const Tensor *input, Tensor *output) : Kernel({input}, {output}) {} | ||
|
||
void HardSwish::configure() | ||
{ | ||
LUCI_INTERPRETER_CHECK(input()->element_type() == output()->element_type()); | ||
output()->resize(input()->shape()); | ||
} | ||
|
||
void HardSwish::execute() const | ||
{ | ||
switch (input()->element_type()) | ||
{ | ||
case DataType::FLOAT32: | ||
luci_interpreter_pal::HardSwish(getTensorShape(input()), getTensorData<float>(input()), | ||
getTensorShape(output()), getTensorData<float>(output())); | ||
break; | ||
default: | ||
throw std::runtime_error("Unsupported type."); | ||
} | ||
} | ||
|
||
} // namespace kernels | ||
} // namespace luci_interpreter |
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,81 @@ | ||
/* | ||
* Copyright (c) 2023 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 "kernels/HardSwish.h" | ||
#include "kernels/TestUtils.h" | ||
#include "luci_interpreter/TestMemoryManager.h" | ||
|
||
namespace luci_interpreter | ||
{ | ||
namespace kernels | ||
{ | ||
namespace | ||
{ | ||
|
||
using namespace testing; | ||
|
||
void Check(std::initializer_list<int32_t> input_shape, std::initializer_list<int32_t> output_shape, | ||
std::initializer_list<float> input_data, std::initializer_list<float> output_data) | ||
{ | ||
std::unique_ptr<IMemoryManager> memory_manager = std::make_unique<TestMemoryManager>(); | ||
Tensor input_tensor = | ||
makeInputTensor<DataType::FLOAT32>(input_shape, input_data, memory_manager.get()); | ||
Tensor output_tensor = makeOutputTensor(DataType::FLOAT32); | ||
|
||
HardSwish kernel(&input_tensor, &output_tensor); | ||
kernel.configure(); | ||
memory_manager->allocate_memory(output_tensor); | ||
kernel.execute(); | ||
|
||
(void)output_shape; | ||
EXPECT_THAT(extractTensorData<float>(output_tensor), FloatArrayNear(output_data)); | ||
} | ||
|
||
TEST(HardSwishTest, SimpleHardSwish) | ||
{ | ||
Check( | ||
/*input_shape=*/{1, 2, 4, 1}, /*output_shape=*/{1, 2, 4, 1}, | ||
/*input_data=*/ | ||
{ | ||
0, -6, 2, -4, // | ||
3, -2, 10, -0.1, // | ||
}, | ||
/*output_data=*/ | ||
{ | ||
0, -0, 1.66667, -0, // | ||
3, -0.333333, 10, -0.0483333, // | ||
}); | ||
} | ||
|
||
TEST(HardSwishTest, InOutTypeMismatch_NEG) | ||
{ | ||
std::unique_ptr<IMemoryManager> memory_manager = std::make_unique<TestMemoryManager>(); | ||
Shape input_shape{1, 2, 4, 1}; | ||
std::vector<float> input_data{ | ||
0, -6, 2, -4, // | ||
3, -2, 10, -0.1, // | ||
}; | ||
Tensor input_tensor = | ||
makeInputTensor<DataType::FLOAT32>(input_shape, input_data, memory_manager.get()); | ||
Tensor output_tensor = makeOutputTensor(DataType::U8); | ||
|
||
HardSwish kernel(&input_tensor, &output_tensor); | ||
EXPECT_ANY_THROW(kernel.configure()); | ||
} | ||
|
||
} // namespace | ||
} // namespace kernels | ||
} // namespace luci_interpreter |
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,35 @@ | ||
/* | ||
* Copyright (c) 2023 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 "Builders.h" | ||
|
||
#include "kernels/HardSwish.h" | ||
|
||
namespace luci_interpreter | ||
{ | ||
|
||
std::unique_ptr<Kernel> build_kernel_CircleHardSwish(const luci::CircleNode *circle_node, | ||
KernelBuilderHelper &helper) | ||
{ | ||
const auto *node = loco::must_cast<const luci::CircleHardSwish *>(circle_node); | ||
assert(node->arity() == 1); | ||
|
||
const Tensor *input = helper.getInputTensor(node->features()); | ||
Tensor *output = helper.getOutputTensor(node); | ||
|
||
return std::make_unique<kernels::HardSwish>(input, output); | ||
} | ||
} // namespace luci_interpreter |
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
37 changes: 37 additions & 0 deletions
37
compiler/luci/import/include/luci/Import/Nodes/CircleHardSwish.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) 2023 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 __LUCI_IMPORT_OP_CIRCLE_HARDSWISH_H__ | ||
#define __LUCI_IMPORT_OP_CIRCLE_HARDSWISH_H__ | ||
|
||
#include "luci/Import/GraphBuilder.h" | ||
|
||
namespace luci | ||
{ | ||
|
||
class CircleHardSwishGraphBuilder : public GraphBuilder | ||
{ | ||
public: | ||
bool validate(const ValidateArgs &args) const final; | ||
|
||
private: | ||
CircleNode *build_node(const circle::OperatorT &op, const std::vector<CircleNode *> &inputs, | ||
loco::Graph *graph) const final; | ||
}; | ||
|
||
} // namespace luci | ||
|
||
#endif // __LUCI_IMPORT_OP_CIRCLE_HARDSWISH_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (c) 2023 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 "luci/Import/Nodes/CircleHardSwish.h" | ||
|
||
#include <luci/IR/Nodes/CircleHardSwish.h> | ||
|
||
#include <loco.h> | ||
|
||
namespace luci | ||
{ | ||
|
||
bool CircleHardSwishGraphBuilder::validate(const ValidateArgs &args) const | ||
{ | ||
return GraphBuilder::validate(args, 1); | ||
} | ||
|
||
CircleNode *CircleHardSwishGraphBuilder::build_node(const circle::OperatorT &, | ||
const std::vector<CircleNode *> &inputs, | ||
loco::Graph *graph) const | ||
{ | ||
auto *node = graph->nodes()->create<CircleHardSwish>(); | ||
node->features(inputs.at(0)); | ||
|
||
return node; | ||
} | ||
|
||
} // namespace luci |
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
Oops, something went wrong.