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
d02d0c99
Commit
d02d0c99
authored
Dec 21, 2017
by
Yixing Lao
Committed by
Scott Cyphers
Dec 21, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
register plugin with Manager class (#318)
parent
588d69a4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
20 deletions
+37
-20
manager.cpp
src/ngraph/runtime/manager.cpp
+36
-19
manager.hpp
src/ngraph/runtime/manager.hpp
+1
-1
No files found.
src/ngraph/runtime/manager.cpp
View file @
d02d0c99
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
#include <dlfcn.h>
#include <dlfcn.h>
#include <iostream>
#include <iostream>
#include <mutex>
#include <sstream>
#include <sstream>
#include <string>
#include <string>
...
@@ -23,57 +24,73 @@
...
@@ -23,57 +24,73 @@
using
namespace
ngraph
::
runtime
;
using
namespace
ngraph
::
runtime
;
static
std
::
mutex
load_plugins_mutex
;
static
std
::
mutex
close_plugins_mutex
;
bool
Manager
::
m_is_factory_map_initialized
=
false
;
bool
Manager
::
m_is_factory_map_initialized
=
false
;
std
::
shared_ptr
<
std
::
vector
<
void
*>>
Manager
::
m_plugin_lib_handles
=
std
::
vector
<
void
*>
Manager
::
m_plugin_handles
=
{};
std
::
make_shared
<
std
::
vector
<
void
*>>
(
std
::
vector
<
void
*>
());
void
Manager
::
load_plugins
(
const
std
::
string
&
runtime_plugin_libs
)
void
Manager
::
load_plugins
(
const
std
::
string
&
runtime_plugin_libs
)
{
{
std
::
vector
<
std
::
string
>
plugin_lib_paths
=
ngraph
::
split
(
runtime_plugin_libs
,
':'
,
false
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
load_plugins_mutex
);
for
(
auto
plugin_lib_path
:
plugin_lib_paths
)
if
(
Manager
::
m_is_factory_map_initialized
)
{
{
if
(
plugin_lib_path
.
size
()
>
0
)
return
;
}
std
::
vector
<
std
::
string
>
plugin_paths
=
ngraph
::
split
(
runtime_plugin_libs
,
':'
,
false
);
for
(
auto
plugin_path
:
plugin_paths
)
{
if
(
plugin_path
.
size
()
>
0
)
{
{
void
*
lib_handle
=
dlopen
(
plugin_lib_path
.
c_str
(),
RTLD_NOW
);
void
*
plugin_handle
=
dlopen
(
plugin_path
.
c_str
(),
RTLD_NOW
|
RTLD_GLOBAL
);
if
(
lib
_handle
)
if
(
plugin
_handle
)
{
{
Manager
::
m_plugin_lib_handles
->
push_back
(
lib_handle
);
void
(
*
register_plugin
)()
=
reinterpret_cast
<
void
(
*
)()
>
(
dlsym
(
plugin_handle
,
"register_plugin"
));
if
(
register_plugin
!=
NULL
)
{
register_plugin
();
Manager
::
m_plugin_handles
.
push_back
(
plugin_handle
);
}
else
{
throw
ngraph_error
(
"register_plugin() not found in "
+
plugin_path
);
}
}
}
else
else
{
{
throw
ngraph_error
(
"Cannot open library "
+
plugin_
lib_
path
);
throw
ngraph_error
(
"Cannot open library "
+
plugin_path
);
}
}
}
}
}
}
Manager
::
m_is_factory_map_initialized
=
true
;
}
}
// TODO: Should call this function after plugin is not needed anymore.
// TODO: Should call this function after plugin is not needed anymore.
void
Manager
::
close_plugins
()
void
Manager
::
close_plugins
()
{
{
for
(
auto
lib_handle
:
*
Manager
::
m_plugin_lib_handles
)
std
::
lock_guard
<
std
::
mutex
>
lock
(
close_plugins_mutex
);
for
(
auto
plugin_handle
:
Manager
::
m_plugin_handles
)
{
{
dlclose
(
lib
_handle
);
dlclose
(
plugin
_handle
);
}
}
Manager
::
m_plugin_
lib_handles
->
clear
();
Manager
::
m_plugin_
handles
.
clear
();
}
}
Manager
::
FactoryMap
&
Manager
::
get_factory_map
()
Manager
::
FactoryMap
&
Manager
::
get_factory_map
()
{
{
// Stores Manager Factories
// Stores Manager Factories
static
FactoryMap
factory_map
;
static
FactoryMap
factory_map
;
// Try to load runtime plugins
if
(
!
Manager
::
m_is_factory_map_initialized
)
{
Manager
::
load_plugins
(
RUNTIME_PLUGIN_LIBS
);
Manager
::
m_is_factory_map_initialized
=
true
;
}
return
factory_map
;
return
factory_map
;
}
}
std
::
shared_ptr
<
Manager
>
Manager
::
get
(
const
std
::
string
&
name
)
std
::
shared_ptr
<
Manager
>
Manager
::
get
(
const
std
::
string
&
name
)
{
{
Manager
::
load_plugins
(
RUNTIME_PLUGIN_LIBS
);
return
get_factory_map
().
at
(
name
)(
name
);
return
get_factory_map
().
at
(
name
)(
name
);
}
}
...
...
src/ngraph/runtime/manager.hpp
View file @
d02d0c99
...
@@ -57,7 +57,7 @@ namespace ngraph
...
@@ -57,7 +57,7 @@ namespace ngraph
static
void
close_plugins
();
static
void
close_plugins
();
static
std
::
shared_ptr
<
std
::
vector
<
void
*>>
m_plugin_lib
_handles
;
static
std
::
vector
<
void
*>
m_plugin
_handles
;
static
bool
m_is_factory_map_initialized
;
static
bool
m_is_factory_map_initialized
;
...
...
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