summaryrefslogtreecommitdiff
path: root/compiler/tflchef/tflite/src
diff options
context:
space:
mode:
authorHyeongseok Oh <hseok82.oh@samsung.com>2023-09-08 10:51:25 +0000
committerHyeongseok Oh <hseok82.oh@samsung.com>2023-09-08 10:51:25 +0000
commiteed258505ee1ad0f72d9e0a8a3934f2e9e7b5e79 (patch)
tree1aa860656489469003375a0f67edb1d729f7dc6b /compiler/tflchef/tflite/src
parent3a0ad354832744d138b361ffcfd21f33494beb6b (diff)
downloadnnfw-eed258505ee1ad0f72d9e0a8a3934f2e9e7b5e79.tar.gz
nnfw-eed258505ee1ad0f72d9e0a8a3934f2e9e7b5e79.tar.bz2
nnfw-eed258505ee1ad0f72d9e0a8a3934f2e9e7b5e79.zip
Diffstat (limited to 'compiler/tflchef/tflite/src')
-rw-r--r--compiler/tflchef/tflite/src/Convert.cpp2
-rw-r--r--compiler/tflchef/tflite/src/Op/Gelu.cpp46
-rw-r--r--compiler/tflchef/tflite/src/Op/HardSwish.cpp40
-rw-r--r--compiler/tflchef/tflite/src/Op/PRelu.cpp5
-rw-r--r--compiler/tflchef/tflite/src/Op/TransposeConv.cpp2
-rw-r--r--compiler/tflchef/tflite/src/Op/include/Gelu.h39
-rw-r--r--compiler/tflchef/tflite/src/Op/include/HardSwish.h39
-rw-r--r--compiler/tflchef/tflite/src/RecipeChef.cpp2
-rw-r--r--compiler/tflchef/tflite/src/TFliteImport.cpp2
-rw-r--r--compiler/tflchef/tflite/src/TFliteOpChefs.h2
-rw-r--r--compiler/tflchef/tflite/src/TFliteOpRegistry.h2
11 files changed, 179 insertions, 2 deletions
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);