-
Notifications
You must be signed in to change notification settings - Fork 5.4k
[src] Remove configure support for threaded math #4185
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
[src] Remove configure support for threaded math #4185
Conversation
@jtrmal, if you have a few minutes, could you PTAL? I checked MKL, but I do not have Atlas handy, although changes there are minimal. |
LGTM, please merge
…On Tue, Jul 21, 2020 at 10:33 AM kkm000 ***@***.***> wrote:
@kkm000 <https://github.com/kkm000> requested your review on: #4185
<#4185> [src] Remove configure
support for threaded math.
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#4185 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACUKYX2ISR2NIPZMSSDBBFDR4VHGTANCNFSM4PB5YMZA>
.
|
@jtrmal Thanks! |
Unfortunately, this PR broke static MKL compilation. Originally link lines for static MKL contained Possible fixes are:
to
I'm not sure what is the best way to do static linking, but I'm happy to provide a PR if needed. |
Would be great if you could provide a PR, Peter! Sorry dont have an
opinion about which is best, you can decide.
…On Thu, Aug 13, 2020 at 7:20 AM Peter Smit ***@***.***> wrote:
Unfortunately, this PR broke static MKL compilation. Originally link lines
for static MKL contained -l/opt/intel/mkl/lib/intel64/libmkl_core.a and
this has been changed to -lmkl. For static compilation, the search path
is not set, so this fails.
Possible fixes are:
1. Also set the search path (-L) for static compilation (like for
non-static
https://github.com/kaldi-asr/kaldi/blob/master/src/configure#L283).
Not sure if that would solve the problem.
2. Restore the old link line by changing
https://github.com/kaldi-asr/kaldi/blob/master/src/configure#L295 from:
linkline+=" -l$file"
to
if ! $static; then
linkline+=" -l$file"
else
linkline+="-l$libfile"
fi
I'm not sure what is the best option, but I'm happy to provide a PR if
needed.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#4185 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAZFLO6C6GOX3NYO3IN6NFTSAMPTDANCNFSM4PB5YMZA>
.
|
@psmit, I've seen your PR, thanks. I am wondering what benefits you are getting form linking to MKL statically, and what are the binary sizes? If you have an approximate idea by how much this increases the binary sizes? They are about 20GB on Linux x64 with gcc and dynamic MKL. I think—better said, thought—that we should to switch to their "single runtime library" linking, or otherwise there are conflicts when calling Kaldi libraries from Python. But that is not available in static. Understanding your use case would be very helpful for us. |
@kkm000 I haven't tested this PR or @psmit's yet, but I statically link MKL to simplify distribution. My project only needs to distribute (from Kaldi) one shared library (which is used by Python via cffi) and a few CLI programs, and doing so is far simpler when linking MKL & OpenFST statically. I would hate to lose that ability. |
@kkm000 For me, the benefit is to be able to distribute very simple/lean/small docker images. During decoding, we only have a single binary application, and static compiling with MKL gives smaller binaries than binary + mkl shared libraries. Also, if we would install the shared MKL libraries through a package manager, it would include a lot of shared libs that aren't even needed. That said, static MKL compilation is sometimes a pain. We link with a rust binary, and using link groups isn't really supported there (unless you dive deep into the cargo config, which is what we did). |
One thing I now realize is that in my case I do the linking of the final binary outside the kaldi tree. Out of "habit" I specify static mkl with the configure command... I guess things should also work if I specify "static kaldi" + "shared mkl" during configure, and once I link my binary with the kaldi static libs, I specify static mkl myself... (Only downside, I have to make sure I have a working shared MKL on my machine to pass the I'll try to find some time next week to experiment with this. I agree that for compiling |
Thanks, interesting, I did not expect that, a good observation. Are you sure that all possible kernels are linked in? I.e., AVX, AVX2 and AVX512 at the minimum? There is a chapter in the 1300-page MKL manual dedicated to this, I read it once around 2014, probably the time to get back to it...
As is, no. But there is a little known syntax
Do not miss that I find it much more potable than
Easy, but you're still looking at ~700MB. Ah, wait. Totally forgot that you can delete the Here's the complete recipe. The idea is to The Dockerfile below does these tricks in a debian image, and copies only the required part of MKL into an empty, non-runnable image with MKL alone: The script run in the Dockerfile may not be the easiest to follow, but I'm sure you'll figure it out: Basically, what it does is:
If you go back to the Dockerfile, you'll see that /opt from that image is copied in the next stage into an empty image Then I do the same thing with CUDA (look in lib/cuda if you want). Again, you can keep it unchanged until you get hold of a new GPUs that needs a later CUDA, or Kaldi is updated with a new arch. I call these images drones: they are unrunnable, but can be added to other images, like When it comes to making Kaldi, I augment the prepared toolchain container, going by name The syntax here is likely unfamiliar, but you'll guess what's going on: the first 3 steps pull the 3 images in parallel, and, when all 3 are available, the 4th layers MKL and CUDA into cxx using this trivial
I am not sure I grok the idea. Of course, unlike the .so case. you do not link a static Kaldi library, you only build an $AR archive of .o files. These contain references to whatever they call, essentially the MKL libs. The final magic only happens when you build the final binary. But I am not sure if the linker does not care if the reference libraries were pure object archives (.a) or DLLs (.so). You can easily see with
Patch it out. A sleight of sed will take care of it as part of build. (see, e.g., this. The "sorry" comment applies to the debugging phase on local machine, when it mangles files in your Git workdir). The test is useless for you, since you are building for a target different than your machine. Also, keep in mind that Kaldi's build is designed to allow a build by a non-privileged user. We "hardcode" paths into all binaries, but it does not mean they cannot be shuffled around: the rpath in the binary is only the default. If This is the point where our paths diverge, but not entirely. After the build, I simply tarball binaries and I do not do that in this script, because of a technicality: this is a separate disk, and I'll merge your change as is. I'm planning to work on configure anyway, and it's a perfectly valid emergency fix. |
Thanks for merging and the extensive comment. Regarding MKL, I'm pretty sure all the architectures are in the binary, but that is more a guess than that I checked (or read that manual). Many of the techniques mentioned, like multi-stage docker files, are indeed what we are using. It took us a lot of time to get our image sizes down, and for us, this was back then with the static MKL. In the near future, I'm looking to bench things more on our side, if this happens I'll share the results and observations also here. |
Closes #3192