From 05db3739aa6962c232f012401b5ecf398362f272 Mon Sep 17 00:00:00 2001 From: Nick Kreeger Date: Fri, 12 Jun 2020 13:56:18 -0700 Subject: [PATCH] Test for missing large tail allocations in the "recording" MicroAllocator. This change ensures that any large tail allocation should be handled and recorded with the RecordingMicroAllocator. The "misc" category for the keyword model currently is at 1004 bytes on my machine. I'll start with exactly 1kb ceiling for now. PiperOrigin-RevId: 316171598 Change-Id: I1fc7a38b7bd89266de9d386648c5ef8dc290899c --- tensorflow/lite/micro/memory_arena_threshold_test.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tensorflow/lite/micro/memory_arena_threshold_test.cc b/tensorflow/lite/micro/memory_arena_threshold_test.cc index 37d323c2a23..19c3d0f1e06 100644 --- a/tensorflow/lite/micro/memory_arena_threshold_test.cc +++ b/tensorflow/lite/micro/memory_arena_threshold_test.cc @@ -30,6 +30,7 @@ namespace { // Ensure memory doesn't expand more that 3%: constexpr float kAllocationThreshold = 0.03; +constexpr float kAllocationTailMiscCeiling = 1024; const bool kIs64BitSystem = sizeof(void*) == 8; constexpr int kKeywordModelTensorArenaSize = 22 * 1024; @@ -127,6 +128,17 @@ void ValidateModelAllocationThresholds( allocator.GetRecordedAllocation(tflite::RecordedAllocationType::kOpData) .used_bytes, thresholds.op_runtime_data_size); + + // Ensure tail allocation recording is not missing any large chunks: + size_t tail_est_length = sizeof(TfLiteTensor) * thresholds.tensor_count + + thresholds.tensor_quantization_data_size + + thresholds.tensor_variable_buffer_data_size + + sizeof(tflite::NodeAndRegistration) * + thresholds.node_and_registration_count + + thresholds.op_runtime_data_size; + + TF_LITE_MICRO_EXPECT_LE(thresholds.tail_alloc_size - tail_est_length, + kAllocationTailMiscCeiling); } } // namespace