Unverified Commit 17c33415 authored by Jayaram Bobba's avatar Jayaram Bobba Committed by GitHub

Make temp memory pools static to avoid memory allocation overheads (#941)

parent cd0f4fbd
...@@ -551,6 +551,30 @@ using namespace ngraph::runtime; ...@@ -551,6 +551,30 @@ using namespace ngraph::runtime;
} }
} }
bool temporaries_used = false;
size_t worst_case_tmp_size = 0;
for (shared_ptr<Node> node : ordered_ops)
{
if (node->liveness_new_list.size() > 0)
{
temporaries_used = true;
for (descriptor::Tensor* tensor : node->liveness_new_list)
{
worst_case_tmp_size += tensor->size();
}
}
}
if (temporaries_used)
{
size_t temp_pool_size = current_function->get_temporary_pool_size();
writer << "// Allocate the memory pool\n";
writer << "// Memory pool size is " << temp_pool_size << " bytes\n";
writer << "// Worst case size is " << worst_case_tmp_size << " bytes\n";
writer << "ngraph::runtime::AlignedBuffer " << current_function->get_name()
<< "_memory_handler(" << temp_pool_size << ", " << s_memory_pool_alignment
<< ");\n";
}
writer << "extern \"C\" void " << current_function->get_name(); writer << "extern \"C\" void " << current_function->get_name();
writer << "(void** inputs, void** outputs, cpu::CPURuntimeContext* ctx)\n"; writer << "(void** inputs, void** outputs, cpu::CPURuntimeContext* ctx)\n";
writer << "{\n"; writer << "{\n";
...@@ -569,28 +593,10 @@ using namespace ngraph::runtime; ...@@ -569,28 +593,10 @@ using namespace ngraph::runtime;
<< "int profiler_count = 0;\n\n"; << "int profiler_count = 0;\n\n";
} }
bool temporaries_used = false;
size_t worst_case_tmp_size = 0;
for (shared_ptr<Node> node : ordered_ops)
{
if (node->liveness_new_list.size() > 0)
{
temporaries_used = true;
for (descriptor::Tensor* tensor : node->liveness_new_list)
{
worst_case_tmp_size += tensor->size();
}
}
}
if (temporaries_used) if (temporaries_used)
{ {
size_t temp_pool_size = current_function->get_temporary_pool_size(); writer << "size_t pool_base_ptr = (size_t)" << current_function->get_name()
writer << "// Allocate the memory pool\n"; << "_memory_handler.get_ptr();\n";
writer << "// Memory pool size is " << temp_pool_size << " bytes\n";
writer << "// Worst case size is " << worst_case_tmp_size << " bytes\n";
writer << "ngraph::runtime::AlignedBuffer memory_handler(" << temp_pool_size << ", "
<< s_memory_pool_alignment << ");\n";
writer << "size_t pool_base_ptr = (size_t)memory_handler.get_ptr();\n";
writer << "\n"; writer << "\n";
// Add temporaries to the variable name map // Add temporaries to the variable name map
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment