Commit 67078856 authored by Jayaram Bobba's avatar Jayaram Bobba Committed by Robert Kimball

Move temporary buffer pools to CPU runtime context to avoid static variable…

Move temporary buffer pools to CPU runtime context to avoid static variable destruction issues with clang (#990)
parent f84b795e
......@@ -16,6 +16,7 @@
#include <algorithm>
#include "ngraph/runtime/aligned_buffer.hpp"
#include "ngraph/runtime/cpu/cpu_call_frame.hpp"
#include "ngraph/runtime/cpu/cpu_external_function.hpp"
#include "ngraph/runtime/cpu/cpu_tensor_view.hpp"
......@@ -102,6 +103,13 @@ void runtime::cpu::CPU_CallFrame::setup_runtime_context()
ctx->op_durations = new int64_t[m_external_function->get_op_attrs().size()];
}
ctx->p_en = new bool[m_external_function->get_parameter_layout_descriptors().size()];
// Create temporary buffer pools
size_t alignment = runtime::cpu::CPU_ExternalFunction::s_memory_pool_alignment;
for (auto buffer_size : m_external_function->get_memory_buffer_sizes())
{
auto buffer = new AlignedBuffer(buffer_size, alignment);
ctx->memory_buffers.push_back(buffer);
}
const auto& mkldnn_emitter = m_external_function->get_mkldnn_emitter();
ctx->mkldnn_primitives = mkldnn_emitter->get_mkldnn_primitives().data();
ctx->mkldnn_workspaces = mkldnn_emitter->get_mkldnn_workspaces().data();
......@@ -111,5 +119,9 @@ void runtime::cpu::CPU_CallFrame::cleanup_runtime_context()
{
delete[] ctx->op_durations;
delete[] ctx->p_en;
for (auto buffer : ctx->memory_buffers)
{
delete buffer;
}
delete ctx;
}
......@@ -139,9 +139,6 @@ using namespace ngraph;
static const string s_output_dir = "cpu_codegen";
// Temporary Memory Pool alignment
static const size_t s_memory_pool_alignment = 4096;
static void
generate_isnan_isinf_check(codegen::CodeWriter& writer,
std::shared_ptr<Node> node,
......@@ -582,12 +579,7 @@ using namespace ngraph::runtime;
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";
m_memory_buffer_sizes.push_back(current_function->get_temporary_pool_size());
}
// Indexing for Control Flags
......@@ -630,8 +622,8 @@ using namespace ngraph::runtime;
if (temporaries_used)
{
writer << "size_t pool_base_ptr = (size_t)" << current_function->get_name()
<< "_memory_handler.get_ptr();\n";
writer << "size_t pool_base_ptr = (size_t) ctx->memory_buffers["
<< m_memory_buffer_sizes.size() - 1 << "]->get_ptr();\n";
writer << "\n";
// Add temporaries to the variable name map
......
......@@ -79,7 +79,10 @@ namespace ngraph
const LayoutDescriptorPtrs& get_parameter_layout_descriptors();
const LayoutDescriptorPtrs& get_result_layout_descriptors();
const std::vector<size_t>& get_memory_buffer_sizes() const
{
return m_memory_buffer_sizes;
}
const std::vector<OpAttributes>& get_op_attrs() const { return m_op_attrs; }
const std::unique_ptr<MKLDNNEmitter>& get_mkldnn_emitter() const
{
......@@ -88,6 +91,9 @@ namespace ngraph
const std::string& get_function_name() const { return m_function_name; }
const std::shared_ptr<ngraph::Function> get_function() { return m_function; }
// Temporary Memory Pool alignment
static const size_t s_memory_pool_alignment = 4096;
protected:
void compile();
......@@ -130,6 +136,7 @@ namespace ngraph
LayoutDescriptorPtrs parameter_layout_descriptors;
LayoutDescriptorPtrs result_layout_descriptors;
std::vector<size_t> m_memory_buffer_sizes;
std::vector<OpAttributes> m_op_attrs;
std::unique_ptr<MKLDNNEmitter> m_mkldnn_emitter;
......
......@@ -24,6 +24,14 @@ namespace mkldnn
class primitive;
}
namespace ngraph
{
namespace runtime
{
class AlignedBuffer;
}
}
namespace ngraph
{
namespace runtime
......@@ -40,6 +48,7 @@ namespace ngraph
int64_t* op_durations;
bool* p_en;
mkldnn::primitive* const* mkldnn_primitives;
std::vector<AlignedBuffer*> memory_buffers;
char* const* mkldnn_workspaces;
};
}
......
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