Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] RFC: BLAS and LAPACK runtime switching
Date: Wed, 29 May 2019 13:32:51
Message-Id: 9d42e0cc818985fcc8141743bbd840b85a58557e.camel@gentoo.org
In Reply to: [gentoo-dev] RFC: BLAS and LAPACK runtime switching by Mo Zhou
1 On Tue, 2019-05-28 at 01:37 -0700, Mo Zhou wrote:
2 > Different BLAS/LAPACK implementations are expected to be compatible
3 > to each other in both the API and ABI level. They can be used as
4 > drop-in replacement to the others. This sounds nice, but the difference
5 > in SONAME hampered the gentoo integration of well-optimized ones.
6
7 If SONAMEs are different, then they are not compatible by definition.
8
9 > Assume a Gentoo user compiled a pile of packages on top of the reference
10 > BLAS and LAPACK, namely these reverse dependencies are linked against
11 > libblas.so.3 and liblapack.so.3 . When the user discovered that
12 > OpenBLAS provides much better performance, they'll have to recompile
13 > the whole reverse dependency tree in order to take advantage from
14 > OpenBLAS,
15 > because the SONAME of OpenBLAS is libopenblas.so.0 . When the user
16 > wants to try MKL (libmkl_rt.so), they'll have to recompile the whole
17 > reverse dependency tree again.
18 >
19 > This is not friendly to our earth.
20 >
21 > Goal
22 > ----
23 >
24 > * When a program is linked against libblas.so or liblapack.so
25 > provided by any BLAS/LAPACK provider, the eselect-based solution
26 > will allow user to switch the underlying library without recompiling
27 > anything.
28 >
29 > * When a program is linked against a specific implementation, e.g.
30 > libmkl_rt.so, the solution doesn't break anything.
31 >
32 > Solution
33 > --------
34 >
35 > Similar to Debian's update-alternatives mechanism, Gentoo's eselect
36 > is good at dealing with drop-in replacements as well. My preliminary
37 > investigation suggests that eselect is enough for enabling BLAS/LAPACK
38 > runtime switching. Hence, the proposed solution is eselect-based:
39 >
40 > * Every BLAS/LAPACK implementation should provide generic library
41 > and eselect candidate libraries at the same time. Taking netlib,
42 > BLIS and OpenBLAS as examples:
43 >
44 > reference:
45 >
46 > usr/lib64/blas/reference/libblas.so.3 (SONAME=libblas.so.3)
47 > -- default BLAS provider
48 > -- candidate of the eselect "blas" unit
49 > -- will be symlinked to usr/lib64/libblas.so.3 by eselect
50
51 /usr/lib64 is not supposed to be modified by eselect, it's package
52 manager area. Yes, I know a lot of modules still do that but that's no
53 reason to make things worse when people are putting significant effort
54 to actually improve things.
55
56 > usr/lib64/lapack/reference/liblapack.so.3 (SONAME=liblapack.so.3)
57 > -- default LAPACK provider
58 > -- candidate of the eselect "lapack" unit
59 > -- will be symlinked to usr/lib64/liblapack.so.3 by eselect
60 >
61 > blis (doesn't provide LAPACK):
62 >
63 > usr/lib64/libblis.so.2 (SONAME=libblis.so.2)
64 > -- general purpose
65 >
66 > usr/lib64/blas/blis/libblas.so.3 (SONAME=libblas.so.3)
67 > -- candidate of the eselect "blas" unit
68 > -- will be symlinked to usr/lib64/libblas.so.3 by eselect
69 > -- compiled from the same set of object files as libblis.so.2
70 >
71 > openblas:
72 >
73 > usr/lib64/libopenblas.so.0 (SONAME=libopenblas.so.0)
74 > -- general purpose
75 >
76 > usr/lib64/blas/openblas/libblas.so.3 (SONAME=libblas.so.3)
77 > -- candidate of the eselect "blas" unit
78 > -- will be symlinked to usr/lib64/libblas.so.3 by eselect
79 > -- compiled from the same set of object files as
80 > libopenblas.so.0
81 >
82 > usr/lib64/lapack/openblas/liblapack.so.3 (SONAME=liblapack.so.3)
83 > -- candidate of the eselect "lapack" unit
84 > -- will be symlinked to usr/lib64/liblapack.so.3 by eselect
85 > -- compiled from the same set of object files as
86 > libopenblas.so.0
87 >
88 > This solution is similar to Debian's[3]. This solution achieves our
89 > goal,
90 > and it requires us to patch upstream build systems (same to Debian).
91 > Preliminary demonstration for this solution is available, see below.
92
93 So basically the three walls of text say in round-about way that you're
94 going to introduce custom hacks to recompile libraries with different
95 SONAME. Ok.
96
97 >
98 > Is this solution reliable?
99 > --------------------------
100 >
101 > * A similar solution has been used by Debian for many years.
102 > * Many projects call BLAS/LAPACK libraries through FFI, including Julia.
103 > (See Julia's standard library: LinearAlgebra)
104 >
105 > Proposed Changes
106 > ----------------
107 >
108 > 1. Deprecate sci-libs/{blas,cblas,lapack,lapacke}-reference from gentoo
109 > main repo. They use exactly the same source tarball. It's not quite
110 > helpful to package these components in a fine-grained manner. A
111 > single
112 > sci-libs/lapack package is enough.
113
114 Where's the gain in that?
115
116 > 2. Merge the "cblas" eselect unit into "blas" unit. It is potentially
117 > harmful when "blas" and "cblas" point to different implementations.
118 > That means "app-eselect/eselect-cblas" should be deprecated.
119 >
120 > 3. Update virtual/{blas,cblas,lapack,lapacke}. BLAS/LAPACK providers
121 > will be registered in their dependency information.
122 >
123 > Note, ebuilds for BLAS/LAPACK reverse dependencies are expected to work
124 > with these changes correctly without change. For example, my local
125 > numpy-1.16.1 compilation was successful without change.
126 >
127 > Preliminary Demonstration
128 > -------------------------
129 >
130 > The preliminary implementation is available in my personal overlay[4].
131 > A simple sanity test script `check-cpp.sh` is provided to illustrate
132 > the effectiveness of the proposed solution.
133 >
134 > The script `check-cpp.sh` compiles two C++ programs -- one calls general
135 > matrix-matrix multiplication from BLAS, while another one calls general
136 > singular value decomposition from LAPACK. Once compiled, this script
137 > will switch different BLAS/LAPACK implementations and run the C++
138 > programs
139 > without recompilation.
140 >
141 > The preliminary result is avaiable here[5]. (CPU=Power9, ARCH=ppc64le)
142 > From the experimental results, we find that
143 >
144 > For (512x512) single precision matrix multiplication:
145 > * reference BLAS takes ~360 ms
146 > * BLIS takes ~70 ms
147 > * OpenBLAS takes ~10 ms
148 >
149 > For (512x512) single precision singular value decomposition:
150 > * reference LAPACK takes ~1900 ms
151 > * BLIS (+reference LAPACK) takes ~1500 ms
152 > * OpenBLAS takes ~1100 ms
153 >
154 > The difference in computation speed illustrates the effectiveness of
155 > the proposed solution. Theoretically, any other package could take
156 > advantage from this solution without any recompilation as long as
157 > it's linked against a library with SONAME.
158
159 An actual ABI compliance test, e.g. done using abi-compliance-checker
160 would be more interesting.
161
162 >
163 > Acknowledgement
164 > ---------------
165 > This is an on-going GSoC-2019 Porject:
166 > https://summerofcode.withgoogle.com/projects/?sp-page=2#6268942782300160
167
168 It would probably have been better if the project was discussed before
169 GSoC. I'm really against pushing a bad idea forward just because
170 someone set it for GSoC without discussing it first.
171
172 --
173 Best regards,
174 Michał Górny

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies

Subject Author
Re: [gentoo-dev] RFC: BLAS and LAPACK runtime switching Benda Xu <heroxbd@g.o>