Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.
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
14 changes: 14 additions & 0 deletions src/tensorflow/lite/core/c/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,18 @@ void TfLiteOpaqueDelegateDelete(TfLiteOpaqueDelegate* opaque_delegate) {
delete tflite_delegate;
}

void* TfLiteOpaqueDelegateGetData(const TfLiteOpaqueDelegate* delegate) {
if (!delegate) return nullptr;

// The following cast is safe only because this code is part of the
// TF Lite runtime implementation. Apps using TF Lite should not rely on
// 'TfLiteOpaqueDelegate' and 'TfLiteDelegate' being equivalent.
const auto* tflite_delegate =
reinterpret_cast<const TfLiteDelegate*>(delegate);

if (!tflite_delegate->opaque_delegate_builder) return nullptr;

return tflite_delegate->opaque_delegate_builder->data;
}

} // extern "C"
11 changes: 11 additions & 0 deletions src/tensorflow/lite/core/c/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,17 @@ TfLiteOpaqueDelegate* TfLiteOpaqueDelegateCreate(
// 'delegate' is a null pointer.
void TfLiteOpaqueDelegateDelete(TfLiteOpaqueDelegate* delegate);

// Returns a pointer to the data associated with the provided opaque 'delegate'.
//
// A null pointer will be returned when:
// - The 'delegate' is null.
// - The 'data' field of the 'TfLiteOpaqueDelegateBuilder' used to construct the
// 'delegate' was null.
// - Or in case of any other error.
// - The 'delegate' has been constructed via a 'TfLiteOpaqueDelegateBuilder',
// but the 'data' field of the 'TfLiteOpaqueDelegateBuilder' is null.
void* TfLiteOpaqueDelegateGetData(const TfLiteOpaqueDelegate* delegate);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion src/tensorflow/lite/micro/kernels/micro_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ TfLiteRegistration Register_MIRROR_PAD();
TfLiteRegistration Register_NEG();
TfLiteRegistration Register_PRELU();
TfLiteRegistration Register_MUL();
TfLiteRegistration Register_PACK();
TfLiteRegistration Register_PAD();
TfLiteRegistration Register_PADV2();
TfLiteRegistration Register_QUANTIZE();
Expand Down Expand Up @@ -113,7 +114,6 @@ TfLiteRegistration Register_LOGICAL_NOT();
TfLiteRegistration Register_MAXIMUM();
TfLiteRegistration Register_MINIMUM();
TfLiteRegistration Register_NOT_EQUAL();
TfLiteRegistration Register_PACK();
TfLiteRegistration Register_RESHAPE();
TfLiteRegistration Register_RESIZE_NEAREST_NEIGHBOR();
TfLiteRegistration Register_ROUND();
Expand Down
11 changes: 3 additions & 8 deletions src/tensorflow/lite/micro/kernels/pack.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
/* Copyright 2022 The TensorFlow Authors. 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.
Expand All @@ -20,9 +20,7 @@ limitations under the License.
#include "tensorflow/lite/micro/micro_log.h"

namespace tflite {
namespace ops {
namespace micro {
namespace pack {

namespace {

constexpr int kOutputTensor = 0;
Expand Down Expand Up @@ -106,12 +104,9 @@ TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
}

} // namespace
} // namespace pack

TfLiteRegistration Register_PACK() {
return tflite::micro::RegisterOp(nullptr, nullptr, pack::Eval);
return tflite::micro::RegisterOp(nullptr, nullptr, Eval);
}

} // namespace micro
} // namespace ops
} // namespace tflite
3 changes: 1 addition & 2 deletions src/tensorflow/lite/micro/micro_mutable_op_resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,7 @@ class MicroMutableOpResolver : public MicroOpResolver {
}

TfLiteStatus AddPack() {
return AddBuiltin(BuiltinOperator_PACK, tflite::ops::micro::Register_PACK(),
ParsePack);
return AddBuiltin(BuiltinOperator_PACK, Register_PACK(), ParsePack);
}

TfLiteStatus AddPad(const TfLiteRegistration& registration = Register_PAD()) {
Expand Down