Skip to content

Commit

Permalink
[DRAFT][tflchef] Support multiple subgraphs
Browse files Browse the repository at this point in the history
This draft adds supporting of multiple subgraphs and While operation.

ONE-DCO-1.0-Signed-off-by: Artem Balyshev <[email protected]>
  • Loading branch information
Artem Balyshev committed Jan 24, 2024
1 parent 9890845 commit eb1cd00
Show file tree
Hide file tree
Showing 236 changed files with 933 additions and 820 deletions.
6 changes: 6 additions & 0 deletions compiler/souschef/include/souschef/TensorFiller.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ class TensorFiller
return false;
}

void clear_tensor_filler() { _tensor_filler.clear(); }

void clear_tensor_filler_vint32() { _tensor_filler_vint32.clear(); }

void clear_tensor_filler_vfloat() { _tensor_filler_vfloat.clear(); }

private:
std::map<uint32_t, bool> _tensor_filler{};
std::map<uint32_t, std::vector<int32_t>> _tensor_filler_vint32{};
Expand Down
6 changes: 3 additions & 3 deletions compiler/tflchef/tflite/src/Op/Abs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ void TFliteOpAbs::filler(const tflite::Operator *op, TFliteImport *import,
// Nothing to do with filler
}

tflchef::Operation *TFliteOpAbs::build(const tflite::Operator *op, TFliteImport *import,
tflchef::ModelRecipe *model_recipe) const
tflchef::Operation *TFliteOpAbs::build(RecipeChefContext *ctx) const
{
auto operation = model_recipe->add_operation();
tflchef::Operation *operation = ctx->chefop;
const tflite::Operator *op = ctx->tflop;

operation->set_type("Abs");

Expand Down
9 changes: 5 additions & 4 deletions compiler/tflchef/tflite/src/Op/Add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ void TFliteOpAdd::filler(const tflite::Operator *op, TFliteImport *import,
fill_two_inputs(op, import);
}

tflchef::Operation *TFliteOpAdd::build(const tflite::Operator *op, TFliteImport *import,
tflchef::ModelRecipe *model_recipe) const
tflchef::Operation *TFliteOpAdd::build(RecipeChefContext *ctx) const

{
tflchef::Operation *operation = ctx->chefop;
const tflite::Operator *op = ctx->tflop;

auto op_params = op->builtin_options_as_AddOptions();
assert(op_params != nullptr);

auto operation = model_recipe->add_operation();

operation->set_type("Add");

auto op_options = operation->mutable_add_options();
Expand Down
7 changes: 4 additions & 3 deletions compiler/tflchef/tflite/src/Op/AddN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ void TFliteOpAddN::filler(const tflite::Operator *op, TFliteImport *import,
fill_tensor_to_import(inputs[idx], import);
}

tflchef::Operation *TFliteOpAddN::build(const tflite::Operator *op, TFliteImport *import,
tflchef::ModelRecipe *model_recipe) const
tflchef::Operation *TFliteOpAddN::build(RecipeChefContext *ctx) const

{
auto operation = model_recipe->add_operation();
tflchef::Operation *operation = ctx->chefop;
const tflite::Operator *op = ctx->tflop;

operation->set_type("AddN");

Expand Down
8 changes: 4 additions & 4 deletions compiler/tflchef/tflite/src/Op/ArgMax.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ void TFliteOpArgMax::filler(const tflite::Operator *op, TFliteImport *import,
import->set_tensor_filler(inputs[1], vec);
}

tflchef::Operation *TFliteOpArgMax::build(const tflite::Operator *op, TFliteImport *import,
tflchef::ModelRecipe *model_recipe) const
tflchef::Operation *TFliteOpArgMax::build(RecipeChefContext *ctx) const
{
tflchef::Operation *operation = ctx->chefop;
const tflite::Operator *op = ctx->tflop;

auto op_params = op->builtin_options_as_ArgMaxOptions();
assert(op_params != nullptr);

auto operation = model_recipe->add_operation();

operation->set_type("ArgMax");

auto op_options = operation->mutable_argmax_options();
Expand Down
9 changes: 5 additions & 4 deletions compiler/tflchef/tflite/src/Op/ArgMin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ void TFliteOpArgMin::filler(const tflite::Operator *op, TFliteImport *import,
import->set_tensor_filler(inputs[1], vec);
}

tflchef::Operation *TFliteOpArgMin::build(const tflite::Operator *op, TFliteImport *import,
tflchef::ModelRecipe *model_recipe) const
tflchef::Operation *TFliteOpArgMin::build(RecipeChefContext *ctx) const

{
tflchef::Operation *operation = ctx->chefop;
const tflite::Operator *op = ctx->tflop;

auto op_params = op->builtin_options_as_ArgMinOptions();
assert(op_params != nullptr);

auto operation = model_recipe->add_operation();

operation->set_type("ArgMin");

auto op_options = operation->mutable_argmin_options();
Expand Down
9 changes: 5 additions & 4 deletions compiler/tflchef/tflite/src/Op/AveragePool2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ void TFliteOpAveragePool2D::filler(const tflite::Operator *op, TFliteImport *imp
// Nothing to do with filler
}

tflchef::Operation *TFliteOpAveragePool2D::build(const tflite::Operator *op, TFliteImport *import,
tflchef::ModelRecipe *model_recipe) const
tflchef::Operation *TFliteOpAveragePool2D::build(RecipeChefContext *ctx) const

{
tflchef::Operation *operation = ctx->chefop;
const tflite::Operator *op = ctx->tflop;

auto op_params = op->builtin_options_as_Pool2DOptions();
assert(op_params != nullptr);

auto operation = model_recipe->add_operation();

operation->set_type("AveragePool2D");

auto op_options = operation->mutable_averagepool2d_options();
Expand Down
7 changes: 4 additions & 3 deletions compiler/tflchef/tflite/src/Op/BatchMatMul.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ void TFliteOpBatchMatMul::filler(const tflite::Operator *op, TFliteImport *impor
// Nothing to do with filler
}

tflchef::Operation *TFliteOpBatchMatMul::build(const tflite::Operator *op, TFliteImport *import,
tflchef::ModelRecipe *model_recipe) const
tflchef::Operation *TFliteOpBatchMatMul::build(RecipeChefContext *ctx) const

{
auto operation = model_recipe->add_operation();
tflchef::Operation *operation = ctx->chefop;
const tflite::Operator *op = ctx->tflop;

operation->set_type("BatchMatMul");

Expand Down
7 changes: 4 additions & 3 deletions compiler/tflchef/tflite/src/Op/BatchToSpaceND.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ void TFliteOpBatchToSpaceND::filler(const tflite::Operator *op, TFliteImport *im
import->set_tensor_filler(inputs[2], vec);
}

tflchef::Operation *TFliteOpBatchToSpaceND::build(const tflite::Operator *op, TFliteImport *import,
tflchef::ModelRecipe *model_recipe) const
tflchef::Operation *TFliteOpBatchToSpaceND::build(RecipeChefContext *ctx) const

{
auto operation = model_recipe->add_operation();
tflchef::Operation *operation = ctx->chefop;
const tflite::Operator *op = ctx->tflop;

operation->set_type("BatchToSpaceND");

Expand Down
9 changes: 4 additions & 5 deletions compiler/tflchef/tflite/src/Op/BidirectionalSequenceLSTM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,14 @@ void TFliteOpBidirectionalSequenceLSTM::filler(const tflite::Operator *op, TFlit
}
}

tflchef::Operation *
TFliteOpBidirectionalSequenceLSTM::build(const tflite::Operator *op, TFliteImport *import,
tflchef::ModelRecipe *model_recipe) const
tflchef::Operation *TFliteOpBidirectionalSequenceLSTM::build(RecipeChefContext *ctx) const
{
tflchef::Operation *operation = ctx->chefop;
const tflite::Operator *op = ctx->tflop;

auto op_params = op->builtin_options_as_BidirectionalSequenceLSTMOptions();
assert(op_params != nullptr);

auto operation = model_recipe->add_operation();

operation->set_type("BidirectionalSequenceLSTM");

auto op_options = operation->mutable_bidirectional_sequence_lstm_options();
Expand Down
7 changes: 4 additions & 3 deletions compiler/tflchef/tflite/src/Op/BroadcastTo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ void TFliteOpBroadcastTo::filler(const tflite::Operator *op, TFliteImport *impor
fill_tensor_to_import(inputs[1], import);
}

tflchef::Operation *TFliteOpBroadcastTo::build(const tflite::Operator *op, TFliteImport *import,
tflchef::ModelRecipe *model_recipe) const
tflchef::Operation *TFliteOpBroadcastTo::build(RecipeChefContext *ctx) const

{
auto operation = model_recipe->add_operation();
tflchef::Operation *operation = ctx->chefop;
const tflite::Operator *op = ctx->tflop;

operation->set_type("BroadcastTo");

Expand Down
9 changes: 5 additions & 4 deletions compiler/tflchef/tflite/src/Op/Cast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ void TFliteOpCast::filler(const tflite::Operator *op, TFliteImport *import,
// Nothing to do with filler
}

tflchef::Operation *TFliteOpCast::build(const tflite::Operator *op, TFliteImport *import,
tflchef::ModelRecipe *model_recipe) const
tflchef::Operation *TFliteOpCast::build(RecipeChefContext *ctx) const

{
tflchef::Operation *operation = ctx->chefop;
const tflite::Operator *op = ctx->tflop;

auto op_params = op->builtin_options_as_CastOptions();
assert(op_params != nullptr);

auto operation = model_recipe->add_operation();

operation->set_type("Cast");

auto op_options = operation->mutable_cast_options();
Expand Down
7 changes: 4 additions & 3 deletions compiler/tflchef/tflite/src/Op/Ceil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ void TFliteOpCeil::filler(const tflite::Operator *, TFliteImport *, tflchef::Mod
// Nothing to do with filler
}

tflchef::Operation *TFliteOpCeil::build(const tflite::Operator *, TFliteImport *,
tflchef::ModelRecipe *model_recipe) const
tflchef::Operation *TFliteOpCeil::build(RecipeChefContext *ctx) const

{
auto operation = model_recipe->add_operation();
tflchef::Operation *operation = ctx->chefop;
const tflite::Operator *op = ctx->tflop;

operation->set_type("Ceil");

Expand Down
9 changes: 5 additions & 4 deletions compiler/tflchef/tflite/src/Op/Concatenation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ void TFliteOpConcatenation::filler(const tflite::Operator *op, TFliteImport *imp
// Nothing to do with filler
}

tflchef::Operation *TFliteOpConcatenation::build(const tflite::Operator *op, TFliteImport *import,
tflchef::ModelRecipe *model_recipe) const
tflchef::Operation *TFliteOpConcatenation::build(RecipeChefContext *ctx) const

{
tflchef::Operation *operation = ctx->chefop;
const tflite::Operator *op = ctx->tflop;

auto op_params = op->builtin_options_as_ConcatenationOptions();
assert(op_params != nullptr);

auto operation = model_recipe->add_operation();

operation->set_type("Concatenation");

auto op_options = operation->mutable_concatenation_options();
Expand Down
9 changes: 5 additions & 4 deletions compiler/tflchef/tflite/src/Op/Conv2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ void TFliteOpConv2D::filler(const tflite::Operator *op, TFliteImport *import,
import->set_tensor_filler(inputs.at(2)); // bias
}

tflchef::Operation *TFliteOpConv2D::build(const tflite::Operator *op, TFliteImport *import,
tflchef::ModelRecipe *model_recipe) const
tflchef::Operation *TFliteOpConv2D::build(RecipeChefContext *ctx) const

{
tflchef::Operation *operation = ctx->chefop;
const tflite::Operator *op = ctx->tflop;

auto op_params = op->builtin_options_as_Conv2DOptions();
assert(op_params != nullptr);

auto operation = model_recipe->add_operation();

operation->set_type("Conv2D");

auto op_options = operation->mutable_conv2d_options();
Expand Down
7 changes: 4 additions & 3 deletions compiler/tflchef/tflite/src/Op/Cos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ void TFliteOpCos::filler(const tflite::Operator *op, TFliteImport *import,
// Nothing to do with filler
}

tflchef::Operation *TFliteOpCos::build(const tflite::Operator *op, TFliteImport *import,
tflchef::ModelRecipe *model_recipe) const
tflchef::Operation *TFliteOpCos::build(RecipeChefContext *ctx) const

{
auto operation = model_recipe->add_operation();
tflchef::Operation *operation = ctx->chefop;
const tflite::Operator *op = ctx->tflop;

operation->set_type("Cos");

Expand Down
9 changes: 5 additions & 4 deletions compiler/tflchef/tflite/src/Op/CumSum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ void TFliteOpCumsum::filler(const tflite::Operator *op, TFliteImport *import,
import->set_tensor_filler(inputs[1], vec);
}

tflchef::Operation *TFliteOpCumsum::build(const tflite::Operator *op, TFliteImport *import,
tflchef::ModelRecipe *model_recipe) const
tflchef::Operation *TFliteOpCumsum::build(RecipeChefContext *ctx) const

{
tflchef::Operation *operation = ctx->chefop;
const tflite::Operator *op = ctx->tflop;

auto op_params = op->builtin_options_as_CumsumOptions();
assert(op_params != nullptr);

auto operation = model_recipe->add_operation();

operation->set_type("CumSum");
auto op_options = operation->mutable_cumsum_options();

Expand Down
7 changes: 4 additions & 3 deletions compiler/tflchef/tflite/src/Op/DepthToSpace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ void TFliteOpDepthToSpace::filler(const tflite::Operator *op, TFliteImport *impo
// Nothing to do with filler
}

tflchef::Operation *TFliteOpDepthToSpace::build(const tflite::Operator *op, TFliteImport *import,
tflchef::ModelRecipe *model_recipe) const
tflchef::Operation *TFliteOpDepthToSpace::build(RecipeChefContext *ctx) const

{
auto operation = model_recipe->add_operation();
tflchef::Operation *operation = ctx->chefop;
const tflite::Operator *op = ctx->tflop;

operation->set_type("DepthToSpace");

Expand Down
9 changes: 5 additions & 4 deletions compiler/tflchef/tflite/src/Op/DepthwiseConv2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ void TFliteOpDepthwiseConv2D::filler(const tflite::Operator *op, TFliteImport *i
import->set_tensor_filler(inputs.at(2)); // bias
}

tflchef::Operation *TFliteOpDepthwiseConv2D::build(const tflite::Operator *op, TFliteImport *import,
tflchef::ModelRecipe *model_recipe) const
tflchef::Operation *TFliteOpDepthwiseConv2D::build(RecipeChefContext *ctx) const

{
tflchef::Operation *operation = ctx->chefop;
const tflite::Operator *op = ctx->tflop;

auto op_params = op->builtin_options_as_DepthwiseConv2DOptions();
assert(op_params != nullptr);

auto operation = model_recipe->add_operation();

operation->set_type("DepthwiseConv2D");

auto op_options = operation->mutable_depthwiseconv2d_options();
Expand Down
7 changes: 4 additions & 3 deletions compiler/tflchef/tflite/src/Op/Dequantize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ void TFliteOpDequantize::filler(const tflite::Operator *op, TFliteImport *import
// Nothing to do with filler
}

tflchef::Operation *TFliteOpDequantize::build(const tflite::Operator *, TFliteImport *import,
tflchef::ModelRecipe *model_recipe) const
tflchef::Operation *TFliteOpDequantize::build(RecipeChefContext *ctx) const

{
auto operation = model_recipe->add_operation();
tflchef::Operation *operation = ctx->chefop;
const tflite::Operator *op = ctx->tflop;

operation->set_type("Dequantize");

Expand Down
8 changes: 4 additions & 4 deletions compiler/tflchef/tflite/src/Op/Div.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ void TFliteOpDiv::filler(const tflite::Operator *op, TFliteImport *import,
// Nothing to do with filler
}

tflchef::Operation *TFliteOpDiv::build(const tflite::Operator *op, TFliteImport *import,
tflchef::ModelRecipe *model_recipe) const
tflchef::Operation *TFliteOpDiv::build(RecipeChefContext *ctx) const
{
tflchef::Operation *operation = ctx->chefop;
const tflite::Operator *op = ctx->tflop;

auto op_params = op->builtin_options_as_DivOptions();
assert(op_params != nullptr);

auto operation = model_recipe->add_operation();

operation->set_type("Div");

auto op_options = operation->mutable_div_options();
Expand Down
7 changes: 4 additions & 3 deletions compiler/tflchef/tflite/src/Op/ELU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ void TFliteOpELU::filler(const tflite::Operator *op, TFliteImport *import,
// Nothing to do with filler
}

tflchef::Operation *TFliteOpELU::build(const tflite::Operator *, TFliteImport *import,
tflchef::ModelRecipe *model_recipe) const
tflchef::Operation *TFliteOpELU::build(RecipeChefContext *ctx) const

{
auto operation = model_recipe->add_operation();
tflchef::Operation *operation = ctx->chefop;
const tflite::Operator *op = ctx->tflop;

operation->set_type("ELU");

Expand Down
7 changes: 4 additions & 3 deletions compiler/tflchef/tflite/src/Op/Equal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ void TFliteOpEqual::filler(const tflite::Operator *op, TFliteImport *import,
// Nothing to do with filler
}

tflchef::Operation *TFliteOpEqual::build(const tflite::Operator *op, TFliteImport *import,
tflchef::ModelRecipe *model_recipe) const
tflchef::Operation *TFliteOpEqual::build(RecipeChefContext *ctx) const

{
auto operation = model_recipe->add_operation();
tflchef::Operation *operation = ctx->chefop;
const tflite::Operator *op = ctx->tflop;

operation->set_type("Equal");

Expand Down
Loading

0 comments on commit eb1cd00

Please sign in to comment.