From b03103dfd2a4a3d1268dbb096822405d010f3bb8 Mon Sep 17 00:00:00 2001 From: SeungHui Lee Date: Wed, 25 Oct 2023 08:04:02 -0400 Subject: [PATCH] Apply comment --- compiler/circlechef/core/src/ModelChef.cpp | 10 +++++----- compiler/tflchef/core/src/CustomOp/AddV2.cpp | 6 +++++- compiler/tflchef/core/src/CustomOp/All.cpp | 6 +++++- compiler/tflchef/core/src/CustomOp/BatchMatMulV2.cpp | 6 +++++- compiler/tflchef/core/src/CustomOp/BroadcastTo.cpp | 6 +++++- compiler/tflchef/core/src/CustomOp/Erf.cpp | 6 +++++- compiler/tflchef/core/src/CustomOp/MatMul.cpp | 6 +++++- compiler/tflchef/core/src/CustomOp/MatrixBandPart.cpp | 6 +++++- .../tflchef/core/src/CustomOp/MaxPoolWithArgmax.cpp | 6 +++++- compiler/tflchef/core/src/ModelChef.cpp | 10 +++++----- compiler/tflchef/tests/custom_erf/test.recipe | 3 ++- res/TensorFlowLiteRecipes/All_000/test.recipe | 3 ++- 12 files changed, 54 insertions(+), 20 deletions(-) diff --git a/compiler/circlechef/core/src/ModelChef.cpp b/compiler/circlechef/core/src/ModelChef.cpp index a2148488eeb..b491a4fe893 100644 --- a/compiler/circlechef/core/src/ModelChef.cpp +++ b/compiler/circlechef/core/src/ModelChef.cpp @@ -135,7 +135,7 @@ gather_builtincode_map(const ::circlechef::ModelRecipe &model_recipe) for (const auto &operation : model_recipe.operation()) { - if (operation.type() == "Custom") + if (operation.has_extype() && operation.extype() == "Custom") continue; auto op_chef = op_chef_registry().lookup(operation.type()).create(&operation); @@ -152,7 +152,7 @@ gather_builtincode_map(const ::circlechef::ModelRecipe &model_recipe) const auto &graph = model_recipe.graph(g); for (const auto &operation : graph.operation()) { - if (operation.type() == "Custom") + if (operation.has_extype() && operation.extype() == "Custom") continue; auto op_chef = op_chef_registry().lookup(operation.type()).create(&operation); @@ -172,7 +172,7 @@ std::set gather_customcode_set(const ::circlechef::ModelRecipe &mod std::set customcode_set; for (const auto &operation : model_recipe.operation()) { - if (operation.type() == "Custom") + if (operation.has_extype() && operation.extype() == "Custom") customcode_set.insert(operation.custom_code()); } @@ -182,7 +182,7 @@ std::set gather_customcode_set(const ::circlechef::ModelRecipe &mod const auto &graph = model_recipe.graph(g); for (const auto &operation : graph.operation()) { - if (operation.type() == "Custom") + if (operation.has_extype() && operation.extype() == "Custom") customcode_set.insert(operation.custom_code()); } } @@ -418,7 +418,7 @@ template void cook_graph(const T &graph, CookParams &cp) assert(operation.has_type()); std::string op_type = operation.type(); - if (op_type == "Custom") + if (operation.has_custom_code()) op_type = operation.custom_code(); auto op_chef = op_chef_registry().lookup(op_type).create(&operation); diff --git a/compiler/tflchef/core/src/CustomOp/AddV2.cpp b/compiler/tflchef/core/src/CustomOp/AddV2.cpp index eeb63b96f6a..151a01025bc 100644 --- a/compiler/tflchef/core/src/CustomOp/AddV2.cpp +++ b/compiler/tflchef/core/src/CustomOp/AddV2.cpp @@ -29,7 +29,11 @@ AddV2Chef::custom_value(flatbuffers::FlatBufferBuilder &fbb) const { auto &operation = (*_operation); - assert(operation.custom_code() == "AddV2"); + if (operation.has_extype() && operation.extype() == "Custom") + { + assert(operation.has_custom_code()); + assert(operation.custom_code() == "AddV2"); + } /** * REGISTER_OP("AddV2") diff --git a/compiler/tflchef/core/src/CustomOp/All.cpp b/compiler/tflchef/core/src/CustomOp/All.cpp index 56a6630470c..7e33c6ffb1a 100644 --- a/compiler/tflchef/core/src/CustomOp/All.cpp +++ b/compiler/tflchef/core/src/CustomOp/All.cpp @@ -29,7 +29,11 @@ AllChef::custom_value(flatbuffers::FlatBufferBuilder &fbb) const { auto &operation = (*_operation); - assert(operation.custom_code() == "All"); + if (operation.has_extype() && operation.extype() == "Custom") + { + assert(operation.has_custom_code()); + assert(operation.custom_code() == "All"); + } /** * REGISTER_OP("All") diff --git a/compiler/tflchef/core/src/CustomOp/BatchMatMulV2.cpp b/compiler/tflchef/core/src/CustomOp/BatchMatMulV2.cpp index 84d05150836..24833c5f48b 100644 --- a/compiler/tflchef/core/src/CustomOp/BatchMatMulV2.cpp +++ b/compiler/tflchef/core/src/CustomOp/BatchMatMulV2.cpp @@ -29,7 +29,11 @@ BatchMatMulV2Chef::custom_value(flatbuffers::FlatBufferBuilder &fbb) const { auto &operation = (*_operation); - assert(operation.custom_code() == "BatchMatMulV2"); + if (operation.has_extype() && operation.extype() == "Custom") + { + assert(operation.has_custom_code()); + assert(operation.custom_code() == "BatchMatMulV2"); + } /** * REGISTER_OP("BatchMatMulV2") diff --git a/compiler/tflchef/core/src/CustomOp/BroadcastTo.cpp b/compiler/tflchef/core/src/CustomOp/BroadcastTo.cpp index 5d43c72a31e..b39c7d666d2 100644 --- a/compiler/tflchef/core/src/CustomOp/BroadcastTo.cpp +++ b/compiler/tflchef/core/src/CustomOp/BroadcastTo.cpp @@ -29,7 +29,11 @@ BroadcastToChef::custom_value(flatbuffers::FlatBufferBuilder &fbb) const { auto &operation = (*_operation); - assert(operation.custom_code() == "BroadcastTo"); + if (operation.has_extype() && operation.extype() == "Custom") + { + assert(operation.has_custom_code()); + assert(operation.custom_code() == "BroadcastTo"); + } /** * REGISTER_OP("BroadcastTo") diff --git a/compiler/tflchef/core/src/CustomOp/Erf.cpp b/compiler/tflchef/core/src/CustomOp/Erf.cpp index 2e2605b6689..6393a5bd3b0 100644 --- a/compiler/tflchef/core/src/CustomOp/Erf.cpp +++ b/compiler/tflchef/core/src/CustomOp/Erf.cpp @@ -29,7 +29,11 @@ ErfChef::custom_value(flatbuffers::FlatBufferBuilder &fbb) const { auto &operation = (*_operation); - assert(operation.custom_code() == "Erf"); + if (operation.has_extype() && operation.extype() == "Custom") + { + assert(operation.has_custom_code()); + assert(operation.custom_code() == "Erf"); + } /** * REGISTER_OP("Erf") diff --git a/compiler/tflchef/core/src/CustomOp/MatMul.cpp b/compiler/tflchef/core/src/CustomOp/MatMul.cpp index 32110d9ecb3..5f5f2c048db 100644 --- a/compiler/tflchef/core/src/CustomOp/MatMul.cpp +++ b/compiler/tflchef/core/src/CustomOp/MatMul.cpp @@ -29,7 +29,11 @@ MatMulChef::custom_value(flatbuffers::FlatBufferBuilder &fbb) const { auto &operation = (*_operation); - assert(operation.custom_code() == "MatMul"); + if (operation.has_extype() && operation.extype() == "Custom") + { + assert(operation.has_custom_code()); + assert(operation.custom_code() == "MatMul"); + } /** * REGISTER_OP("MatMul") diff --git a/compiler/tflchef/core/src/CustomOp/MatrixBandPart.cpp b/compiler/tflchef/core/src/CustomOp/MatrixBandPart.cpp index 2efaa447b1f..46ea5c0d574 100644 --- a/compiler/tflchef/core/src/CustomOp/MatrixBandPart.cpp +++ b/compiler/tflchef/core/src/CustomOp/MatrixBandPart.cpp @@ -29,7 +29,11 @@ MatrixBandPartChef::custom_value(flatbuffers::FlatBufferBuilder &fbb) const { auto &operation = (*_operation); - assert(operation.custom_code() == "MatrixBandPart"); + if (operation.has_extype() && operation.extype() == "Custom") + { + assert(operation.has_custom_code()); + assert(operation.custom_code() == "MatrixBandPart"); + } /** * REGISTER_OP("MatrixBandPart") diff --git a/compiler/tflchef/core/src/CustomOp/MaxPoolWithArgmax.cpp b/compiler/tflchef/core/src/CustomOp/MaxPoolWithArgmax.cpp index d930819a26b..a2c0ed2e79e 100644 --- a/compiler/tflchef/core/src/CustomOp/MaxPoolWithArgmax.cpp +++ b/compiler/tflchef/core/src/CustomOp/MaxPoolWithArgmax.cpp @@ -29,7 +29,11 @@ MaxPoolWithArgmaxChef::custom_value(flatbuffers::FlatBufferBuilder &fbb) const { auto &operation = (*_operation); - assert(operation.custom_code() == "MaxPoolWithArgmax"); + if (operation.has_extype() && operation.extype() == "Custom") + { + assert(operation.has_custom_code()); + assert(operation.custom_code() == "MaxPoolWithArgmax"); + } /** * REGISTER_OP("MaxPoolWithArgmax") diff --git a/compiler/tflchef/core/src/ModelChef.cpp b/compiler/tflchef/core/src/ModelChef.cpp index 00dbaeed15c..128f818ed4e 100644 --- a/compiler/tflchef/core/src/ModelChef.cpp +++ b/compiler/tflchef/core/src/ModelChef.cpp @@ -141,7 +141,7 @@ gather_builtincode_map(const ::tflchef::ModelRecipe &model_recipe) for (const auto &operation : model_recipe.operation()) { - if (operation.type() == "Custom") + if (operation.has_extype() && operation.extype() == "Custom") continue; auto op_chef = op_chef_registry().lookup(operation.type()).create(&operation); @@ -157,7 +157,7 @@ gather_builtincode_map(const ::tflchef::ModelRecipe &model_recipe) const auto &graph = model_recipe.graph(g); for (const auto &operation : graph.operation()) { - if (operation.type() == "Custom") + if (operation.has_extype() && operation.extype() == "Custom") continue; auto op_chef = op_chef_registry().lookup(operation.type()).create(&operation); @@ -177,7 +177,7 @@ std::set gather_customcode_set(const ::tflchef::ModelRecipe &model_ std::set customcode_set; for (const auto &operation : model_recipe.operation()) { - if (operation.type() == "Custom") + if (operation.has_extype() && operation.extype() == "Custom") customcode_set.insert(operation.custom_code()); } @@ -187,7 +187,7 @@ std::set gather_customcode_set(const ::tflchef::ModelRecipe &model_ const auto &graph = model_recipe.graph(g); for (const auto &operation : graph.operation()) { - if (operation.type() == "Custom") + if (operation.has_extype() && operation.extype() == "Custom") customcode_set.insert(operation.custom_code()); } } @@ -618,7 +618,7 @@ template std::map cook_graph(const T &graph, assert(operation.has_type()); std::string op_type = operation.type(); - if (op_type == "Custom") + if (operation.has_custom_code()) op_type = operation.custom_code(); auto op_chef = op_chef_registry().lookup(op_type).create(&operation); diff --git a/compiler/tflchef/tests/custom_erf/test.recipe b/compiler/tflchef/tests/custom_erf/test.recipe index 8877b0ebc8b..417455bd058 100644 --- a/compiler/tflchef/tests/custom_erf/test.recipe +++ b/compiler/tflchef/tests/custom_erf/test.recipe @@ -9,10 +9,11 @@ operand { shape { dim: 1 dim: 3 dim: 3 dim: 2 } } operation { - type: "Custom" + type: "Erf" input: "ifm" output: "ofm" custom_code: "Erf" + extype: "Custom" } input: "ifm" output: "ofm" diff --git a/res/TensorFlowLiteRecipes/All_000/test.recipe b/res/TensorFlowLiteRecipes/All_000/test.recipe index 38187222f32..5a44082149f 100644 --- a/res/TensorFlowLiteRecipes/All_000/test.recipe +++ b/res/TensorFlowLiteRecipes/All_000/test.recipe @@ -18,7 +18,7 @@ operand { } } operation { - type: "Custom" + type: "All" all_options { keep_dims: false } @@ -26,6 +26,7 @@ operation { input: "All/reduction_indices" output: "ofm" custom_code: "All" + extype: "Custom" } input: "ifm" output: "ofm"