diff options
Diffstat (limited to 'compiler/tflchef')
30 files changed, 506 insertions, 14 deletions
diff --git a/compiler/tflchef/CMakeLists.txt b/compiler/tflchef/CMakeLists.txt index 6205ac650..73a8a0d6e 100644 --- a/compiler/tflchef/CMakeLists.txt +++ b/compiler/tflchef/CMakeLists.txt @@ -5,10 +5,10 @@ if(NOT Protobuf_FOUND) return() endif(NOT Protobuf_FOUND) -if(NOT TARGET mio_tflite280) - message(STATUS "Build tflchef: FAILED (missing mio_tflite280)") +if(NOT TARGET mio_tflite2121) + message(STATUS "Build tflchef: FAILED (missing mio_tflite2121)") return() -endif(NOT TARGET mio_tflite280) +endif(NOT TARGET mio_tflite2121) # Recipe Parser add_subdirectory(proto) diff --git a/compiler/tflchef/core/CMakeLists.txt b/compiler/tflchef/core/CMakeLists.txt index 6b6fed57b..b9f735278 100644 --- a/compiler/tflchef/core/CMakeLists.txt +++ b/compiler/tflchef/core/CMakeLists.txt @@ -5,5 +5,5 @@ target_include_directories(tflchef_core PUBLIC include) target_include_directories(tflchef_core PRIVATE src) target_link_libraries(tflchef_core tflchef_proto) target_link_libraries(tflchef_core tflchef_log) -target_link_libraries(tflchef_core mio_tflite280) +target_link_libraries(tflchef_core mio_tflite2121) target_link_libraries(tflchef_core souschef) diff --git a/compiler/tflchef/core/src/Convert.cpp b/compiler/tflchef/core/src/Convert.cpp index f4dd4b332..d1babf09a 100644 --- a/compiler/tflchef/core/src/Convert.cpp +++ b/compiler/tflchef/core/src/Convert.cpp @@ -77,6 +77,8 @@ tflite::TensorType as_tflite_tensortype(const tflchef::TensorType &value) return tflite::TensorType_BOOL; case tflchef::INT16: return tflite::TensorType_INT16; + case tflchef::INT8: + return tflite::TensorType_INT8; default: break; } diff --git a/compiler/tflchef/core/src/CustomOp/Erf.cpp b/compiler/tflchef/core/src/CustomOp/Erf.cpp new file mode 100644 index 000000000..f611b68e1 --- /dev/null +++ b/compiler/tflchef/core/src/CustomOp/Erf.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved + * Copyright 2015 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. + */ + +#include "Erf.h" + +#include <flatbuffers/flexbuffers.h> + +flatbuffers::Offset<void> ErfChef::value(flatbuffers::FlatBufferBuilder &fbb) const +{ + return flatbuffers::Offset<void>(); +} + +flatbuffers::Offset<flatbuffers::Vector<uint8_t>> +ErfChef::custom_value(flatbuffers::FlatBufferBuilder &fbb) const +{ + auto &operation = (*_operation); + + assert(operation.type() == "Erf"); + + /** + * REGISTER_OP("Erf") + .Input("x: T") + .Output("y: T") + .Attr("T: {bfloat16, half, float, double}") + .SetShapeFn(shape_inference::UnchangedShape) + */ + + auto flex_buffers = std::make_unique<flexbuffers::Builder>(); + size_t map_start = flex_buffers->StartMap(); + + // TODO Support more data types + flex_buffers->Int("T", tflite::TensorType_FLOAT32); + + flex_buffers->EndMap(map_start); + flex_buffers->Finish(); + + auto circle_custom_options = fbb.CreateVector(flex_buffers->GetBuffer()); + return circle_custom_options; +} + +std::unique_ptr<OpChef> ErfChefFactory::create(const tflchef::Operation *operation) const +{ + return std::unique_ptr<OpChef>{new ErfChef{operation}}; +} diff --git a/compiler/tflchef/core/src/CustomOp/Erf.h b/compiler/tflchef/core/src/CustomOp/Erf.h new file mode 100644 index 000000000..192c5f334 --- /dev/null +++ b/compiler/tflchef/core/src/CustomOp/Erf.h @@ -0,0 +1,49 @@ +/* + * 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 __OP_ERF_H__ +#define __OP_ERF_H__ + +#include "OpChef.h" + +class ErfChef final : public OpChef +{ +public: + explicit ErfChef(const tflchef::Operation *operation) : _operation{operation} + { + // DO NOTHING + } + +public: + tflite::BuiltinOperator code(void) const override { return tflite::BuiltinOperator_CUSTOM; } + + tflite::BuiltinOptions type(void) const override { return tflite::BuiltinOptions_NONE; } + + flatbuffers::Offset<void> value(flatbuffers::FlatBufferBuilder &fbb) const override; + + flatbuffers::Offset<flatbuffers::Vector<uint8_t>> + custom_value(flatbuffers::FlatBufferBuilder &fbb) const override; + +private: + const tflchef::Operation *_operation; +}; + +struct ErfChefFactory final : public OpChefFactory +{ + std::unique_ptr<OpChef> create(const tflchef::Operation *operation) const override; +}; + +#endif // __OP_ERF_H__ diff --git a/compiler/tflchef/core/src/DataChef.def b/compiler/tflchef/core/src/DataChef.def index 28a5b7617..abe642645 100644 --- a/compiler/tflchef/core/src/DataChef.def +++ b/compiler/tflchef/core/src/DataChef.def @@ -7,12 +7,14 @@ DATA_CHEF(FLOAT32, constant, ConstantDataChefFactory<float>) DATA_CHEF(BOOL, constant, ConstantDataChefFactory<bool>) DATA_CHEF(UINT8, constant, ConstantDataChefFactory<uint8_t>) +DATA_CHEF(INT8, constant, ConstantDataChefFactory<int8_t>) DATA_CHEF(INT16, constant, ConstantDataChefFactory<int16_t>) DATA_CHEF(INT32, constant, ConstantDataChefFactory<int32_t>) DATA_CHEF(INT64, constant, ConstantDataChefFactory<int64_t>) DATA_CHEF(INT64, explicit, ExplicitDataChefFactory<int64_t>) DATA_CHEF(INT32, explicit, ExplicitDataChefFactory<int32_t>) DATA_CHEF(INT16, explicit, ExplicitDataChefFactory<int16_t>) +DATA_CHEF(INT8, explicit, ExplicitDataChefFactory<int8_t>) DATA_CHEF(UINT8, explicit, ExplicitDataChefFactory<uint8_t>) DATA_CHEF(BOOL, explicit, ExplicitDataChefFactory<bool>) DATA_CHEF(FLOAT32, explicit, ExplicitDataChefFactory<float>) @@ -20,6 +22,7 @@ DATA_CHEF(STRING, explicit, ExplicitDataChefFactory<std::string>) DATA_CHEF(FLOAT32, gaussian, GaussianFloat32DataChefFactory) DATA_CHEF(INT32, gaussian, GaussianInt32DataChefFactory) DATA_CHEF(INT16, gaussian, GaussianInt16DataChefFactory) +DATA_CHEF(INT8, gaussian, GaussianInt8DataChefFactory) DATA_CHEF(UINT8, gaussian, GaussianUint8DataChefFactory) // FLOAT16 support for only gaussian, explicit for now diff --git a/compiler/tflchef/core/src/ModelChef.cpp b/compiler/tflchef/core/src/ModelChef.cpp index a788adc02..3afcd232d 100644 --- a/compiler/tflchef/core/src/ModelChef.cpp +++ b/compiler/tflchef/core/src/ModelChef.cpp @@ -93,6 +93,7 @@ DataChefRegistry &data_chef_registry(const tflchef::TensorType &type) static DataChefRegistry boolean; static DataChefRegistry s16; static DataChefRegistry fp16; + static DataChefRegistry s8; switch (type) { @@ -112,6 +113,8 @@ DataChefRegistry &data_chef_registry(const tflchef::TensorType &type) return boolean; case tflchef::INT16: return s16; + case tflchef::INT8: + return s8; default: break; } @@ -734,9 +737,19 @@ GeneratedModel cook(const ::tflchef::ModelRecipe &model_recipe) for (auto const &opcode : builtin_code_map) { tflite::OperatorCodeBuilder code_builder{*flatbuffer_builder}; - // TODO support for opcode.first >= 127 - assert(opcode.first < 127); - code_builder.add_deprecated_builtin_code(opcode.first); + // 127 is BuiltinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES + // This is the way to handle deprecated builtin code + // See + // https://github.com/tensorflow/tensorflow/blob/a0afe8f9218be5eb9ed5dffc2dff652996da8c28/tensorflow/lite/schema/schema.fbs#L1061-L1077 + if (opcode.first < 127) + { + code_builder.add_deprecated_builtin_code(opcode.first); + } + else + { + code_builder.add_deprecated_builtin_code( + ::tflite::BuiltinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES); + } code_builder.add_version(opcode.second); code_builder.add_builtin_code(opcode.first); auto code = code_builder.Finish(); diff --git a/compiler/tflchef/core/src/Op/Gelu.cpp b/compiler/tflchef/core/src/Op/Gelu.cpp new file mode 100644 index 000000000..91d2bb36c --- /dev/null +++ b/compiler/tflchef/core/src/Op/Gelu.cpp @@ -0,0 +1,34 @@ +/* + * 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 "Gelu.h" + +flatbuffers::Offset<void> GeluChef::value(flatbuffers::FlatBufferBuilder &fbb) const +{ + assert(_operation->has_gelu_options()); + + const auto &options = _operation->gelu_options(); + + tflite::GeluOptionsBuilder options_builder{fbb}; + options_builder.add_approximate(options.approximate()); + + return options_builder.Finish().Union(); +} + +std::unique_ptr<OpChef> GeluChefFactory::create(const tflchef::Operation *operation) const +{ + return std::unique_ptr<OpChef>{new GeluChef{operation}}; +} diff --git a/compiler/tflchef/core/src/Op/Gelu.h b/compiler/tflchef/core/src/Op/Gelu.h new file mode 100644 index 000000000..64d9361e6 --- /dev/null +++ b/compiler/tflchef/core/src/Op/Gelu.h @@ -0,0 +1,46 @@ +/* + * 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 __OP_GELU_H__ +#define __OP_GELU_H__ + +#include "OpChef.h" + +class GeluChef final : public OpChef +{ +public: + explicit GeluChef(const tflchef::Operation *operation) : _operation{operation} + { + // DO NOTHING + } + +public: + tflite::BuiltinOperator code(void) const override { return tflite::BuiltinOperator_GELU; } + + tflite::BuiltinOptions type(void) const override { return tflite::BuiltinOptions_GeluOptions; } + + flatbuffers::Offset<void> value(flatbuffers::FlatBufferBuilder &fbb) const override; + +private: + const tflchef::Operation *_operation; +}; + +struct GeluChefFactory final : public OpChefFactory +{ + std::unique_ptr<OpChef> create(const tflchef::Operation *operation) const override; +}; + +#endif // __OP_GELU_H__ diff --git a/compiler/tflchef/core/src/Op/HardSwish.cpp b/compiler/tflchef/core/src/Op/HardSwish.cpp new file mode 100644 index 000000000..27ab8b5ab --- /dev/null +++ b/compiler/tflchef/core/src/Op/HardSwish.cpp @@ -0,0 +1,27 @@ +/* + * 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 "HardSwish.h" + +flatbuffers::Offset<void> HardSwishChef::value(flatbuffers::FlatBufferBuilder &fbb) const +{ + return flatbuffers::Offset<void>(); +} + +std::unique_ptr<OpChef> HardSwishChefFactory::create(const tflchef::Operation *operation) const +{ + return std::unique_ptr<OpChef>{new HardSwishChef{operation}}; +} diff --git a/compiler/tflchef/core/src/Op/HardSwish.h b/compiler/tflchef/core/src/Op/HardSwish.h new file mode 100644 index 000000000..10ed51e61 --- /dev/null +++ b/compiler/tflchef/core/src/Op/HardSwish.h @@ -0,0 +1,46 @@ +/* + * 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 __OP_HARDSWISH_H__ +#define __OP_HARDSWISH_H__ + +#include "OpChef.h" + +class HardSwishChef final : public OpChef +{ +public: + explicit HardSwishChef(const tflchef::Operation *operation) : _operation{operation} + { + // DO NOTHING + } + +public: + tflite::BuiltinOperator code(void) const override { return tflite::BuiltinOperator_HARD_SWISH; } + + tflite::BuiltinOptions type(void) const override { return tflite::BuiltinOptions_NONE; } + + flatbuffers::Offset<void> value(flatbuffers::FlatBufferBuilder &fbb) const override; + +private: + const tflchef::Operation *_operation; +}; + +struct HardSwishChefFactory final : public OpChefFactory +{ + std::unique_ptr<OpChef> create(const tflchef::Operation *operation) const override; +}; + +#endif // __OP_HARDSWISH_H__ diff --git a/compiler/tflchef/core/src/Op/TransposeConv.cpp b/compiler/tflchef/core/src/Op/TransposeConv.cpp index c9e452714..530ebae78 100644 --- a/compiler/tflchef/core/src/Op/TransposeConv.cpp +++ b/compiler/tflchef/core/src/Op/TransposeConv.cpp @@ -34,6 +34,13 @@ flatbuffers::Offset<void> TransposeConvChef::value(flatbuffers::FlatBufferBuilde options_builder.add_stride_h(operation.transpose_conv_options().stride_h()); options_builder.add_stride_w(operation.transpose_conv_options().stride_w()); + // TODO remove calling has_activation + auto chef_activation = operation.transpose_conv_options().has_activation() + ? operation.transpose_conv_options().activation() + : tflchef::NONE; + auto tflite_activation = as_tflite_activation(chef_activation); + options_builder.add_fused_activation_function(tflite_activation); + return options_builder.Finish().Union(); } diff --git a/compiler/tflchef/core/src/OpChef.def b/compiler/tflchef/core/src/OpChef.def index c19d00dfb..9a2164640 100644 --- a/compiler/tflchef/core/src/OpChef.def +++ b/compiler/tflchef/core/src/OpChef.def @@ -35,8 +35,10 @@ OP_CHEF(FloorMod, FloorModChefFactory) OP_CHEF(FullyConnected, FullyConnectedChefFactory) OP_CHEF(Gather, GatherChefFactory) OP_CHEF(GatherNd, GatherNdChefFactory) +OP_CHEF(Gelu, GeluChefFactory) OP_CHEF(Greater, GreaterChefFactory) OP_CHEF(GreaterEqual, GreaterEqualChefFactory) +OP_CHEF(HardSwish, HardSwishChefFactory) OP_CHEF(If, IfChefFactory) OP_CHEF(L2Normalize, L2NormalizeChefFactory) OP_CHEF(L2Pool2D, L2Pool2DChefFactory) @@ -123,6 +125,7 @@ OP_CHEF(AddV2, AddV2ChefFactory) OP_CHEF(All, AllChefFactory) OP_CHEF(BatchMatMulV2, BatchMatMulV2ChefFactory) OP_CHEF(BroadcastTo, BroadcastToChefFactory) +OP_CHEF(Erf, ErfChefFactory) OP_CHEF(MatMul, MatMulChefFactory) OP_CHEF(MatrixBandPart, MatrixBandPartChefFactory) OP_CHEF(MaxPoolWithArgmax, MaxPoolWithArgmaxChefFactory) diff --git a/compiler/tflchef/core/src/OpChefs.h b/compiler/tflchef/core/src/OpChefs.h index 3cd3be558..ba2b17571 100644 --- a/compiler/tflchef/core/src/OpChefs.h +++ b/compiler/tflchef/core/src/OpChefs.h @@ -48,8 +48,10 @@ #include "Op/FullyConnected.h" #include "Op/Gather.h" #include "Op/GatherNd.h" +#include "Op/Gelu.h" #include "Op/Greater.h" #include "Op/GreaterEqual.h" +#include "Op/HardSwish.h" #include "Op/If.h" #include "Op/L2Normalize.h" #include "Op/L2Pool2D.h" @@ -135,6 +137,7 @@ #include "CustomOp/All.h" #include "CustomOp/BatchMatMulV2.h" #include "CustomOp/BroadcastTo.h" +#include "CustomOp/Erf.h" #include "CustomOp/MatMul.h" #include "CustomOp/MatrixBandPart.h" #include "CustomOp/MaxPoolWithArgmax.h" diff --git a/compiler/tflchef/proto/tflchef.proto b/compiler/tflchef/proto/tflchef.proto index da4b6920d..98ae2b23f 100644 --- a/compiler/tflchef/proto/tflchef.proto +++ b/compiler/tflchef/proto/tflchef.proto @@ -22,6 +22,7 @@ enum TensorType { STRING = 5; BOOL = 6; INT16 = 7; + INT8 = 9; } enum DimensionType { @@ -436,6 +437,10 @@ message GatherNdOptions { // None } +message GeluOptions { + optional bool approximate = 1 [default = false]; +} + message NonMaxSuppressionV4Options { // None } @@ -473,6 +478,7 @@ message TransposeConvOptions { optional Padding padding = 1 [default = VALID]; optional int32 stride_w = 2 [default = 1]; optional int32 stride_h = 3 [default = 1]; + optional Activation activation = 4 [default = NONE]; } message ReverseSequenceOptions { @@ -662,6 +668,7 @@ message Operation { optional MatMulOptions matmul_options = 208; optional MaxPoolWithArgmaxOptions max_pool_with_argmax_options = 209; optional DensifyOptions densify_options = 210; + optional GeluOptions gelu_options = 211; // NOTE if there are more than two options with same type of Options // use the number not listed in the above reserve list } diff --git a/compiler/tflchef/requires.cmake b/compiler/tflchef/requires.cmake index a01da4258..8d86632fb 100644 --- a/compiler/tflchef/requires.cmake +++ b/compiler/tflchef/requires.cmake @@ -1,7 +1,7 @@ require("arser") require("nnkit") require("cwrap") -require("mio-tflite280") +require("mio-tflite2121") require("safemain") require("hermes") require("hermes-std") diff --git a/compiler/tflchef/tests/CMakeLists.txt b/compiler/tflchef/tests/CMakeLists.txt index 26cf67f4f..79b00845b 100644 --- a/compiler/tflchef/tests/CMakeLists.txt +++ b/compiler/tflchef/tests/CMakeLists.txt @@ -124,9 +124,9 @@ add_custom_target(tflchef_testfiles ALL DEPENDS ${TESTFILES}) # Using mio_tflite_validate for temporary as it only calls flatbuffer validate # TODO do testing with running the model with runtime/interpreter -# NOTE for ARM32 cross build, $<TARGET_FILE:mio_tflite280_validate> is used as-is +# NOTE for ARM32 cross build, $<TARGET_FILE:mio_tflite2121_validate> is used as-is # as test should run in ARM32 device add_test(NAME tflchef_test COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/runvalidate.sh" - $<TARGET_FILE:mio_tflite280_validate> + $<TARGET_FILE:mio_tflite2121_validate> ${TESTS}) diff --git a/compiler/tflchef/tests/custom_erf/test.recipe b/compiler/tflchef/tests/custom_erf/test.recipe new file mode 100644 index 000000000..ab093a30e --- /dev/null +++ b/compiler/tflchef/tests/custom_erf/test.recipe @@ -0,0 +1,17 @@ +operand { + name: "ifm" + type: FLOAT32 + shape { dim: 1 dim: 3 dim: 3 dim: 2 } +} +operand { + name: "ofm" + type: FLOAT32 + shape { dim: 1 dim: 3 dim: 3 dim: 2 } +} +operation { + type: "Erf" + input: "ifm" + output: "ofm" +} +input: "ifm" +output: "ofm" diff --git a/compiler/tflchef/tflite/CMakeLists.txt b/compiler/tflchef/tflite/CMakeLists.txt index d9a20a2e1..bf20f31c2 100644 --- a/compiler/tflchef/tflite/CMakeLists.txt +++ b/compiler/tflchef/tflite/CMakeLists.txt @@ -5,7 +5,7 @@ target_include_directories(tflchef_tflite PUBLIC include) target_include_directories(tflchef_tflite PRIVATE src) target_include_directories(tflchef_tflite PRIVATE src/Op/include) target_link_libraries(tflchef_tflite tflchef_proto) -target_link_libraries(tflchef_tflite mio_tflite280) -target_link_libraries(tflchef_tflite mio_tflite280_helper) +target_link_libraries(tflchef_tflite mio_tflite2121) +target_link_libraries(tflchef_tflite mio_tflite2121_helper) target_link_libraries(tflchef_tflite cwrap) target_link_libraries(tflchef_tflite souschef) diff --git a/compiler/tflchef/tflite/src/Convert.cpp b/compiler/tflchef/tflite/src/Convert.cpp index 242987661..46812f4d6 100644 --- a/compiler/tflchef/tflite/src/Convert.cpp +++ b/compiler/tflchef/tflite/src/Convert.cpp @@ -33,6 +33,8 @@ tflchef::TensorType as_tflchef_type(const tflite::TensorType type) return tflchef::UINT8; case tflite::TensorType_BOOL: return tflchef::BOOL; + case tflite::TensorType_INT8: + return tflchef::INT8; case tflite::TensorType_INT16: return tflchef::INT16; case tflite::TensorType_FLOAT16: diff --git a/compiler/tflchef/tflite/src/Op/Gelu.cpp b/compiler/tflchef/tflite/src/Op/Gelu.cpp new file mode 100644 index 000000000..23cee07b0 --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/Gelu.cpp @@ -0,0 +1,46 @@ +/* + * 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 "Gelu.h" + +#include "Convert.h" + +namespace tflchef +{ + +void TFliteOpGelu::filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + // Nothing to do with filler +} + +tflchef::Operation *TFliteOpGelu::build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + auto op_params = op->builtin_options_as_GeluOptions(); + + auto operation = model_recipe->add_operation(); + + operation->set_type("Gelu"); + + auto *op_options = operation->mutable_gelu_options(); + + op_options->set_approximate(op_params->approximate()); + + return operation; +} + +} // namespace tflchef diff --git a/compiler/tflchef/tflite/src/Op/HardSwish.cpp b/compiler/tflchef/tflite/src/Op/HardSwish.cpp new file mode 100644 index 000000000..2282ff97d --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/HardSwish.cpp @@ -0,0 +1,40 @@ +/* + * 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 "HardSwish.h" + +#include "Convert.h" + +namespace tflchef +{ + +void TFliteOpHardSwish::filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + // Nothing to do with filler +} + +tflchef::Operation *TFliteOpHardSwish::build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + auto operation = model_recipe->add_operation(); + + operation->set_type("HardSwish"); + + return operation; +} + +} // namespace tflchef diff --git a/compiler/tflchef/tflite/src/Op/PRelu.cpp b/compiler/tflchef/tflite/src/Op/PRelu.cpp index 8a5e83a84..1a1a84bce 100644 --- a/compiler/tflchef/tflite/src/Op/PRelu.cpp +++ b/compiler/tflchef/tflite/src/Op/PRelu.cpp @@ -24,6 +24,11 @@ namespace tflchef void TFliteOpPRelu::filler(const tflite::Operator *op, TFliteImport *import, tflchef::ModelRecipe *model_recipe) const { + const std::vector<int32_t> &inputs = as_index_vector(op->inputs()); + + assert(inputs.size() == 2); + + import->set_tensor_filler(inputs.at(1)); // alpha } tflchef::Operation *TFliteOpPRelu::build(const tflite::Operator *op, TFliteImport *import, diff --git a/compiler/tflchef/tflite/src/Op/TransposeConv.cpp b/compiler/tflchef/tflite/src/Op/TransposeConv.cpp index 4e7adf6c6..875ccb51b 100644 --- a/compiler/tflchef/tflite/src/Op/TransposeConv.cpp +++ b/compiler/tflchef/tflite/src/Op/TransposeConv.cpp @@ -53,10 +53,12 @@ tflchef::Operation *TFliteOpTransposeConv::build(const tflite::Operator *op, TFl operation->set_type("TransposeConv"); auto op_options = operation->mutable_transpose_conv_options(); + auto tflchef_activation = as_tflchef_activation(op_params->fused_activation_function()); op_options->set_stride_h(op_params->stride_h()); op_options->set_stride_w(op_params->stride_w()); op_options->set_padding(as_tflchef_padding(op_params->padding())); + op_options->set_activation(tflchef_activation); return operation; } diff --git a/compiler/tflchef/tflite/src/Op/include/Gelu.h b/compiler/tflchef/tflite/src/Op/include/Gelu.h new file mode 100644 index 000000000..0c51a51be --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/include/Gelu.h @@ -0,0 +1,39 @@ +/* + * 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 __TFLITE_OP_GELU_H__ +#define __TFLITE_OP_GELU_H__ + +#include "TFliteOpChef.h" + +namespace tflchef +{ + +/** + * @brief tflchef operator builder for Gelu + */ +class TFliteOpGelu : public TFliteOpChef +{ +public: + void filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; + tflchef::Operation *build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; +}; + +} // namespace tflchef + +#endif // __TFLITE_OP_GELU_H__ diff --git a/compiler/tflchef/tflite/src/Op/include/HardSwish.h b/compiler/tflchef/tflite/src/Op/include/HardSwish.h new file mode 100644 index 000000000..d9b5a5382 --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/include/HardSwish.h @@ -0,0 +1,39 @@ +/* + * 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 __TFLITE_OP_HARDSWISH_H__ +#define __TFLITE_OP_HARDSWISH_H__ + +#include "TFliteOpChef.h" + +namespace tflchef +{ + +/** + * @brief tflchef operator builder for Hard Swish + */ +class TFliteOpHardSwish : public TFliteOpChef +{ +public: + void filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; + tflchef::Operation *build(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const override; +}; + +} // namespace tflchef + +#endif // __TFLITE_OP_HARDSWISH_H__ diff --git a/compiler/tflchef/tflite/src/RecipeChef.cpp b/compiler/tflchef/tflite/src/RecipeChef.cpp index 0701707c1..2203f5906 100644 --- a/compiler/tflchef/tflite/src/RecipeChef.cpp +++ b/compiler/tflchef/tflite/src/RecipeChef.cpp @@ -15,7 +15,7 @@ */ #include <tflchef/RecipeChef.h> -#include <mio_tflite280/Helper.h> +#include <mio_tflite2121/Helper.h> #include "Convert.h" #include "TFliteImport.h" diff --git a/compiler/tflchef/tflite/src/TFliteImport.cpp b/compiler/tflchef/tflite/src/TFliteImport.cpp index 7114ab019..9abec9a08 100644 --- a/compiler/tflchef/tflite/src/TFliteImport.cpp +++ b/compiler/tflchef/tflite/src/TFliteImport.cpp @@ -18,7 +18,7 @@ #include "Convert.h" -#include <mio_tflite280/Helper.h> +#include <mio_tflite2121/Helper.h> #include <sstream> diff --git a/compiler/tflchef/tflite/src/TFliteOpChefs.h b/compiler/tflchef/tflite/src/TFliteOpChefs.h index 1b9d420e5..34cb1bae2 100644 --- a/compiler/tflchef/tflite/src/TFliteOpChefs.h +++ b/compiler/tflchef/tflite/src/TFliteOpChefs.h @@ -48,8 +48,10 @@ #include "Op/include/FullyConnected.h" #include "Op/include/Gather.h" #include "Op/include/GatherNd.h" +#include "Op/include/Gelu.h" #include "Op/include/Greater.h" #include "Op/include/GreaterEqual.h" +#include "Op/include/HardSwish.h" #include "Op/include/L2Normalize.h" #include "Op/include/L2Pool2D.h" #include "Op/include/LeakyRelu.h" diff --git a/compiler/tflchef/tflite/src/TFliteOpRegistry.h b/compiler/tflchef/tflite/src/TFliteOpRegistry.h index 4cbe7cfcb..a37f15c0c 100644 --- a/compiler/tflchef/tflite/src/TFliteOpRegistry.h +++ b/compiler/tflchef/tflite/src/TFliteOpRegistry.h @@ -85,8 +85,10 @@ private: REG_TFL_OP(FULLY_CONNECTED, TFliteOpFullyConnected); REG_TFL_OP(GATHER, TFliteOpGather); REG_TFL_OP(GATHER_ND, TFliteOpGatherNd); + REG_TFL_OP(GELU, TFliteOpGelu); REG_TFL_OP(GREATER, TFliteOpGreater); REG_TFL_OP(GREATER_EQUAL, TFliteOpGreaterEqual); + REG_TFL_OP(HARD_SWISH, TFliteOpHardSwish); REG_TFL_OP(L2_NORMALIZATION, TFliteOpL2Normalize); REG_TFL_OP(L2_POOL_2D, TFliteOpL2Pool2D); REG_TFL_OP(LEAKY_RELU, TFliteOpLeakyRelu); |