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
ee1f6929
Unverified
Commit
ee1f6929
authored
Nov 21, 2017
by
Robert Kimball
Committed by
GitHub
Nov 21, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #251 from NervanaSystems/bob/pch
Bob/pch
parents
8ff5c586
d98771f8
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
34 deletions
+54
-34
CMakeLists.txt
CMakeLists.txt
+5
-0
compiler.cpp
src/ngraph/codegen/compiler.cpp
+36
-30
compiler.hpp
src/ngraph/codegen/compiler.hpp
+9
-3
external_function.cpp
src/ngraph/runtime/cpu/external_function.cpp
+3
-0
CMakeLists.txt
test/CMakeLists.txt
+1
-1
No files found.
CMakeLists.txt
View file @
ee1f6929
...
...
@@ -87,6 +87,11 @@ endif()
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-std=c++11"
)
# 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
#-----------------------------------------------------------------------------------------------
...
...
src/ngraph/codegen/compiler.cpp
View file @
ee1f6929
...
...
@@ -42,6 +42,7 @@
#include <clang/Basic/TargetInfo.h>
#include <clang/CodeGen/CodeGenAction.h>
#include <clang/Frontend/CompilerInstance.h>
#include <clang/Frontend/FrontendActions.h>
#include <clang/Frontend/TextDiagnosticPrinter.h>
#include <llvm/Support/TargetSelect.h>
...
...
@@ -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
)
{
lock_guard
<
mutex
>
lock
(
m_mutex
);
...
...
@@ -88,14 +94,10 @@ static std::string GetExecutablePath(const char* Argv0)
}
StaticCompiler
::
StaticCompiler
()
:
m_precompiled_header
s_enable
d
(
false
)
:
m_precompiled_header
_vali
d
(
false
)
,
m_debuginfo_enabled
(
false
)
,
m_source_name
(
"code.cpp"
)
{
#if NGCPU_PCH
m_precompiled_headers_enabled
=
true
;
#endif
#if NGCPU_DEBUGINFO
m_debuginfo_enabled
=
true
;
#endif
...
...
@@ -214,14 +216,6 @@ StaticCompiler::StaticCompiler()
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
// Most of these are for Eigen
auto
&
TO
=
m_compiler
->
getInvocation
().
getTargetOpts
();
...
...
@@ -313,6 +307,18 @@ void StaticCompiler::use_cached_files()
std
::
unique_ptr
<
llvm
::
Module
>
StaticCompiler
::
compile
(
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
StringRef
source_ref
(
source
);
unique_ptr
<
MemoryBuffer
>
buffer
=
MemoryBuffer
::
getMemBufferCopy
(
source_ref
);
...
...
@@ -333,24 +339,24 @@ std::unique_ptr<llvm::Module> StaticCompiler::compile(const string& source)
return
rc
;
}
// std::unique_ptr<llvm::Module> StaticCompiler::generate_pch(const string& source)
// {
// // Map code filename to a memoryBuffer
// StringRef source_ref(source);
// unique_ptr<MemoryBuffer> buffer = MemoryBuffer::getMemBufferCopy(source_ref);
// m_compiler->getInvocation().getPreprocessorOpts().addRemappedFile(m_source_name, buffer.get());
void
StaticCompiler
::
generate_pch
(
const
string
&
source
)
{
m_pch_path
=
file_util
::
path_join
(
file_util
::
get_temp_directory
(),
"ngraph.pch"
);
m_compiler
->
getFrontendOpts
().
OutputFile
=
m_pch_path
;
// // Create and execute action
// CodeGenAction* compilerAction = new GeneratePCHAction();
// std::unique_ptr<llvm::Module> rc;
// if (m_compiler->ExecuteAction(*compilerAction) == true)
// {
// rc = compilerAction->takeModule();
// }
// Map code filename to a memoryBuffer
StringRef
source_ref
(
source
);
unique_ptr
<
MemoryBuffer
>
buffer
=
MemoryBuffer
::
getMemBufferCopy
(
source_ref
);
m_compiler
->
getInvocation
().
getPreprocessorOpts
().
addRemappedFile
(
m_source_name
,
buffer
.
get
());
// 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
()
;
}
src/ngraph/codegen/compiler.hpp
View file @
ee1f6929
...
...
@@ -51,6 +51,7 @@ class ngraph::codegen::Compiler
public
:
Compiler
();
~
Compiler
();
void
set_precompiled_header_source
(
const
std
::
string
&
source
);
std
::
unique_ptr
<
llvm
::
Module
>
compile
(
const
std
::
string
&
source
);
private
:
...
...
@@ -62,19 +63,24 @@ public:
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
;
}
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
);
std
::
unique_ptr
<
llvm
::
Module
>
compile
(
const
std
::
string
&
source
);
void
generate_pch
(
const
std
::
string
&
source
);
private
:
std
::
unique_ptr
<
clang
::
CompilerInstance
>
m_compiler
;
bool
m_precompiled_header
s_enable
d
;
bool
m_precompiled_header
_vali
d
;
bool
m_debuginfo_enabled
;
std
::
string
m_source_name
;
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
);
void
use_cached_files
();
...
...
src/ngraph/runtime/cpu/external_function.cpp
View file @
ee1f6929
...
...
@@ -197,6 +197,7 @@ void ExternalFunction::compile()
using namespace ngraph::runtime::cpu::eigen;
)"
;
string
pch_header_source
=
TU
.
get_code
();
TU
<<
"// Declare all functions
\n
"
;
for
(
shared_ptr
<
Function
>
f
:
pass_manager
.
get_state
().
get_functions
())
...
...
@@ -318,6 +319,8 @@ using namespace ngraph::runtime::cpu::eigen;
codegen
::
Compiler
compiler
;
codegen
::
ExecutionEngine
execution_engine
;
compiler
.
set_precompiled_header_source
(
pch_header_source
);
auto
llvm_module
=
compiler
.
compile
(
code
);
if
(
llvm_module
==
nullptr
)
{
...
...
test/CMakeLists.txt
View file @
ee1f6929
...
...
@@ -57,7 +57,7 @@ if(MKLDNN_INCLUDE_DIR)
set
(
SRC
${
SRC
}
mkldnn.cpp
)
endif
()
if
(
LLVM_INCLUDE_DIR
)
if
(
NGRAPH_CPU_ENABLE AND
LLVM_INCLUDE_DIR
)
include_directories
(
SYSTEM
${
LLVM_INCLUDE_DIR
}
)
link_directories
(
${
LLVM_LIB_DIR
}
)
set
(
SRC
${
SRC
}
codegen.cpp
)
...
...
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