diff options
Diffstat (limited to 'compiler/tflchef/core/src/Op')
23 files changed, 762 insertions, 5 deletions
diff --git a/compiler/tflchef/core/src/Op/BidirectionalSequenceLSTM.cpp b/compiler/tflchef/core/src/Op/BidirectionalSequenceLSTM.cpp new file mode 100644 index 000000000..1bf2264ab --- /dev/null +++ b/compiler/tflchef/core/src/Op/BidirectionalSequenceLSTM.cpp @@ -0,0 +1,47 @@ +/* + * 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 "BidirectionalSequenceLSTM.h" +#include "Convert.h" + +#include <cassert> + +flatbuffers::Offset<void> +BidirectionalSequenceLSTMChef::value(flatbuffers::FlatBufferBuilder &fbb) const +{ + auto &operation = (*_operation); + + assert(operation.has_bidirectional_sequence_lstm_options()); + + tflite::BidirectionalSequenceLSTMOptionsBuilder options_builder(fbb); + options_builder.add_fused_activation_function( + as_tflite_activation(operation.bidirectional_sequence_lstm_options().activation())); + options_builder.add_cell_clip(operation.bidirectional_sequence_lstm_options().cell_clip()); + options_builder.add_proj_clip(operation.bidirectional_sequence_lstm_options().proj_clip()); + options_builder.add_time_major(operation.bidirectional_sequence_lstm_options().time_major()); + options_builder.add_asymmetric_quantize_inputs( + operation.bidirectional_sequence_lstm_options().asymmetric_quantize_inputs()); + options_builder.add_merge_outputs( + operation.bidirectional_sequence_lstm_options().merge_outputs()); + + return options_builder.Finish().Union(); +} + +std::unique_ptr<OpChef> +BidirectionalSequenceLSTMChefFactory::create(const tflchef::Operation *operation) const +{ + return std::unique_ptr<OpChef>{new BidirectionalSequenceLSTMChef{operation}}; +} diff --git a/compiler/tflchef/core/src/Op/BidirectionalSequenceLSTM.h b/compiler/tflchef/core/src/Op/BidirectionalSequenceLSTM.h new file mode 100644 index 000000000..e66917b97 --- /dev/null +++ b/compiler/tflchef/core/src/Op/BidirectionalSequenceLSTM.h @@ -0,0 +1,53 @@ +/* + * 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 __OP_BIDIRECTIONALSEQUENCE_LSTM_H__ +#define __OP_BIDIRECTIONALSEQUENCE_LSTM_H__ + +#include "OpChef.h" + +class BidirectionalSequenceLSTMChef final : public OpChef +{ +public: + explicit BidirectionalSequenceLSTMChef(const tflchef::Operation *operation) + : _operation{operation} + { + // DO NOTHING + } + +public: + tflite::BuiltinOperator code(void) const override + { + return tflite::BuiltinOperator_BIDIRECTIONAL_SEQUENCE_LSTM; + } + + tflite::BuiltinOptions type(void) const override + { + return tflite::BuiltinOptions_BidirectionalSequenceLSTMOptions; + } + + flatbuffers::Offset<void> value(flatbuffers::FlatBufferBuilder &fbb) const override; + +private: + const tflchef::Operation *_operation; +}; + +struct BidirectionalSequenceLSTMChefFactory final : public OpChefFactory +{ + std::unique_ptr<OpChef> create(const tflchef::Operation *operation) const override; +}; + +#endif // __OP_BIDIRECTIONALSEQUENCE_LSTM_H__ diff --git a/compiler/tflchef/core/src/Op/Densify.cpp b/compiler/tflchef/core/src/Op/Densify.cpp new file mode 100644 index 000000000..63c4e207a --- /dev/null +++ b/compiler/tflchef/core/src/Op/Densify.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2022 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 "Densify.h" + +flatbuffers::Offset<void> DensifyChef::value(flatbuffers::FlatBufferBuilder &fbb) const +{ + tflite::DensifyOptionsBuilder options_builder{fbb}; + + return options_builder.Finish().Union(); +} + +std::unique_ptr<OpChef> DensifyChefFactory::create(const tflchef::Operation *operation) const +{ + return std::unique_ptr<OpChef>{new DensifyChef{operation}}; +} diff --git a/compiler/tflchef/core/src/Op/Densify.h b/compiler/tflchef/core/src/Op/Densify.h new file mode 100644 index 000000000..f6af693d9 --- /dev/null +++ b/compiler/tflchef/core/src/Op/Densify.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 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_DENSIFY_H__ +#define __OP_DENSIFY_H__ + +#include "OpChef.h" + +class DensifyChef final : public OpChef +{ +public: + explicit DensifyChef(const tflchef::Operation *operation) : _operation{operation} + { + // DO NOTHING + } + +public: + tflite::BuiltinOperator code(void) const override { return tflite::BuiltinOperator_DENSIFY; } + + tflite::BuiltinOptions type(void) const override { return tflite::BuiltinOptions_DensifyOptions; } + + flatbuffers::Offset<void> value(flatbuffers::FlatBufferBuilder &fbb) const override; + +private: + const tflchef::Operation *_operation; +}; + +struct DensifyChefFactory final : public OpChefFactory +{ + std::unique_ptr<OpChef> create(const tflchef::Operation *operation) const override; +}; + +#endif // __OP_DENSIFY_H__ diff --git a/compiler/tflchef/core/src/Op/Dequantize.cpp b/compiler/tflchef/core/src/Op/Dequantize.cpp new file mode 100644 index 000000000..761d7f99e --- /dev/null +++ b/compiler/tflchef/core/src/Op/Dequantize.cpp @@ -0,0 +1,27 @@ +/* + * 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 "Dequantize.h" + +flatbuffers::Offset<void> DequantizeChef::value(flatbuffers::FlatBufferBuilder &fbb) const +{ + return flatbuffers::Offset<void>(); +} + +std::unique_ptr<OpChef> DequantizeChefFactory::create(const tflchef::Operation *operation) const +{ + return std::unique_ptr<OpChef>{new DequantizeChef{operation}}; +} diff --git a/compiler/tflchef/core/src/Op/Dequantize.h b/compiler/tflchef/core/src/Op/Dequantize.h new file mode 100644 index 000000000..82580560d --- /dev/null +++ b/compiler/tflchef/core/src/Op/Dequantize.h @@ -0,0 +1,46 @@ +/* + * 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 __OP_DEQUANTIZE_H__ +#define __OP_DEQUANTIZE_H__ + +#include "OpChef.h" + +class DequantizeChef final : public OpChef +{ +public: + explicit DequantizeChef(const tflchef::Operation *operation) : _operation{operation} + { + // DO NOTHING + } + +public: + tflite::BuiltinOperator code(void) const override { return tflite::BuiltinOperator_DEQUANTIZE; } + + 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 DequantizeChefFactory 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/Op/FakeQuant.cpp b/compiler/tflchef/core/src/Op/FakeQuant.cpp new file mode 100644 index 000000000..e4cbbfe44 --- /dev/null +++ b/compiler/tflchef/core/src/Op/FakeQuant.cpp @@ -0,0 +1,41 @@ +/* + * 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 "FakeQuant.h" +#include "Convert.h" + +#include <cassert> + +flatbuffers::Offset<void> FakeQuantChef::value(flatbuffers::FlatBufferBuilder &fbb) const +{ + auto &operation = (*_operation); + assert(operation.has_fakequant_options()); + + auto options = operation.fakequant_options(); + + tflite::FakeQuantOptionsBuilder fq_options_builder{fbb}; + fq_options_builder.add_min(options.min()); + fq_options_builder.add_max(options.max()); + fq_options_builder.add_num_bits(options.num_bits()); + fq_options_builder.add_narrow_range(options.narrow_range()); + + return fq_options_builder.Finish().Union(); +} + +std::unique_ptr<OpChef> FakeQuantChefFactory::create(const tflchef::Operation *operation) const +{ + return std::unique_ptr<OpChef>{new FakeQuantChef{operation}}; +} diff --git a/compiler/tflchef/core/src/Op/FakeQuant.h b/compiler/tflchef/core/src/Op/FakeQuant.h new file mode 100644 index 000000000..0fbfea315 --- /dev/null +++ b/compiler/tflchef/core/src/Op/FakeQuant.h @@ -0,0 +1,49 @@ +/* + * 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_FAKE_QUANT_H__ +#define __OP_FAKE_QUANT_H__ + +#include "OpChef.h" + +class FakeQuantChef final : public OpChef +{ +public: + explicit FakeQuantChef(const tflchef::Operation *operation) : _operation{operation} + { + // DO NOTHING + } + +public: + tflite::BuiltinOperator code(void) const override { return tflite::BuiltinOperator_FAKE_QUANT; } + + tflite::BuiltinOptions type(void) const override + { + return tflite::BuiltinOptions_FakeQuantOptions; + } + + flatbuffers::Offset<void> value(flatbuffers::FlatBufferBuilder &fbb) const override; + +private: + const tflchef::Operation *_operation; +}; + +struct FakeQuantChefFactory final : public OpChefFactory +{ + std::unique_ptr<OpChef> create(const tflchef::Operation *operation) const override; +}; + +#endif // __OP_FAKE_QUANT_H__ diff --git a/compiler/tflchef/core/src/Op/FullyConnected.cpp b/compiler/tflchef/core/src/Op/FullyConnected.cpp index 45269916c..7173a67ba 100644 --- a/compiler/tflchef/core/src/Op/FullyConnected.cpp +++ b/compiler/tflchef/core/src/Op/FullyConnected.cpp @@ -29,6 +29,7 @@ flatbuffers::Offset<void> FullyConnectedChef::value(flatbuffers::FlatBufferBuild tflite::FullyConnectedOptionsBuilder fc_options_builder{fbb}; fc_options_builder.add_fused_activation_function(tflite_activation); + fc_options_builder.add_keep_num_dims(operation.fullyconnected_options().keep_num_dims()); return fc_options_builder.Finish().Union(); } 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/LocalResponseNormalization.h b/compiler/tflchef/core/src/Op/LocalResponseNormalization.h index 62a2355f2..afc37e6ec 100644 --- a/compiler/tflchef/core/src/Op/LocalResponseNormalization.h +++ b/compiler/tflchef/core/src/Op/LocalResponseNormalization.h @@ -23,7 +23,7 @@ class LocalResponseNormalizationChef final : public OpChef { public: explicit LocalResponseNormalizationChef(const tflchef::Operation *operation) - : _operation{operation} + : _operation{operation} { // DO NOTHING } 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/Op/SVDF.cpp b/compiler/tflchef/core/src/Op/SVDF.cpp new file mode 100644 index 000000000..690896cf1 --- /dev/null +++ b/compiler/tflchef/core/src/Op/SVDF.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2022 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 "SVDF.h" +#include "Convert.h" + +#include <cassert> + +flatbuffers::Offset<void> SVDFChef::value(flatbuffers::FlatBufferBuilder &fbb) const +{ + assert(_operation->has_svdf_options()); + + const auto &svdf_options = _operation->svdf_options(); + + const auto tflite_activation = as_tflite_activation(svdf_options.activation()); + + tflite::SVDFOptionsBuilder svdf_options_builder{fbb}; + svdf_options_builder.add_fused_activation_function(tflite_activation); + svdf_options_builder.add_asymmetric_quantize_inputs(svdf_options.asymmetric_quantize_inputs()); + svdf_options_builder.add_rank(svdf_options.rank()); + + return svdf_options_builder.Finish().Union(); +} + +std::unique_ptr<OpChef> SVDFChefFactory::create(const tflchef::Operation *operation) const +{ + return std::unique_ptr<OpChef>{new SVDFChef{operation}}; +} diff --git a/compiler/tflchef/core/src/Op/SVDF.h b/compiler/tflchef/core/src/Op/SVDF.h new file mode 100644 index 000000000..9bf0b6efb --- /dev/null +++ b/compiler/tflchef/core/src/Op/SVDF.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 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_SVDF_H__ +#define __OP_SVDF_H__ + +#include "OpChef.h" + +class SVDFChef final : public OpChef +{ +public: + explicit SVDFChef(const tflchef::Operation *operation) : _operation{operation} + { + // DO NOTHING + } + +public: + tflite::BuiltinOperator code(void) const override { return tflite::BuiltinOperator_SVDF; } + + tflite::BuiltinOptions type(void) const override { return tflite::BuiltinOptions_SVDFOptions; } + + flatbuffers::Offset<void> value(flatbuffers::FlatBufferBuilder &fbb) const override; + +private: + const tflchef::Operation *_operation; +}; + +struct SVDFChefFactory final : public OpChefFactory +{ + std::unique_ptr<OpChef> create(const tflchef::Operation *operation) const override; +}; + +#endif // __OP_SVDF_H__ diff --git a/compiler/tflchef/core/src/Op/Squeeze.cpp b/compiler/tflchef/core/src/Op/Squeeze.cpp index 8d6ef42d6..1c1d99a01 100644 --- a/compiler/tflchef/core/src/Op/Squeeze.cpp +++ b/compiler/tflchef/core/src/Op/Squeeze.cpp @@ -30,7 +30,7 @@ flatbuffers::Offset<void> SqueezeChef::value(flatbuffers::FlatBufferBuilder &fbb // Note: 'CreateVector' should be placed before 'CreateOptions' // Read flatbuffers.h 'void NotNested()' for more information auto fb_squeeze_dims = - fbb.CreateVector(options.squeeze_dim().data(), options.squeeze_dim().size()); + fbb.CreateVector(options.squeeze_dim().data(), options.squeeze_dim().size()); return tflite::CreateSqueezeOptions(fbb, fb_squeeze_dims).Union(); } diff --git a/compiler/tflchef/core/src/Op/StridedSlice.cpp b/compiler/tflchef/core/src/Op/StridedSlice.cpp index 587a95c66..67fd03140 100644 --- a/compiler/tflchef/core/src/Op/StridedSlice.cpp +++ b/compiler/tflchef/core/src/Op/StridedSlice.cpp @@ -29,11 +29,11 @@ flatbuffers::Offset<void> StridedSliceChef::value(flatbuffers::FlatBufferBuilder strided_slice_options_builder.add_begin_mask(operation.strided_slice_options().begin_mask()); strided_slice_options_builder.add_end_mask(operation.strided_slice_options().end_mask()); strided_slice_options_builder.add_ellipsis_mask( - operation.strided_slice_options().ellipsis_mask()); + operation.strided_slice_options().ellipsis_mask()); strided_slice_options_builder.add_new_axis_mask( - operation.strided_slice_options().new_axis_mask()); + operation.strided_slice_options().new_axis_mask()); strided_slice_options_builder.add_shrink_axis_mask( - operation.strided_slice_options().shrink_axis_mask()); + operation.strided_slice_options().shrink_axis_mask()); return strided_slice_options_builder.Finish().Union(); } 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/Op/UnidirectionalSequenceLSTM.cpp b/compiler/tflchef/core/src/Op/UnidirectionalSequenceLSTM.cpp new file mode 100644 index 000000000..2d6becdff --- /dev/null +++ b/compiler/tflchef/core/src/Op/UnidirectionalSequenceLSTM.cpp @@ -0,0 +1,45 @@ +/* + * 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 "UnidirectionalSequenceLSTM.h" +#include "Convert.h" + +#include <cassert> + +flatbuffers::Offset<void> +UnidirectionalSequenceLSTMChef::value(flatbuffers::FlatBufferBuilder &fbb) const +{ + auto &operation = (*_operation); + + assert(operation.has_unidirectional_sequence_lstm_options()); + + tflite::UnidirectionalSequenceLSTMOptionsBuilder options_builder(fbb); + options_builder.add_fused_activation_function( + as_tflite_activation(operation.unidirectional_sequence_lstm_options().activation())); + options_builder.add_cell_clip(operation.unidirectional_sequence_lstm_options().cell_clip()); + options_builder.add_proj_clip(operation.unidirectional_sequence_lstm_options().proj_clip()); + options_builder.add_time_major(operation.unidirectional_sequence_lstm_options().time_major()); + options_builder.add_asymmetric_quantize_inputs( + operation.unidirectional_sequence_lstm_options().asymmetric_quantize_inputs()); + + return options_builder.Finish().Union(); +} + +std::unique_ptr<OpChef> +UnidirectionalSequenceLSTMChefFactory::create(const tflchef::Operation *operation) const +{ + return std::unique_ptr<OpChef>{new UnidirectionalSequenceLSTMChef{operation}}; +} diff --git a/compiler/tflchef/core/src/Op/UnidirectionalSequenceLSTM.h b/compiler/tflchef/core/src/Op/UnidirectionalSequenceLSTM.h new file mode 100644 index 000000000..b8a6d8103 --- /dev/null +++ b/compiler/tflchef/core/src/Op/UnidirectionalSequenceLSTM.h @@ -0,0 +1,53 @@ +/* + * 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 __OP_UNIDIRECTIONALSEQUENCELSTM_H__ +#define __OP_UNIDIRECTIONALSEQUENCELSTM_H__ + +#include "OpChef.h" + +class UnidirectionalSequenceLSTMChef final : public OpChef +{ +public: + explicit UnidirectionalSequenceLSTMChef(const tflchef::Operation *operation) + : _operation{operation} + { + // DO NOTHING + } + +public: + tflite::BuiltinOperator code(void) const override + { + return tflite::BuiltinOperator_UNIDIRECTIONAL_SEQUENCE_LSTM; + } + + tflite::BuiltinOptions type(void) const override + { + return tflite::BuiltinOptions_UnidirectionalSequenceLSTMOptions; + } + + flatbuffers::Offset<void> value(flatbuffers::FlatBufferBuilder &fbb) const override; + +private: + const tflchef::Operation *_operation; +}; + +struct UnidirectionalSequenceLSTMChefFactory final : public OpChefFactory +{ + std::unique_ptr<OpChef> create(const tflchef::Operation *operation) const override; +}; + +#endif // __OP_UNIDIRECTIONALSEQUENCELSTM_H__ |