Skip to content
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

MKL/non-MKL Reconciliation #165

Merged
merged 24 commits into from
Mar 23, 2014
Merged

MKL/non-MKL Reconciliation #165

merged 24 commits into from
Mar 23, 2014

Conversation

shelhamer
Copy link
Member

After no short journey, the port of Caffe away from MKL has come full circle and is ready for integration.

Chronicle:

  • boost/eigen3 port of Caffe started by @rodrigob, carried forward by @kloudkl, then fixed up by Alejandro Dubrovsky and @jeffdonahue.
  • A boost + openblas alternative was tried and our options weighed.
  • Rowland Depp emerges from the shadows with a brilliant commit 56b8ca0 to settle the issue.
  • cpp/cu layer implementations were split by @erictzeng
  • @shelhamer fixed the OSX break according to @satol's suggestion of a façade to hide boost rng from cuda code

There could be dragons here.

I made this PR from BVLC:boost-eigen so that we can join together for this glorious merge.

@shelhamer shelhamer mentioned this pull request Feb 26, 2014
@shelhamer
Copy link
Member Author

Water, water, every where,
And all the diffs did shrink.

Incorporated the linting.

@shelhamer
Copy link
Member Author

Builds on ubuntu 12.04 in MKL and non-MKL modes. Does not build on OSX.

@erictzeng the only conflicts were in the dropout layer since it 1. was not split in this branch and 2. relied on random number generation before Rowland Depp's MKL/non-MKL integration.

@erictzeng
Copy link
Contributor

Seems alright to me!

@shelhamer
Copy link
Member Author

Ok, I fixed a little makefile logic. Sadly, this still breaks in OSX, but less so.

/usr/local/cuda/bin/nvcc -ccbin=/usr/bin/clang++ -Xcompiler -fPIC -DNDEBUG -O2  -DUSE_MKL -I/Users/shelhamer/anaconda/include -I/Users/shelhamer/anaconda/include/python2.7 -I/Users/shelhamer/anaconda/lib/python2.7/site-packages/numpy/core/include -I/usr/local/include -I./src -I./include -I/usr/local/cuda/include -I/opt/intel/mkl/include -gencode arch=compute_30,code=sm_30 -c src/caffe/layers/bnll_layer.cu -o build/src/caffe/layers/bnll_layer.cuo
/usr/local/include/boost/type_traits/is_abstract.hpp(72): error: identifier "__is_abstract" is undefined

/usr/local/include/boost/type_traits/is_abstract.hpp(72): error: function call is not allowed in a constant expression

/usr/local/include/boost/type_traits/is_abstract.hpp(72): error: type name is not allowed

/usr/local/include/boost/type_traits/is_enum.hpp(181): error: identifier "__is_enum" is undefined

/usr/local/include/boost/type_traits/is_enum.hpp(181): error: function call is not allowed in a constant expression

/usr/local/include/boost/type_traits/is_enum.hpp(181): error: type name is not allowed

Any ideas? Perhaps building with g++ could work (see this Gadgetron build thread), but I don't exactly want to try it out.

Recall that this is a CUDA/boost conflict, so a CPU only compilation would partially sidestep this.

@shelhamer
Copy link
Member Author

This seems to be isolated to boost RNG in <boost/random/mersenne_twister.hpp>. Splitting random number generation into two flavors, MKL and boost, should resolve the OSX issues with the condition that OSX still requires MKL.

@satol
Copy link

satol commented Feb 27, 2014

@shelhamer Hi! May I suggest more radical splitting of cu files? Right now the split files still reference boost. Do you really need this? See the commit on my fork that fixes bnll_layer build on 10.9. Seems similar fixes should be done for other issues (dropout_layer, etc)?
satol@1bbe45f

@shelhamer
Copy link
Member Author

@satol Thank you! I like your suggestion and proof-of-concept commit more than my original plan. Splitting off common_cu.hpp and layer_cu.hpp should provide the separation we need. It should avoid introducing a per-layer header too. If you could further develop this line of refactoring and submit a PR I would welcome the contribution! (Please PR to BVLC:boost-eigen.)

Thoughts? @Yangqing @jeffdonahue @erictzeng

@satol
Copy link

satol commented Mar 3, 2014

@shelhamer To make it build on mac, instead of changing many cu files, I refactored the random generator to hide the <boost/random/mersenne_twister.hpp> from CUDA. Everything compiled ok.
https://github.com/satol/caffe/tree/boost-eigen

@sergeyk sergeyk added this to the 1.0 milestone Mar 13, 2014
@jamt9000
Copy link
Contributor

Can the changes be merged into dev soon? I do not have MKL, so contributing changes against the dev branch is currently quite hard since I cannot test them!

@shelhamer
Copy link
Member Author

@jamt9000 we'd certainly like to merge too! However we're held up on some boost/CUDA integration work for OSX. Now that v0.99 is out we'll take another stab at it–this branch has gone on long enough.

Rebased: fast-forward, but still breaks OSX.

shelhamer and others added 7 commits March 21, 2014 13:52
add MKL dirs conditioned on USE_MKL
include libraries before making LD_FLAGS
They were the wrong way round, causing linking to fail in some cases
This ensures that it works with ATLAS's header file, which doesn't include such
a guard itself (whereas the reference version from Ubuntu's libblas-dev does)
The FIXMEs about RNG were addressed by caffe_nextafter for
uniform distributions and the normal distribution concern is surely a
typo in the boost documentation, since the normal pdf is correctly
stated elsewhere in the documentation.
@shelhamer
Copy link
Member Author

This beast is slain. This builds and tests pass on linux and osx.

Although the facade to hide boost rng from cuda makes it look unnecessarily complex, it doesn't intrude into the rest of the code and the caffe_vRng* methods are none the worse for it.

@Yangqing, please let me know if you have any reservations about this approach. @jeffdonahue, any comments on style are welcome.

Let's merge this soon.

p.s. I tried to totally split common into cpp / cu code but it's not so simple.

@kloudkl
Copy link
Contributor

kloudkl commented Mar 22, 2014

Since the solution was proposed by @satol and authored by @shelhamer, the Copyright comment of the HDF5DataLayer which was also authored by two contributors would be a nice example to follow.

// Copyright 2014 BVLC.
/*
Contributors:
- Sergey Karayev, 2014.
- Tobias Domhan, 2014.

@shelhamer
Copy link
Member Author

I've set the copyright to blanket BVLC and contributors for now, since code contributions are tracked per-author by versioning and @satol is thanked in the commit message of 19bcf2b. Let's all discuss this at #249.

@jeffdonahue
Copy link
Contributor

Looks great Evan! Thanks for getting this long-standing issue resolved.

Split boost random number generation from the common Caffe singleton and
add a helper function for rng. This resolves a build conflict in OSX
between boost rng and nvcc compilation of cuda code.

Refer to #165 for a full discussion.

Thanks to @satol for suggesting a random number generation facade rather
than a total split of cpp and cu code, which is far more involved.
The exact details of the contributions are recorded by versioning.
shelhamer added a commit that referenced this pull request Mar 23, 2014
MKL/non-MKL Reconciliation

Caffe no longer requires MKL. By default it builds without it, relying on atlas and cblas instead. Set the `USE_MKL` var in your Makefile.config accordingly.
@shelhamer shelhamer merged commit 699b557 into dev Mar 23, 2014
@shelhamer
Copy link
Member Author

druid circle

Join hands! We are one.

@shelhamer shelhamer deleted the boost-eigen branch May 2, 2014 15:04
@shelhamer shelhamer mentioned this pull request May 20, 2014
This was referenced Jul 3, 2014
mitmul pushed a commit to mitmul/caffe that referenced this pull request Sep 30, 2014
Split boost random number generation from the common Caffe singleton and
add a helper function for rng. This resolves a build conflict in OSX
between boost rng and nvcc compilation of cuda code.

Refer to BVLC#165 for a full discussion.

Thanks to @satol for suggesting a random number generation facade rather
than a total split of cpp and cu code, which is far more involved.
mitmul pushed a commit to mitmul/caffe that referenced this pull request Sep 30, 2014
MKL/non-MKL Reconciliation

Caffe no longer requires MKL. By default it builds without it, relying on atlas and cblas instead. Set the `USE_MKL` var in your Makefile.config accordingly.
slayton58 pushed a commit to slayton58/caffe that referenced this pull request Jun 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants