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 Boost.Python interface #821
Conversation
Sorry for delay, I was away at a conference:
|
I will keep posted on the progress. |
Progress status:
(will keep editing this message as things evolve) apps/ tutorial/ Known issue: python object reference counting is not properly handled in ndarray_to_image (e.g. if the input array is deleted, the Image object points to de-allocated memory). |
Quick status update: all tutorials ported. Some of them pass, some do not. Next steps: bugs ironing and covering the missing corners of the API. |
Quick status update: The bulk of the API coverage is done (all bit and pieces used in the lessons, only left out areas I have never seen used, e.g. Stage API). All lessons are converted too.
~~Other than that the other two known issues are:
|
All python demonstration application and lessons now work as desired.
|
This branch is now feature complete. All the known issues are solved. Most of the code is pretty straightforward, with some pieces of C++ magic (recursive calls over list types) to avoid too much copy&paste code. Stage and Func have some copy&paste code (between them), but so does the C++ codebase. Code has been tested on Ubuntu 14.04 with python 3.4, and llvm 3.5. Please let me know if there is any feature/code change that I should do/consider. |
I get stuck here:
Looks like the local type_of_helper specialization can't be in a different anonymous namespace to Halide's. Is there some simpler way to do this switch (e.g. by passing a list of Halide::Type instead of a variadic type pack)? If variadic templates are required then perhaps a wrapper of type_of in a local namespace is necessary. |
Also, in the branch you should delete the old python_bindings and rename boost_python_bindings to python_bindings. |
just for info (so I can try reproduce the issue) which compiler (and compiler options) are you using ? |
gcc 4.8.2 Followed the instructions in the readme, so no special compiler flags. Let On Mon, Jun 22, 2015 at 10:42 AM, Rodrigo Benenson <notifications@github.com
|
Okidoki. I can reproduce the issue indeed, clang-3.5 and gcc-4.8 do not agree on what is permitted or not. Param.cpp seems to be the only source of trouble (with I did not like that much that piece of code anyway, will try a variant based on boost/mpl (which should provide robust support across compilers). |
The last two pushes should fix the gcc 4.8 issue (while still working on clang 3.5) and replace the old swig python bindings with the new boost.python bindings. |
I just noticed that I missed two additional python demonstration applications from the old swig version (somehow I though I had copied them all, I did not).
|
I'm having a hell of a time trying to get boost_numpy to compile for python3 instead of python2. Any hints? |
Ahhh, for me it was a breeze (maybe I have done it too many times already...). For python3 you need to make sure cmake is happy.
that piece of code assumes you have python3.4 installed. Change to the adequate python 3 version if needed (and make sure it matches your boost installation). Boost.Numpy also needs numpy installed. That is for generic advice. For more help, can you point me to the specific error you are having ? |
Quick status update:
From my point of view the branch is feature complete and usable as is.
|
@abadams any help I can provide with |
To make things easier I have imported the bits of Boost.Numpy we need into the repository (under These are eight files total, summing up < 1k lines of code (and I could strip more, but I decided to strip files, not lines of code). To let the user choose I changed the semantics of the cmake
Bottom line, now things should work well even if Boost.Numpy is not installed. Let me know if |
@abadams Anything that I can do to help the review/merge consideration process ? |
Apologies, I got caught up with other stuff over the last week and let this On Wed, Jul 1, 2015 at 8:55 PM, Rodrigo Benenson notifications@github.com
|
Here's my experience on OS X with macports: First I install a bunch of relevant-seeming stuff:
Then I try to build
After much messing around, I'm still unable to get cmake to see my python3.4 installation. This is the same problem I had on linux. I'll proceed manually and record the list of changes I needed to make to get it to build on OS X: change forward declaration of "class Type" to "struct Type" in Type.h change reinterpret_cast<size_t>(that.dev) to just that.dev in Buffer.cpp (You can't reinterpret a uint64_t as a size_t - size_t might be 32-bit). include boost/format.hpp before boost/python.hpp in Type.cpp (see http://stackoverflow.com/questions/29443497/cannot-include-both-boost-python-and-boost-any) include boost/format.hpp before python.hpp in make_array.h Seems like rtti is required for boost python to do its thing, but llvm is built without it, so Halide fails to build if I turn it off in the Halide makefile. At this point I'm stuck. Is rtti supposed to be on or off? I don't see any mention of it in the python_bindings folder.
Here's the makefile I ended up with:
|
Wow, that is quite a bit of pain indeed. For the python experience it is quite a bit better if Halide raises exceptions (as mentioned in the python_bindings readme). I understand C++ exceptions rely on RTTI. You ask "is rtti supposed to be on or off?", why should it be off ? Given your error it clearly should be on, but why would you want it to be off ? (other than for leaner executables ) |
(by the way just noticed that Halide's Makefile does not work properly when (the fix is to add -fno-exceptions in the omit part of the LLVM_CXX_FLAGS; I also added the -fexceptions by hand, not sure if was needed or not) |
I'm not against rtti per-se, but my llvm was compiled with -fno-rtti (3.6 built with cmake with default settings), which is why it had to be off for the Halide build. If I remove -fno-rtti from the Halide Makefile I get the following error while building libHalide
I turned on Halide exceptions for the reasons you state. Based on some googling, I think you can have exceptions without rtti. My llvm-config flags didn't include -fno-exceptions, so WITH_EXCEPTIONS=1 worked for me. Here are my versions:
I'll try building Halide with cmake to see if it ends up differently... no, same error about missing reference to typeinfo for ImageParam. This page claims I can use boost without rtti (or more accurately, with its own internal rtti): However I still get the same error if I add those flags to my CCFLAGS. I guess boost-python really does need rtti. what does "make VERBOSE=1" look like for you when compiling the python bindings with cmake? Maybe there are some clever flags I'm missing. |
It looks like this
the only options I spot are |
My boost version is 1.55, so the "format.hpp before python.hpp" might be compiler specific. |
… yet work as desired.
…ome of the tutorials. Also run_tutorial does not stop on first failure.
Fixed the merge conflict. I think this version should be considered for merging into Master. All tutorials and apps run.
|
@@ -1303,6 +1303,7 @@ Stage FuncRefVar::operator/=(Expr e) { | |||
} | |||
|
|||
FuncRefVar::operator Expr() const { | |||
//printf("func.name() == '%s'\n", func.name().c_str() ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like some debugging code left in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never mind, I want to merge this now, so I'll just cut this line myself during the merge.
Merged. Thanks for all this work - I owe you a beer. I've included it in the nightly tests too. |
Yey ! Well thank you for Halide. I am happy now that I can do more/faster Halide hacking from Python directly. |
This branch is now feature complete, see bottom of the thread for updates/discussions.
Following the spirit of other repositories this is a pull request of an ongoing branch. The code is not ready for merge, but this pull request enables to have an ongoing discussion to guide the development.
The rationale for this new branch is explained in the readme.text, basically current python bindings rely in a broken tool (swig), has too much spagethi (see
__init__.py
) and not enough link to the C++ codebase.The current status is:
a) Proof of concept of the approach is valided (see d),
b)
70%80%90%all of the ground work is in place (most notable missing pieces is the gpu API, Tuple, RDom),c) Code compiles and runs,
d) blur.py runs and blurs the image as desired (
erode.py
,bilateral_grid.py
also works).e) No real unit-tests in place (see Q4).On principle code should work perfectly fine on python 2 and 3; but I have only tested for python 3.
Some of feedback I would like to have:
Q1) Likelihood of a merge with master once API/tests coverage is good enough.
Q2) Suggested strategy to better address the drift between Python bindings and C++ code base (i.e. how to include in continuous integration).
Q3) Current code adds dependency with Boost.Numpy (which is not part of boost) for convenient I/O. I am considering including a copy into the repository, opinions on the cleanest way of handling the dependency?
Q4) Suggestions for the best testing approach. For now I will focus on porting the demonstration apps from the old python bindings, and covering the areas I will be using; but I guess we could do better.
Q5) Anyone interested on giving a hand ? Second brain helps make code cleaner. Also, I would not mind delegating the gpu API part (which I am not planning to use in the short term).