Commit f490903b authored by Robert Kimball's avatar Robert Kimball Committed by Scott Cyphers

replace tabs with spaces (#3221)

parent 7d250919
...@@ -31,29 +31,29 @@ struct CPURuntimeContextCG ...@@ -31,29 +31,29 @@ struct CPURuntimeContextCG
std::vector<mkldnn::primitive*> mkldnn_primitives; std::vector<mkldnn::primitive*> mkldnn_primitives;
std::vector<char*> mkldnn_workspaces; std::vector<char*> mkldnn_workspaces;
std::vector<mkldnn::memory::desc*> mkldnn_descriptors; std::vector<mkldnn::memory::desc*> mkldnn_descriptors;
mkldnn::engine global_cpu_engine = mkldnn::engine(mkldnn::engine::cpu, 0); mkldnn::engine global_cpu_engine = mkldnn::engine(mkldnn::engine::cpu, 0);
void set_memory_ptr(size_t primitive_index, void set_memory_ptr(size_t primitive_index,
void* ptr) void* ptr)
{ {
auto primitive = static_cast<mkldnn::memory*>(mkldnn_primitives[primitive_index]); auto primitive = static_cast<mkldnn::memory*>(mkldnn_primitives[primitive_index]);
primitive->set_data_handle(ptr); primitive->set_data_handle(ptr);
} }
void mkldnn_invoke_primitive(size_t primitive_index) void mkldnn_invoke_primitive(size_t primitive_index)
{ {
mkldnn::stream s(mkldnn::stream::kind::eager); mkldnn::stream s(mkldnn::stream::kind::eager);
try try
{ {
s.submit({*mkldnn_primitives[primitive_index]}).wait(); s.submit({*mkldnn_primitives[primitive_index]}).wait();
} }
catch (const mkldnn::error& e) catch (const mkldnn::error& e)
{ {
throw std::runtime_error("Could not run mkldnn primitive " + e.message); throw std::runtime_error("Could not run mkldnn primitive " + e.message);
} }
} }
private: private:
...@@ -89,32 +89,32 @@ private: ...@@ -89,32 +89,32 @@ private:
void init_mkldnn_primitives(); void init_mkldnn_primitives();
inline void cleanup_mkldnn_primitives() inline void cleanup_mkldnn_primitives()
{ {
for (auto p : mkldnn_primitives) for (auto p : mkldnn_primitives)
{ {
delete p; delete p;
} }
#ifndef _WIN32 #ifndef _WIN32
//To avoid memory leak in mkldnn, release any buffers that are not free'd yet. //To avoid memory leak in mkldnn, release any buffers that are not free'd yet.
//https://software.intel.com/en-us/mkl-linux-developer-guide-avoiding-memory-leaks-in-intel-mkl //https://software.intel.com/en-us/mkl-linux-developer-guide-avoiding-memory-leaks-in-intel-mkl
//mkl_free_buffers() is not exposed at this point, hence using mkl_serv_free_buffers() //mkl_free_buffers() is not exposed at this point, hence using mkl_serv_free_buffers()
ngraph::runtime::cpu::mkldnn_utils::mkl_serv_free_buffers(); ngraph::runtime::cpu::mkldnn_utils::mkl_serv_free_buffers();
#endif #endif
for (auto w : mkldnn_workspaces) for (auto w : mkldnn_workspaces)
{ {
free(w); free(w);
} }
} }
inline void cleanup_mkldnn_descriptors() inline void cleanup_mkldnn_descriptors()
{ {
for (auto d : mkldnn_descriptors) for (auto d : mkldnn_descriptors)
{ {
free(d); free(d);
} }
} }
}; };
extern "C" CPURuntimeContextCG* init_cg_ctx() extern "C" CPURuntimeContextCG* init_cg_ctx()
...@@ -128,23 +128,23 @@ extern "C" void destroy_cg_ctx(CPURuntimeContextCG* cg_ctx) ...@@ -128,23 +128,23 @@ extern "C" void destroy_cg_ctx(CPURuntimeContextCG* cg_ctx)
} }
static void static void
deserialize_memory_descs_and_build_memory_primitives(std::ifstream& desc_file, deserialize_memory_descs_and_build_memory_primitives(std::ifstream& desc_file,
CPURuntimeContextCG* cg_ctx, CPURuntimeContextCG* cg_ctx,
size_t descs_count) size_t descs_count)
{ {
cg_ctx->mkldnn_descriptors = std::vector<mkldnn::memory::desc*>(descs_count); cg_ctx->mkldnn_descriptors = std::vector<mkldnn::memory::desc*>(descs_count);
for (auto i = 0; i < descs_count; i++) for (auto i = 0; i < descs_count; i++)
{ {
size_t primitive_index; size_t primitive_index;
desc_file >> primitive_index; desc_file >> primitive_index;
auto desc = (mkldnn::memory::desc*)malloc(sizeof(mkldnn::memory::desc)); auto desc = (mkldnn::memory::desc*)malloc(sizeof(mkldnn::memory::desc));
if (!desc) if (!desc)
{ {
throw std::bad_alloc(); throw std::bad_alloc();
} }
desc_file.read(reinterpret_cast<char*>(desc), sizeof(mkldnn::memory::desc)); desc_file.read(reinterpret_cast<char*>(desc), sizeof(mkldnn::memory::desc));
cg_ctx->mkldnn_descriptors[i] = desc; cg_ctx->mkldnn_descriptors[i] = desc;
cg_ctx->mkldnn_primitives[primitive_index] = new mkldnn::memory({*cg_ctx->mkldnn_descriptors[i], cg_ctx->global_cpu_engine}, nullptr); cg_ctx->mkldnn_primitives[primitive_index] = new mkldnn::memory({*cg_ctx->mkldnn_descriptors[i], cg_ctx->global_cpu_engine}, nullptr);
} }
}; };
)" )"
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