Shift memory allocation parameters to lite/util. Also make specifying these parameters explicit in runtime code.

PiperOrigin-RevId: 320416196
Change-Id: I3e321b7ca6a83a968600d64278e991a6280ebd80
This commit is contained in:
Sachin Joglekar 2020-07-09 09:52:21 -07:00 committed by TensorFlower Gardener
parent 393242481a
commit 634c600cc3
4 changed files with 11 additions and 5 deletions

View File

@ -106,6 +106,7 @@ cc_library(
":graph_info",
":memory_planner",
":simple_memory_arena",
":util",
"//tensorflow/lite/c:common",
],
)

View File

@ -23,13 +23,11 @@ limitations under the License.
#include "tensorflow/lite/graph_info.h"
#include "tensorflow/lite/memory_planner.h"
#include "tensorflow/lite/simple_memory_arena.h"
#include "tensorflow/lite/util.h"
namespace tflite {
// Memory allocation tuning
constexpr const int kDefaultArenaAlignment = 64;
constexpr const int kDefaultTensorAlignment = 64;
struct AllocationInfo;
// A memory planner that makes all the allocations using arenas.
@ -53,7 +51,7 @@ class ArenaPlanner : public MemoryPlanner {
// them until the end of inference.
ArenaPlanner(TfLiteContext* context, std::unique_ptr<GraphInfo> graph_info,
bool preserve_inputs, bool preserve_intermediates,
int tensor_alignment = kDefaultTensorAlignment);
int tensor_alignment);
~ArenaPlanner() override;
ArenaPlanner(const ArenaPlanner&) = delete;
ArenaPlanner& operator=(const ArenaPlanner&) = delete;

View File

@ -859,7 +859,8 @@ TfLiteStatus Subgraph::PrepareOpsAndTensors() {
if (!memory_planner_) {
memory_planner_.reset(new ArenaPlanner(
&context_, std::unique_ptr<GraphInfo>(new InterpreterInfo(this)),
/*preserve_inputs=*/true, /*preserve_intermediates*/ false));
/*preserve_inputs=*/true, /*preserve_intermediates*/ false,
kDefaultTensorAlignment));
memory_planner_->PlanAllocations();
}

View File

@ -29,6 +29,12 @@ limitations under the License.
namespace tflite {
// Memory allocation parameter used by ArenaPlanner.
// Clients (such as delegates) might look at this to ensure interop between
// TFLite memory & hardware buffers.
// NOTE: This only holds for tensors allocated on the arena.
constexpr int kDefaultTensorAlignment = 64;
// The prefix of Flex op custom code.
// This will be matched agains the `custom_code` field in `OperatorCode`
// Flatbuffer Table.