Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unique Init, Prepare, Eval functions Kernels N-Z #2351

Merged
merged 6 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tensorflow/lite/micro/kernels/neg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace {
constexpr int kInputTensor = 0;
constexpr int kOutputTensor = 0;

TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
TfLiteStatus NegEval(TfLiteContext* context, TfLiteNode* node) {
const TfLiteEvalTensor* input =
tflite::micro::GetEvalInput(context, node, kInputTensor);
TfLiteEvalTensor* output =
Expand All @@ -51,7 +51,7 @@ TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
} // namespace

TFLMRegistration Register_NEG() {
return tflite::micro::RegisterOp(nullptr, nullptr, Eval);
return tflite::micro::RegisterOp(nullptr, nullptr, NegEval);
}

} // namespace tflite
4 changes: 2 additions & 2 deletions tensorflow/lite/micro/kernels/pack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ TfLiteStatus PackImpl(TfLiteContext* context, TfLiteNode* node,
return kTfLiteOk;
}

TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
TfLiteStatus PackEval(TfLiteContext* context, TfLiteNode* node) {
const TfLitePackParams* data =
reinterpret_cast<TfLitePackParams*>(node->builtin_data);

Expand Down Expand Up @@ -106,7 +106,7 @@ TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
} // namespace

TFLMRegistration Register_PACK() {
return tflite::micro::RegisterOp(nullptr, nullptr, Eval);
return tflite::micro::RegisterOp(nullptr, nullptr, PackEval);
}

} // namespace tflite
8 changes: 4 additions & 4 deletions tensorflow/lite/micro/kernels/pad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ struct OpData {
int32_t output_zero_point;
};

void* Init(TfLiteContext* context, const char* buffer, size_t length) {
void* PadInit(TfLiteContext* context, const char* buffer, size_t length) {
TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr);
return context->AllocatePersistentBuffer(context, sizeof(OpData));
}

TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
TfLiteStatus PadEval(TfLiteContext* context, TfLiteNode* node) {
TFLITE_DCHECK(node->user_data != nullptr);
const OpData* data = static_cast<const OpData*>(node->user_data);

Expand Down Expand Up @@ -218,12 +218,12 @@ TfLiteStatus PadPrepare(TfLiteContext* context, TfLiteNode* node) {
}

TFLMRegistration Register_PAD() {
return tflite::micro::RegisterOp(Init, PadPrepare, Eval);
return tflite::micro::RegisterOp(PadInit, PadPrepare, PadEval);
}

// Also register Pad as PadV2.
TFLMRegistration Register_PADV2() {
return tflite::micro::RegisterOp(Init, PadPrepare, Eval);
return tflite::micro::RegisterOp(PadInit, PadPrepare, PadEval);
}

} // namespace tflite
6 changes: 3 additions & 3 deletions tensorflow/lite/micro/kernels/pooling.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,19 @@ TfLiteStatus MaxEval(TfLiteContext* context, TfLiteNode* node) {
return kTfLiteOk;
}

void* Init(TfLiteContext* context, const char* buffer, size_t length) {
void* PoolInit(TfLiteContext* context, const char* buffer, size_t length) {
TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr);
return context->AllocatePersistentBuffer(context, sizeof(OpDataPooling));
}

} // namespace

TFLMRegistration Register_AVERAGE_POOL_2D() {
return tflite::micro::RegisterOp(Init, PoolingPrepare, AverageEval);
return tflite::micro::RegisterOp(PoolInit, PoolingPrepare, AverageEval);
}

TFLMRegistration Register_MAX_POOL_2D() {
return tflite::micro::RegisterOp(Init, PoolingPrepare, MaxEval);
return tflite::micro::RegisterOp(PoolInit, PoolingPrepare, MaxEval);
}

} // namespace tflite
7 changes: 4 additions & 3 deletions tensorflow/lite/micro/kernels/quantize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ limitations under the License.
namespace tflite {
namespace {

void* Init(TfLiteContext* context, const char* buffer, size_t length) {
void* InitQuantizeReference(TfLiteContext* context, const char* buffer,
size_t length) {
TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr);
return context->AllocatePersistentBuffer(context,
sizeof(OpDataQuantizeReference));
Expand All @@ -34,8 +35,8 @@ void* Init(TfLiteContext* context, const char* buffer, size_t length) {
} // namespace

TFLMRegistration Register_QUANTIZE() {
return tflite::micro::RegisterOp(Init, PrepareQuantizeReference,
EvalQuantizeReference);
return tflite::micro::RegisterOp(
InitQuantizeReference, PrepareQuantizeReference, EvalQuantizeReference);
}

} // namespace tflite
5 changes: 3 additions & 2 deletions tensorflow/lite/micro/kernels/reshape.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ limitations under the License.
namespace tflite {
namespace {

TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
TfLiteStatus EvalReshapeReference(TfLiteContext* context, TfLiteNode* node) {
const TfLiteEvalTensor* input =
tflite::micro::GetEvalInput(context, node, kReshapeInputTensor);
TfLiteEvalTensor* output =
Expand All @@ -52,7 +52,8 @@ TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
} // namespace

TFLMRegistration Register_RESHAPE() {
return tflite::micro::RegisterOp(nullptr, PrepareReshapeReference, Eval);
return tflite::micro::RegisterOp(nullptr, PrepareReshapeReference,
EvalReshapeReference);
}

} // namespace tflite
7 changes: 4 additions & 3 deletions tensorflow/lite/micro/kernels/resize_bilinear.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ constexpr int kInputTensor = 0;
constexpr int kSizeTensor = 1;
constexpr int kOutputTensor = 0;

TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
TfLiteStatus ResizeBilinearPrepare(TfLiteContext* context, TfLiteNode* node) {
MicroContext* micro_context = GetMicroContext(context);

TF_LITE_ENSURE_EQ(context, NumInputs(node), 2);
Expand Down Expand Up @@ -66,7 +66,7 @@ TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
return kTfLiteOk;
}

TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
TfLiteStatus ResizeBilinearEval(TfLiteContext* context, TfLiteNode* node) {
auto* params =
reinterpret_cast<TfLiteResizeBilinearParams*>(node->builtin_data);

Expand Down Expand Up @@ -110,7 +110,8 @@ TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
} // namespace

TFLMRegistration Register_RESIZE_BILINEAR() {
return tflite::micro::RegisterOp(nullptr, Prepare, Eval);
return tflite::micro::RegisterOp(nullptr, ResizeBilinearPrepare,
ResizeBilinearEval);
}

} // namespace tflite
9 changes: 6 additions & 3 deletions tensorflow/lite/micro/kernels/resize_nearest_neighbor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ constexpr int kInputTensor = 0;
constexpr int kSizeTensor = 1;
constexpr int kOutputTensor = 0;

TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
TfLiteStatus ResizeNearestNeighborPrepare(TfLiteContext* context,
TfLiteNode* node) {
MicroContext* micro_context = GetMicroContext(context);

TF_LITE_ENSURE_EQ(context, NumInputs(node), 2);
Expand Down Expand Up @@ -65,7 +66,8 @@ TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
return kTfLiteOk;
}

TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
TfLiteStatus ResizeNearestNeighborEval(TfLiteContext* context,
TfLiteNode* node) {
auto* params =
reinterpret_cast<TfLiteResizeNearestNeighborParams*>(node->builtin_data);

Expand Down Expand Up @@ -117,7 +119,8 @@ TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
} // namespace

TFLMRegistration Register_RESIZE_NEAREST_NEIGHBOR() {
return tflite::micro::RegisterOp(nullptr, Prepare, Eval);
return tflite::micro::RegisterOp(nullptr, ResizeNearestNeighborPrepare,
ResizeNearestNeighborEval);
}

} // namespace tflite
6 changes: 3 additions & 3 deletions tensorflow/lite/micro/kernels/round.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace {
constexpr int kInputTensor = 0;
constexpr int kOutputTensor = 0;

TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
TfLiteStatus RoundPrepare(TfLiteContext* context, TfLiteNode* node) {
MicroContext* micro_context = GetMicroContext(context);

TfLiteTensor* input =
Expand All @@ -50,7 +50,7 @@ TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
return kTfLiteOk;
}

TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
TfLiteStatus RoundEval(TfLiteContext* context, TfLiteNode* node) {
const TfLiteEvalTensor* input =
tflite::micro::GetEvalInput(context, node, kInputTensor);
TfLiteEvalTensor* output =
Expand All @@ -66,7 +66,7 @@ TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
} // namespace

TFLMRegistration Register_ROUND() {
return tflite::micro::RegisterOp(nullptr, Prepare, Eval);
return tflite::micro::RegisterOp(nullptr, RoundPrepare, RoundEval);
}

} // namespace tflite
6 changes: 3 additions & 3 deletions tensorflow/lite/micro/kernels/shape.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ void ExtractShape(const TfLiteEvalTensor* input, int32_t* output_data) {
}
}

TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
TfLiteStatus ShapePrepare(TfLiteContext* context, TfLiteNode* node) {
TF_LITE_ENSURE_EQ(context, NumInputs(node), 1);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);

return kTfLiteOk;
}

TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
TfLiteStatus ShapeEval(TfLiteContext* context, TfLiteNode* node) {
const TfLiteEvalTensor* input =
tflite::micro::GetEvalInput(context, node, kInputTensor);
TfLiteEvalTensor* output =
Expand All @@ -61,7 +61,7 @@ TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
} // namespace

TFLMRegistration Register_SHAPE() {
return tflite::micro::RegisterOp(nullptr, Prepare, Eval);
return tflite::micro::RegisterOp(nullptr, ShapePrepare, ShapeEval);
}

} // namespace tflite
6 changes: 3 additions & 3 deletions tensorflow/lite/micro/kernels/slice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void GetBeginAndSizeVectors(int dimensions, const TfLiteEvalTensor* begin,
}
}

TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
TfLiteStatus SlicePrepare(TfLiteContext* context, TfLiteNode* node) {
MicroContext* micro_context = GetMicroContext(context);

TF_LITE_ENSURE_EQ(context, NumInputs(node), 3);
Expand Down Expand Up @@ -81,7 +81,7 @@ TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
return kTfLiteOk;
}

TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
TfLiteStatus SliceEval(TfLiteContext* context, TfLiteNode* node) {
const TfLiteEvalTensor* input =
tflite::micro::GetEvalInput(context, node, kInputTensor);
const TfLiteEvalTensor* begin =
Expand Down Expand Up @@ -158,7 +158,7 @@ TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
} // namespace

TFLMRegistration Register_SLICE() {
return tflite::micro::RegisterOp(nullptr, Prepare, Eval);
return tflite::micro::RegisterOp(nullptr, SlicePrepare, SliceEval);
}

} // namespace tflite
10 changes: 6 additions & 4 deletions tensorflow/lite/micro/kernels/space_to_batch_nd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ constexpr int kOutputTensor = 0;
const int kInputOutputMinDimensionNum = 3;
const int kInputOutputMaxDimensionNum = 4;

void* Init(TfLiteContext* context, const char* buffer, size_t length) {
void* SpaceToBatchNDInit(TfLiteContext* context, const char* buffer,
size_t length) {
TFLITE_DCHECK(context->AllocatePersistentBuffer != nullptr);
return context->AllocatePersistentBuffer(context, sizeof(SpaceToBatchParams));
}

TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
TfLiteStatus SpaceToBatchNDPrepare(TfLiteContext* context, TfLiteNode* node) {
MicroContext* micro_context = GetMicroContext(context);

TF_LITE_ENSURE_EQ(context, NumInputs(node), 3);
Expand All @@ -67,7 +68,7 @@ TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
return kTfLiteOk;
}

TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
TfLiteStatus SpaceToBatchNDEval(TfLiteContext* context, TfLiteNode* node) {
TFLITE_DCHECK(node->user_data != nullptr);
const SpaceToBatchParams& params =
*(static_cast<const SpaceToBatchParams*>(node->user_data));
Expand Down Expand Up @@ -115,7 +116,8 @@ TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
} // namespace.

TFLMRegistration Register_SPACE_TO_BATCH_ND() {
return tflite::micro::RegisterOp(Init, Prepare, Eval);
return tflite::micro::RegisterOp(SpaceToBatchNDInit, SpaceToBatchNDPrepare,
SpaceToBatchNDEval);
}

} // namespace tflite
6 changes: 3 additions & 3 deletions tensorflow/lite/micro/kernels/split.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ TfLiteStatus SplitImpl(TfLiteContext* context, TfLiteNode* node,
return kTfLiteOk;
}

TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
TfLiteStatus SplitPrepare(TfLiteContext* context, TfLiteNode* node) {
MicroContext* micro_context = GetMicroContext(context);
TfLiteTensor* axis = micro_context->AllocateTempInputTensor(node, 0);
TF_LITE_ENSURE(context, axis != nullptr);
Expand All @@ -82,7 +82,7 @@ TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
return kTfLiteOk;
}

TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
TfLiteStatus SplitEval(TfLiteContext* context, TfLiteNode* node) {
const TfLiteEvalTensor* axis = tflite::micro::GetEvalInput(context, node, 0);
const TfLiteEvalTensor* input = tflite::micro::GetEvalInput(context, node, 1);

Expand Down Expand Up @@ -119,7 +119,7 @@ TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
} // namespace

TFLMRegistration Register_SPLIT() {
return tflite::micro::RegisterOp(nullptr, Prepare, Eval);
return tflite::micro::RegisterOp(nullptr, SplitPrepare, SplitEval);
}

} // namespace tflite
6 changes: 3 additions & 3 deletions tensorflow/lite/micro/kernels/split_v.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ TfLiteStatus SplitImpl(TfLiteContext* context, TfLiteNode* node,
return kTfLiteOk;
}

TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
TfLiteStatus SplitVPrepare(TfLiteContext* context, TfLiteNode* node) {
TF_LITE_ENSURE_EQ(context, NumInputs(node), 3);

MicroContext* micro_context = GetMicroContext(context);
Expand All @@ -85,7 +85,7 @@ TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
return kTfLiteOk;
}

TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
TfLiteStatus SplitVEval(TfLiteContext* context, TfLiteNode* node) {
const TfLiteEvalTensor* input = tflite::micro::GetEvalInput(context, node, 0);
const TfLiteEvalTensor* axis = tflite::micro::GetEvalInput(context, node, 2);

Expand Down Expand Up @@ -121,7 +121,7 @@ TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
} // namespace

TFLMRegistration Register_SPLIT_V() {
return tflite::micro::RegisterOp(nullptr, Prepare, Eval);
return tflite::micro::RegisterOp(nullptr, SplitVPrepare, SplitVEval);
}

} // namespace tflite
6 changes: 3 additions & 3 deletions tensorflow/lite/micro/kernels/squeeze.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct SqueezeContext {
TfLiteTensor* output;
};

TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
TfLiteStatus SqueezePrepare(TfLiteContext* context, TfLiteNode* node) {
TF_LITE_ENSURE_EQ(context, NumInputs(node), 1);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);

Expand Down Expand Up @@ -87,7 +87,7 @@ TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
return kTfLiteOk;
}

TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
TfLiteStatus SqueezeEval(TfLiteContext* context, TfLiteNode* node) {
const TfLiteEvalTensor* input = tflite::micro::GetEvalInput(context, node, 0);

if (input->type == kTfLiteString) {
Expand All @@ -112,7 +112,7 @@ TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
} // namespace

TFLMRegistration Register_SQUEEZE() {
return tflite::micro::RegisterOp(nullptr, Prepare, Eval);
return tflite::micro::RegisterOp(nullptr, SqueezePrepare, SqueezeEval);
}

} // namespace tflite
Loading
Loading