diff options
author | Chunseok Lee <chunseok.lee@samsung.com> | 2021-08-23 13:25:15 +0900 |
---|---|---|
committer | Chunseok Lee <chunseok.lee@samsung.com> | 2021-08-23 13:25:15 +0900 |
commit | f4cf19e579a19c5346ccb2aad55bfd251065e447 (patch) | |
tree | 5d436b11f89be0e8a8289ea82b773da6402c1add /compiler/tflchef | |
parent | 589bb1db6db6784efe21b3fbbfbfdb79aaa5f14e (diff) | |
download | nnfw-f4cf19e579a19c5346ccb2aad55bfd251065e447.tar.gz nnfw-f4cf19e579a19c5346ccb2aad55bfd251065e447.tar.bz2 nnfw-f4cf19e579a19c5346ccb2aad55bfd251065e447.zip |
Imported Upstream version 1.17.0upstream/1.17.0submit/tizen/20210823.054833submit/tizen/20210823.045832submit/tizen/20210823.044411accepted/tizen/unified/20210823.124210
Diffstat (limited to 'compiler/tflchef')
16 files changed, 260 insertions, 14 deletions
diff --git a/compiler/tflchef/core/src/Convert.cpp b/compiler/tflchef/core/src/Convert.cpp index de3ae4ed1..200c71eca 100644 --- a/compiler/tflchef/core/src/Convert.cpp +++ b/compiler/tflchef/core/src/Convert.cpp @@ -68,6 +68,8 @@ tflite::TensorType as_tflite_tensortype(const tflchef::TensorType &value) return tflite::TensorType_UINT8; case tflchef::INT64: return tflite::TensorType_INT64; + case tflchef::STRING: + return tflite::TensorType_STRING; case tflchef::BOOL: return tflite::TensorType_BOOL; case tflchef::INT16: diff --git a/compiler/tflchef/core/src/CustomOp/MaxPoolWithArgMax.cpp b/compiler/tflchef/core/src/CustomOp/MaxPoolWithArgmax.cpp index 13bf2e5e9..9dacf7bf6 100644 --- a/compiler/tflchef/core/src/CustomOp/MaxPoolWithArgMax.cpp +++ b/compiler/tflchef/core/src/CustomOp/MaxPoolWithArgmax.cpp @@ -15,21 +15,21 @@ * limitations under the License. */ -#include "MaxPoolWithArgMax.h" +#include "MaxPoolWithArgmax.h" #include "flatbuffers/flexbuffers.h" -flatbuffers::Offset<void> MaxPoolWithArgMaxChef::value(flatbuffers::FlatBufferBuilder &fbb) const +flatbuffers::Offset<void> MaxPoolWithArgmaxChef::value(flatbuffers::FlatBufferBuilder &fbb) const { return flatbuffers::Offset<void>(); } flatbuffers::Offset<flatbuffers::Vector<uint8_t>> -MaxPoolWithArgMaxChef::custom_value(flatbuffers::FlatBufferBuilder &fbb) const +MaxPoolWithArgmaxChef::custom_value(flatbuffers::FlatBufferBuilder &fbb) const { auto &operation = (*_operation); - assert(operation.type() == "MaxPoolWithArgMax"); + assert(operation.type() == "MaxPoolWithArgmax"); /** * REGISTER_OP("MaxPoolWithArgmax") @@ -80,7 +80,7 @@ MaxPoolWithArgMaxChef::custom_value(flatbuffers::FlatBufferBuilder &fbb) const } std::unique_ptr<OpChef> -MaxPoolWithArgMaxChefFactory::create(const tflchef::Operation *operation) const +MaxPoolWithArgmaxChefFactory::create(const tflchef::Operation *operation) const { - return std::unique_ptr<OpChef>{new MaxPoolWithArgMaxChef{operation}}; + return std::unique_ptr<OpChef>{new MaxPoolWithArgmaxChef{operation}}; } diff --git a/compiler/tflchef/core/src/CustomOp/MaxPoolWithArgMax.h b/compiler/tflchef/core/src/CustomOp/MaxPoolWithArgmax.h index 2123a86bd..338ee8026 100644 --- a/compiler/tflchef/core/src/CustomOp/MaxPoolWithArgMax.h +++ b/compiler/tflchef/core/src/CustomOp/MaxPoolWithArgmax.h @@ -19,10 +19,10 @@ #include "OpChef.h" -class MaxPoolWithArgMaxChef final : public OpChef +class MaxPoolWithArgmaxChef final : public OpChef { public: - explicit MaxPoolWithArgMaxChef(const tflchef::Operation *operation) : _operation{operation} + explicit MaxPoolWithArgmaxChef(const tflchef::Operation *operation) : _operation{operation} { // DO NOTHING } @@ -41,7 +41,7 @@ private: const tflchef::Operation *_operation; }; -struct MaxPoolWithArgMaxChefFactory final : public OpChefFactory +struct MaxPoolWithArgmaxChefFactory final : public OpChefFactory { std::unique_ptr<OpChef> create(const tflchef::Operation *operation) const override; }; diff --git a/compiler/tflchef/core/src/DataChef.def b/compiler/tflchef/core/src/DataChef.def new file mode 100644 index 000000000..c634c047e --- /dev/null +++ b/compiler/tflchef/core/src/DataChef.def @@ -0,0 +1,23 @@ +#ifndef DATA_CHEF +#error "Define DATA_CHEF first" +#endif // DATA_CHEF + +// DATA_CHEF(TYPE, NAME, FACTORY_CLASS) +// "TYPE" SHOULD BE an enum tag of tflchef::TensorType +DATA_CHEF(FLOAT32, constant, ConstantDataChefFactory<float>) +DATA_CHEF(BOOL, constant, ConstantDataChefFactory<bool>) +DATA_CHEF(UINT8, constant, ConstantDataChefFactory<uint8_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(UINT8, explicit, ExplicitDataChefFactory<uint8_t>) +DATA_CHEF(BOOL, explicit, ExplicitDataChefFactory<bool>) +DATA_CHEF(FLOAT32, explicit, ExplicitDataChefFactory<float>) +DATA_CHEF(STRING, explicit, ExplicitDataChefFactory<std::string>) +DATA_CHEF(FLOAT32, gaussian, GaussianFloat32DataChefFactory) +DATA_CHEF(INT32, gaussian, GaussianInt32DataChefFactory) +DATA_CHEF(INT16, gaussian, GaussianInt16DataChefFactory) +DATA_CHEF(UINT8, gaussian, GaussianUint8DataChefFactory) diff --git a/compiler/tflchef/core/src/ModelChef.cpp b/compiler/tflchef/core/src/ModelChef.cpp index 467b0d300..aba20dcbf 100644 --- a/compiler/tflchef/core/src/ModelChef.cpp +++ b/compiler/tflchef/core/src/ModelChef.cpp @@ -89,6 +89,7 @@ DataChefRegistry &data_chef_registry(const tflchef::TensorType &type) static DataChefRegistry s64; static DataChefRegistry fp32; static DataChefRegistry u8; + static DataChefRegistry string; static DataChefRegistry boolean; static DataChefRegistry s16; @@ -102,6 +103,8 @@ DataChefRegistry &data_chef_registry(const tflchef::TensorType &type) return fp32; case tflchef::UINT8: return u8; + case tflchef::STRING: + return string; case tflchef::BOOL: return boolean; case tflchef::INT16: @@ -556,7 +559,7 @@ GeneratedModel cook(const ::tflchef::ModelRecipe &model_recipe) #define DATA_CHEF(TYPE, NAME, FACTORY_CLASS) \ data_chef_registry(::tflchef::TYPE) \ .add(#NAME, std::unique_ptr<FACTORY_CLASS>(new FACTORY_CLASS())); -#include <souschef/DataChef.def> +#include "DataChef.def" #undef DATA_CHEF // diff --git a/compiler/tflchef/core/src/Op/Quantize.cpp b/compiler/tflchef/core/src/Op/Quantize.cpp new file mode 100644 index 000000000..39b902805 --- /dev/null +++ b/compiler/tflchef/core/src/Op/Quantize.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2021 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 "Quantize.h" + +flatbuffers::Offset<void> QuantizeChef::value(flatbuffers::FlatBufferBuilder &fbb) const +{ + return flatbuffers::Offset<void>(); +} + +std::unique_ptr<OpChef> QuantizeChefFactory::create(const tflchef::Operation *operation) const +{ + return std::unique_ptr<OpChef>{new QuantizeChef{operation}}; +} diff --git a/compiler/tflchef/core/src/Op/Quantize.h b/compiler/tflchef/core/src/Op/Quantize.h new file mode 100644 index 000000000..fe7a029bf --- /dev/null +++ b/compiler/tflchef/core/src/Op/Quantize.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2021 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_QUANTIZE_H__ +#define __OP_QUANTIZE_H__ + +#include "OpChef.h" + +class QuantizeChef final : public OpChef +{ +public: + explicit QuantizeChef(const tflchef::Operation *operation) : _operation{operation} + { + // DO NOTHING + } + +public: + tflite::BuiltinOperator code(void) const override { return tflite::BuiltinOperator_QUANTIZE; } + + 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 QuantizeChefFactory final : public OpChefFactory +{ + std::unique_ptr<OpChef> create(const tflchef::Operation *operation) const override; +}; + +#endif // __OP_DEQUANTIZE_H__ diff --git a/compiler/tflchef/core/src/OpChef.def b/compiler/tflchef/core/src/OpChef.def index 714e8947b..b1e8a3829 100644 --- a/compiler/tflchef/core/src/OpChef.def +++ b/compiler/tflchef/core/src/OpChef.def @@ -67,6 +67,7 @@ OP_CHEF(Pad, PadChefFactory) OP_CHEF(PadV2, PadV2ChefFactory) OP_CHEF(Pow, PowChefFactory) OP_CHEF(PRelu, PReluChefFactory) +OP_CHEF(Quantize, QuantizeChefFactory) OP_CHEF(Range, RangeChefFactory) OP_CHEF(Rank, RankChefFactory) OP_CHEF(ReduceAny, ReduceAnyChefFactory) @@ -122,4 +123,4 @@ OP_CHEF(BatchMatMulV2, BatchMatMulV2ChefFactory) OP_CHEF(BroadcastTo, BroadcastToChefFactory) OP_CHEF(MatMul, MatMulChefFactory) OP_CHEF(MatrixBandPart, MatrixBandPartChefFactory) -OP_CHEF(MaxPoolWithArgMax, MaxPoolWithArgMaxChefFactory) +OP_CHEF(MaxPoolWithArgmax, MaxPoolWithArgmaxChefFactory) diff --git a/compiler/tflchef/core/src/OpChefs.h b/compiler/tflchef/core/src/OpChefs.h index 99f331e37..35688ba95 100644 --- a/compiler/tflchef/core/src/OpChefs.h +++ b/compiler/tflchef/core/src/OpChefs.h @@ -96,6 +96,7 @@ #include "Op/ReverseV2.h" #include "Op/Round.h" #include "Op/Rsqrt.h" +#include "Op/Quantize.h" #include "Op/ScatterNd.h" #include "Op/SegmentSum.h" #include "Op/Select.h" @@ -134,6 +135,6 @@ #include "CustomOp/BroadcastTo.h" #include "CustomOp/MatMul.h" #include "CustomOp/MatrixBandPart.h" -#include "CustomOp/MaxPoolWithArgMax.h" +#include "CustomOp/MaxPoolWithArgmax.h" #endif // __OP_CHEFS_H__ diff --git a/compiler/tflchef/proto/tflchef.proto b/compiler/tflchef/proto/tflchef.proto index c5e44f68c..34d50d985 100644 --- a/compiler/tflchef/proto/tflchef.proto +++ b/compiler/tflchef/proto/tflchef.proto @@ -18,6 +18,7 @@ enum TensorType { INT32 = 2; UINT8 = 3; INT64 = 4; + STRING = 5; BOOL = 6; INT16 = 7; } @@ -509,7 +510,7 @@ message DequantizeOptions { // NONE } -message MaxPoolWithArgMaxOptions { +message MaxPoolWithArgmaxOptions { optional Padding padding = 1 [default = VALID]; optional int32 stride_w = 2 [default = 1]; optional int32 stride_h = 3 [default = 1]; @@ -641,7 +642,7 @@ message Operation { optional SegmentSumOptions segment_sum_options = 206; optional AddNOptions add_n_options = 207; optional MatMulOptions matmul_options = 208; - optional MaxPoolWithArgMaxOptions max_pool_with_argmax_options = 209; + optional MaxPoolWithArgmaxOptions max_pool_with_argmax_options = 209; // 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/tests/explicit_bool/test.recipe b/compiler/tflchef/tests/explicit_bool/test.recipe new file mode 100644 index 000000000..8f09edd13 --- /dev/null +++ b/compiler/tflchef/tests/explicit_bool/test.recipe @@ -0,0 +1,31 @@ +operand { + name: "ifm1" + type: BOOL + shape { dim: 6 } +} +operand { + name: "ifm2" + type: BOOL + shape { dim: 6 } + filler { + tag: "explicit" + arg: "T" + arg: "f" + arg: "0" + arg: "1" + arg: "true" + arg: "FALSE" + } +} +operand { + name: "ofm" + type: BOOL + shape { dim: 6 } +} +operation { + type: "LogicalAnd" + input: "ifm1" + input: "ifm2" + output: "ofm" +} +output: "ofm" diff --git a/compiler/tflchef/tests/string_tensor/test.recipe b/compiler/tflchef/tests/string_tensor/test.recipe new file mode 100644 index 000000000..eecfbc6f7 --- /dev/null +++ b/compiler/tflchef/tests/string_tensor/test.recipe @@ -0,0 +1,30 @@ +operand { + name: "ifm" + type: STRING + shape { } +} +operand { + name: "suffix" + type: STRING + shape { } + filler { + tag: "explicit" + arg: "Hello" + } +} +operand { + name: "ofm" + type: STRING + shape { } +} +operation { + type: "Add" + input: "ifm" + input: "suffix" + output: "ofm" + add_options { + activation: NONE + } +} +input: "ifm" +output: "ofm" diff --git a/compiler/tflchef/tflite/src/Op/Quantize.cpp b/compiler/tflchef/tflite/src/Op/Quantize.cpp new file mode 100644 index 000000000..0808b9c3f --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/Quantize.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021 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 "Quantize.h" + +#include "Convert.h" + +namespace tflchef +{ + +void TFliteOpQuantize::filler(const tflite::Operator *op, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + // Nothing to do with filler +} + +tflchef::Operation *TFliteOpQuantize::build(const tflite::Operator *, TFliteImport *import, + tflchef::ModelRecipe *model_recipe) const +{ + auto operation = model_recipe->add_operation(); + + operation->set_type("Quantize"); + + return operation; +} + +} // namespace tflchef diff --git a/compiler/tflchef/tflite/src/Op/Quantize.h b/compiler/tflchef/tflite/src/Op/Quantize.h new file mode 100644 index 000000000..256ed5a5c --- /dev/null +++ b/compiler/tflchef/tflite/src/Op/Quantize.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2021 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_QUANTIZE_H__ +#define __TFLITE_OP_QUANTIZE_H__ + +#include "TFliteOpChef.h" + +namespace tflchef +{ + +/** + * @brief tflchef operator builder for Quantize + */ +class TFliteOpQuantize : 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_QUANTIZE_H__ diff --git a/compiler/tflchef/tflite/src/TFliteOpChefs.h b/compiler/tflchef/tflite/src/TFliteOpChefs.h index 960ff6e36..26ada7d0a 100644 --- a/compiler/tflchef/tflite/src/TFliteOpChefs.h +++ b/compiler/tflchef/tflite/src/TFliteOpChefs.h @@ -80,6 +80,7 @@ #include "Op/PadV2.h" #include "Op/Pow.h" #include "Op/PRelu.h" +#include "Op/Quantize.h" #include "Op/Range.h" #include "Op/Rank.h" #include "Op/ReduceAny.h" diff --git a/compiler/tflchef/tflite/src/TFliteOpRegistry.h b/compiler/tflchef/tflite/src/TFliteOpRegistry.h index c240bcf52..06394ddfa 100644 --- a/compiler/tflchef/tflite/src/TFliteOpRegistry.h +++ b/compiler/tflchef/tflite/src/TFliteOpRegistry.h @@ -117,6 +117,7 @@ private: REG_TFL_OP(PADV2, TFliteOpPadV2); REG_TFL_OP(POW, TFliteOpPow); REG_TFL_OP(PRELU, TFliteOpPRelu); + REG_TFL_OP(QUANTIZE, TFliteOpQuantize); REG_TFL_OP(RANGE, TFliteOpRange); REG_TFL_OP(RANK, TFliteOpRank); REG_TFL_OP(REDUCE_ANY, TFliteOpReduceAny); |