Commit 2a438ff2 authored by Jaikrishnan Menon's avatar Jaikrishnan Menon

CPU: MKLDNN build WIP

parent 00fb503f
...@@ -171,6 +171,7 @@ if (NGRAPH_CPU_ENABLE AND LLVM_INCLUDE_DIR AND ...@@ -171,6 +171,7 @@ if (NGRAPH_CPU_ENABLE AND LLVM_INCLUDE_DIR AND
runtime/cpu/cpu_external_function.cpp runtime/cpu/cpu_external_function.cpp
runtime/cpu/cpu_tensor_view_wrapper.cpp runtime/cpu/cpu_tensor_view_wrapper.cpp
runtime/cpu/cpu_tracing.cpp runtime/cpu/cpu_tracing.cpp
runtime/cpu/mkldnn_invoke.cpp
runtime/cpu/ops/matmul_bias.cpp runtime/cpu/ops/matmul_bias.cpp
runtime/cpu/pass/cpu_fusion.cpp runtime/cpu/pass/cpu_fusion.cpp
) )
......
...@@ -226,6 +226,8 @@ void runtime::cpu::CPU_ExternalFunction::compile() ...@@ -226,6 +226,8 @@ void runtime::cpu::CPU_ExternalFunction::compile()
string function_name = m_function->get_name(); string function_name = m_function->get_name();
mkldnn_emitter.reset(new MKLDNNEmitter(shared_from_this()));
pass::Manager pass_manager; pass::Manager pass_manager;
// For now, just make everyone row-major. // For now, just make everyone row-major.
pass_manager.register_pass<pass::CPUFusion>(); pass_manager.register_pass<pass::CPUFusion>();
......
...@@ -24,12 +24,15 @@ ...@@ -24,12 +24,15 @@
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include <mkldnn.hpp>
#include "ngraph/codegen/code_writer.hpp" #include "ngraph/codegen/code_writer.hpp"
#include "ngraph/codegen/compiler.hpp" #include "ngraph/codegen/compiler.hpp"
#include "ngraph/codegen/execution_engine.hpp" #include "ngraph/codegen/execution_engine.hpp"
#include "ngraph/function.hpp" #include "ngraph/function.hpp"
#include "ngraph/runtime/cpu/cpu_call_frame.hpp" #include "ngraph/runtime/cpu/cpu_call_frame.hpp"
#include "ngraph/runtime/cpu/cpu_tensor_view_wrapper.hpp" #include "ngraph/runtime/cpu/cpu_tensor_view_wrapper.hpp"
#include "ngraph/runtime/cpu/mkldnn_emitter.hpp"
#include "ngraph/runtime/external_function.hpp" #include "ngraph/runtime/external_function.hpp"
namespace ngraph namespace ngraph
...@@ -41,6 +44,7 @@ namespace ngraph ...@@ -41,6 +44,7 @@ namespace ngraph
class CPU_ExternalFunction; class CPU_ExternalFunction;
class CPU_Emitter; class CPU_Emitter;
class CPU_CallFrame; class CPU_CallFrame;
class MKLDNNEmitter;
using OpFunction = std::function<void(codegen::CodeWriter&, using OpFunction = std::function<void(codegen::CodeWriter&,
const ngraph::Node*, const ngraph::Node*,
...@@ -75,6 +79,11 @@ namespace ngraph ...@@ -75,6 +79,11 @@ namespace ngraph
std::shared_ptr<ngraph::runtime::CallFrame> make_call_frame(); std::shared_ptr<ngraph::runtime::CallFrame> make_call_frame();
const std::vector<OpAttributes>& get_op_attrs() const { return m_op_attrs; } const std::vector<OpAttributes>& get_op_attrs() const { return m_op_attrs; }
const std::vector<mkldnn::primitive>& get_mkldnn_primitives() const
{
return m_mkldnn_primitives;
}
protected: protected:
void compile(); void compile();
...@@ -107,6 +116,9 @@ namespace ngraph ...@@ -107,6 +116,9 @@ namespace ngraph
bool m_use_tbb; bool m_use_tbb;
std::unordered_map<std::string, std::string> m_variable_name_map; std::unordered_map<std::string, std::string> m_variable_name_map;
std::vector<OpAttributes> m_op_attrs; std::vector<OpAttributes> m_op_attrs;
std::vector<mkldnn::primitive> m_mkldnn_primitives;
std::unique_ptr<MKLDNNEmitter> mkldnn_emitter;
}; };
} }
} }
......
...@@ -17,6 +17,11 @@ ...@@ -17,6 +17,11 @@
#include <chrono> #include <chrono>
#include <cstdint> #include <cstdint>
namespace mkldnn
{
class primitive;
}
namespace ngraph namespace ngraph
{ {
namespace runtime namespace runtime
...@@ -31,6 +36,7 @@ namespace ngraph ...@@ -31,6 +36,7 @@ namespace ngraph
struct CPURuntimeContext struct CPURuntimeContext
{ {
int64_t* op_durations; int64_t* op_durations;
mkldnn::primitive* mkldnn_primitives;
}; };
} }
} }
......
// ----------------------------------------------------------------------------
// Copyright 2018 Nervana Systems Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// ----------------------------------------------------------------------------
#pragma once
#include <memory>
#include "ngraph/codegen/code_writer.hpp"
#include "ngraph/shape.hpp"
namespace ngraph
{
namespace runtime
{
namespace cpu
{
class CPU_ExternalFunction;
class MKLDNNEmitter
{
public:
MKLDNNEmitter(std::shared_ptr<CPU_ExternalFunction> ef)
: external_function(ef)
{
}
void build_memory_descriptor();
private:
std::shared_ptr<CPU_ExternalFunction> external_function;
};
}
}
}
// ----------------------------------------------------------------------------
// Copyright 2018 Nervana Systems Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// ----------------------------------------------------------------------------
#include "mkldnn_invoke.hpp"
extern "C" void
ngraph::runtime::cpu::mkldnn_utils::mkldnn_invoke_primitive(CPURuntimeContext* ctx,
unsigned int primitive_index)
{
}
// ----------------------------------------------------------------------------
// Copyright 2018 Nervana Systems Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// ----------------------------------------------------------------------------
#pragma once
namespace ngraph
{
namespace runtime
{
namespace cpu
{
struct CPURuntimeContext;
namespace mkldnn_utils
{
extern "C" void mkldnn_invoke_primitive(CPURuntimeContext* ctx,
unsigned int primitive_index);
}
}
}
}
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