Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
seminar-breakout
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
seminar-breakout
Commits
398cb933
Commit
398cb933
authored
Aug 03, 2017
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[zmq op] get rid of protobuf dependency (#221)
parent
d899c925
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
20 deletions
+31
-20
tensorpack/user_ops/Makefile
tensorpack/user_ops/Makefile
+3
-3
tensorpack/user_ops/__init__.py
tensorpack/user_ops/__init__.py
+1
-0
tensorpack/user_ops/zmq_conn.h
tensorpack/user_ops/zmq_conn.h
+12
-9
tensorpack/user_ops/zmq_recv_op.cc
tensorpack/user_ops/zmq_recv_op.cc
+2
-2
tensorpack/utils/serialize.py
tensorpack/utils/serialize.py
+13
-6
No files found.
tensorpack/user_ops/Makefile
View file @
398cb933
# $File: Makefile
# $File: Makefile
# $Date:
Wed Jun 17 20:52:38 2015 +08
00
# $Date:
Thu Aug 03 16:14:29 2017 -07
00
OBJ_DIR
=
obj
OBJ_DIR
=
obj
...
@@ -16,7 +16,7 @@ OPTFLAGS ?= -O3 -march=native
...
@@ -16,7 +16,7 @@ OPTFLAGS ?= -O3 -march=native
#OPTFLAGS ?= -g3 -fsanitize=leak -O2 -lubsan
#OPTFLAGS ?= -g3 -fsanitize=leak -O2 -lubsan
# extra packages from pkg-config
# extra packages from pkg-config
LIBS
=
protobuf
libzmq
LIBS
=
libzmq
INCLUDE_DIR
+=
$(
shell
pkg-config
--cflags
$(LIBS)
)
INCLUDE_DIR
+=
$(
shell
pkg-config
--cflags
$(LIBS)
)
LDFLAGS
+=
$(
shell
pkg-config
$(LIBS)
--libs
)
LDFLAGS
+=
$(
shell
pkg-config
$(LIBS)
--libs
)
...
@@ -24,7 +24,7 @@ CXXFLAGS += $(INCLUDE_DIR)
...
@@ -24,7 +24,7 @@ CXXFLAGS += $(INCLUDE_DIR)
CXXFLAGS
+=
-Wall
-Wextra
CXXFLAGS
+=
-Wall
-Wextra
CXXFLAGS
+=
$(DEFINES)
-std
=
c++11
$(OPTFLAGS)
-fPIC
CXXFLAGS
+=
$(DEFINES)
-std
=
c++11
$(OPTFLAGS)
-fPIC
# https://github.com/tensorflow/tensorflow/issues/1569
#
TODO
https://github.com/tensorflow/tensorflow/issues/1569
# You may need to disable this flag if you compile tensorflow yourself with gcc>=5
# You may need to disable this flag if you compile tensorflow yourself with gcc>=5
CXXFLAGS
+=
-D_GLIBCXX_USE_CXX11_ABI
=
0
CXXFLAGS
+=
-D_GLIBCXX_USE_CXX11_ABI
=
0
...
...
tensorpack/user_ops/__init__.py
View file @
398cb933
...
@@ -16,6 +16,7 @@ print("Compiling user ops ...")
...
@@ -16,6 +16,7 @@ print("Compiling user ops ...")
ret
=
os
.
system
(
compile_cmd
)
ret
=
os
.
system
(
compile_cmd
)
if
ret
!=
0
:
if
ret
!=
0
:
print
(
"Failed to compile user ops!"
)
print
(
"Failed to compile user ops!"
)
zmq_recv
=
None
else
:
else
:
recv_mod
=
tf
.
load_op_library
(
os
.
path
.
join
(
file_dir
,
'zmq_recv_op.so'
))
recv_mod
=
tf
.
load_op_library
(
os
.
path
.
join
(
file_dir
,
'zmq_recv_op.so'
))
# TODO trigger recompile when load fails
# TODO trigger recompile when load fails
...
...
tensorpack/user_ops/zmq_conn.h
View file @
398cb933
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
#include <string>
#include <string>
#include <iostream>
#include <iostream>
#include <tensorflow/core/framework/tensor
.pb
.h>
#include <tensorflow/core/framework/tensor
_shape
.h>
#include <tensorflow/core/lib/gtl/inlined_vector.h>
#include <tensorflow/core/lib/gtl/inlined_vector.h>
#include "zmq.hpp"
#include "zmq.hpp"
...
@@ -21,11 +21,10 @@ struct RecvTensorList {
...
@@ -21,11 +21,10 @@ struct RecvTensorList {
zmq
::
message_t
message
;
zmq
::
message_t
message
;
struct
TensorConstructor
{
struct
TensorConstructor
{
// TODO make it allocated on stack
tensorflow
::
DataType
dtype
;
// only contains shape and type
tensorflow
::
TensorShape
shape
;
tensorflow
::
TensorProto
meta
;
int
size
;
// TODO bufsize
char
*
buf
;
char
*
buf
;
int
size
;
};
};
tensorflow
::
gtl
::
InlinedVector
<
TensorConstructor
,
4
>
tensors
;
tensorflow
::
gtl
::
InlinedVector
<
TensorConstructor
,
4
>
tensors
;
...
@@ -53,11 +52,15 @@ class ZMQConnection {
...
@@ -53,11 +52,15 @@ class ZMQConnection {
CHECK_LE
(
num
,
15
);
// probably a format error
CHECK_LE
(
num
,
15
);
// probably a format error
for
(
int
i
=
0
;
i
<
num
;
++
i
)
{
for
(
int
i
=
0
;
i
<
num
;
++
i
)
{
int
dt
=
read_int32
(
&
pos
);
tensors
[
i
].
dtype
=
tensorflow
::
DataType
(
dt
);
int
ndim
=
read_int32
(
&
pos
);
CHECK_LE
(
ndim
,
8
);
// probably an error.
for
(
int
k
=
0
;
k
<
ndim
;
++
k
)
{
int
shp
=
read_int32
(
&
pos
);
tensors
[
i
].
shape
.
AddDim
(
shp
);
}
int
sz
=
read_int32
(
&
pos
);
int
sz
=
read_int32
(
&
pos
);
CHECK
(
tensors
[
i
].
meta
.
ParseFromArray
(
pos
,
sz
));
pos
+=
sz
;
sz
=
read_int32
(
&
pos
);
tensors
[
i
].
buf
=
pos
;
tensors
[
i
].
buf
=
pos
;
tensors
[
i
].
size
=
sz
;
tensors
[
i
].
size
=
sz
;
pos
+=
sz
;
pos
+=
sz
;
...
...
tensorpack/user_ops/zmq_recv_op.cc
View file @
398cb933
...
@@ -51,7 +51,7 @@ class ZMQRecvOp: public OpKernel {
...
@@ -51,7 +51,7 @@ class ZMQRecvOp: public OpKernel {
for
(
int
i
=
start
;
i
<
stop
;
++
i
)
{
for
(
int
i
=
start
;
i
<
stop
;
++
i
)
{
Tensor
*
output
=
nullptr
;
Tensor
*
output
=
nullptr
;
int
j
=
i
-
start
;
int
j
=
i
-
start
;
auto
recv_dtype
=
tensors
[
j
].
meta
.
dtype
()
;
auto
recv_dtype
=
tensors
[
j
].
dtype
;
OP_REQUIRES
(
OP_REQUIRES
(
ctx
,
component_types_
[
j
]
==
recv_dtype
,
ctx
,
component_types_
[
j
]
==
recv_dtype
,
errors
::
InvalidArgument
(
"Type mismatch between parsed tensor ("
,
errors
::
InvalidArgument
(
"Type mismatch between parsed tensor ("
,
...
@@ -59,7 +59,7 @@ class ZMQRecvOp: public OpKernel {
...
@@ -59,7 +59,7 @@ class ZMQRecvOp: public OpKernel {
DataTypeString
(
component_types_
[
j
]),
")"
));
DataTypeString
(
component_types_
[
j
]),
")"
));
TensorShape
shape
{
tensors
[
j
].
meta
.
tensor_shape
()}
;
TensorShape
&
shape
=
tensors
[
j
].
shape
;
OP_REQUIRES_OK
(
ctx
,
ctx
->
allocate_output
(
i
,
shape
,
&
output
));
OP_REQUIRES_OK
(
ctx
,
ctx
->
allocate_output
(
i
,
shape
,
&
output
));
auto
ptr
=
output
->
bit_casted_shaped
<
char
,
1
>
({
shape
.
num_elements
()});
auto
ptr
=
output
->
bit_casted_shaped
<
char
,
1
>
({
shape
.
num_elements
()});
memcpy
(
ptr
.
data
(),
tensors
[
j
].
buf
,
tensors
[
j
].
size
);
memcpy
(
ptr
.
data
(),
tensors
[
j
].
buf
,
tensors
[
j
].
size
);
...
...
tensorpack/utils/serialize.py
View file @
398cb933
...
@@ -81,17 +81,24 @@ def dump_tensor_protos(protos):
...
@@ -81,17 +81,24 @@ def dump_tensor_protos(protos):
The format is:
The format is:
[#tensors(int32)]
[#tensors(int32)]
(tensor1)[size of meta proto][serialized meta proto][size of buffer][buffer]
[tensor1][tensor2]...
(tensor2)...
Where each tensor is:
[dtype(int32)][ndims(int32)][shape[0](int32)]...[shape[n](int32)]
[len(buffer)(int32)][buffer]
"""
"""
# TODO use int64
s
=
struct
.
pack
(
'=i'
,
len
(
protos
))
s
=
struct
.
pack
(
'=i'
,
len
(
protos
))
for
p
in
protos
:
for
p
in
protos
:
tensor_content
=
p
.
tensor_content
tensor_content
=
p
.
tensor_content
p
.
tensor_content
=
b
'xxx'
# clear content
buf
=
p
.
SerializeToString
()
s
+=
struct
.
pack
(
'=i'
,
int
(
p
.
dtype
))
s
+=
struct
.
pack
(
'=i'
,
len
(
buf
))
dims
=
p
.
tensor_shape
.
dim
s
+=
buf
s
+=
struct
.
pack
(
'=i'
,
len
(
dims
))
for
k
in
dims
:
s
+=
struct
.
pack
(
'=i'
,
k
.
size
)
s
+=
struct
.
pack
(
'=i'
,
len
(
tensor_content
))
# won't send stuff over 2G
s
+=
struct
.
pack
(
'=i'
,
len
(
tensor_content
))
# won't send stuff over 2G
s
+=
tensor_content
s
+=
tensor_content
return
s
return
s
...
...
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