Commit 24a7db84 authored by Robert Kimball's avatar Robert Kimball

only emit memory handler if there are temporaries

parent efc53f25
...@@ -214,25 +214,37 @@ using namespace ngraph::runtime::cpu::eigen; ...@@ -214,25 +214,37 @@ using namespace ngraph::runtime::cpu::eigen;
TU << " const std::vector<void*>& inputs,\n"; TU << " const std::vector<void*>& inputs,\n";
TU << " const std::vector<void*>& outputs)\n"; TU << " const std::vector<void*>& outputs)\n";
TU << "{\n"; TU << "{\n";
TU.indent++; TU.indent++;
size_t temp_pool_size = pass_manager.get_state().get_temporary_pool_size();
TU << "// Allocate the memory pool\n";
TU << "ngraph::runtime::cpu::MemoryHandler memory_handler(" << temp_pool_size << ", "
<< ngraph::runtime::cpu::alignment << ");\n";
TU << "\n";
TU << "// Define temporary tensors\n"; bool temporaries_used = false;
for (shared_ptr<Node> node : current_function->get_ordered_ops()) for (shared_ptr<Node> node : current_function->get_ordered_ops())
{ {
for (descriptor::Tensor* tensor : node->liveness_new_list) if (node->liveness_new_list.size() > 0)
{ {
TU << tensor->get_element_type() << "* " << tensor->get_name() << " = (" temporaries_used = true;
<< tensor->get_element_type() << "*)(memory_handler.get_ptr(" break;
<< tensor->get_pool_offset() << "));\n";
} }
} }
TU << "\n"; if (temporaries_used)
{
size_t temp_pool_size = pass_manager.get_state().get_temporary_pool_size();
TU << "// Allocate the memory pool\n";
TU << "ngraph::runtime::cpu::MemoryHandler memory_handler(" << temp_pool_size << ", "
<< ngraph::runtime::cpu::alignment << ");\n";
TU << "\n";
TU << "// Define temporary tensors\n";
for (shared_ptr<Node> node : current_function->get_ordered_ops())
{
for (descriptor::Tensor* tensor : node->liveness_new_list)
{
TU << tensor->get_element_type() << "* " << tensor->get_name() << " = ("
<< tensor->get_element_type() << "*)(memory_handler.get_ptr("
<< tensor->get_pool_offset() << "));\n";
}
}
TU << "\n";
}
TU << "// Define inputs\n"; TU << "// Define inputs\n";
size_t arg_index = 0; size_t arg_index = 0;
...@@ -263,13 +275,10 @@ using namespace ngraph::runtime::cpu::eigen; ...@@ -263,13 +275,10 @@ using namespace ngraph::runtime::cpu::eigen;
} }
TU << "\n"; TU << "\n";
TU << "// Define tensor views\n";
TU << "\n";
for (shared_ptr<Node> node : current_function->get_ordered_ops()) for (shared_ptr<Node> node : current_function->get_ordered_ops())
{ {
auto& n = *node; // Work around a compiler warning (*node inside typeid may have effects auto& n = *node; // Work around a compiler warning (*node inside typeid may have effects
// with shared pointers, which is fine here but clang doesn't like it.) // with shared pointers, which is fine here but clang doesn't like it.)
auto handler = dispatcher.find(type_index(typeid(n))); auto handler = dispatcher.find(type_index(typeid(n)));
if (handler == dispatcher.end()) if (handler == dispatcher.end())
{ {
......
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