-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Python/C++ interface #2750
Comments
For sure, we may only support Python in a long time, consider time and workload, but some choices need to be considered:
In short, |
So I think we can't avoid making a c wrapper at last, once we have it, implement python extension is simple. |
What is supposed to be included in the Go API? I my mind, the Go API differs from the Python API significantly. In particular, we don't need Go packages like paddle.op, paddle.layer, paddle.scope, paddle.variable. Is this correct? @typhoonzero |
There are another lib |
At least paddle.variable or paddle.tensor I think. The current implementation of go pserver and optimizer use an independent implementation of tensor, at We don't need Go packages like paddle.op, paddle.layer, paddle.scope, paddle.variable indeed. Making parameter server as an "op" like tensorflow isn't what we intended to. |
consider that we just write operator in C++ and generate them in python. We cannot find a proper language binding generator library/generate technical. Maybe it is too hard to generate OP for Go at present.
|
Whether uses C-API depends on is there any other languages need invoke Paddle C++ Core or not. I am not sure only Python API is enough or not. At least there are several needs for us to give a C-API.
Also, I think pybind11 is better than But if we have a C-API for Paddle, wrap that C-API to Python is extremely easy by Cython. cdef extern from "math.h":
double sin(double x) |
Also, See video here |
@wangkuiyi and all, I write two demos, one used The conclusion is:
|
Fixed by #2793 |
I read and followed this article http://intermediate-and-advanced-software-carpentry.readthedocs.io/en/latest/c++-wrapping.html, which compares the following interfacing technology:
manual wrapping. I followed this official Python document for more details: https://docs.python.org/2/extending/extending.html for some example programs. There includes some complex boilerplate code -- parsing argument in each C function, build and return Python object in each C function, and the method list.
SWIG. It seems a general method that can generate bindings for various client languages, but not "native" enough. Also, it takes some time to learn the interfacing language (*.i files).
ctypes. This requires us to respecify the return type and other meta-data about each C function at the Python side, again.
SIP. This is the Qt community's version of SWIG. We also need to learn an interfacing language.
Boost.Python. This is some C++ templates that simplify the manual wrapping. We no longer need to write a C wrapper function for each C++ function. Only a few extra lines in addition to the original C++ code are required to build a .so that can be called from Python.
I personally prefer Boost.Python. Here is an example for your reference:
Suppose that we already have C++ functions like:
only the following few lines is required to build the Python-callable .so file:
The text was updated successfully, but these errors were encountered: