Skip to content

Commit 0709653

Browse files
authored
Sync from tflite-micro. (tensorflow#163)
1 parent 3d4e452 commit 0709653

File tree

5 files changed

+30
-11
lines changed

5 files changed

+30
-11
lines changed

src/tensorflow/lite/core/c/common.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,4 +331,18 @@ void TfLiteOpaqueDelegateDelete(TfLiteOpaqueDelegate* opaque_delegate) {
331331
delete tflite_delegate;
332332
}
333333

334+
void* TfLiteOpaqueDelegateGetData(const TfLiteOpaqueDelegate* delegate) {
335+
if (!delegate) return nullptr;
336+
337+
// The following cast is safe only because this code is part of the
338+
// TF Lite runtime implementation. Apps using TF Lite should not rely on
339+
// 'TfLiteOpaqueDelegate' and 'TfLiteDelegate' being equivalent.
340+
const auto* tflite_delegate =
341+
reinterpret_cast<const TfLiteDelegate*>(delegate);
342+
343+
if (!tflite_delegate->opaque_delegate_builder) return nullptr;
344+
345+
return tflite_delegate->opaque_delegate_builder->data;
346+
}
347+
334348
} // extern "C"

src/tensorflow/lite/core/c/common.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,17 @@ TfLiteOpaqueDelegate* TfLiteOpaqueDelegateCreate(
11351135
// 'delegate' is a null pointer.
11361136
void TfLiteOpaqueDelegateDelete(TfLiteOpaqueDelegate* delegate);
11371137

1138+
// Returns a pointer to the data associated with the provided opaque 'delegate'.
1139+
//
1140+
// A null pointer will be returned when:
1141+
// - The 'delegate' is null.
1142+
// - The 'data' field of the 'TfLiteOpaqueDelegateBuilder' used to construct the
1143+
// 'delegate' was null.
1144+
// - Or in case of any other error.
1145+
// - The 'delegate' has been constructed via a 'TfLiteOpaqueDelegateBuilder',
1146+
// but the 'data' field of the 'TfLiteOpaqueDelegateBuilder' is null.
1147+
void* TfLiteOpaqueDelegateGetData(const TfLiteOpaqueDelegate* delegate);
1148+
11381149
#ifdef __cplusplus
11391150
} // extern "C"
11401151
#endif // __cplusplus

src/tensorflow/lite/micro/kernels/micro_ops.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ TfLiteRegistration Register_MIRROR_PAD();
7070
TfLiteRegistration Register_NEG();
7171
TfLiteRegistration Register_PRELU();
7272
TfLiteRegistration Register_MUL();
73+
TfLiteRegistration Register_PACK();
7374
TfLiteRegistration Register_PAD();
7475
TfLiteRegistration Register_PADV2();
7576
TfLiteRegistration Register_QUANTIZE();
@@ -113,7 +114,6 @@ TfLiteRegistration Register_LOGICAL_NOT();
113114
TfLiteRegistration Register_MAXIMUM();
114115
TfLiteRegistration Register_MINIMUM();
115116
TfLiteRegistration Register_NOT_EQUAL();
116-
TfLiteRegistration Register_PACK();
117117
TfLiteRegistration Register_RESHAPE();
118118
TfLiteRegistration Register_RESIZE_NEAREST_NEIGHBOR();
119119
TfLiteRegistration Register_ROUND();

src/tensorflow/lite/micro/kernels/pack.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
1+
/* Copyright 2022 The TensorFlow Authors. All Rights Reserved.
22
33
Licensed under the Apache License, Version 2.0 (the "License");
44
you may not use this file except in compliance with the License.
@@ -20,9 +20,7 @@ limitations under the License.
2020
#include "tensorflow/lite/micro/micro_log.h"
2121

2222
namespace tflite {
23-
namespace ops {
24-
namespace micro {
25-
namespace pack {
23+
2624
namespace {
2725

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

108106
} // namespace
109-
} // namespace pack
110107

111108
TfLiteRegistration Register_PACK() {
112-
return tflite::micro::RegisterOp(nullptr, nullptr, pack::Eval);
109+
return tflite::micro::RegisterOp(nullptr, nullptr, Eval);
113110
}
114111

115-
} // namespace micro
116-
} // namespace ops
117112
} // namespace tflite

src/tensorflow/lite/micro/micro_mutable_op_resolver.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,7 @@ class MicroMutableOpResolver : public MicroOpResolver {
399399
}
400400

401401
TfLiteStatus AddPack() {
402-
return AddBuiltin(BuiltinOperator_PACK, tflite::ops::micro::Register_PACK(),
403-
ParsePack);
402+
return AddBuiltin(BuiltinOperator_PACK, Register_PACK(), ParsePack);
404403
}
405404

406405
TfLiteStatus AddPad(const TfLiteRegistration& registration = Register_PAD()) {

0 commit comments

Comments
 (0)