I was wondering if we should tweak Stan such that it can specifically take advantage of the MKL? I know this thing cost money, but those who have it get some speedups here for free (assuming its there). Use cases
1. Enabling the MKL for Eigen gave me ~10-20% speedup. Depending on your model you may get even more.
2. It is possible to make CVODES use the Intel MKL. I have never tried this, but from talking to people this may give a 2X speedup for ODE solving; again "for free".
Specifically what I have in mind to do is to let the build system define a macro, called
STAN_USE_MKL
for example. If this macro is defined, then CVODES is instructed to be built slightly different and will then use MKL routines which hopefully expedite things.
Another advantage to deploy this in a pre-configured way is that we can ensure that the MKL is used in the right way as you can shoot yourself in the foot otherwise. At least the unit tests of stan-math are not successful whenever you switch on all optimizations from the Intel compiler.
Would that be an appropiate approach?
Sebastian
Yes, this is a good topic for the meetings. Let me clarify that two things are involved here:
- MKL
- Intel compiler
The MKL can come independent of the Intel compiler while the Intel compiler usually brings with it the MKL. As far as I am aware neither are free, only if you use it for academic only purposes there are some possibilities to use them free of charge.
I myself was always curious at what the real speedup for CVODES is - the 2X sounds to good to be true, but I am already happy with a 1.5X. The changes this implies, I can easily maintain; but I can't do magic, i.e. I can do so with what we have here which is the 2015.3 version (the second latest to my knowledge).
Wrt. to stan-math and the Intel compiler: You have to enable the options "-fp-model precise -fp-model source" in order to get units tests to pass (I am not sure if the cmdstan manual states this). As far as I recall, I did not dare to throw in the MKL on top of that, but I can investigate should we want this.
Best,
Sebastian
On Monday, August 22, 2016 at 1:04:14 PM UTC+2, Bob Carpenter wrote:
> > On Aug 22, 2016, at 10:40 AM, Sebastian Weber
> >
--
You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Let's go in steps here:
1. Ensure in the built system that the intel compiler is called with the right options
2. Include in the build system a flag for having the MKL which allows to instruct Eigen to use MKL as well
3. Evaluate the performance gain for CVODES when using the MKL; only if this is promising, we decide for keeping this
However, in any case I do not think that we need to have travis changed or any of the test systems. The reason being that not many users will use the MKL and hence this is not of such a major concern. Nonetheless, I will run once in a while tests on our MKL installation. Does that make sense?
Sebastian
On Monday, August 22, 2016 at 5:42:14 PM UTC+2, Bob Carpenter wrote:
> > On Aug 22, 2016, at 5:23 PM, Daniel Lee
> >
Yes, this is a good topic for the meetings. Let me clarify that two things are involved here:- MKL
- Intel compilerThe MKL can come independent of the Intel compiler while the Intel compiler usually brings with it the MKL. As far as I am aware neither are free, only if you use it for academic only purposes there are some possibilities to use them free of charge.
Possibly the reason why you don't see as much is that Stan made the decision to use Eigen, which specifically does not use the system BLAS but for philosophical reasons builds its own routines. See these two messages by the authors of Armadillo (which uses BLAS/LAPACK) and RcppEigen on the R-devel list from 2012:
* http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2012-June/003899.html
* http://lists.r-forge.r-project.org/pipermail/rcpp-devel/2012-June/003909.html
So in Stan's case, unless Eigen has greatly changed from 2012, the benefit of using the MKL (or OpenBLAS or ATLAS) will be restricted to the non-Eigen sections of the code, I believe.
Thanks,
Avi
Again, I am neither a programmer nor do I play one on the radio, but if some of that C++ ability allows Stan to get out of the gate, and behind the scenes something is passed to the MKL, it is remotely possible that mayhem may ensue.
That's why YOUZ GUYZ get the big bucks 8-)
Avi
In summary, we are talking about conditional builds which I have already done, will anyway maintain and are suggesting to add to Stan.
@Ben: Yes, wherever the MKL is around, the Intel compiler will be close and vice versa. However, from my experience with Stan and R I would NOT setup a production system to build with Intel anymore. If you make as a company the decision to go with open-soruce, then you should actually use the compilers of that community. This means the optimal system from my perspective is built on the Rtools compiler (gcc 4.9 as of now) and then you simply link in the MKL. That would have saved me (and other here, sorry) a lot of trouble.
Cheers,
Sebastian
Hmmm. Eigen is not set up to recognize an open-source optimized BLAS like OpenBLAS, is it?
Thanks,
Avi
I hope I need not to sign any contract... but I will certainly be responsible for this stuff.
Sebastian