Gentoo Archives: gentoo-commits

From: WANG Xuerui <xen0n@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: sci-libs/openblas/files/, sci-libs/openblas/
Date: Fri, 13 May 2022 12:58:07
Message-Id: 1652446647.c3426da5b81db4d54864ea17d31074e0c60d7e35.xen0n@gentoo
1 commit: c3426da5b81db4d54864ea17d31074e0c60d7e35
2 Author: WANG Xuerui <xen0n <AT> gentoo <DOT> org>
3 AuthorDate: Fri May 13 12:44:07 2022 +0000
4 Commit: WANG Xuerui <xen0n <AT> gentoo <DOT> org>
5 CommitDate: Fri May 13 12:57:27 2022 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=c3426da5
7
8 sci-libs/openblas: fix build on loong
9
10 Closes: https://bugs.gentoo.org/844013
11 Signed-off-by: WANG Xuerui <xen0n <AT> gentoo.org>
12
13 .../openblas/files/openblas-0.3.20-fix-loong.patch | 178 +++++++++++++++++++++
14 sci-libs/openblas/openblas-0.3.20.ebuild | 1 +
15 2 files changed, 179 insertions(+)
16
17 diff --git a/sci-libs/openblas/files/openblas-0.3.20-fix-loong.patch b/sci-libs/openblas/files/openblas-0.3.20-fix-loong.patch
18 new file mode 100644
19 index 000000000000..2745d26cb3a5
20 --- /dev/null
21 +++ b/sci-libs/openblas/files/openblas-0.3.20-fix-loong.patch
22 @@ -0,0 +1,178 @@
23 +https://github.com/xianyi/OpenBLAS/pull/3626, rebased on top of v0.3.20.
24 +
25 +From: WANG Xuerui <xen0n@g.o>
26 +Date: Fri, 13 May 2022 15:26:33 +0800
27 +Subject: [PATCH 1/3] Move LoongArch make rules to Makefile.loongarch64
28 +
29 +--- a/Makefile.loongarch64
30 ++++ b/Makefile.loongarch64
31 +@@ -1,3 +1,4 @@
32 +-ifdef BINARY64
33 +-else
34 ++ifeq ($(CORE), LOONGSON3R5)
35 ++CCOMMON_OPT += -march=loongarch64 -mabi=lp64
36 ++FCOMMON_OPT += -march=loongarch64 -mabi=lp64
37 + endif
38 +--- a/Makefile.system
39 ++++ b/Makefile.system
40 +@@ -886,13 +886,6 @@ ifeq ($(OSNAME), AIX)
41 + BINARY_DEFINED = 1
42 + endif
43 +
44 +-ifeq ($(ARCH), loongarch64)
45 +-ifeq ($(CORE), LOONGSON3R5)
46 +-CCOMMON_OPT += -march=loongarch64 -mabi=lp64
47 +-FCOMMON_OPT += -march=loongarch64 -mabi=lp64
48 +-endif
49 +-endif
50 +-
51 + endif
52 +
53 + ifndef BINARY_DEFINED
54 +From: WANG Xuerui <xen0n@g.o>
55 +Date: Fri, 13 May 2022 15:53:22 +0800
56 +Subject: [PATCH 2/3] Probe for old-world LASX flavor on LoongArch and use
57 + generic DGEMM kernel otherwise
58 +
59 +See: https://bugs.gentoo.org/844013
60 +--- a/Makefile.system
61 ++++ b/Makefile.system
62 +@@ -1683,6 +1683,7 @@ export TARGET_CORE
63 + export NO_AVX512
64 + export NO_AVX2
65 + export BUILD_BFLOAT16
66 ++export NO_LASX
67 +
68 + export SBGEMM_UNROLL_M
69 + export SBGEMM_UNROLL_N
70 +--- a/c_check
71 ++++ b/c_check
72 +@@ -270,6 +270,37 @@ if (($architecture eq "x86") || ($architecture eq "x86_64")) {
73 + }
74 + }
75 +
76 ++$no_lasx = 0;
77 ++if (($architecture eq "loongarch64")) {
78 ++ eval "use File::Temp qw(tempfile)";
79 ++ if ($@){
80 ++ warn "could not load PERL module File::Temp, so could not check compiler compatibility with the LoongArch LASX extension";
81 ++ # Assume no LASX, because currently LASX is only present in vendor
82 ++ # toolchains, undocumented nor upstreamed.
83 ++ $no_lasx = 1;
84 ++ } else {
85 ++ # Old-world assembly flavor: LASX registers named "$xrNN", different
86 ++ # from the ISA manual which suggests "$xNN". This is the flavor we
87 ++ # currently support.
88 ++ #
89 ++ # As the LASX ISA manual is not out yet, we cannot predict what the
90 ++ # new-world flavor would look like, so do not probe flavor for now.
91 ++ # The compiler flags are also unsuitable for new-world gcc.
92 ++ ($fh,$tmpf) = tempfile( SUFFIX => '.c' , UNLINK => 1 );
93 ++ $code = '"xvld $xr0, $a0, 0\n"';
94 ++ print $fh "int main(void){ __asm__ volatile($code); }\n";
95 ++ $args = " -march=loongarch64 -mabi=lp64 -mlasx -c -o $tmpf.o $tmpf";
96 ++ my @cmd = ("$compiler_name $flags $args >/dev/null 2>/dev/null");
97 ++ system(@cmd) == 0;
98 ++ if ($? != 0) {
99 ++ $no_lasx = 1;
100 ++ } else {
101 ++ $no_lasx = 0;
102 ++ }
103 ++ unlink("$tmpf.o");
104 ++ }
105 ++}
106 ++
107 + $c11_atomics = 0;
108 + if ($data =~ /HAVE_C11/) {
109 + eval "use File::Temp qw(tempfile)";
110 +@@ -393,6 +424,7 @@ print MAKEFILE "HAVE_MSA=1\n" if $have_msa eq 1;
111 + print MAKEFILE "MSA_FLAGS=$msa_flags\n" if $have_msa eq 1;
112 + print MAKEFILE "NO_AVX512=1\n" if $no_avx512 eq 1;
113 + print MAKEFILE "NO_AVX2=1\n" if $no_avx2 eq 1;
114 ++print MAKEFILE "NO_LASX=1\n" if $no_lasx eq 1;
115 + print MAKEFILE "OLDGCC=1\n" if $oldgcc eq 1;
116 +
117 + $os =~ tr/[a-z]/[A-Z]/;
118 +--- a/kernel/loongarch64/KERNEL.LOONGSON3R5
119 ++++ b/kernel/loongarch64/KERNEL.LOONGSON3R5
120 +@@ -1,3 +1,7 @@
121 ++ifeq ($(NO_LASX), 1)
122 ++# No LASX support in compiler, unable to consume the optimized version
123 ++# leave out DGEMMKERNEL to pull in the generic version
124 ++else
125 + DGEMMKERNEL = dgemm_kernel_16x4.S
126 + DGEMMINCOPY = dgemm_ncopy_16.S
127 + DGEMMITCOPY = dgemm_tcopy_16.S
128 +@@ -7,6 +11,7 @@ DGEMMINCOPYOBJ = dgemm_incopy.o
129 + DGEMMITCOPYOBJ = dgemm_itcopy.o
130 + DGEMMONCOPYOBJ = dgemm_oncopy.o
131 + DGEMMOTCOPYOBJ = dgemm_otcopy.o
132 ++endif
133 +
134 + DTRSMKERNEL_LN = ../generic/trsm_kernel_LN.c
135 + DTRSMKERNEL_LT = ../generic/trsm_kernel_LT.c
136 +From: WANG Xuerui <xen0n@g.o>
137 +Date: Fri, 13 May 2022 16:23:46 +0800
138 +Subject: [PATCH 3/3] Fix ABI CFLAGS setting on new-world LoongArch
139 +
140 +See: https://bugs.gentoo.org/844013
141 +--- a/Makefile.loongarch64
142 ++++ b/Makefile.loongarch64
143 +@@ -1,4 +1,13 @@
144 + ifeq ($(CORE), LOONGSON3R5)
145 +-CCOMMON_OPT += -march=loongarch64 -mabi=lp64
146 +-FCOMMON_OPT += -march=loongarch64 -mabi=lp64
147 ++CCOMMON_OPT += -march=loongarch64
148 ++FCOMMON_OPT += -march=loongarch64
149 ++
150 ++ifeq ($(LOONGARCH_CC_FLAVOR), NEW)
151 ++CCOMMON_OPT += -mabi=lp64d
152 ++FCOMMON_OPT += -mabi=lp64d
153 ++endif
154 ++ifeq ($(LOONGARCH_CC_FLAVOR), OLD)
155 ++CCOMMON_OPT += -mabi=lp64
156 ++FCOMMON_OPT += -mabi=lp64
157 ++endif
158 + endif
159 +--- a/Makefile.system
160 ++++ b/Makefile.system
161 +@@ -1683,6 +1683,7 @@ export TARGET_CORE
162 + export NO_AVX512
163 + export NO_AVX2
164 + export BUILD_BFLOAT16
165 ++export LOONGARCH_CC_FLAVOR
166 + export NO_LASX
167 +
168 + export SBGEMM_UNROLL_M
169 +--- a/c_check
170 ++++ b/c_check
171 +@@ -270,6 +270,21 @@ if (($architecture eq "x86") || ($architecture eq "x86_64")) {
172 + }
173 + }
174 +
175 ++$loongarch_cc_flavor = "";
176 ++if (($architecture eq "loongarch64")) {
177 ++ # Currently there are only 2 flavors: new-world and old-world.
178 ++ # They differ in ABI names accepted, so check it to avoid creating temp
179 ++ # files.
180 ++ $args = " -mabi=lp64d -E -o - /dev/null";
181 ++ my @cmd = ("$compiler_name $flags $args >/dev/null 2>/dev/null");
182 ++ system(@cmd) == 0;
183 ++ if ($? != 0) {
184 ++ $loongarch_cc_flavor = "OLD";
185 ++ } else {
186 ++ $loongarch_cc_flavor = "NEW";
187 ++ }
188 ++}
189 ++
190 + $no_lasx = 0;
191 + if (($architecture eq "loongarch64")) {
192 + eval "use File::Temp qw(tempfile)";
193 +@@ -424,6 +439,7 @@ print MAKEFILE "HAVE_MSA=1\n" if $have_msa eq 1;
194 + print MAKEFILE "MSA_FLAGS=$msa_flags\n" if $have_msa eq 1;
195 + print MAKEFILE "NO_AVX512=1\n" if $no_avx512 eq 1;
196 + print MAKEFILE "NO_AVX2=1\n" if $no_avx2 eq 1;
197 ++print MAKEFILE "LOONGARCH_CC_FLAVOR=$loongarch_cc_flavor\n" if $architecture eq "loongarch64";
198 + print MAKEFILE "NO_LASX=1\n" if $no_lasx eq 1;
199 + print MAKEFILE "OLDGCC=1\n" if $oldgcc eq 1;
200 +
201
202 diff --git a/sci-libs/openblas/openblas-0.3.20.ebuild b/sci-libs/openblas/openblas-0.3.20.ebuild
203 index 5d2349e6998f..5b1ac906fd43 100644
204 --- a/sci-libs/openblas/openblas-0.3.20.ebuild
205 +++ b/sci-libs/openblas/openblas-0.3.20.ebuild
206 @@ -28,6 +28,7 @@ BDEPEND="virtual/pkgconfig"
207 PATCHES=(
208 "${FILESDIR}/${PN}-0.3.12-shared-blas-lapack.patch"
209 "${FILESDIR}/${PN}-0.3.20-fix-riscv.patch"
210 + "${FILESDIR}/${PN}-0.3.20-fix-loong.patch"
211 )
212
213 pkg_pretend() {