Commit 3fa332b6 authored by Jaikrishnan Menon's avatar Jaikrishnan Menon

Merge branch 'master' into mem_leaks

parents 225b12bb ffe657df
...@@ -43,6 +43,9 @@ endif() ...@@ -43,6 +43,9 @@ endif()
set(CMAKE_DISABLE_SOURCE_CHANGES ON) set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
# Create compilation database compile_commands.json
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# set directory where the custom finders live # set directory where the custom finders live
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
...@@ -87,6 +90,11 @@ endif() ...@@ -87,6 +90,11 @@ endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++") # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
# Set true if CPU backend is built by default
if (NOT DEFINED NGRAPH_CPU_ENABLE)
SET(NGRAPH_CPU_ENABLE TRUE)
endif()
#----------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------
# External projects install directory # External projects install directory
#----------------------------------------------------------------------------------------------- #-----------------------------------------------------------------------------------------------
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include <clang/Basic/TargetInfo.h> #include <clang/Basic/TargetInfo.h>
#include <clang/CodeGen/CodeGenAction.h> #include <clang/CodeGen/CodeGenAction.h>
#include <clang/Frontend/CompilerInstance.h> #include <clang/Frontend/CompilerInstance.h>
#include <clang/Frontend/FrontendActions.h>
#include <clang/Frontend/TextDiagnosticPrinter.h> #include <clang/Frontend/TextDiagnosticPrinter.h>
#include <llvm/Support/TargetSelect.h> #include <llvm/Support/TargetSelect.h>
...@@ -73,6 +74,11 @@ Compiler::~Compiler() ...@@ -73,6 +74,11 @@ Compiler::~Compiler()
{ {
} }
void Compiler::set_precompiled_header_source(const std::string& source)
{
s_static_compiler.set_precompiled_header_source(source);
}
std::unique_ptr<llvm::Module> Compiler::compile(const std::string& source) std::unique_ptr<llvm::Module> Compiler::compile(const std::string& source)
{ {
lock_guard<mutex> lock(m_mutex); lock_guard<mutex> lock(m_mutex);
...@@ -88,14 +94,10 @@ static std::string GetExecutablePath(const char* Argv0) ...@@ -88,14 +94,10 @@ static std::string GetExecutablePath(const char* Argv0)
} }
StaticCompiler::StaticCompiler() StaticCompiler::StaticCompiler()
: m_precompiled_headers_enabled(false) : m_precompiled_header_valid(false)
, m_debuginfo_enabled(false) , m_debuginfo_enabled(false)
, m_source_name("code.cpp") , m_source_name("code.cpp")
{ {
#if NGCPU_PCH
m_precompiled_headers_enabled = true;
#endif
#if NGCPU_DEBUGINFO #if NGCPU_DEBUGINFO
m_debuginfo_enabled = true; m_debuginfo_enabled = true;
#endif #endif
...@@ -213,14 +215,6 @@ StaticCompiler::StaticCompiler() ...@@ -213,14 +215,6 @@ StaticCompiler::StaticCompiler()
CGO.setDebugInfo(codegenoptions::FullDebugInfo); CGO.setDebugInfo(codegenoptions::FullDebugInfo);
} }
if (m_precompiled_headers_enabled)
{
// Preprocessor options
auto& PPO = m_compiler->getInvocation().getPreprocessorOpts();
PPO.ImplicitPCHInclude = "ngcpu.pch";
PPO.DisablePCHValidation = 1;
}
// Enable various target features // Enable various target features
// Most of these are for Eigen // Most of these are for Eigen
auto& TO = m_compiler->getInvocation().getTargetOpts(); auto& TO = m_compiler->getInvocation().getTargetOpts();
...@@ -314,6 +308,18 @@ std::unique_ptr<llvm::Module> ...@@ -314,6 +308,18 @@ std::unique_ptr<llvm::Module>
StaticCompiler::compile(std::unique_ptr<clang::CodeGenAction>& compiler_action, StaticCompiler::compile(std::unique_ptr<clang::CodeGenAction>& compiler_action,
const string& source) const string& source)
{ {
if (!m_precompiled_header_valid && m_precomiled_header_source.empty() == false)
{
generate_pch(m_precomiled_header_source);
}
if (m_precompiled_header_valid)
{
// Preprocessor options
auto& PPO = m_compiler->getInvocation().getPreprocessorOpts();
PPO.ImplicitPCHInclude = m_pch_path;
PPO.DisablePCHValidation = 0;
}
// Map code filename to a memoryBuffer // Map code filename to a memoryBuffer
StringRef source_ref(source); StringRef source_ref(source);
unique_ptr<MemoryBuffer> buffer = MemoryBuffer::getMemBufferCopy(source_ref); unique_ptr<MemoryBuffer> buffer = MemoryBuffer::getMemBufferCopy(source_ref);
...@@ -334,24 +340,24 @@ std::unique_ptr<llvm::Module> ...@@ -334,24 +340,24 @@ std::unique_ptr<llvm::Module>
return rc; return rc;
} }
// std::unique_ptr<llvm::Module> StaticCompiler::generate_pch(const string& source) void StaticCompiler::generate_pch(const string& source)
// { {
// // Map code filename to a memoryBuffer m_pch_path = file_util::tmp_filename();
// StringRef source_ref(source); m_compiler->getFrontendOpts().OutputFile = m_pch_path;
// unique_ptr<MemoryBuffer> buffer = MemoryBuffer::getMemBufferCopy(source_ref);
// m_compiler->getInvocation().getPreprocessorOpts().addRemappedFile(m_source_name, buffer.get());
// // Create and execute action // Map code filename to a memoryBuffer
// CodeGenAction* compilerAction = new GeneratePCHAction(); StringRef source_ref(source);
// std::unique_ptr<llvm::Module> rc; unique_ptr<MemoryBuffer> buffer = MemoryBuffer::getMemBufferCopy(source_ref);
// if (m_compiler->ExecuteAction(*compilerAction) == true) m_compiler->getInvocation().getPreprocessorOpts().addRemappedFile(m_source_name, buffer.get());
// {
// rc = compilerAction->takeModule();
// }
// buffer.release(); // Create and execute action
clang::GeneratePCHAction* compilerAction = new clang::GeneratePCHAction();
if (m_compiler->ExecuteAction(*compilerAction) == true)
{
m_precompiled_header_valid = true;
}
// m_compiler->getInvocation().getPreprocessorOpts().clearRemappedFiles(); buffer.release();
// return rc; m_compiler->getInvocation().getPreprocessorOpts().clearRemappedFiles();
// } }
...@@ -53,6 +53,7 @@ class ngraph::codegen::Compiler ...@@ -53,6 +53,7 @@ class ngraph::codegen::Compiler
public: public:
Compiler(); Compiler();
~Compiler(); ~Compiler();
void set_precompiled_header_source(const std::string& source);
std::unique_ptr<llvm::Module> compile(const std::string& source); std::unique_ptr<llvm::Module> compile(const std::string& source);
std::unique_ptr<clang::CodeGenAction>& get_compiler_action() { return compiler_action; } std::unique_ptr<clang::CodeGenAction>& get_compiler_action() { return compiler_action; }
private: private:
...@@ -65,20 +66,26 @@ public: ...@@ -65,20 +66,26 @@ public:
StaticCompiler(); StaticCompiler();
~StaticCompiler(); ~StaticCompiler();
void set_precompiled_headers_enabled(bool state) { m_precompiled_headers_enabled = state; }
bool is_precompiled_headers_enabled() { return m_precompiled_headers_enabled; }
void set_debuginfo_enabled(bool state) { m_debuginfo_enabled = state; } void set_debuginfo_enabled(bool state) { m_debuginfo_enabled = state; }
bool is_debuginfo_enabled() { return m_debuginfo_enabled; } bool is_debuginfo_enabled() { return m_debuginfo_enabled; }
void set_precompiled_header_source(const std::string& source)
{
m_precomiled_header_source = source;
}
void add_header_search_path(const std::string& path); void add_header_search_path(const std::string& path);
std::unique_ptr<llvm::Module> compile(std::unique_ptr<clang::CodeGenAction>& compiler_action, std::unique_ptr<llvm::Module> compile(std::unique_ptr<clang::CodeGenAction>& compiler_action,
const std::string& source); const std::string& source);
void generate_pch(const std::string& source);
private: private:
std::unique_ptr<clang::CompilerInstance> m_compiler; std::unique_ptr<clang::CompilerInstance> m_compiler;
bool m_precompiled_headers_enabled; bool m_precompiled_header_valid;
bool m_debuginfo_enabled; bool m_debuginfo_enabled;
std::string m_source_name; std::string m_source_name;
std::vector<std::string> m_extra_search_path_list; std::vector<std::string> m_extra_search_path_list;
std::string m_pch_path;
std::string m_precomiled_header_source;
bool is_version_number(const std::string& path); bool is_version_number(const std::string& path);
void use_cached_files(); void use_cached_files();
......
...@@ -31,6 +31,7 @@ Function::Function(const std::shared_ptr<Node>& result, ...@@ -31,6 +31,7 @@ Function::Function(const std::shared_ptr<Node>& result,
, m_name(name) , m_name(name)
, m_result_type(result_type) , m_result_type(result_type)
, m_ordered_ops_valid(false) , m_ordered_ops_valid(false)
, m_temporary_pool_size(0)
, m_instance_id(m_next_instance_id.fetch_add(1)) , m_instance_id(m_next_instance_id.fetch_add(1))
{ {
m_result->set_is_output(); m_result->set_is_output();
...@@ -97,6 +98,16 @@ void Function::set_name(const string& name) ...@@ -97,6 +98,16 @@ void Function::set_name(const string& name)
} }
} }
size_t Function::get_temporary_pool_size()
{
return m_temporary_pool_size;
}
void Function::set_temporary_pool_size(size_t size)
{
m_temporary_pool_size = size;
}
std::ostream& ngraph::operator<<(std::ostream& out, const Function& f) std::ostream& ngraph::operator<<(std::ostream& out, const Function& f)
{ {
out << "Function(" << f.get_name() << ")"; out << "Function(" << f.get_name() << ")";
......
...@@ -56,6 +56,9 @@ namespace ngraph ...@@ -56,6 +56,9 @@ namespace ngraph
void clear_ordered_ops_valid() { m_ordered_ops_valid = false; } void clear_ordered_ops_valid() { m_ordered_ops_valid = false; }
friend std::ostream& operator<<(std::ostream&, const Function&); friend std::ostream& operator<<(std::ostream&, const Function&);
size_t get_instance_id() { return m_instance_id; } size_t get_instance_id() { return m_instance_id; }
size_t get_temporary_pool_size();
void set_temporary_pool_size(size_t);
protected: protected:
std::shared_ptr<Node> m_result; std::shared_ptr<Node> m_result;
std::vector<std::shared_ptr<ngraph::op::Parameter>> m_parameters; std::vector<std::shared_ptr<ngraph::op::Parameter>> m_parameters;
...@@ -64,6 +67,7 @@ namespace ngraph ...@@ -64,6 +67,7 @@ namespace ngraph
bool m_ordered_ops_valid; bool m_ordered_ops_valid;
std::list<std::shared_ptr<Node>> m_ordered_ops; std::list<std::shared_ptr<Node>> m_ordered_ops;
std::list<std::shared_ptr<Node>> m_ops; std::list<std::shared_ptr<Node>> m_ops;
size_t m_temporary_pool_size;
private: private:
Function(const Function&) = delete; Function(const Function&) = delete;
......
...@@ -27,13 +27,3 @@ const vector<shared_ptr<Function>>& ngraph::pass::ManagerState::get_functions() ...@@ -27,13 +27,3 @@ const vector<shared_ptr<Function>>& ngraph::pass::ManagerState::get_functions()
{ {
return m_function_list; return m_function_list;
} }
size_t ngraph::pass::ManagerState::get_temporary_pool_size()
{
return m_temporary_pool_size;
}
void ngraph::pass::ManagerState::set_temporary_pool_size(size_t size)
{
m_temporary_pool_size = size;
}
...@@ -39,10 +39,6 @@ public: ...@@ -39,10 +39,6 @@ public:
m_function_list.insert(m_function_list.begin(), collection.begin(), collection.end()); m_function_list.insert(m_function_list.begin(), collection.begin(), collection.end());
} }
size_t get_temporary_pool_size();
void set_temporary_pool_size(size_t);
private: private:
size_t m_temporary_pool_size = 0;
std::vector<std::shared_ptr<Function>> m_function_list; std::vector<std::shared_ptr<Function>> m_function_list;
}; };
...@@ -31,10 +31,10 @@ pass::MemoryLayout::MemoryLayout(size_t alignment) ...@@ -31,10 +31,10 @@ pass::MemoryLayout::MemoryLayout(size_t alignment)
{ {
} }
bool pass::MemoryLayout::run_on_call_graph(std::list<std::shared_ptr<Node>>& node_list) bool pass::MemoryLayout::run_on_function(std::shared_ptr<ngraph::Function> function)
{ {
MemoryManager mm(m_alignment); MemoryManager mm(m_alignment);
for (shared_ptr<Node> node : node_list) for (shared_ptr<Node> node : function->get_ordered_ops())
{ {
for (Tensor* tensor : node->liveness_new_list) for (Tensor* tensor : node->liveness_new_list)
{ {
...@@ -46,7 +46,7 @@ bool pass::MemoryLayout::run_on_call_graph(std::list<std::shared_ptr<Node>>& nod ...@@ -46,7 +46,7 @@ bool pass::MemoryLayout::run_on_call_graph(std::list<std::shared_ptr<Node>>& nod
mm.free(tensor->get_pool_offset()); mm.free(tensor->get_pool_offset());
} }
} }
get_state().set_temporary_pool_size(mm.max_allocated()); function->set_temporary_pool_size(mm.max_allocated());
return false; return false;
} }
......
...@@ -30,11 +30,11 @@ namespace ngraph ...@@ -30,11 +30,11 @@ namespace ngraph
} }
} }
class ngraph::pass::MemoryLayout : public CallGraphPass class ngraph::pass::MemoryLayout : public FunctionPass
{ {
public: public:
MemoryLayout(size_t alignment = 1); MemoryLayout(size_t alignment = 1);
virtual bool run_on_call_graph(std::list<std::shared_ptr<Node>>&) override; bool run_on_function(std::shared_ptr<ngraph::Function>) override;
private: private:
size_t m_alignment; size_t m_alignment;
......
...@@ -47,7 +47,7 @@ void CallFrame::tensor_call( ...@@ -47,7 +47,7 @@ void CallFrame::tensor_call(
} }
// Invoke compiled computation // Invoke compiled computation
m_compiled_function(inputs, outputs); m_compiled_function(inputs.data(), outputs.data());
} }
void CallFrame::operator()(const std::vector<std::shared_ptr<ngraph::runtime::Value>>& arguments, void CallFrame::operator()(const std::vector<std::shared_ptr<ngraph::runtime::Value>>& arguments,
......
...@@ -33,8 +33,7 @@ namespace ngraph ...@@ -33,8 +33,7 @@ namespace ngraph
class CallFrame; class CallFrame;
class ExternalFunction; class ExternalFunction;
using EntryPoint_t = void(const std::vector<void*>& inputs, using EntryPoint_t = void(void** inputs, void** outputs);
const std::vector<void*>& outputs);
using EntryPoint = std::function<EntryPoint_t>; using EntryPoint = std::function<EntryPoint_t>;
......
...@@ -56,14 +56,12 @@ static std::string eigen_matrix_format(const ngraph::Shape& shape, const ngraph: ...@@ -56,14 +56,12 @@ static std::string eigen_matrix_format(const ngraph::Shape& shape, const ngraph:
} }
void Emitter::EmitNop(const ngraph::Node* n, void Emitter::EmitNop(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
} }
void Emitter::EmitAdd(const ngraph::Node* n, void Emitter::EmitAdd(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -78,7 +76,6 @@ void Emitter::EmitAdd(const ngraph::Node* n, ...@@ -78,7 +76,6 @@ void Emitter::EmitAdd(const ngraph::Node* n,
} }
void Emitter::EmitDot(const ngraph::Node* n, void Emitter::EmitDot(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -172,7 +169,6 @@ void Emitter::EmitDot(const ngraph::Node* n, ...@@ -172,7 +169,6 @@ void Emitter::EmitDot(const ngraph::Node* n,
} }
void Emitter::EmitMultiply(const ngraph::Node* n, void Emitter::EmitMultiply(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -191,7 +187,6 @@ void Emitter::EmitMultiply(const ngraph::Node* n, ...@@ -191,7 +187,6 @@ void Emitter::EmitMultiply(const ngraph::Node* n,
} }
void Emitter::EmitGetTupleElement(const ngraph::Node* n, void Emitter::EmitGetTupleElement(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -213,7 +208,6 @@ void Emitter::EmitGetTupleElement(const ngraph::Node* n, ...@@ -213,7 +208,6 @@ void Emitter::EmitGetTupleElement(const ngraph::Node* n,
} }
void Emitter::EmitTuple(const ngraph::Node* n, void Emitter::EmitTuple(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -239,7 +233,6 @@ void Emitter::EmitTuple(const ngraph::Node* n, ...@@ -239,7 +233,6 @@ void Emitter::EmitTuple(const ngraph::Node* n,
} }
void Emitter::EmitAbs(const ngraph::Node* n, void Emitter::EmitAbs(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -252,7 +245,6 @@ void Emitter::EmitAbs(const ngraph::Node* n, ...@@ -252,7 +245,6 @@ void Emitter::EmitAbs(const ngraph::Node* n,
} }
void Emitter::EmitConcat(const ngraph::Node* n, void Emitter::EmitConcat(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -306,7 +298,6 @@ void Emitter::EmitConcat(const ngraph::Node* n, ...@@ -306,7 +298,6 @@ void Emitter::EmitConcat(const ngraph::Node* n,
} }
void Emitter::EmitDivide(const ngraph::Node* n, void Emitter::EmitDivide(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -320,7 +311,6 @@ void Emitter::EmitDivide(const ngraph::Node* n, ...@@ -320,7 +311,6 @@ void Emitter::EmitDivide(const ngraph::Node* n,
} }
void Emitter::EmitEqual(const ngraph::Node* n, void Emitter::EmitEqual(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -334,7 +324,6 @@ void Emitter::EmitEqual(const ngraph::Node* n, ...@@ -334,7 +324,6 @@ void Emitter::EmitEqual(const ngraph::Node* n,
} }
void Emitter::EmitGreater(const ngraph::Node* n, void Emitter::EmitGreater(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -348,7 +337,6 @@ void Emitter::EmitGreater(const ngraph::Node* n, ...@@ -348,7 +337,6 @@ void Emitter::EmitGreater(const ngraph::Node* n,
} }
void Emitter::EmitGreaterEq(const ngraph::Node* n, void Emitter::EmitGreaterEq(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -362,7 +350,6 @@ void Emitter::EmitGreaterEq(const ngraph::Node* n, ...@@ -362,7 +350,6 @@ void Emitter::EmitGreaterEq(const ngraph::Node* n,
} }
void Emitter::EmitLess(const ngraph::Node* n, void Emitter::EmitLess(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -376,7 +363,6 @@ void Emitter::EmitLess(const ngraph::Node* n, ...@@ -376,7 +363,6 @@ void Emitter::EmitLess(const ngraph::Node* n,
} }
void Emitter::EmitLessEq(const ngraph::Node* n, void Emitter::EmitLessEq(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -390,7 +376,6 @@ void Emitter::EmitLessEq(const ngraph::Node* n, ...@@ -390,7 +376,6 @@ void Emitter::EmitLessEq(const ngraph::Node* n,
} }
void Emitter::EmitLog(const ngraph::Node* n, void Emitter::EmitLog(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -403,7 +388,6 @@ void Emitter::EmitLog(const ngraph::Node* n, ...@@ -403,7 +388,6 @@ void Emitter::EmitLog(const ngraph::Node* n,
} }
void Emitter::EmitMaximum(const ngraph::Node* n, void Emitter::EmitMaximum(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -417,7 +401,6 @@ void Emitter::EmitMaximum(const ngraph::Node* n, ...@@ -417,7 +401,6 @@ void Emitter::EmitMaximum(const ngraph::Node* n,
} }
void Emitter::EmitMinimum(const ngraph::Node* n, void Emitter::EmitMinimum(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -431,7 +414,6 @@ void Emitter::EmitMinimum(const ngraph::Node* n, ...@@ -431,7 +414,6 @@ void Emitter::EmitMinimum(const ngraph::Node* n,
} }
void Emitter::EmitNegative(const ngraph::Node* n, void Emitter::EmitNegative(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -444,7 +426,6 @@ void Emitter::EmitNegative(const ngraph::Node* n, ...@@ -444,7 +426,6 @@ void Emitter::EmitNegative(const ngraph::Node* n,
} }
void Emitter::EmitNotEqual(const ngraph::Node* n, void Emitter::EmitNotEqual(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -458,7 +439,6 @@ void Emitter::EmitNotEqual(const ngraph::Node* n, ...@@ -458,7 +439,6 @@ void Emitter::EmitNotEqual(const ngraph::Node* n,
} }
void Emitter::EmitSelect(const ngraph::Node* n, void Emitter::EmitSelect(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -473,7 +453,6 @@ void Emitter::EmitSelect(const ngraph::Node* n, ...@@ -473,7 +453,6 @@ void Emitter::EmitSelect(const ngraph::Node* n,
} }
void Emitter::EmitSubtract(const ngraph::Node* n, void Emitter::EmitSubtract(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -487,7 +466,6 @@ void Emitter::EmitSubtract(const ngraph::Node* n, ...@@ -487,7 +466,6 @@ void Emitter::EmitSubtract(const ngraph::Node* n,
} }
void Emitter::EmitParameterizedConstantBool(const ngraph::Node* n, void Emitter::EmitParameterizedConstantBool(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -501,14 +479,14 @@ void Emitter::EmitParameterizedConstantBool(const ngraph::Node* n, ...@@ -501,14 +479,14 @@ void Emitter::EmitParameterizedConstantBool(const ngraph::Node* n,
// Special case where constant is stored directly in the output // Special case where constant is stored directly in the output
for (size_t i = 0; i < value.size(); i++) for (size_t i = 0; i < value.size(); i++)
{ {
TU << outputs[0].get_tensor().get_name() << "[" << i << "] = static_cast<bool>(" TU << outputs[0].get_tensor().get_name() << "[" << i << "] = static_cast<char>("
<< (value[i] ? "true" : "false") << ");\n"; << (value[i] ? "true" : "false") << ");\n";
} }
} }
else else
{ {
TU << "// this should be const but eigen hates const :(\n"; TU << "// this should be const but eigen hates const :(\n";
TU << "bool " << outputs[0].get_tensor().get_name() << "[] = {\n"; TU << "char " << outputs[0].get_tensor().get_name() << "[] = {\n";
for (size_t i = 0; i < value.size(); i++) for (size_t i = 0; i < value.size(); i++)
{ {
if (i != 0) if (i != 0)
...@@ -546,7 +524,6 @@ static string format_float_as_string(float value) ...@@ -546,7 +524,6 @@ static string format_float_as_string(float value)
} }
void Emitter::EmitParameterizedConstantFloat32(const ngraph::Node* n, void Emitter::EmitParameterizedConstantFloat32(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -583,7 +560,6 @@ void Emitter::EmitParameterizedConstantFloat32(const ngraph::Node* n, ...@@ -583,7 +560,6 @@ void Emitter::EmitParameterizedConstantFloat32(const ngraph::Node* n,
} }
void Emitter::EmitParameterizedConstantInt8(const ngraph::Node* n, void Emitter::EmitParameterizedConstantInt8(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -620,7 +596,6 @@ void Emitter::EmitParameterizedConstantInt8(const ngraph::Node* n, ...@@ -620,7 +596,6 @@ void Emitter::EmitParameterizedConstantInt8(const ngraph::Node* n,
} }
void Emitter::EmitParameterizedConstantInt32(const ngraph::Node* n, void Emitter::EmitParameterizedConstantInt32(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -657,7 +632,6 @@ void Emitter::EmitParameterizedConstantInt32(const ngraph::Node* n, ...@@ -657,7 +632,6 @@ void Emitter::EmitParameterizedConstantInt32(const ngraph::Node* n,
} }
void Emitter::EmitParameterizedConstantInt64(const ngraph::Node* n, void Emitter::EmitParameterizedConstantInt64(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -694,7 +668,6 @@ void Emitter::EmitParameterizedConstantInt64(const ngraph::Node* n, ...@@ -694,7 +668,6 @@ void Emitter::EmitParameterizedConstantInt64(const ngraph::Node* n,
} }
void Emitter::EmitParameterizedConstantUInt8(const ngraph::Node* n, void Emitter::EmitParameterizedConstantUInt8(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -731,7 +704,6 @@ void Emitter::EmitParameterizedConstantUInt8(const ngraph::Node* n, ...@@ -731,7 +704,6 @@ void Emitter::EmitParameterizedConstantUInt8(const ngraph::Node* n,
} }
void Emitter::EmitParameterizedConstantUInt32(const ngraph::Node* n, void Emitter::EmitParameterizedConstantUInt32(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -768,7 +740,6 @@ void Emitter::EmitParameterizedConstantUInt32(const ngraph::Node* n, ...@@ -768,7 +740,6 @@ void Emitter::EmitParameterizedConstantUInt32(const ngraph::Node* n,
} }
void Emitter::EmitParameterizedConstantUInt64(const ngraph::Node* n, void Emitter::EmitParameterizedConstantUInt64(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -805,7 +776,6 @@ void Emitter::EmitParameterizedConstantUInt64(const ngraph::Node* n, ...@@ -805,7 +776,6 @@ void Emitter::EmitParameterizedConstantUInt64(const ngraph::Node* n,
} }
void Emitter::EmitBroadcast(const ngraph::Node* n, void Emitter::EmitBroadcast(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -880,7 +850,6 @@ void Emitter::EmitBroadcast(const ngraph::Node* n, ...@@ -880,7 +850,6 @@ void Emitter::EmitBroadcast(const ngraph::Node* n,
} }
void Emitter::EmitConvert(const ngraph::Node* n, void Emitter::EmitConvert(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -904,7 +873,6 @@ void Emitter::EmitConvert(const ngraph::Node* n, ...@@ -904,7 +873,6 @@ void Emitter::EmitConvert(const ngraph::Node* n,
} }
void Emitter::EmitConstant(const ngraph::Node* n, void Emitter::EmitConstant(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -926,7 +894,6 @@ void Emitter::EmitConstant(const ngraph::Node* n, ...@@ -926,7 +894,6 @@ void Emitter::EmitConstant(const ngraph::Node* n,
} }
void Emitter::EmitReshape(const ngraph::Node* n, void Emitter::EmitReshape(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -1009,7 +976,6 @@ void Emitter::EmitReshape(const ngraph::Node* n, ...@@ -1009,7 +976,6 @@ void Emitter::EmitReshape(const ngraph::Node* n,
} }
void Emitter::EmitFunctionCall(const ngraph::Node* n, void Emitter::EmitFunctionCall(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -1030,7 +996,6 @@ void Emitter::EmitFunctionCall(const ngraph::Node* n, ...@@ -1030,7 +996,6 @@ void Emitter::EmitFunctionCall(const ngraph::Node* n,
// to what's seen there (for now atleast) // to what's seen there (for now atleast)
void Emitter::EmitReduce(const ngraph::Node* n, void Emitter::EmitReduce(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -1118,8 +1083,8 @@ void Emitter::EmitReduce(const ngraph::Node* n, ...@@ -1118,8 +1083,8 @@ void Emitter::EmitReduce(const ngraph::Node* n,
TU.indent++; TU.indent++;
TU << "\n"; TU << "\n";
TU << type << " result;\n"; TU << type << " result;\n";
TU << "std::vector<void*> inputs = {&x, &y};\n"; TU << "void* inputs[] = {&x, &y};\n";
TU << "std::vector<void*> outputs = {&result};\n"; TU << "void* outputs[] = {&result};\n";
TU << reduction_function->get_name() << "(inputs, outputs);\n"; TU << reduction_function->get_name() << "(inputs, outputs);\n";
TU << "return result;\n"; TU << "return result;\n";
TU.indent--; TU.indent--;
...@@ -1154,8 +1119,8 @@ void Emitter::EmitReduce(const ngraph::Node* n, ...@@ -1154,8 +1119,8 @@ void Emitter::EmitReduce(const ngraph::Node* n,
TU.indent++; TU.indent++;
TU << "\n"; TU << "\n";
TU << type << " result;\n"; TU << type << " result;\n";
TU << "std::vector<void*> inputs = {&x, &y};\n"; TU << "void* inputs[] = {&x, &y};\n";
TU << "std::vector<void*> outputs = {&result};\n"; TU << "void* outputs[] = {&result};\n";
TU << reduction_function->get_name() << "(inputs, outputs);\n"; TU << reduction_function->get_name() << "(inputs, outputs);\n";
TU << "return result;\n"; TU << "return result;\n";
TU.indent--; TU.indent--;
...@@ -1186,8 +1151,8 @@ void Emitter::EmitReduce(const ngraph::Node* n, ...@@ -1186,8 +1151,8 @@ void Emitter::EmitReduce(const ngraph::Node* n,
TU.indent++; TU.indent++;
TU << "\n"; TU << "\n";
TU << type << " result;\n"; TU << type << " result;\n";
TU << "std::vector<void*> inputs = {&x, &y};\n"; TU << "void* inputs[] = {&x, &y};\n";
TU << "std::vector<void*> outputs = {&result};\n"; TU << "void* outputs[] = {&result};\n";
TU << reduction_function->get_name() << "(inputs, outputs);\n"; TU << reduction_function->get_name() << "(inputs, outputs);\n";
TU << "return result;\n"; TU << "return result;\n";
TU.indent--; TU.indent--;
...@@ -1205,7 +1170,6 @@ void Emitter::EmitReduce(const ngraph::Node* n, ...@@ -1205,7 +1170,6 @@ void Emitter::EmitReduce(const ngraph::Node* n,
} }
void Emitter::EmitSign(const ngraph::Node* n, void Emitter::EmitSign(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -1218,7 +1182,6 @@ void Emitter::EmitSign(const ngraph::Node* n, ...@@ -1218,7 +1182,6 @@ void Emitter::EmitSign(const ngraph::Node* n,
} }
void Emitter::EmitSlice(const ngraph::Node* n, void Emitter::EmitSlice(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -1288,7 +1251,6 @@ void Emitter::EmitSlice(const ngraph::Node* n, ...@@ -1288,7 +1251,6 @@ void Emitter::EmitSlice(const ngraph::Node* n,
} }
void Emitter::EmitSum(const ngraph::Node* n, void Emitter::EmitSum(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -1359,7 +1321,6 @@ void Emitter::EmitSum(const ngraph::Node* n, ...@@ -1359,7 +1321,6 @@ void Emitter::EmitSum(const ngraph::Node* n,
} }
void Emitter::EmitExp(const ngraph::Node* n, void Emitter::EmitExp(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -1372,7 +1333,6 @@ void Emitter::EmitExp(const ngraph::Node* n, ...@@ -1372,7 +1333,6 @@ void Emitter::EmitExp(const ngraph::Node* n,
} }
void Emitter::EmitSin(const ngraph::Node* n, void Emitter::EmitSin(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -1385,7 +1345,6 @@ void Emitter::EmitSin(const ngraph::Node* n, ...@@ -1385,7 +1345,6 @@ void Emitter::EmitSin(const ngraph::Node* n,
} }
void Emitter::EmitSinh(const ngraph::Node* n, void Emitter::EmitSinh(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -1398,7 +1357,6 @@ void Emitter::EmitSinh(const ngraph::Node* n, ...@@ -1398,7 +1357,6 @@ void Emitter::EmitSinh(const ngraph::Node* n,
} }
void Emitter::EmitCos(const ngraph::Node* n, void Emitter::EmitCos(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -1411,7 +1369,6 @@ void Emitter::EmitCos(const ngraph::Node* n, ...@@ -1411,7 +1369,6 @@ void Emitter::EmitCos(const ngraph::Node* n,
} }
void Emitter::EmitCosh(const ngraph::Node* n, void Emitter::EmitCosh(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -1424,7 +1381,6 @@ void Emitter::EmitCosh(const ngraph::Node* n, ...@@ -1424,7 +1381,6 @@ void Emitter::EmitCosh(const ngraph::Node* n,
} }
void Emitter::EmitTan(const ngraph::Node* n, void Emitter::EmitTan(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -1437,7 +1393,6 @@ void Emitter::EmitTan(const ngraph::Node* n, ...@@ -1437,7 +1393,6 @@ void Emitter::EmitTan(const ngraph::Node* n,
} }
void Emitter::EmitTanh(const ngraph::Node* n, void Emitter::EmitTanh(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -1457,7 +1412,6 @@ void Emitter::EmitTanh(const ngraph::Node* n, ...@@ -1457,7 +1412,6 @@ void Emitter::EmitTanh(const ngraph::Node* n,
} }
void Emitter::EmitAsin(const ngraph::Node* n, void Emitter::EmitAsin(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -1470,7 +1424,6 @@ void Emitter::EmitAsin(const ngraph::Node* n, ...@@ -1470,7 +1424,6 @@ void Emitter::EmitAsin(const ngraph::Node* n,
} }
void Emitter::EmitAcos(const ngraph::Node* n, void Emitter::EmitAcos(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -1483,7 +1436,6 @@ void Emitter::EmitAcos(const ngraph::Node* n, ...@@ -1483,7 +1436,6 @@ void Emitter::EmitAcos(const ngraph::Node* n,
} }
void Emitter::EmitAtan(const ngraph::Node* n, void Emitter::EmitAtan(const ngraph::Node* n,
ExternalFunction* ef,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
{ {
...@@ -1516,13 +1468,13 @@ void Emitter::generate_call(const std::vector<TensorViewInfo>& inputs, ...@@ -1516,13 +1468,13 @@ void Emitter::generate_call(const std::vector<TensorViewInfo>& inputs,
output_names.push_back(output.get_tensor().get_name()); output_names.push_back(output.get_tensor().get_name());
} }
TU << "std::vector<void*> inputs =\n{"; TU << "void* inputs[] =\n{";
TU.indent++; TU.indent++;
TU << "\n" << join(input_names, ",\n"); TU << "\n" << join(input_names, ",\n");
TU.indent--; TU.indent--;
TU << "\n};\n"; TU << "\n};\n";
TU << "std::vector<void*> outputs =\n{"; TU << "void* outputs[] =\n{";
TU.indent++; TU.indent++;
TU << "\n" << join(output_names, ",\n"); TU << "\n" << join(output_names, ",\n");
TU.indent--; TU.indent--;
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#define EMITTER_DECL(E) \ #define EMITTER_DECL(E) \
E(const ngraph::Node* n, \ E(const ngraph::Node* n, \
ExternalFunction* ef, \
const std::vector<TensorViewInfo>& inputs, \ const std::vector<TensorViewInfo>& inputs, \
const std::vector<TensorViewInfo>& outputs) const std::vector<TensorViewInfo>& outputs)
......
...@@ -183,15 +183,9 @@ void ExternalFunction::compile() ...@@ -183,15 +183,9 @@ void ExternalFunction::compile()
Emitter emitter; Emitter emitter;
codegen::CodeWriter& TU = emitter.get_code_writer(); codegen::CodeWriter& TU = emitter.get_code_writer();
// The "dso_handle" symbol below is required by __cxa_atexit()
// which is enabled because the JIT uses it as the default mechanism
// to register cleanup handlers. We use it, and not atexit(), because
// atexit() happens too late, when the JIT is no longer alive
TU += TU +=
R"(// Generated by the NGraph CPU backend R"(// Generated by the NGraph CPU backend
#include <cmath> #include <cmath>
#include <vector>
#include <Eigen/Dense> #include <Eigen/Dense>
...@@ -201,24 +195,27 @@ void ExternalFunction::compile() ...@@ -201,24 +195,27 @@ void ExternalFunction::compile()
using namespace ngraph::runtime::cpu::eigen; using namespace ngraph::runtime::cpu::eigen;
void *__dso_handle = 0;
)"; )";
string pch_header_source = TU.get_code();
// The "dso_handle" symbol is required by __cxa_atexit()
// which is enabled because the JIT uses it as the default mechanism
// to register cleanup handlers. We use it, and not atexit(), because
// atexit() happens too late, when the JIT is no longer alive
TU << "void *__dso_handle = 0;\n\n";
TU << "// Declare all functions\n"; TU << "// Declare all functions\n";
for (shared_ptr<Function> f : pass_manager.get_state().get_functions()) for (shared_ptr<Function> f : pass_manager.get_state().get_functions())
{ {
TU << "extern \"C\" void " << f->get_name() << "(\n"; TU << "extern \"C\" void " << f->get_name() << "(void** inputs, void** outputs);\n";
TU << " const std::vector<void*>& inputs,\n";
TU << " const std::vector<void*>& outputs);\n";
} }
TU << "\n"; TU << "\n";
for (shared_ptr<Function> current_function : pass_manager.get_state().get_functions()) for (shared_ptr<Function> current_function : pass_manager.get_state().get_functions())
{ {
TU << "extern \"C\" void " << current_function->get_name() << "(\n"; TU << "extern \"C\" void " << current_function->get_name();
TU << " const std::vector<void*>& inputs,\n"; TU << "(void** inputs, void** outputs)\n";
TU << " const std::vector<void*>& outputs)\n";
TU << "{\n"; TU << "{\n";
TU.indent++; TU.indent++;
...@@ -233,7 +230,7 @@ void *__dso_handle = 0; ...@@ -233,7 +230,7 @@ void *__dso_handle = 0;
} }
if (temporaries_used) if (temporaries_used)
{ {
size_t temp_pool_size = pass_manager.get_state().get_temporary_pool_size(); size_t temp_pool_size = current_function->get_temporary_pool_size();
TU << "// Allocate the memory pool\n"; TU << "// Allocate the memory pool\n";
TU << "ngraph::runtime::AlignedBuffer memory_handler(" << temp_pool_size << ", " TU << "ngraph::runtime::AlignedBuffer memory_handler(" << temp_pool_size << ", "
<< ngraph::runtime::cpu::alignment << ");\n"; << ngraph::runtime::cpu::alignment << ");\n";
...@@ -303,7 +300,7 @@ void *__dso_handle = 0; ...@@ -303,7 +300,7 @@ void *__dso_handle = 0;
auto tv = output.get_tensor_view(); auto tv = output.get_tensor_view();
out.push_back({0, tv}); out.push_back({0, tv});
} }
handler->second(&emitter, node.get(), this, in, out); handler->second(&emitter, node.get(), in, out);
} }
TU.indent--; TU.indent--;
...@@ -325,7 +322,10 @@ void *__dso_handle = 0; ...@@ -325,7 +322,10 @@ void *__dso_handle = 0;
compiler.reset(new codegen::Compiler()); compiler.reset(new codegen::Compiler());
execution_engine.reset(new codegen::ExecutionEngine()); execution_engine.reset(new codegen::ExecutionEngine());
compiler->set_precompiled_header_source(pch_header_source);
auto llvm_module = compiler->compile(code); auto llvm_module = compiler->compile(code);
if (llvm_module == nullptr) if (llvm_module == nullptr)
{ {
throw runtime_error("function failed to compile"); throw runtime_error("function failed to compile");
......
...@@ -39,7 +39,6 @@ namespace ngraph ...@@ -39,7 +39,6 @@ namespace ngraph
using OpFunction = std::function<void(Emitter*, using OpFunction = std::function<void(Emitter*,
const ngraph::Node*, const ngraph::Node*,
ExternalFunction*,
const std::vector<TensorViewInfo>& inputs, const std::vector<TensorViewInfo>& inputs,
const std::vector<TensorViewInfo>& outputs)>; const std::vector<TensorViewInfo>& outputs)>;
......
...@@ -57,7 +57,7 @@ if(MKLDNN_INCLUDE_DIR) ...@@ -57,7 +57,7 @@ if(MKLDNN_INCLUDE_DIR)
set(SRC ${SRC} mkldnn.cpp) set(SRC ${SRC} mkldnn.cpp)
endif() endif()
if(LLVM_INCLUDE_DIR) if(NGRAPH_CPU_ENABLE AND LLVM_INCLUDE_DIR)
include_directories(SYSTEM ${LLVM_INCLUDE_DIR}) include_directories(SYSTEM ${LLVM_INCLUDE_DIR})
link_directories(${LLVM_LIB_DIR}) link_directories(${LLVM_LIB_DIR})
set(SRC ${SRC} codegen.cpp) set(SRC ${SRC} codegen.cpp)
......
...@@ -2708,3 +2708,30 @@ TEST(${BACKEND_NAME}, sign) ...@@ -2708,3 +2708,30 @@ TEST(${BACKEND_NAME}, sign)
(*cf)({a}, {result}); (*cf)({a}, {result});
ASSERT_EQ((vector<float>{1, -1, 0, -1, 1, 0}), result->get_vector<float>()); ASSERT_EQ((vector<float>{1, -1, 0, -1, 1, 0}), result->get_vector<float>());
} }
TEST(${BACKEND_NAME}, constant_equality_bool)
{
auto shape = Shape{4};
// auto A = make_shared<op::Parameter>(element::Bool::element_type(), shape);
// auto B = make_shared<op::Parameter>(element::Bool::element_type(), shape);
// auto result_type = make_shared<TensorViewType>(element::Bool::element_type(), shape);
// auto f = make_shared<Function>(make_shared<op::Equal>(A, B), result_type, op::Parameters{A, B});
auto a = runtime::make_tensor<element::Bool>(shape, {true, false, true, false});
auto A = make_shared<op::ParameterizedConstant<element::Bool>>(shape, a);
auto b = runtime::make_tensor<element::Bool>(shape, {true, true, true, true});
auto B = make_shared<op::ParameterizedConstant<element::Bool>>(shape, b);
auto rt = make_shared<TensorViewType>(element::Bool::element_type(), shape);
auto f = make_shared<Function>(make_shared<op::Equal>(A, B), rt, op::Parameters{});
auto manager = runtime::Manager::get("${BACKEND_NAME}");
auto external = manager->compile(f);
auto backend = manager->allocate_backend();
auto cf = backend->make_call_frame(external);
// Create some tensors for input/output
auto result = backend->make_primary_tensor_view(element::Bool::element_type(), shape);
(*cf)({}, {result});
ASSERT_EQ((vector<char>{true, false, true, false}), result->get_vector<char>());
}
...@@ -215,7 +215,7 @@ TEST(memory_layout, basic) ...@@ -215,7 +215,7 @@ TEST(memory_layout, basic)
auto graph = make_test_graph(); auto graph = make_test_graph();
pass_manager.run_passes(graph); pass_manager.run_passes(graph);
auto sorted = graph->get_ordered_ops(); auto sorted = graph->get_ordered_ops();
size_t temporary_pool_size = pass_manager.get_state().get_temporary_pool_size(); size_t temporary_pool_size = graph->get_temporary_pool_size();
EXPECT_EQ(12, temporary_pool_size); EXPECT_EQ(12, temporary_pool_size);
} }
...@@ -235,6 +235,6 @@ TEST(memory_layout, constant) ...@@ -235,6 +235,6 @@ TEST(memory_layout, constant)
pass_manager.run_passes(f); pass_manager.run_passes(f);
auto sorted = f->get_ordered_ops(); auto sorted = f->get_ordered_ops();
size_t temporary_pool_size = pass_manager.get_state().get_temporary_pool_size(); size_t temporary_pool_size = f->get_temporary_pool_size();
EXPECT_EQ(0, temporary_pool_size); EXPECT_EQ(0, temporary_pool_size);
} }
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