Gentoo Archives: gentoo-dev

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

Attachments

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

Replies

Subject Author
Re: [gentoo-dev] RFC: BLAS and LAPACK runtime switching David Seifert <soap@g.o>