flame / blis

BLAS-like Library Instantiation Software Framework
Other
2.31k stars 367 forks source link

[feature] Building separate shared objects: libblas.so and libcblas.so #321

Open cdluminate opened 5 years ago

cdluminate commented 5 years ago

BLIS provides compat code for the BLAS/CBLAS API, which means we can use BLIS as an binary-compatible alternative to the reference BLAS/CBLAS. However, symlinking libblis.so.* into libblas.so.* and libcblas.so.* is questionable because during compilation, a program linked to the "libblas.so" will eventually require a library called libblis.so* due to the SONAME. For linux distributions that provide sort or "alternatives" mechanism such as Debian and Gentoo, being able to build seperate shared objects such as libblas.so* and libcblas.so* without downstream patches is a wonderful feature.

Debian's patch and Gentoo's patch are similar (same author). The current patches build libblis.so more than once with different SONAMEs, and hide some symbols with a customized linker script (see https://github.com/flame/blis/issues/301). This solution is working well but is not good enough.

For Gentoo, the most ideal solution is to build a libblas.so (SONAME=libblas.so.3) with BASE_OBJ_BLAS_PATH/%.o (excluding the CBLAS symbols) and a libcblas.so (SONAME=libcblas.so.3) with CBLAS objects. Both the two separate shared objects are linked against the libblis.so.* to avoid unnecessary redundant code.

For Debian, I think I have to stay at the "linker script" solution, because Debian is currently trying to introduce BLAS implementations compiled with different threadding model (e.g. blis-pthread, blis-openmp, blis-serial). These "variants" provide the samely-named libblis.so.2 which could be switched with the update-alternatives mechanism. Due to this design, linking seperated libblas.so* against libblis* would be quite ambiguous. So separated libblas.so should contain all the code in this case.

I tried to write a patch for building separated shared objects for Gentoo, but obviously I still need to manually select some object files from ./frame/base to avoid potential undefined symbol error.

This feature is for linux distribution integration, so please leave the actual work to me. I'll submit a PR when I have worked out a fine patch. Any comment?

CC: @heroxbd

fgvanzee commented 5 years ago

@cdluminate Thanks for volunteering to work on this. Just let me know if you have any questions about the inner workings of the top-level Makefile or build system. I always assume it may be a little trickier to decipher code that you did not write yourself. :)