Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
N
ngraph
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ngraph
Commits
7c59ca2e
Unverified
Commit
7c59ca2e
authored
Dec 29, 2017
by
Yixing Lao
Committed by
GitHub
Dec 29, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove LLVM/Clang dependency in headers (#341)
* remove llvm/clang dependency in headers * copy elision
parent
1c5abc19
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
56 additions
and
29 deletions
+56
-29
compiler.cpp
src/ngraph/codegen/compiler.cpp
+19
-3
compiler.hpp
src/ngraph/codegen/compiler.hpp
+17
-12
execution_engine.cpp
src/ngraph/codegen/execution_engine.cpp
+7
-3
execution_engine.hpp
src/ngraph/codegen/execution_engine.hpp
+10
-7
cpu_external_function.cpp
src/ngraph/runtime/cpu/cpu_external_function.cpp
+3
-4
No files found.
src/ngraph/codegen/compiler.cpp
View file @
7c59ca2e
...
...
@@ -31,6 +31,8 @@
#include <clang/Lex/Preprocessor.h>
#include <clang/Lex/PreprocessorOptions.h>
#include <llvm/ADT/Statistic.h>
#include <llvm/ExecutionEngine/MCJIT.h> // forces JIT to link in
#include <llvm/IR/Module.h>
#include <llvm/LinkAllPasses.h>
#include <llvm/Option/Arg.h>
#include <llvm/Option/ArgList.h>
...
...
@@ -72,6 +74,20 @@ using namespace ngraph::codegen;
static
StaticCompiler
s_static_compiler
;
static
std
::
mutex
m_mutex
;
ngraph
::
codegen
::
Module
::
Module
(
std
::
unique_ptr
<
llvm
::
Module
>
module
)
:
m_module
(
move
(
module
))
{
}
ngraph
::
codegen
::
Module
::~
Module
()
{
}
std
::
unique_ptr
<
llvm
::
Module
>
ngraph
::
codegen
::
Module
::
take_module
()
{
return
move
(
m_module
);
}
Compiler
::
Compiler
()
{
}
...
...
@@ -90,7 +106,7 @@ void Compiler::add_header_search_path(const std::string& path)
s_static_compiler
.
add_header_search_path
(
path
);
}
std
::
unique_ptr
<
llvm
::
Module
>
Compiler
::
compile
(
const
std
::
string
&
source
)
std
::
unique_ptr
<
ngraph
::
codegen
::
Module
>
Compiler
::
compile
(
const
std
::
string
&
source
)
{
lock_guard
<
mutex
>
lock
(
m_mutex
);
return
s_static_compiler
.
compile
(
compiler_action
,
source
);
...
...
@@ -231,7 +247,7 @@ void StaticCompiler::add_header_search_path(const string& path)
}
}
std
::
unique_ptr
<
llvm
::
Module
>
std
::
unique_ptr
<
ngraph
::
codegen
::
Module
>
StaticCompiler
::
compile
(
std
::
unique_ptr
<
clang
::
CodeGenAction
>&
compiler_action
,
const
string
&
source
)
{
...
...
@@ -264,7 +280,7 @@ std::unique_ptr<llvm::Module>
m_compiler
->
getInvocation
().
getPreprocessorOpts
().
clearRemappedFiles
();
return
rc
;
return
unique_ptr
<
ngraph
::
codegen
::
Module
>
(
new
ngraph
::
codegen
::
Module
(
move
(
rc
)))
;
}
void
StaticCompiler
::
generate_pch
(
const
string
&
source
)
...
...
src/ngraph/codegen/compiler.hpp
View file @
7c59ca2e
...
...
@@ -17,18 +17,13 @@
#include <functional>
#include <memory>
#include <string>
#include <clang/CodeGen/CodeGenAction.h>
#include <llvm/ExecutionEngine/MCJIT.h> // forces JIT to link in
#include <llvm/ExecutionEngine/SectionMemoryManager.h>
#include <llvm/Option/Arg.h>
#include <vector>
namespace
ngraph
{
namespace
codegen
{
class
m
odule
;
class
M
odule
;
class
Compiler
;
class
StaticCompiler
;
class
HeaderCache
;
...
...
@@ -39,11 +34,21 @@ namespace clang
{
class
HeaderSearchOptions
;
class
CompilerInstance
;
class
CodeGenAction
;
}
namespace
llvm
{
class
Module
;
}
class
ngraph
::
codegen
::
m
odule
class
ngraph
::
codegen
::
M
odule
{
public
:
Module
(
std
::
unique_ptr
<
llvm
::
Module
>
module
);
~
Module
();
std
::
unique_ptr
<
llvm
::
Module
>
take_module
();
private
:
std
::
unique_ptr
<
llvm
::
Module
>
m_module
;
};
...
...
@@ -55,13 +60,13 @@ public:
~
Compiler
();
void
set_precompiled_header_source
(
const
std
::
string
&
source
);
void
add_header_search_path
(
const
std
::
string
&
path
);
std
::
unique_ptr
<
llvm
::
Module
>
compile
(
const
std
::
string
&
source
);
std
::
unique_ptr
<
ngraph
::
codegen
::
Module
>
compile
(
const
std
::
string
&
source
);
std
::
unique_ptr
<
clang
::
CodeGenAction
>&
get_compiler_action
()
{
return
compiler_action
;
}
private
:
std
::
unique_ptr
<
clang
::
CodeGenAction
>
compiler_action
;
};
class
ngraph
::
codegen
::
StaticCompiler
:
public
llvm
::
SectionMemoryManager
class
ngraph
::
codegen
::
StaticCompiler
{
public
:
StaticCompiler
();
...
...
@@ -75,8 +80,8 @@ public:
}
void
add_header_search_path
(
const
std
::
string
&
path
);
std
::
unique_ptr
<
llvm
::
Module
>
compile
(
std
::
unique_ptr
<
clang
::
CodeGenAction
>&
compiler_action
,
const
std
::
string
&
source
);
std
::
unique_ptr
<
ngraph
::
codegen
::
Module
>
compile
(
std
::
unique_ptr
<
clang
::
CodeGenAction
>&
compiler_action
,
const
std
::
string
&
source
);
void
generate_pch
(
const
std
::
string
&
source
);
private
:
...
...
src/ngraph/codegen/execution_engine.cpp
View file @
7c59ca2e
...
...
@@ -13,7 +13,6 @@
// ----------------------------------------------------------------------------
#include <llvm/ExecutionEngine/ExecutionEngine.h>
#include <llvm/ExecutionEngine/SectionMemoryManager.h>
#include "ngraph/codegen/execution_engine.hpp"
...
...
@@ -32,13 +31,13 @@ codegen::ExecutionEngine::~ExecutionEngine()
}
}
bool
codegen
::
ExecutionEngine
::
add_module
(
std
::
unique_ptr
<
llvm
::
Module
>&
module
)
bool
codegen
::
ExecutionEngine
::
add_module
(
std
::
unique_ptr
<
ngraph
::
codegen
::
Module
>&
module
)
{
if
(
module
)
{
if
(
!
m_execution_engine
)
{
m_execution_engine
.
reset
(
llvm
::
EngineBuilder
(
mo
ve
(
module
))
m_execution_engine
.
reset
(
llvm
::
EngineBuilder
(
mo
dule
->
take_module
(
))
.
setEngineKind
(
llvm
::
EngineKind
::
JIT
)
.
setOptLevel
(
llvm
::
CodeGenOpt
::
Aggressive
)
.
setMCPU
(
llvm
::
sys
::
getHostCPUName
())
...
...
@@ -74,3 +73,8 @@ void codegen::ExecutionEngine::finalize()
(
m_jit_error
.
empty
()
?
"Could not create an execution engine"
:
m_jit_error
));
}
}
void
*
codegen
::
ExecutionEngine
::
get_pointer_to_named_function
(
const
std
::
string
&
func_name
)
{
return
m_execution_engine
->
getPointerToNamedFunction
(
func_name
);
}
src/ngraph/codegen/execution_engine.hpp
View file @
7c59ca2e
...
...
@@ -16,9 +16,7 @@
#include <memory>
#include <llvm/ExecutionEngine/MCJIT.h> // forces JIT to link in
#include <llvm/ExecutionEngine/SectionMemoryManager.h>
#include <llvm/Option/Arg.h>
#include "ngraph/codegen/compiler.hpp"
namespace
ngraph
{
...
...
@@ -28,27 +26,32 @@ namespace ngraph
}
}
namespace
llvm
{
class
Module
;
class
ExecutionEngine
;
}
class
ngraph
::
codegen
::
ExecutionEngine
{
public
:
ExecutionEngine
();
~
ExecutionEngine
();
bool
add_module
(
std
::
unique_ptr
<
llvm
::
Module
>&
module
);
bool
add_module
(
std
::
unique_ptr
<
ngraph
::
codegen
::
Module
>&
module
);
void
finalize
();
template
<
typename
ftype
>
std
::
function
<
ftype
>
find_function
(
const
std
::
string
&
func_name
)
{
auto
f
=
m_execution_engine
->
getPointerToNamedFunction
(
func_name
);
return
f_cast
<
ftype
>
(
f
);
return
f_cast
<
ftype
>
(
get_pointer_to_named_function
(
func_name
));
}
private
:
std
::
unique_ptr
<
llvm
::
ExecutionEngine
>
m_execution_engine
;
std
::
string
m_jit_error
;
void
*
get_pointer_to_named_function
(
const
std
::
string
&
func_name
);
template
<
typename
signature
>
std
::
function
<
signature
>
f_cast
(
void
*
f
)
{
...
...
src/ngraph/runtime/cpu/cpu_external_function.cpp
View file @
7c59ca2e
...
...
@@ -76,7 +76,6 @@
#include "ngraph/ops/tan.hpp"
#include "ngraph/ops/tanh.hpp"
#include "ngraph/ops/xla_get_tuple_element.hpp"
#include "ngraph/ops/xla_get_tuple_element.hpp"
#include "ngraph/ops/xla_tuple.hpp"
#include "ngraph/pass/assign_layout.hpp"
#include "ngraph/pass/dump_sorted.hpp"
...
...
@@ -571,13 +570,13 @@ using namespace ngraph::runtime;
m_compiler
->
set_precompiled_header_source
(
pch_header_source
);
auto
llvm
_module
=
m_compiler
->
compile
(
code
);
auto
codegen
_module
=
m_compiler
->
compile
(
code
);
if
(
llvm
_module
==
nullptr
)
if
(
codegen
_module
==
nullptr
)
{
throw
runtime_error
(
"function failed to compile"
);
}
m_execution_engine
->
add_module
(
llvm
_module
);
m_execution_engine
->
add_module
(
codegen
_module
);
m_execution_engine
->
finalize
();
m_compiled_function
=
m_execution_engine
->
find_function
<
EntryPoint_t
>
(
function_name
);
assert
(
m_compiled_function
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment