Daniel Konegen / MNIST_example

Dependencies:   mbed-os

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers linear_memory_planner.cc Source File

linear_memory_planner.cc

00001 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
00002 
00003 Licensed under the Apache License, Version 2.0 (the "License");
00004 you may not use this file except in compliance with the License.
00005 You may obtain a copy of the License at
00006 
00007     http://www.apache.org/licenses/LICENSE-2.0
00008 
00009 Unless required by applicable law or agreed to in writing, software
00010 distributed under the License is distributed on an "AS IS" BASIS,
00011 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 See the License for the specific language governing permissions and
00013 limitations under the License.
00014 ==============================================================================*/
00015 
00016 #include "tensorflow/lite/experimental/micro/memory_planner/linear_memory_planner.h"
00017 
00018 namespace tflite {
00019 
00020 LinearMemoryPlanner::LinearMemoryPlanner()
00021     : current_buffer_count_(0), next_free_offset_(0) {}
00022 LinearMemoryPlanner::~LinearMemoryPlanner() {}
00023 
00024 TfLiteStatus LinearMemoryPlanner::AddBuffer(
00025     tflite::ErrorReporter* error_reporter, int size, int first_time_used,
00026     int last_time_used) {
00027   if (current_buffer_count_ >= kMaxBufferCount) {
00028     error_reporter->Report("Too many buffers (max is %d)", kMaxBufferCount);
00029     return kTfLiteError;
00030   }
00031   buffer_offsets_[current_buffer_count_] = next_free_offset_;
00032   next_free_offset_ += size;
00033   ++current_buffer_count_;
00034   return kTfLiteOk;
00035 }
00036 
00037 int LinearMemoryPlanner::GetMaximumMemorySize() { return next_free_offset_; }
00038 
00039 int LinearMemoryPlanner::GetBufferCount() { return current_buffer_count_; }
00040 
00041 TfLiteStatus LinearMemoryPlanner::GetOffsetForBuffer(
00042     tflite::ErrorReporter* error_reporter, int buffer_index, int* offset) {
00043   if ((buffer_index < 0) || (buffer_index >= current_buffer_count_)) {
00044     error_reporter->Report("buffer index %d is outside range 0 to %d",
00045                            buffer_index, current_buffer_count_);
00046     return kTfLiteError;
00047   }
00048   *offset = buffer_offsets_[buffer_index];
00049   return kTfLiteOk;
00050 }
00051 
00052 }  // namespace tflite