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
ef309cf6
Unverified
Commit
ef309cf6
authored
Aug 03, 2018
by
Robert Kimball
Committed by
GitHub
Aug 03, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Start of windows build (#1306)
* compiles but does not link
parent
7d6a41f3
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
155 additions
and
33 deletions
+155
-33
CMakeLists.txt
CMakeLists.txt
+4
-0
CMakeLists.txt
src/ngraph/CMakeLists.txt
+3
-1
file_util.cpp
src/ngraph/file_util.cpp
+45
-8
node.cpp
src/ngraph/node.cpp
+0
-4
manager.cpp
src/ngraph/pass/manager.cpp
+5
-0
memory_visualize.cpp
src/ngraph/pass/memory_visualize.cpp
+5
-5
backend.cpp
src/ngraph/runtime/backend.cpp
+41
-14
backend.hpp
src/ngraph/runtime/backend.hpp
+9
-1
min.hpp
src/ngraph/runtime/reference/min.hpp
+4
-0
benchmark.cpp
src/tools/nbench/benchmark.cpp
+39
-0
No files found.
CMakeLists.txt
View file @
ef309cf6
...
...
@@ -159,6 +159,10 @@ if (NGRAPH_USE_GOLD)
set
(
CMAKE_C_FLAGS
"
${
CMAKE_C_FLAGS
}
-fuse-ld=gold"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-fuse-ld=gold"
)
endif
()
if
(
WIN32
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-DNOMINMAX"
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-D_CRT_SECURE_NO_WARNINGS"
)
endif
()
include
(
unit_test_control
)
set
(
UNIT_TEST_CONFIG_LIST
""
CACHE INTERNAL
""
)
...
...
src/ngraph/CMakeLists.txt
View file @
ef309cf6
...
...
@@ -217,7 +217,9 @@ endif()
# Defines macro in C++ to load backend plugin
target_include_directories
(
ngraph PUBLIC
"
${
NGRAPH_INCLUDE_PATH
}
"
)
target_link_libraries
(
ngraph PUBLIC dl pthread
)
if
(
NOT WIN32
)
target_link_libraries
(
ngraph PUBLIC dl pthread
)
endif
()
if
(
NGRAPH_ONNX_IMPORT_ENABLE
)
target_sources
(
ngraph PRIVATE $<TARGET_OBJECTS:onnx_import_interface>
)
...
...
src/ngraph/file_util.cpp
View file @
ef309cf6
...
...
@@ -15,24 +15,36 @@
*******************************************************************************/
#include <cassert>
#ifdef WIN32
#include <windows.h>
#else
#include <dirent.h>
#include <ftw.h>
#include <sys/file.h>
#include <sys/time.h>
#include <unistd.h>
#endif
#include <fcntl.h>
#include <fstream>
#include <ftw.h>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <string.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>
#include <vector>
#include "ngraph/file_util.hpp"
#include "ngraph/log.hpp"
#ifdef WIN32
#define RMDIR(a) RemoveDirectoryA(a)
#define RMFILE(a) DeleteFileA(a)
#else
#define RMDIR(a) rmdir(a)
#define RMFILE(a) remove(a)
#endif
using
namespace
std
;
using
namespace
ngraph
;
...
...
@@ -135,15 +147,15 @@ void file_util::remove_directory(const string& dir)
[](
const
string
&
file
,
bool
is_dir
)
{
if
(
is_dir
)
{
rmdir
(
file
.
c_str
());
RMDIR
(
file
.
c_str
());
}
else
{
remove
(
file
.
c_str
());
RMFILE
(
file
.
c_str
());
}
},
true
);
rmdir
(
dir
.
c_str
());
RMDIR
(
dir
.
c_str
());
}
}
...
...
@@ -154,6 +166,9 @@ void file_util::remove_file(const string& file)
bool
file_util
::
make_directory
(
const
string
&
dir
)
{
#ifdef WIN32
CreateDirectoryA
(
dir
.
c_str
(),
nullptr
);
#else
if
(
mkdir
(
dir
.
c_str
(),
S_IRWXU
|
S_IRWXG
|
S_IROTH
|
S_IXOTH
))
{
if
(
errno
==
EEXIST
)
...
...
@@ -163,6 +178,7 @@ bool file_util::make_directory(const string& dir)
}
throw
runtime_error
(
"error making directory "
+
dir
+
" "
+
strerror
(
errno
));
}
#endif
return
true
;
}
...
...
@@ -221,6 +237,7 @@ string file_util::read_file_to_string(const string& path)
return
ss
.
str
();
}
#ifndef WIN32
static
void
iterate_files_worker
(
const
string
&
path
,
function
<
void
(
const
string
&
file
,
bool
is_dir
)
>
func
,
bool
recurse
,
...
...
@@ -272,6 +289,7 @@ static void iterate_files_worker(const string& path,
throw
runtime_error
(
"error enumerating file "
+
path
);
}
}
#endif
void
file_util
::
iterate_files
(
const
string
&
path
,
function
<
void
(
const
string
&
file
,
bool
is_dir
)
>
func
,
...
...
@@ -280,6 +298,19 @@ void file_util::iterate_files(const string& path,
{
vector
<
string
>
files
;
vector
<
string
>
dirs
;
#ifdef WIN32
string
file_match
=
path_join
(
path
,
"*"
);
WIN32_FIND_DATA
data
;
HANDLE
hFind
=
FindFirstFile
(
file_match
.
c_str
(),
&
data
);
if
(
hFind
!=
INVALID_HANDLE_VALUE
)
{
do
{
std
::
cout
<<
data
.
cFileName
<<
std
::
endl
;
}
while
(
FindNextFile
(
hFind
,
&
data
));
FindClose
(
hFind
);
}
#else
iterate_files_worker
(
path
,
[
&
files
,
&
dirs
](
const
string
&
file
,
bool
is_dir
)
{
if
(
is_dir
)
...
...
@@ -293,6 +324,7 @@ void file_util::iterate_files(const string& path,
},
recurse
,
include_links
);
#endif
for
(
auto
f
:
files
)
{
...
...
@@ -306,6 +338,10 @@ void file_util::iterate_files(const string& path,
string
file_util
::
tmp_filename
(
const
string
&
extension
)
{
string
rc
;
#ifdef WIN32
rc
=
_tempnam
(
file_util
::
get_temp_directory_path
().
c_str
(),
"ngraph_"
);
#else
string
tmp_template
=
file_util
::
path_join
(
file_util
::
get_temp_directory_path
(),
"ngraph_XXXXXX"
+
extension
);
char
*
tmpname
=
strdup
(
tmp_template
.
c_str
());
...
...
@@ -313,8 +349,9 @@ string file_util::tmp_filename(const string& extension)
// mkstemp opens the file with open() so we need to close it
close
(
mkstemps
(
tmpname
,
static_cast
<
int
>
(
extension
.
size
())));
string
rc
=
tmpname
;
rc
=
tmpname
;
free
(
tmpname
);
#endif
return
rc
;
}
...
...
src/ngraph/node.cpp
View file @
ef309cf6
...
...
@@ -27,10 +27,6 @@
#include "ngraph/op/result.hpp"
#include "ngraph/placement.hpp"
#if not defined(EIGEN_MPL2_ONLY)
#error("The flag `EIGEN_MPL2_ONLY` must be defined");
#endif
using
namespace
std
;
using
namespace
ngraph
;
...
...
src/ngraph/pass/manager.cpp
View file @
ef309cf6
...
...
@@ -15,7 +15,10 @@
*******************************************************************************/
#include <algorithm>
#ifdef WIN32
#else
#include <cxxabi.h>
#endif
#include <iomanip>
#include <iostream>
#include <memory>
...
...
@@ -142,8 +145,10 @@ void ngraph::pass::Manager::run_passes(shared_ptr<Function> func, bool transitiv
{
PassBase
*
p
=
pass
.
get
();
string
name
=
typeid
(
*
p
).
name
();
#ifndef WIN32
int
status
;
name
=
abi
::
__cxa_demangle
(
name
.
c_str
(),
0
,
0
,
&
status
);
#endif
cout
<<
setw
(
7
)
<<
pass_timer
.
get_milliseconds
()
<<
"ms "
<<
name
<<
"
\n
"
;
}
}
...
...
src/ngraph/pass/memory_visualize.cpp
View file @
ef309cf6
...
...
@@ -185,7 +185,7 @@ void pass::MemoryVisualize::draw_histogram(ostream& file, const list<shared_ptr<
size_t
offset
=
200
;
size_t
width
=
1000
;
size_t
scale
=
width
-
offset
;
size_t
line_spacing
=
st
roke_width
*
1.5
;
size_t
line_spacing
=
st
atic_cast
<
size_t
>
(
stroke_width
*
1.5
)
;
size_t
line_count
=
0
;
for
(
shared_ptr
<
Node
>
node
:
nodes
)
{
...
...
@@ -203,7 +203,7 @@ void pass::MemoryVisualize::draw_histogram(ostream& file, const list<shared_ptr<
float
footprint
=
float
(
MemoryVisualize
::
memory_footprint
(
node
));
y
+=
line_spacing
;
size_t
x1
=
offset
;
size_t
x2
=
((
usage
/
memory_footprint
)
*
scale
)
+
offset
;
size_t
x2
=
static_cast
<
size_t
>
(((
usage
/
memory_footprint
)
*
scale
)
+
offset
)
;
file
<<
"<text x=
\"
"
<<
0
<<
"
\"
y=
\"
"
<<
y
+
text_offset
<<
"
\"
fill=
\"
"
<<
"black"
<<
"
\"
>"
<<
node
->
get_name
()
<<
"</text>
\n
"
;
...
...
@@ -211,7 +211,7 @@ void pass::MemoryVisualize::draw_histogram(ostream& file, const list<shared_ptr<
<<
"
\"
"
;
file
<<
" style=
\"
stroke:forestgreen;stroke-width:"
<<
stroke_width
<<
"
\"
/>
\n
"
;
x1
=
x2
;
x2
=
((
footprint
/
memory_footprint
)
*
scale
)
+
offset
;
x2
=
static_cast
<
size_t
>
(((
footprint
/
memory_footprint
)
*
scale
)
+
offset
)
;
file
<<
"<line x1=
\"
"
<<
x1
<<
"
\"
y1=
\"
"
<<
y
<<
"
\"
x2=
\"
"
<<
x2
<<
"
\"
y2=
\"
"
<<
y
<<
"
\"
"
;
file
<<
" style=
\"
stroke:firebrick;stroke-width:"
<<
stroke_width
<<
"
\"
/>
\n
"
;
...
...
@@ -241,11 +241,11 @@ int pass::MemoryVisualize::compute_op_weight(const shared_ptr<Node> exop)
int
mass
=
0
;
for
(
const
descriptor
::
Tensor
*
tensor
:
exop
->
liveness_new_list
)
{
mass
+=
tensor
->
size
(
);
mass
+=
static_cast
<
int
>
(
tensor
->
size
()
);
}
for
(
const
descriptor
::
Tensor
*
tensor
:
exop
->
liveness_free_list
)
{
mass
-=
tensor
->
size
(
);
mass
-=
static_cast
<
int
>
(
tensor
->
size
()
);
}
return
mass
;
}
...
...
src/ngraph/runtime/backend.cpp
View file @
ef309cf6
...
...
@@ -14,7 +14,11 @@
* limitations under the License.
*******************************************************************************/
#ifdef WIN32
#include <windows.h>
#else
#include <dlfcn.h>
#endif
#include <sstream>
#include "ngraph/file_util.hpp"
...
...
@@ -25,6 +29,16 @@
using
namespace
std
;
using
namespace
ngraph
;
#ifdef WIN32
#define OPEN_LIBRARY(a, b) LoadLibrary(a)
#define CLOSE_LIBRARY(a) FreeLibrary(a)
#define DLSYM(a, b) GetProcAddress(a, b)
#else
// #define OPEN_LIBRARY(a, b) dlopen(a, b)
#define CLOSE_LIBRARY(a) dlclose(a)
#define DLSYM(a, b) dlsym(a, b)
#endif
runtime
::
Backend
::~
Backend
()
{
}
...
...
@@ -32,16 +46,20 @@ runtime::Backend::~Backend()
// This doodad finds the full path of the containing shared library
static
string
find_my_file
()
{
#ifdef WIN32
return
"."
;
#else
Dl_info
dl_info
;
dladdr
(
reinterpret_cast
<
void
*>
(
find_my_file
),
&
dl_info
);
return
dl_info
.
dli_fname
;
#endif
}
void
*
runtime
::
Backend
::
open_shared_library
(
string
type
)
DL_HANDLE
runtime
::
Backend
::
open_shared_library
(
string
type
)
{
string
ext
=
SHARED_LIB_EXT
;
void
*
handle
=
nullptr
;
DL_HANDLE
handle
;
// strip off attributes, IE:CPU becomes IE
auto
colon
=
type
.
find
(
":"
);
...
...
@@ -53,7 +71,11 @@ void* runtime::Backend::open_shared_library(string type)
string
library_name
=
"lib"
+
to_lower
(
type
)
+
"_backend"
+
string
(
SHARED_LIB_EXT
);
string
my_directory
=
file_util
::
get_directory
(
find_my_file
());
string
library_path
=
file_util
::
path_join
(
my_directory
,
library_name
);
#ifdef WIN32
handle
=
LoadLibrary
(
library_path
.
c_str
());
#else
handle
=
dlopen
(
library_path
.
c_str
(),
RTLD_NOW
|
RTLD_GLOBAL
);
#endif
return
handle
;
}
...
...
@@ -61,7 +83,7 @@ void* runtime::Backend::open_shared_library(string type)
shared_ptr
<
runtime
::
Backend
>
runtime
::
Backend
::
create
(
const
string
&
type
)
{
shared_ptr
<
runtime
::
Backend
>
rc
;
void
*
handle
=
open_shared_library
(
type
);
DL_HANDLE
handle
=
open_shared_library
(
type
);
if
(
!
handle
)
{
throw
runtime_error
(
"Backend '"
+
type
+
"' not found"
);
...
...
@@ -69,34 +91,34 @@ shared_ptr<runtime::Backend> runtime::Backend::create(const string& type)
else
{
function
<
const
char
*
()
>
get_ngraph_version_string
=
reinterpret_cast
<
const
char
*
(
*
)()
>
(
dlsym
(
handle
,
"get_ngraph_version_string"
));
reinterpret_cast
<
const
char
*
(
*
)()
>
(
DLSYM
(
handle
,
"get_ngraph_version_string"
));
if
(
!
get_ngraph_version_string
)
{
dlclose
(
handle
);
CLOSE_LIBRARY
(
handle
);
throw
runtime_error
(
"Backend '"
+
type
+
"' does not implement get_ngraph_version_string"
);
}
function
<
runtime
::
Backend
*
(
const
char
*
)
>
new_backend
=
reinterpret_cast
<
runtime
::
Backend
*
(
*
)(
const
char
*
)
>
(
dlsym
(
handle
,
"new_backend"
));
reinterpret_cast
<
runtime
::
Backend
*
(
*
)(
const
char
*
)
>
(
DLSYM
(
handle
,
"new_backend"
));
if
(
!
new_backend
)
{
dlclose
(
handle
);
CLOSE_LIBRARY
(
handle
);
throw
runtime_error
(
"Backend '"
+
type
+
"' does not implement new_backend"
);
}
function
<
void
(
runtime
::
Backend
*
)
>
delete_backend
=
reinterpret_cast
<
void
(
*
)(
runtime
::
Backend
*
)
>
(
dlsym
(
handle
,
"delete_backend"
));
reinterpret_cast
<
void
(
*
)(
runtime
::
Backend
*
)
>
(
DLSYM
(
handle
,
"delete_backend"
));
if
(
!
delete_backend
)
{
dlclose
(
handle
);
CLOSE_LIBRARY
(
handle
);
throw
runtime_error
(
"Backend '"
+
type
+
"' does not implement delete_backend"
);
}
runtime
::
Backend
*
backend
=
new_backend
(
type
.
c_str
());
rc
=
shared_ptr
<
runtime
::
Backend
>
(
backend
,
[
=
](
runtime
::
Backend
*
b
)
{
delete_backend
(
b
);
//
dlclose
(handle);
//
CLOSE_LIBRARY
(handle);
});
}
return
rc
;
...
...
@@ -113,14 +135,19 @@ map<string, string> runtime::Backend::get_registered_device_map()
string
backend_name
;
if
(
is_backend_name
(
name
,
backend_name
))
{
auto
handle
=
dlopen
(
file
.
c_str
(),
RTLD_LAZY
|
RTLD_LOCAL
);
DL_HANDLE
handle
;
#ifdef WIN32
handle
=
LoadLibrary
(
file
.
c_str
());
#else
handle
=
dlopen
(
file
.
c_str
(),
RTLD_LAZY
|
RTLD_LOCAL
);
#endif
if
(
handle
)
{
if
(
dlsym
(
handle
,
"new_backend"
)
&&
dlsym
(
handle
,
"delete_backend"
))
if
(
DLSYM
(
handle
,
"new_backend"
)
&&
DLSYM
(
handle
,
"delete_backend"
))
{
function
<
const
char
*
()
>
get_ngraph_version_string
=
reinterpret_cast
<
const
char
*
(
*
)()
>
(
dlsym
(
handle
,
"get_ngraph_version_string"
));
DLSYM
(
handle
,
"get_ngraph_version_string"
));
if
(
get_ngraph_version_string
&&
get_ngraph_version_string
()
==
string
(
NGRAPH_VERSION
))
{
...
...
@@ -128,7 +155,7 @@ map<string, string> runtime::Backend::get_registered_device_map()
}
}
dlclose
(
handle
);
CLOSE_LIBRARY
(
handle
);
}
}
};
...
...
src/ngraph/runtime/backend.hpp
View file @
ef309cf6
...
...
@@ -17,12 +17,20 @@
#pragma once
#include <memory>
#include <string>
#include "ngraph/function.hpp"
#include "ngraph/runtime/performance_counter.hpp"
#include "ngraph/shape.hpp"
#include "ngraph/type/element_type.hpp"
#ifdef WIN32
#include <windows.h>
#define DL_HANDLE HMODULE
#else
#define DL_HANDLE void*
#endif
namespace
ngraph
{
namespace
runtime
...
...
@@ -83,7 +91,7 @@ namespace ngraph
const
std
::
vector
<
std
::
shared_ptr
<
runtime
::
TensorView
>>&
inputs
);
private
:
static
void
*
open_shared_library
(
std
::
string
type
);
static
DL_HANDLE
open_shared_library
(
std
::
string
type
);
static
std
::
map
<
std
::
string
,
std
::
string
>
get_registered_device_map
();
static
bool
is_backend_name
(
const
std
::
string
&
file
,
std
::
string
&
backend_name
);
};
...
...
src/ngraph/runtime/reference/min.hpp
View file @
ef309cf6
...
...
@@ -21,6 +21,10 @@
#include "ngraph/coordinate_transform.hpp"
#ifdef WIN32
#undef min
#endif
namespace
ngraph
{
namespace
runtime
...
...
src/tools/nbench/benchmark.cpp
View file @
ef309cf6
...
...
@@ -130,6 +130,45 @@ void init_int_tv(shared_ptr<runtime::TensorView> tv, T min, T max)
tv
->
write
(
vec
.
data
(),
0
,
vec
.
size
()
*
sizeof
(
T
));
}
template
<>
void
init_int_tv
<
char
>
(
shared_ptr
<
runtime
::
TensorView
>
tv
,
char
min
,
char
max
)
{
size_t
size
=
tv
->
get_element_count
();
uniform_int_distribution
<
int16_t
>
dist
(
static_cast
<
short
>
(
min
),
static_cast
<
short
>
(
max
));
vector
<
char
>
vec
(
size
);
for
(
char
&
element
:
vec
)
{
element
=
static_cast
<
char
>
(
dist
(
s_random_engine
));
}
tv
->
write
(
vec
.
data
(),
0
,
vec
.
size
()
*
sizeof
(
char
));
}
template
<>
void
init_int_tv
<
int8_t
>
(
shared_ptr
<
runtime
::
TensorView
>
tv
,
int8_t
min
,
int8_t
max
)
{
size_t
size
=
tv
->
get_element_count
();
uniform_int_distribution
<
int16_t
>
dist
(
static_cast
<
short
>
(
min
),
static_cast
<
short
>
(
max
));
vector
<
int8_t
>
vec
(
size
);
for
(
int8_t
&
element
:
vec
)
{
element
=
static_cast
<
int8_t
>
(
dist
(
s_random_engine
));
}
tv
->
write
(
vec
.
data
(),
0
,
vec
.
size
()
*
sizeof
(
int8_t
));
}
template
<>
void
init_int_tv
<
uint8_t
>
(
shared_ptr
<
runtime
::
TensorView
>
tv
,
uint8_t
min
,
uint8_t
max
)
{
size_t
size
=
tv
->
get_element_count
();
uniform_int_distribution
<
int16_t
>
dist
(
static_cast
<
short
>
(
min
),
static_cast
<
short
>
(
max
));
vector
<
uint8_t
>
vec
(
size
);
for
(
uint8_t
&
element
:
vec
)
{
element
=
static_cast
<
uint8_t
>
(
dist
(
s_random_engine
));
}
tv
->
write
(
vec
.
data
(),
0
,
vec
.
size
()
*
sizeof
(
uint8_t
));
}
template
<
typename
T
>
void
init_real_tv
(
shared_ptr
<
runtime
::
TensorView
>
tv
,
T
min
,
T
max
)
{
...
...
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