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
6fe8f8e5
Commit
6fe8f8e5
authored
Oct 26, 2017
by
Yixing Lao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support for runtime dlopen
parent
82563638
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
74 additions
and
3 deletions
+74
-3
CMakeLists.txt
src/ngraph/CMakeLists.txt
+22
-0
manager.cpp
src/ngraph/runtime/manager.cpp
+43
-0
manager.hpp
src/ngraph/runtime/manager.hpp
+9
-3
No files found.
src/ngraph/CMakeLists.txt
View file @
6fe8f8e5
...
...
@@ -130,6 +130,27 @@ if (NGRAPH_CPU_ENABLE AND LLVM_INCLUDE_DIR AND
endif
()
add_library
(
ngraph SHARED
${
SRC
}
)
# Colon separated string for specified runtime plugin loading, this is made explicit s.t. if a
# plugin is specified at compile time but the corresponding library could not be resolved at run-
# time, an error will be generated.
# E.g. assume compiling with Argon and Xpu, then -DRUNTIME_PLUGIN_LIBS="libargon.so:libxpu.so".
if
(
RUNTIME_PLUGIN_LIBS
)
target_compile_definitions
(
ngraph PRIVATE RUNTIME_PLUGIN_LIBS=
${
RUNTIME_PLUGIN_LIBS
}
)
else
()
target_compile_definitions
(
ngraph PRIVATE RUNTIME_PLUGIN_LIBS=
""
)
endif
()
# This is used to ensure that libngraph.so and libargon.so are in the same directory for dlopen.
# Effective at build time. Does not affect `make install` logics.
if
(
COMMON_LIBRARY_OUTPUT_DIRECTORY
)
set_target_properties
(
ngraph PROPERTIES
LIBRARY_OUTPUT_DIRECTORY
${
COMMON_LIBRARY_OUTPUT_DIRECTORY
}
)
message
(
STATUS
"LIBRARY_OUTPUT_DIRECTORY set to:
${
COMMON_LIBRARY_OUTPUT_DIRECTORY
}
"
)
else
()
message
(
STATUS
"LIBRARY_OUTPUT_DIRECTORY not set, will use the defualt value"
)
endif
()
target_include_directories
(
ngraph PUBLIC
"
${
NGRAPH_INCLUDE_PATH
}
"
)
if
(
NGRAPH_CPU_ENABLE AND LLVM_LINK_LIBS
)
...
...
@@ -146,6 +167,7 @@ if(NGRAPH_CPU_ENABLE AND MKLDNN_LIB_DIR)
target_link_libraries
(
ngraph LINK_PRIVATE mkldnn
)
endif
()
#-----------------------------------------------------------------------------------------------
# Installation logic...
#-----------------------------------------------------------------------------------------------
...
...
src/ngraph/runtime/manager.cpp
View file @
6fe8f8e5
...
...
@@ -13,12 +13,53 @@
// ----------------------------------------------------------------------------
#include "ngraph/runtime/manager.hpp"
#include <dlfcn.h>
#include <iostream>
#include <sstream>
#include <string>
using
namespace
ngraph
::
runtime
;
bool
Manager
::
load_plugins
(
const
std
::
string
&
runtime_plugin_libs
)
{
std
::
istringstream
ss
(
runtime_plugin_libs
);
std
::
string
plugin_lib_path
;
while
(
std
::
getline
(
ss
,
plugin_lib_path
,
':'
))
{
if
(
plugin_lib_path
.
size
()
>
0
)
{
void
*
lib_handle
=
dlopen
(
plugin_lib_path
.
c_str
(),
RTLD_NOW
);
if
(
!
lib_handle
)
{
std
::
cerr
<<
"Cannot open library: "
<<
plugin_lib_path
<<
", "
<<
dlerror
()
<<
std
::
endl
;
return
false
;
}
else
{
std
::
cerr
<<
"Loaded runtime at "
<<
lib_handle
<<
std
::
endl
;
}
}
}
return
true
;
}
Manager
::
FactoryMap
&
Manager
::
get_factory_map
()
{
// Stores Manager Factories
static
FactoryMap
factory_map
;
// Try to load runtime plugins
if
(
!
Manager
::
m_is_factory_map_initialized
)
{
if
(
!
Manager
::
load_plugins
(
RUNTIME_PLUGIN_LIBS
))
{
std
::
cerr
<<
"Failed to load at least one of the following libraries: "
<<
RUNTIME_PLUGIN_LIBS
<<
std
::
endl
;
}
Manager
::
m_is_factory_map_initialized
=
true
;
}
return
factory_map
;
}
...
...
@@ -32,3 +73,5 @@ Manager::Factory Manager::register_factory(std::string name, Factory factory)
get_factory_map
()[
name
]
=
factory
;
return
factory
;
}
bool
Manager
::
m_is_factory_map_initialized
=
false
;
src/ngraph/runtime/manager.hpp
View file @
6fe8f8e5
...
...
@@ -46,13 +46,19 @@ namespace ngraph
compile
(
const
std
::
shared_ptr
<
ngraph
::
Function
>&
fun
)
=
0
;
using
Factory
=
std
::
function
<
std
::
shared_ptr
<
Manager
>
(
const
std
::
string
&
)
>
;
using
FactoryMap
=
std
::
map
<
std
::
string
,
Factory
>
;
static
FactoryMap
&
get_factory_map
();
static
std
::
shared_ptr
<
Manager
>
get
(
const
std
::
string
&
name
);
static
Factory
register_factory
(
std
::
string
name
,
Factory
factory
);
private
:
static
bool
load_plugins
(
const
std
::
string
&
runtime_plugin_libs
);
static
bool
m_is_factory_map_initialized
;
using
FactoryMap
=
std
::
map
<
std
::
string
,
Factory
>
;
static
FactoryMap
&
get_factory_map
();
};
}
}
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