Initialize context using memset

PiperOrigin-RevId: 251821825
This commit is contained in:
Tiezhen WANG 2019-06-06 03:47:24 -07:00 committed by TensorFlower Gardener
parent 28b65d088c
commit 1c0c9f2f6b
2 changed files with 9 additions and 12 deletions

View File

@ -67,7 +67,8 @@ MicroInterpreter::MicroInterpreter(const Model* model,
op_resolver_(op_resolver), op_resolver_(op_resolver),
tensor_allocator_(tensor_allocator), tensor_allocator_(tensor_allocator),
error_reporter_(error_reporter), error_reporter_(error_reporter),
initialization_status_(kTfLiteOk) { initialization_status_(kTfLiteOk),
context_() {
auto* subgraphs = model->subgraphs(); auto* subgraphs = model->subgraphs();
if (subgraphs->size() != 1) { if (subgraphs->size() != 1) {
error_reporter->Report("Only 1 subgraph is currently supported.\n"); error_reporter->Report("Only 1 subgraph is currently supported.\n");
@ -82,23 +83,15 @@ MicroInterpreter::MicroInterpreter(const Model* model,
context_.tensors = context_.tensors =
reinterpret_cast<TfLiteTensor*>(tensor_allocator_->AllocateMemory( reinterpret_cast<TfLiteTensor*>(tensor_allocator_->AllocateMemory(
sizeof(TfLiteTensor) * context_.tensors_size, 4)); sizeof(TfLiteTensor) * context_.tensors_size, 4));
context_.impl_ = static_cast<void*>(this);
context_.ReportError = ReportOpError;
context_.recommended_num_threads = 1;
initialization_status_ = AllocateInputAndActTensors(); initialization_status_ = AllocateInputAndActTensors();
if (initialization_status_ != kTfLiteOk) { if (initialization_status_ != kTfLiteOk) {
return; return;
} }
context_.impl_ = static_cast<void*>(this);
context_.GetExecutionPlan = nullptr;
context_.ResizeTensor = nullptr;
context_.ReportError = ReportOpError;
context_.AddTensors = nullptr;
context_.GetNodeAndRegistration = nullptr;
context_.ReplaceNodeSubsetsWithDelegateKernels = nullptr;
context_.recommended_num_threads = 1;
context_.GetExternalContext = nullptr;
context_.SetExternalContext = nullptr;
initialization_status_ = AllocateTemporaryTensors(); initialization_status_ = AllocateTemporaryTensors();
if (initialization_status_ != kTfLiteOk) { if (initialization_status_ != kTfLiteOk) {
return; return;

View File

@ -20,6 +20,10 @@ limitations under the License.
namespace tflite { namespace tflite {
namespace { namespace {
void* MockInit(TfLiteContext* context, const char* buffer, size_t length) { void* MockInit(TfLiteContext* context, const char* buffer, size_t length) {
// We don't support delegate in TFL micro. This is a weak check to test if
// context struct being zero-initialized.
TF_LITE_MICRO_EXPECT_EQ(nullptr,
context->ReplaceNodeSubsetsWithDelegateKernels);
// Do nothing. // Do nothing.
return nullptr; return nullptr;
} }