- Notifications
You must be signed in to change notification settings - Fork 5.4k
Simplify installation and document the use of Intel MKL #3194
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
Conversation
| Great work!! And it's really good that you are updating the documentation too. I ran the scripts on mac and got this: ``` extras/check_dependencies.sh extras/check_dependencies.sh: Intel MKL is not installed. Run extras/install_mkl.sh to intall it. ... You can also use other matrix algebra libraries; for information, see ... http://kaldi-asr.org/doc/matrixwrap.html extras/check_dependencies.sh: line 152: syntax error near unexpected token `;;' extras/check_dependencies.sh: line 152: ` rhel|centos|redhat) echo "yum install $redhat_packages"; break;;' make: *** [check_required_programs] Error 2 mac:tools: extras/install_mkl.sh extras/install_mkl.sh: This script can be used on Linux only, and your system is Darwin. Installer packages for Mac and Windows are available for download from Intel: https://software.intel.com/mkl/choose-download mac:tools: `` I went through the mkl installation process on mac (I chose 'root' rather than 'administrator' when it asked, not sure if this matters in terms of where it is installed to). After that, running check_dependencies.sh didn't print anything about MKL: ``` mac:tools: extras/check_dependencies.sh extras/check_dependencies.sh: line 152: syntax error near unexpected token `;;' extras/check_dependencies.sh: line 152: ` rhel|centos|redhat) echo "yum install $redhat_packages"; break;;' ``` However, when I ran configure on mac, it picked up the accelerate framework, and I see that the configure script doesn't support MKL yet. It would be great if someone could figure out how to get it to work for mac. Do you think we could have a slightly more customized message printed on mac from either check_dependencies.sh or the mkl script, which points out that while installing MKL will improve performance, it's not necessary? I think accelerate is installed by default on mac. (Or for now, we could just not have it check for MKL on mac at all, until the configure script supports it). Dan …On Mon, Apr 1, 2019 at 8:52 AM kkm (aka Kirill Katsnelson) < ***@***.***> wrote: Ok, here are my changes so far. The only thing I did not do here is change the configure default to MKL. so this may possibly be a WIP. I debugged the script on 20 different Docker images, ranging from deprecated systems to the latest stable branches: https://github.com/kkm000/install_mkl. The tests use the expect tool, since the script asks to run sudo, sudo asks for the password, etc. Now, how do we handle that transition overall? Just change the default blindly to MKL and see what is the fallout? I wold at least post a heads-up to the kaldi-help list. The current default is ATLAS, which is not good at all. What I am thinking of doing is maybe add some detection code (MKL in the recent packaging is very easy to detect, so it's either it's either in the system (just compiles) or in a well known directory /opt/inte/mkl). Except I do not know where to look for it on a Mac. My co-worker has a Mac, I'll email him to bring it, but I do not know if he still has it, and I do not remember if he's coming back from vacation today. Generally, regarding openblas detection, I think invoking a test compile is a better approach than poking around trying to find it it's in the system in a known location. If it is, a compile with -l... will do the trick. If not, then it's likely missing. In any case, it's probably better to build OpenBLAS from source. At the very least, it might be better optimized for the user's system. Running the reference CBLAS will probably be disastrously slow anyway. So, in the end, I'm thinking we should, in the case the user did not ask for a specific math lib: - Check if MKL is there, and use it. - Check for OpenBlas in tools/. Then check for it in the system. What we can do about packaging, I dunno yet. rhel packages seem to package <cblas.h>, should work as is. debian packages use a known filename, I'll see if we can adapt it. - If OpenBLAS is found, print a note that MKL is better, and use OpenBLAS. - If not, print an error and ask to use the option to specify the library. I. e., do not probe for neither the reference blas or ATLAS, because these are rather inferior options. What do you think? Am I making sense? ------------------------------ You can view, comment on, or merge this pull request online at: #3194 Commit Summary - Simplify and document the use of Intel MKL File Changes - *M* src/doc/build_setup.dox <https://github.com/kaldi-asr/kaldi/pull/3194/files#diff-0> (10) - *M* src/doc/matrixwrap.dox <https://github.com/kaldi-asr/kaldi/pull/3194/files#diff-1> (235) - *M* tools/extras/check_dependencies.sh <https://github.com/kaldi-asr/kaldi/pull/3194/files#diff-2> (175) - *A* tools/extras/install_mkl.sh <https://github.com/kaldi-asr/kaldi/pull/3194/files#diff-3> (265) Patch Links: - https://github.com/kaldi-asr/kaldi/pull/3194.patch - https://github.com/kaldi-asr/kaldi/pull/3194.diff — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#3194>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ADJVu4mwrtcs1pnllW1dRakeqf5IpGYBks5vcgDygaJpZM4cVo0p> . |
| Thanks for checking with MKL on Mac! I'll try to understand what did not it like about the check_dependencies.sh.
Can you please figure out where did the MKL files end up installed, includes and libs? Was it also /opt/intel, or some Mac-specific location? I'll update the missing MKL message. I remember I pretty much s/ATLAS/MKL/, but you are right, it became confusing. install_mkl.sh can work on Linux only (Intel provides rm and deb only packages, and only for Linux, on the feed. So the message is misleading for Mac, should point to the intel's site instead. I have not touched configure yet, so no changes there. |
| mac:tools: ls /opt/intel/mkl/lib/ libmkl_avx.dylib libmkl_core.a libmkl_intel_lp64.dylib libmkl_mc.dylib libmkl_tbb_thread.a libmkl_vml_mc.dylib libmkl_avx2.dylib libmkl_core.dylib libmkl_intel_thread.a libmkl_mc3.dylib libmkl_tbb_thread.dylib libmkl_vml_mc2.dylib libmkl_avx512.dylib libmkl_intel_ilp64.a libmkl_intel_thread.dylib libmkl_rt.dylib libmkl_vml_avx.dylib libmkl_vml_mc3.dylib libmkl_blas95_ilp64.a libmkl_intel_ilp64.dylib libmkl_lapack95_ilp64.a libmkl_sequential.a libmkl_vml_avx2.dylib locale libmkl_blas95_lp64.a libmkl_intel_lp64.a libmkl_lapack95_lp64.a libmkl_sequential.dylib libmkl_vml_avx512.dylib …On Mon, Apr 1, 2019 at 2:47 PM kkm (aka Kirill Katsnelson) < ***@***.***> wrote: Thanks for checking with MKL on Mac! I'll try to understand what did not it like about the check_dependencies.sh. After that, running check_dependencies.sh didn't print anything about MKL Can you please figure out where did the MKL files end up installed, includes and libs? Was it also /opt/intel, or some Mac-specific location? I'll update the missing MKL message. I remember I pretty much s/ATLAS/MKL/, but you are right, it became confusing. install_mkl.sh can work on Linux only (Intel provides rm and deb only packages, and only for Linux, on the feed. So the message is misleading for Mac, should point to the intel's site instead. I have not touched configure yet, so no changes there. — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#3194 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ADJVu2xabAKy9ZpnJ-GiFIXr6zXptExrks5vclQugaJpZM4cVo0p> . |
| Super, thank you! Now I know everything I need except why bash on Mac is not like bash everywhere else, and did not digest the line 152, and why did the script print the line |
| It looks like the reason is that /etc/os_release does not exist on mac, so it becomes case in a|b|c) foo;; esac which cannot be parsed. Quoting them might help. Or just skip the whole block on mac. …On Mon, Apr 1, 2019 at 7:30 PM kkm (aka Kirill Katsnelson) < ***@***.***> wrote: Super, thank you! Now I know everything I need except why bash on Mac is not like bash everywhere else, and did not digest the line 152, and why did the script print the line mac:tools: at the end of the message. My fellow Mac owner will be working from home this whole week, but I'll ask around. — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#3194 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ADJVu-IyIDJYeI5R_AM20DhLBIM8tQhtks5vcpafgaJpZM4cVo0p> . |
| It's bash 3.2, actually. It requires the The missing file is handled by |
| Do you think the steps I described in the text for trying OpenBLAS if MKL not installed are sensible? /cc @jtrmal |
| Which specific text are you talking about? …On Mon, Apr 1, 2019 at 9:22 PM kkm (aka Kirill Katsnelson) < ***@***.***> wrote: Do you think the steps I described in the text for trying OpenBLAS if MKL not installed are sensible? /cc @jtrmal <https://github.com/jtrmal> — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#3194 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ADJVu0k1A23WGeO_AM_t3GNJU_WKYmlwks5vcrDlgaJpZM4cVo0p> . |
| The main question is about detecting the matrix library in configure: “ Running the reference CBLAS will probably be disastrously slow anyway. So, in the end, I'm thinking we should, in the case the user did not ask for a specific math lib:
I. e., do not probe for neither the reference blas or ATLAS, because these are rather inferior options. What do you think? Am I making sense? |
| Only in case the user did not specify an explicit library. |
| I suppose that's OK, at least on linux. But let's leave the part about detecting the system OpenBLAS off the table until we have finalized a basic version of this PR-- it will expand the scope too much, and we can leave it till later. On Mac, MKL is a rather large thing (half a gig) and not very easy to install; I don't want to push people towards it too aggressively on that platform. The inbuilt accelerate framework is a reasonable thing to use on mac, I think; people mostly just use mac for development/debugging. …On Mon, Apr 1, 2019 at 9:29 PM kkm (aka Kirill Katsnelson) < ***@***.***> wrote: Only in case the user did not specify an explicit library. — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#3194 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ADJVu_56FOdtiyVL6GkZjzwLSuzsogoSks5vcrJ7gaJpZM4cVo0p> . |
| The current default in configure is ATLAS on Linux, and that's not good. What should we use? |
| MKL, like you suggest. …On Mon, Apr 1, 2019 at 9:36 PM kkm (aka Kirill Katsnelson) < ***@***.***> wrote: The current default in configure is ATLAS on Linux, and that's not good. What should we use? — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#3194 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ADJVu2ynenPbRaxY7kSAYwiPe_PLXGgZks5vcrQlgaJpZM4cVo0p> . |
| Aha, I see. So it's always accelerate on Mac. And for Linux, I'll just change to MKL for now. |
|
| Cool! …On Mon, Apr 1, 2019 at 9:48 PM kkm (aka Kirill Katsnelson) < ***@***.***> wrote: $ ./configure Configuring KALDI to use MKL Configuring ... Checking compiler g++ ... Checking OpenFst library in /home/kkm/work/kaldi2/tools/openfst ... Checking cub library in /home/kkm/work/kaldi2/tools/cub ... Doing OS specific configurations ... On Linux: Checking for linear algebra header files ... Configuring MKL library directory: Found: /opt/intel/mkl/lib/intel64 MKL configured with threading: sequential, libs: -L/opt/intel/mkl/lib/intel64 -Wl,-rpath=/opt/intel/mkl/lib/intel64 -lmkl_intel_lp64 -lmkl_core -lmkl_sequential MKL include directory configured as: /opt/intel/mkl/include Configuring MKL threading as sequential MKL threading libraries configured as -ldl -lpthread -lm Using Intel MKL as the linear algebra library. Intel(R) Math Kernel Library Version 2019.0.2 Product Build 20190118 for Intel(R) 64 architecture applications Successfully configured for Linux with MKL libs from /opt/intel/mkl CUDA will not be used! If you have already installed cuda drivers and cuda toolkit, try using --cudatk-dir=... option. Note: this is only relevant for neural net experiments Info: configuring Kaldi not to link with Speex (don't worry, it's only needed if you intend to use 'compress-uncompress-speex', which is very unlikely) SUCCESS To compile: make clean -j; make depend -j; make -j ... or e.g. -j 10, instead of -j, to use a specified number of CPUs — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#3194 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ADJVu-vEXS6gF0AicgdTCtk9QderWf60ks5vcrbjgaJpZM4cVo0p> . |
| @huangruizhe can you please test this branch on our grid and see if it compiles, and also compare the speed (e.g. of matrix-lib-test) with our current installation? Please show the output of the check_dependencies.sh and configure scripts. |
| Got it. |
| @danpovey It seems it requires sudo to install this branch. Here are the commands and outputs: extras/check_dependencies.sh extras/install_mkl.sh Could you help me with this? Thanks! |
| @huangruizhe, just chiming in to confirm that what you are seeing is this is the correct behavior so far. BTW, The If your CPU support the AVX512 instruction set, I would be surprised if you do not see at the least 3× speed improvement over OpenBLAS. If it's only AVX2, the figure would be more modest, my guess is 1.4 to 2.0+ times improvement. Very interesting, actually, I'm eager to see the result. The Full output on my machine: I'd say the test is a bit too short for the result to be amenable to a real comparison, but as a ballpark baseline it's perfectly OK. The above figures are for a build with the same MKL version on quite a modern high-end CPU, which we can check by querying the /proc filesystem: Below is a cleaner way to spot these AVX512 instruction subsets among this mess of CPU capability flags (I'm using So we have the avx512f, avx512dq, avx512cd, avx512bw and avx512vl instruction subsets, and MKL will derive it's larges performance gains in matrix ops from these. But my CPU is of a desktop variety; xeons sometimes have a larger cache than the 21MB this CPU has, which is even better for large matrices. The 2.80GHz figure is a bit misleading, as the CPU has an advanced modern clock control. The clock actually varies during computation and reaches 4.6GHz, but with AVX512 units in use, will probably drop to 3.2GHz or so, because of the large amount of heat these computations produce. It would be very interesting what kind of performance figures you'd finally get on MKL vs OpenBLAS, and if you post the output of the same Thanks for your work, really appreciate, and while you are unable to get MKL on the nodes, you may configure with OpenBLAS and get the reference run time with it, to compare with the MKL runtime later, if you have time. |
| @kkm000 Thanks for the kind explanation! I would try to get it run, replicate your experiments, and find out the speedup. For the moment, I do not have a sudo access so I cannot install MKL. Here is what I get if I type "Y": Let us see how Dan would comment.
Would you point me to how to configure it with OpenBLAS? Is it the current configuration of Kaldi? Perhaps I should read some info here. Thanks again! |
| I see, thanks for checking. Actually, I likely was wrong about exactly OpenBLAS, sorry. What Dan initially asked was
I do not know what is your "current installation"; I incorrectly assumed it was OpenBLAS (as it's usually the fastest choice AFAIK), but it may be something else. So basically it's all about doing exactly the same test as above using the regular configuration that you normally use. To be comparable, both tests should be better performed on the same machine, if that's doable (I do not know if it's possible, as all clusters are different). |
| Kirill, can you have it so that instead of doing the sudo command for you it just prints out what you are supposed to do? I don't feel comfortable asking people to execute Kaldi scripts via sudo. …On Wed, Apr 3, 2019 at 9:12 PM kkm (aka Kirill Katsnelson) < ***@***.***> wrote: I see, thanks for checking. Actually, I likely was wrong about exactly OpenBLAS, sorry. What Dan initially asked was and also compare the speed (e.g. of matrix-lib-test) with our current installation I do not know what is your "current installation"; I incorrectly assumed it was OpenBLAS (as it's usually the fastest choice AFAIK), but it may be something else. So basically it's all about doing exactly the same test as above using the regular configuration that you normally use. To be comparable, both tests should be better performed on the same machine, if that's doable (I do not know if it's possible, as all clusters are different). — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#3194 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ADJVu6A1S2RhhxcjBOnSrnu-xMkUReTaks5vdXvKgaJpZM4cVo0p> . |
| Dan, I am not sure I understand which of the two options do you mean: just omit the 'exec sudo', or give the user the commands to run instead of scripting them? Both options look inferior, the latter more so. If first, there is less potential for error, and I'm adding command line options to skip as much stuff as possible (full message that also explains it to the user in @huangruizhe's comment above): Restart this script using the 'sudo' command, as: sudo $0 -sp $distro $package ... more blah blah ... if [ -t 0 ]; then echo; read -ep "Run the above sudo command now? [Y/n]:" case $REPLY in ''|[Yy]*) set -x; exec sudo "$0" -sp "$distro" "$package" ...Nothing wrong with that, really. Say yes or retype the command? To me, yes is less error-prone. If you mean to "just give them commands to run", then it's not as simple as it sounds, and sometimes worse than ugly, for apt in particular. I won't copy the whole kaboom here, but look at this, including old/new apt detection: https://github.com/kaldi-asr/kaldi/blob/a4785af4e/tools/extras/install_mkl.sh#L213-L243 I did it quite the best recommended way. The old I've run serious interactive (using 'expect') tests of this script for correctness on 20 different Linuxes, here's the test harness: https://github.com/kkm000/install_mkl. Every command that is run in elevated privilege state is printed (set -x). As a final, although quite a weak argument, I'm with a SaaS company that works with customer's data, which means one break-in and we're out. So every line I write for privileged code is habitually passed through my internal "what-if" filter. Not a great argument, really, as everyone, me included, is biased in estimating their own cognitive biases, but still, what's certain is that I'm very likely much more security-conscious than not... If this does not sound convincing, then I think it is better to simply drop the script and point to the Intel's site. I do respect and understand your security diligence, but I'm sure this script is not the most dangerous piece of software among those which an average user casually runs using sudo five times a day, really. |
| Oh, I see now that it's not in the standard repo but some special Intel repo. OK, you can leave it as-is. …On Fri, Apr 5, 2019 at 1:10 PM kkm (aka Kirill Katsnelson) < ***@***.***> wrote: Dan, I am not sure I understand which of the two options do you mean: just omit the 'exec sudo', or give the user the commands to run instead of scripting them? Both options look inferior, the latter more so. If first, there is less potential for error, and I'm adding command line options to skip as much stuff as possible (full message that also explains it to the user in @huangruizhe <https://github.com/huangruizhe>'s comment above): Restart this script using the 'sudo' command, as: sudo $0 -sp $distro $package ... more blah blah ... if [ -t 0 ]; then echo; read -ep "Run the above sudo command now? [Y/n]:" case $REPLY in ''|[Yy]*) set -x; exec sudo "$0" -sp "$distro" "$package" ... Nothing wrong with that, really. Say yes or retype the command? To me, yes is less error-prone. If you mean to "just give them commands to run", then it's not as simple as it sounds, and sometimes worse than ugly, for apt in particular. I won't copy the whole kaboom here, but look at this, including old/new apt detection: https://github.com/kaldi-asr/kaldi/blob/a4785af4e/tools/extras/install_mkl.sh#L213-L243 I did it quite the best recommended way. The old apt-key import way of dropping the signing key into the common store is not considered the best practice today, but is the only way to do it with apt before v1.2. This version is already rare in the wild (debian 7 and ubuntu 14, both EOL), but *all* instructions you'd find for setting apt repos suggest doing that--for simplicity, because apt does not have a way to do it correctly and simply, choose one. I'm faithfully doing the setup the long but the most secure way (as I always do on my own machine). So from the security standpoint, I am doing it significantly better than even the own Intel's instructions say. I'm even going as far as to give the notice that their apt is not the latest and how to restore the currently recommended, more secure setup when/if they upgrade the distro. And even further, I'm printing that notice *after* apt-get has finished its churn, so maybe the user would really read it... I've run serious interactive (using 'expect') tests of this script for correctness on 20 different Linuxes, here's the test harness: https://github.com/kkm000/install_mkl. Every command that is run in elevated privilege state is printed (set -x). As a final, although quite a weak argument, I'm with a SaaS company that works with customer's data, which means one break-in and we're out. So every line I write for privileged code is habitually passed through my internal "what-if" filter. Not a great argument, really, as everyone, me included, is biased in estimating their own cognitive biases, but still, what's certain is that I'm very likely much more security-conscious than not... If this does not sound convincing, then I think it is better to simply drop the script and point to the Intel's site. I do respect and understand your security diligence, but I'm sure this script is not the most dangerous piece of software among those which an average user casually runs using sudo five times a day, really. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#3194 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ADJVu9sW8iMlNO0ueM3-Dlv3Z2HnJ3Zeks5vd629gaJpZM4cVo0p> . |
Establish MATHLIB as the single ground-truth source for the chosen matrix algebra library.
| X-ref: Follow-up fix in #3216. |
Establish MATHLIB as the single ground-truth source for the chosen matrix algebra library.
Establish MATHLIB as the single ground-truth source for the chosen matrix algebra library.
Ok, here are my changes so far. The only thing I did not do here is change the configure default to MKL. so this may possibly be a WIP.
I debugged the script on 20 different Docker images, ranging from deprecated systems to the latest stable branches: https://github.com/kkm000/install_mkl. The tests use the expect tool, since the script asks to run sudo, sudo asks for the password, etc.
Now, how do we handle that transition overall? Just change the default blindly to MKL and see what is the fallout? I wold at least post a heads-up to the kaldi-help list. The current default is ATLAS, which is not good at all. What I am thinking of doing is maybe add some detection code (MKL in the recent packaging is very easy to detect, so it's either it's either in the system (just compiles) or in a well known directory /opt/inte/mkl). Except I do not know where to look for it on a Mac. My co-worker has a Mac, I'll email him to bring it, but I do not know if he still has it, and I do not remember if he's coming back from vacation today.
Generally, regarding openblas detection, I think invoking a test compile is a better approach than poking around trying to find it it's in the system in a known location. If it is, a compile with -l... will do the trick. If not, then it's likely missing. In any case, it's probably better to build OpenBLAS from source. At the very least, it might be better optimized for the user's system.
Running the reference CBLAS will probably be disastrously slow anyway.
So, in the end, I'm thinking we should, in the case the user did not ask for a specific math lib:
<cblas.h>, should work as is. debian packages use a known filename, I'll see if we can adapt it.I. e., do not probe for neither the reference blas or ATLAS, because these are rather inferior options.
What do you think? Am I making sense?
Close #3078