Python should be able to manipulate Protobuf message because: 1. Python's `create_op_creation_methods` take the `OpProto` array to generate all `op_creation_methods` in RunTime. 2. All `op_creation_methods` will create an `OpDesc` and pass it to Paddle C++ method `CreateOp` and return the Op handle. Here is the list of what is added in this commit: * Add `protobuf_generate_python` if it is not defined. * Before cmake 3.4, `protobuf_generate_python` is not defined. Just copy the implementation of that function in `protobuf.cmake` * Add `py_proto_compile` function in `cmake/generic.cmake`. * It follows bazel's API interface. * https://github.com/pubref/rules_protobuf#rules * Add an empty package named `paddle.v2.framework`, all python code of `paddle::framework` will be in that package. * Generate protobuf's python module `__init__.py` by `touch` while compiling. * Change setup.py.in, make `paddle.v2.framework.proto` uses the generated protobuf pythons.gangliao-patch-1
parent
4d899a8e6b
commit
e2ea1f42e9
@ -0,0 +1 @@
|
||||
__all__ = ['proto']
|
@ -0,0 +1 @@
|
||||
add_python_test(test_framework test_protobuf.py)
|
@ -0,0 +1,26 @@
|
||||
import paddle.v2.framework.proto.op_proto_pb2
|
||||
import paddle.v2.framework.proto.attr_type_pb2
|
||||
import unittest
|
||||
|
||||
|
||||
class TestFrameworkProto(unittest.TestCase):
|
||||
def test_all(self):
|
||||
op_proto_lib = paddle.v2.framework.proto.op_proto_pb2
|
||||
attr_type_lib = paddle.v2.framework.proto.attr_type_pb2
|
||||
op_proto = op_proto_lib.OpProto()
|
||||
ipt0 = op_proto.inputs.add()
|
||||
ipt0.name = "a"
|
||||
ipt0.comment = "the input of cosine op"
|
||||
ipt1 = op_proto.inputs.add()
|
||||
ipt1.name = "b"
|
||||
ipt1.comment = "the other input of cosine op"
|
||||
opt = op_proto.outputs.add()
|
||||
opt.name = "output"
|
||||
opt.comment = "the output of cosine op"
|
||||
op_proto.comment = "cosine op, output = scale*cos(a, b)"
|
||||
attr = op_proto.attrs.add()
|
||||
attr.name = "scale"
|
||||
attr.comment = "scale of cosine op"
|
||||
attr.type = attr_type_lib.FLOAT
|
||||
op_proto.type = "cos"
|
||||
self.assertTrue(op_proto.IsInitialized())
|
Loading…
Reference in new issue