Preallocate the node structure std::vector
PiperOrigin-RevId: 209830234
This commit is contained in:
parent
915fd68aa4
commit
091c9809b8
@ -476,6 +476,10 @@ TfLiteStatus Interpreter::ResetVariableTensorsToZero() {
|
|||||||
return kTfLiteOk;
|
return kTfLiteOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Interpreter::ReserveNodes(int count) {
|
||||||
|
nodes_and_registration_.reserve(count);
|
||||||
|
}
|
||||||
|
|
||||||
TfLiteStatus Interpreter::AddNodeWithParameters(
|
TfLiteStatus Interpreter::AddNodeWithParameters(
|
||||||
const std::vector<int>& inputs, const std::vector<int>& outputs,
|
const std::vector<int>& inputs, const std::vector<int>& outputs,
|
||||||
const char* init_data, size_t init_data_size, void* builtin_data,
|
const char* init_data, size_t init_data_size, void* builtin_data,
|
||||||
|
@ -136,6 +136,11 @@ class Interpreter {
|
|||||||
// interpreter.
|
// interpreter.
|
||||||
TfLiteStatus SetVariables(std::vector<int> variables);
|
TfLiteStatus SetVariables(std::vector<int> variables);
|
||||||
|
|
||||||
|
// Ensure the internal node storage memory allocates at least `count`
|
||||||
|
// spots for node. NOTE, this doesn't actually add operators. This is an
|
||||||
|
// efficiency optimization that is subject to change.
|
||||||
|
void ReserveNodes(int count);
|
||||||
|
|
||||||
// Adds a node with the given parameters and returns the index of the new
|
// Adds a node with the given parameters and returns the index of the new
|
||||||
// node in `node_index` (optionally). Interpreter will take ownership of
|
// node in `node_index` (optionally). Interpreter will take ownership of
|
||||||
// `builtin_data` and destroy it with `free`. Ownership of 'init_data'
|
// `builtin_data` and destroy it with `free`. Ownership of 'init_data'
|
||||||
|
@ -802,6 +802,10 @@ TfLiteStatus InterpreterBuilder::ParseNodes(
|
|||||||
const flatbuffers::Vector<flatbuffers::Offset<Operator>>* operators,
|
const flatbuffers::Vector<flatbuffers::Offset<Operator>>* operators,
|
||||||
Interpreter* interpreter) {
|
Interpreter* interpreter) {
|
||||||
TfLiteStatus status = kTfLiteOk;
|
TfLiteStatus status = kTfLiteOk;
|
||||||
|
|
||||||
|
// Reduce the number of redundant allocations
|
||||||
|
interpreter->ReserveNodes(operators->Length());
|
||||||
|
|
||||||
for (int i = 0; i < operators->Length(); ++i) {
|
for (int i = 0; i < operators->Length(); ++i) {
|
||||||
const auto* op = operators->Get(i);
|
const auto* op = operators->Get(i);
|
||||||
int index = op->opcode_index();
|
int index = op->opcode_index();
|
||||||
|
Loading…
Reference in New Issue
Block a user