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
ba2cbdd6
Unverified
Commit
ba2cbdd6
authored
May 31, 2018
by
Robert Kimball
Committed by
GitHub
May 31, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing ops to serializer (#1060)
* update serializer for all new ops
parent
f6b84d67
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
9 deletions
+61
-9
cpio.cpp
src/ngraph/cpio.cpp
+36
-0
cpio.hpp
src/ngraph/cpio.hpp
+3
-0
serializer.cpp
src/ngraph/serializer.cpp
+21
-9
serialize.cpp
test/serialize.cpp
+1
-0
No files found.
src/ngraph/cpio.cpp
View file @
ba2cbdd6
...
...
@@ -213,6 +213,7 @@ cpio::Reader::~Reader()
void
cpio
::
Reader
::
open
(
istream
&
in
)
{
m_stream
=
&
in
;
m_stream
->
seekg
(
0
,
ios_base
::
beg
);
}
void
cpio
::
Reader
::
open
(
const
string
&
filename
)
...
...
@@ -280,6 +281,41 @@ void cpio::Reader::read(const string& file_name, void* data, size_t size_in_byte
}
}
bool
cpio
::
is_cpio
(
const
string
&
path
)
{
ifstream
in
(
path
,
ios_base
::
binary
|
ios_base
::
in
);
return
is_cpio
(
in
);
}
bool
cpio
::
is_cpio
(
istream
&
in
)
{
size_t
offset
=
in
.
tellg
();
in
.
seekg
(
0
,
ios_base
::
beg
);
bool
rc
=
false
;
uint8_t
ch
;
in
.
read
(
reinterpret_cast
<
char
*>
(
&
ch
),
1
);
switch
(
ch
)
{
case
0x71
:
// Big Endian
in
.
read
(
reinterpret_cast
<
char
*>
(
&
ch
),
1
);
if
(
ch
==
0xC7
)
{
rc
=
true
;
}
break
;
case
0xC7
:
// Little Endian
in
.
read
(
reinterpret_cast
<
char
*>
(
&
ch
),
1
);
if
(
ch
==
0x71
)
{
rc
=
true
;
}
break
;
default
:
break
;
}
in
.
seekg
(
offset
,
ios_base
::
beg
);
return
rc
;
}
const
string
&
cpio
::
FileInfo
::
get_name
()
const
{
return
m_name
;
...
...
src/ngraph/cpio.hpp
View file @
ba2cbdd6
...
...
@@ -29,6 +29,9 @@ namespace ngraph
class
FileInfo
;
class
Writer
;
class
Reader
;
bool
is_cpio
(
const
std
::
string
&
);
bool
is_cpio
(
std
::
istream
&
);
}
}
...
...
src/ngraph/serializer.cpp
View file @
ba2cbdd6
...
...
@@ -212,18 +212,11 @@ std::string ngraph::serialize(std::shared_ptr<ngraph::Function> func, size_t ind
}
shared_ptr
<
ngraph
::
Function
>
ngraph
::
deserialize
(
istream
&
in
)
{
std
::
stringstream
ss
;
ss
<<
in
.
rdbuf
();
return
deserialize
(
ss
.
str
());
}
shared_ptr
<
ngraph
::
Function
>
ngraph
::
deserialize
(
const
string
&
s
)
{
shared_ptr
<
Function
>
rc
;
if
(
file_util
::
exists
(
s
))
if
(
cpio
::
is_cpio
(
in
))
{
cpio
::
Reader
reader
(
s
);
cpio
::
Reader
reader
(
in
);
vector
<
cpio
::
FileInfo
>
file_info
=
reader
.
get_file_info
();
if
(
file_info
.
size
()
>
0
)
{
...
...
@@ -260,6 +253,25 @@ shared_ptr<ngraph::Function> ngraph::deserialize(const string& s)
}
}
else
{
// json file?
std
::
stringstream
ss
;
ss
<<
in
.
rdbuf
();
rc
=
deserialize
(
ss
.
str
());
}
return
rc
;
}
shared_ptr
<
ngraph
::
Function
>
ngraph
::
deserialize
(
const
string
&
s
)
{
shared_ptr
<
Function
>
rc
;
if
(
file_util
::
exists
(
s
))
{
// s is a file and not a json string
ifstream
in
(
s
,
ios_base
::
binary
|
ios_base
::
in
);
rc
=
deserialize
(
in
);
}
else
{
json
js
=
json
::
parse
(
s
);
unordered_map
<
string
,
shared_ptr
<
Function
>>
function_map
;
...
...
test/serialize.cpp
View file @
ba2cbdd6
...
...
@@ -140,6 +140,7 @@ TEST(serialize, constant)
EXPECT_EQ
((
vector
<
float
>
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
}),
A
->
get_vector
<
float
>
());
serialize
(
tmp_file
,
f
);
auto
g
=
deserialize
(
tmp_file
);
ASSERT_NE
(
g
,
nullptr
);
file_util
::
remove_file
(
tmp_file
);
bool
found
=
false
;
for
(
shared_ptr
<
Node
>
node
:
g
->
get_ops
())
...
...
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