Debian Codegraph @

kernels/armv8a/3/sup/bli_gemmsup_rv_armv8a_asm_d8x4m.c

raw symbols SCIP
1 /*
2
3 BLIS
4 An object-based framework for developing high-performance BLAS-like
5 libraries.
6
7 Copyright (C) 2014, The University of Texas at Austin
8 Copyright (C) 2019, Advanced Micro Devices, Inc.
9
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are
12 met:
13 - Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
15 - Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in the
17 documentation and/or other materials provided with the distribution.
18 - Neither the name(s) of the copyright holder(s) nor the names of its
19 contributors may be used to endorse or promote products derived
20 from this software without specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34 */
35
36 #include "blis.h"
37 #include "assert.h"
38
39
40 // Label locality & misc.
41 #include "../armv8a_asm_utils.h"
42
43 // Nanokernel operations.
44 #include "../armv8a_asm_d2x2.h"
45
46 /*
47 * +---+ +---+
48 * | 0 | | 4 |
49 * +---+ +---+
50 * +---+ +---+
51 * | 1 | | 5 |
52 * +---+ +---+
53 * +---+ +---+
54 * | 2 | | 6 |
55 * +---+ +---+
56 * +---+ +---+
57 * | 3 | | 7 |
58 * +---+ +---+
59 *
60 */
61 #define DGEMM_8X4_MKER_LOOP_PLAIN(C00,C10,C20,C30,C01,C11,C21,C31,C02,C12,C22,C32,C03,C13,C23,C33,A0,A1,A2,A3,B0,B1,BADDR,BSHIFT,LOADNEXT) \
62 DGEMM_2X2_NANOKERNEL(C00,C01,A0,B0) \
63 DGEMM_2X2_NANOKERNEL(C10,C11,A1,B0) \
64 DGEMM_2X2_NANOKERNEL(C20,C21,A2,B0) \
65 DGEMM_2X2_NANOKERNEL(C30,C31,A3,B0) \
66 DGEMM_LOAD1V_ ##LOADNEXT (B0,BADDR,BSHIFT) \
67 DGEMM_2X2_NANOKERNEL(C02,C03,A0,B1) \
68 DGEMM_2X2_NANOKERNEL(C12,C13,A1,B1) \
69 DGEMM_2X2_NANOKERNEL(C22,C23,A2,B1) \
70 DGEMM_2X2_NANOKERNEL(C32,C33,A3,B1)
71
72 // Interleaving load or not.
73 #define DGEMM_LOAD1V_noload(V1,ADDR,IMM)
74 #define DGEMM_LOAD1V_load(V1,ADDR,IMM) \
75 " ldr q"#V1", ["#ADDR", #"#IMM"] \n\t"
76
77 #define DLOADC_4V_C_FWD(C0,C1,C2,C3,CADDR,CSHIFT,LDC) \
78 DLOAD4V(C0,C1,C2,C3,CADDR,CSHIFT) \
79 " add "#CADDR", "#CADDR", "#LDC" \n\t"
80 #define DSTOREC_4V_C_FWD(C0,C1,C2,C3,CADDR,CSHIFT,LDC) \
81 DSTORE4V(C0,C1,C2,C3,CADDR,CSHIFT) \
82 " add "#CADDR", "#CADDR", "#LDC" \n\t"
83
84 #define DLOADC_4V_R_FWD(C00,C01,C10,C11,CADDR,CSHIFT,RSC) \
85 DLOAD2V(C00,C01,CADDR,CSHIFT) \
86 " add "#CADDR", "#CADDR", "#RSC" \n\t" \
87 DLOAD2V(C10,C11,CADDR,CSHIFT) \
88 " add "#CADDR", "#CADDR", "#RSC" \n\t"
89 #define DSTOREC_4V_R_FWD(C00,C01,C10,C11,CADDR,CSHIFT,RSC) \
90 DSTORE2V(C00,C01,CADDR,CSHIFT) \
91 " add "#CADDR", "#CADDR", "#RSC" \n\t" \
92 DSTORE2V(C10,C11,CADDR,CSHIFT) \
93 " add "#CADDR", "#CADDR", "#RSC" \n\t"
94
95 /*
96 * 8x4 kernel for dgemmsup.
97 *
98 * R-dimension too short.
99 * Not recommanded for use.
100 */
101 void bli_dgemmsup_rv_armv8a_asm_8x4m
102 (
103 conj_t conja,
104 conj_t conjb,
105 dim_t m0,
106 dim_t n0,
107 dim_t k0,
108 const void* alpha,
109 const void* a, inc_t rs_a0, inc_t cs_a0,
110 const void* b, inc_t rs_b0, inc_t cs_b0,
111 const void* beta,
112 void* c, inc_t rs_c0, inc_t cs_c0,
113 const auxinfo_t* data,
114 const cntx_t* cntx
115 )
116 {
117 // Fixme: This uker has no dispatching for unalighed sizes.
118 // Currently it only serves as a dispatch target for other kernels
119 // and cannot be registered in configurations.
120 assert( n0 == 4 );
121
122 const void* a_next = bli_auxinfo_next_a( data );
123 const void* b_next = bli_auxinfo_next_b( data );
124
125 uint64_t ps_a = bli_auxinfo_ps_a( data );
126
127 // Typecast local copies of integers in case dim_t and inc_t are a
128 // different size than is expected by load instructions.
129 uint64_t k_mker = k0 / 6;
130 uint64_t k_left = k0 % 6;
131
132 int64_t m_iter = m0 / 8;
133 int64_t m_left = m0 % 8;
134
135 uint64_t rs_a = rs_a0;
136 uint64_t cs_a = cs_a0;
137 uint64_t rs_b = rs_b0;
138 uint64_t rs_c = rs_c0;
139 uint64_t cs_c = cs_c0;
140 // uint64_t cs_b = cs_b0;
141 assert( cs_b0 == 1 );
142
143 if ( m_iter == 0 ) goto consider_edge_cases;
144
145 __asm__ volatile
146 (
147 " ldr x10, %[a] \n\t"
148 " ldr x13, %[c] \n\t"
149 " ldr x12, %[m_iter] \n\t"
150 " ldr x11, %[ps_a] \n\t" // Panel-skip of A.
151 " ldr x2, %[cs_a] \n\t" // Column-skip of A.
152 " ldr x9, %[rs_a] \n\t" // Row-skip of A.
153 " ldr x3, %[rs_b] \n\t" // Row-skip of B.
154 " \n\t"
155 " ldr x6, %[rs_c] \n\t" // Row-skip of C.
156 " ldr x7, %[cs_c] \n\t" // Column-skip of C.
157 " \n\t"
158 " \n\t" // Multiply some address skips by sizeof(double).
159 " lsl x11, x11, #3 \n\t" // ps_a
160 " lsl x9, x9, #3 \n\t" // rs_a
161 " lsl x2, x2, #3 \n\t" // cs_a
162 " lsl x3, x3, #3 \n\t" // rs_b
163 " lsl x6, x6, #3 \n\t" // rs_c
164 " lsl x7, x7, #3 \n\t" // cs_c
165 " \n\t"
166 LABEL(MILLIKER_MLOOP)
167 " \n\t"
168 " mov x0, x10 \n\t" // Parameters to be reloaded
169 " mov x5, x13 \n\t" // within each millikernel loop.
170 " ldr x1, %[b] \n\t"
171 " ldr x4, %[k_mker] \n\t"
172 " ldr x8, %[k_left] \n\t"
173 " \n\t"
174 // Storage scheme:
175 // V[ 0:15] <- C
176 // V[16:19] <- B; Allowed latency: 24 cycles / # of FPUs.
177 // V[20:31] <- A; Allowed latency: 32 cycles / # of FPUs.
178 // Under this scheme, the following is defined:
179 #define DGEMM_8X4_MKER_LOOP_PLAIN_LOC(A0,A1,A2,A3,B0,B1,BADDR,BSHIFT,LOADNEXT) \
180 DGEMM_8X4_MKER_LOOP_PLAIN(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,A0,A1,A2,A3,B0,B1,BADDR,BSHIFT,LOADNEXT)
181 LABEL(LOAD_ABC)
182 " \n\t" // No-microkernel early return is a must
183 " cmp x4, #0 \n\t" // to avoid out-of-boundary read.
184 BEQ(CLEAR_CCOLS)
185 " \n\t"
186 " mov x14, x0 \n\t"
187 " ld1 {v20.d}[0], [x14], x9 \n\t"
188 " ld1 {v20.d}[1], [x14], x9 \n\t"
189 " ld1 {v21.d}[0], [x14], x9 \n\t"
190 " ld1 {v21.d}[1], [x14], x9 \n\t"
191 " ld1 {v22.d}[0], [x14], x9 \n\t"
192 " ld1 {v22.d}[1], [x14], x9 \n\t"
193 " ld1 {v23.d}[0], [x14], x9 \n\t"
194 " ld1 {v23.d}[1], [x14], x9 \n\t"
195 " add x0, x0, x2 \n\t"
196 " mov x14, x0 \n\t"
197 " ld1 {v24.d}[0], [x14], x9 \n\t"
198 " ld1 {v24.d}[1], [x14], x9 \n\t"
199 " ld1 {v25.d}[0], [x14], x9 \n\t"
200 " ld1 {v25.d}[1], [x14], x9 \n\t"
201 " ld1 {v26.d}[0], [x14], x9 \n\t"
202 " ld1 {v26.d}[1], [x14], x9 \n\t"
203 " ld1 {v27.d}[0], [x14], x9 \n\t"
204 " ld1 {v27.d}[1], [x14], x9 \n\t"
205 " add x0, x0, x2 \n\t"
206 " mov x14, x0 \n\t"
207 " ld1 {v28.d}[0], [x14], x9 \n\t"
208 " ld1 {v28.d}[1], [x14], x9 \n\t"
209 " ld1 {v29.d}[0], [x14], x9 \n\t"
210 " ld1 {v29.d}[1], [x14], x9 \n\t"
211 " ld1 {v30.d}[0], [x14], x9 \n\t"
212 " ld1 {v30.d}[1], [x14], x9 \n\t"
213 " ld1 {v31.d}[0], [x14], x9 \n\t"
214 " ld1 {v31.d}[1], [x14], x9 \n\t"
215 " add x0, x0, x2 \n\t"
216 " \n\t"
217 " ldr q16, [x1, #16*0] \n\t"
218 " ldr q17, [x1, #16*1] \n\t"
219 " add x1, x1, x3 \n\t"
220 " ldr q18, [x1, #16*0] \n\t"
221 " ldr q19, [x1, #16*1] \n\t"
222 " add x1, x1, x3 \n\t"
223 LABEL(CLEAR_CCOLS)
224 CLEAR8V(0,1,2,3,4,5,6,7)
225 CLEAR8V(8,9,10,11,12,13,14,15)
226 // No-microkernel early return, once again.
227 BEQ(K_LEFT_LOOP)
228 //
229 // Microkernel is defined here as:
230 #define DGEMM_8X4_MKER_LOOP_PLAIN_LOC_FWD(A0,A1,A2,A3,B0,B1) \
231 DGEMM_8X4_MKER_LOOP_PLAIN_LOC(A0,A1,A2,A3,B0,B1,x1,0,load) \
232 "mov x14, x0 \n\t" \
233 "ld1 {v"#A0".d}[0], [x14], x9 \n\t" \
234 "ld1 {v"#A0".d}[1], [x14], x9 \n\t" \
235 "ld1 {v"#A1".d}[0], [x14], x9 \n\t" \
236 "ld1 {v"#A1".d}[1], [x14], x9 \n\t" \
237 "ld1 {v"#A2".d}[0], [x14], x9 \n\t" \
238 "ld1 {v"#A2".d}[1], [x14], x9 \n\t" \
239 "ld1 {v"#A3".d}[0], [x14], x9 \n\t" \
240 "ld1 {v"#A3".d}[1], [x14], x9 \n\t" \
241 "ldr q"#B1", [x1, #16*1] \n\t" \
242 "add x1, x1, x3 \n\t" \
243 "add x0, x0, x2 \n\t"
244 // Start microkernel loop.
245 LABEL(K_MKER_LOOP)
246 DGEMM_8X4_MKER_LOOP_PLAIN_LOC_FWD(20,21,22,23,16,17)
247 DGEMM_8X4_MKER_LOOP_PLAIN_LOC_FWD(24,25,26,27,18,19)
248 DGEMM_8X4_MKER_LOOP_PLAIN_LOC_FWD(28,29,30,31,16,17)
249 " \n\t" // Decrease counter before final replica.
250 " subs x4, x4, #1 \n\t" // Branch early to avoid reading excess mem.
251 BEQ(FIN_MKER_LOOP)
252 DGEMM_8X4_MKER_LOOP_PLAIN_LOC_FWD(20,21,22,23,18,19)
253 DGEMM_8X4_MKER_LOOP_PLAIN_LOC_FWD(24,25,26,27,16,17)
254 DGEMM_8X4_MKER_LOOP_PLAIN_LOC_FWD(28,29,30,31,18,19)
255 BRANCH(K_MKER_LOOP)
256 //
257 // Final microkernel loop.
258 LABEL(FIN_MKER_LOOP)
259 DGEMM_8X4_MKER_LOOP_PLAIN_LOC(20,21,22,23,18,19,x1,0,load)
260 " ldr q19, [x1, #16*1] \n\t"
261 " add x1, x1, x3 \n\t"
262 DGEMM_8X4_MKER_LOOP_PLAIN_LOC(24,25,26,27,16,17,xzr,-1,noload)
263 DGEMM_8X4_MKER_LOOP_PLAIN_LOC(28,29,30,31,18,19,xzr,-1,noload)
264 //
265 // Loops left behind microkernels.
266 LABEL(K_LEFT_LOOP)
267 " cmp x8, #0 \n\t" // End of exec.
268 BEQ(WRITE_MEM_PREP)
269 " mov x14, x0 \n\t"
270 " ld1 {v20.d}[0], [x14], x9 \n\t" // Load A col.
271 " ld1 {v20.d}[1], [x14], x9 \n\t"
272 " ld1 {v21.d}[0], [x14], x9 \n\t"
273 " ld1 {v21.d}[1], [x14], x9 \n\t"
274 " ld1 {v22.d}[0], [x14], x9 \n\t"
275 " ld1 {v22.d}[1], [x14], x9 \n\t"
276 " ld1 {v23.d}[0], [x14], x9 \n\t"
277 " ld1 {v23.d}[1], [x14], x9 \n\t"
278 " add x0, x0, x2 \n\t"
279 " ldr q16, [x1, #16*0] \n\t" // Load B col.
280 " ldr q17, [x1, #16*1] \n\t"
281 " add x1, x1, x3 \n\t"
282 " sub x8, x8, #1 \n\t"
283 DGEMM_8X4_MKER_LOOP_PLAIN_LOC(20,21,22,23,16,17,xzr,-1,noload)
284 BRANCH(K_LEFT_LOOP)
285 //
286 // Scale and write to memory.
287 LABEL(WRITE_MEM_PREP)
288 " ldr x4, %[alpha] \n\t" // Load alpha & beta (address).
289 " ldr x8, %[beta] \n\t"
290 " ld1r {v16.2d}, [x4] \n\t" // Load alpha & beta (value).
291 " ld1r {v17.2d}, [x8] \n\t"
292 " fmov d18, #1.0 \n\t"
293 " fcmp d16, d18 \n\t"
294 BEQ(UNIT_ALPHA)
295 DSCALE8V(0,1,2,3,4,5,6,7,16,0)
296 DSCALE8V(8,9,10,11,12,13,14,15,16,0)
297 LABEL(UNIT_ALPHA)
298 " \n\t"
299 " mov x1, x5 \n\t" // C address for loading.
300 " \n\t" // C address for storing is x5 itself.
301 " cmp x6, #8 \n\t" // Check for row-storage.
302 BNE(WRITE_MEM_R)
303 //
304 // C storage in columns.
305 LABEL(WRITE_MEM_C)
306 " fcmp d17, #0.0 \n\t"
307 BEQ(ZERO_BETA_C)
308 DLOADC_4V_C_FWD(20,21,22,23,x1,0,x7)
309 DLOADC_4V_C_FWD(24,25,26,27,x1,0,x7)
310 DSCALEA8V(0,1,2,3,4,5,6,7,20,21,22,23,24,25,26,27,17,0)
311 //
312 DLOADC_4V_C_FWD(20,21,22,23,x1,0,x7)
313 DLOADC_4V_C_FWD(24,25,26,27,x1,0,x7)
314 DSCALEA8V(8,9,10,11,12,13,14,15,20,21,22,23,24,25,26,27,17,0)
315 LABEL(ZERO_BETA_C)
316 //
317 DSTOREC_4V_C_FWD(0,1,2,3,x5,0,x7)
318 DSTOREC_4V_C_FWD(4,5,6,7,x5,0,x7)
319 DSTOREC_4V_C_FWD(8,9,10,11,x5,0,x7)
320 DSTOREC_4V_C_FWD(12,13,14,15,x5,0,x7)
321 BRANCH(END_WRITE_MEM)
322 //
323 // C storage in rows.
324 LABEL(WRITE_MEM_R)
325 // In-register transpose.
326 " trn1 v16.2d, v0.2d, v4.2d \n\t" // Row 0.
327 " trn1 v17.2d, v8.2d, v12.2d \n\t"
328 " trn2 v18.2d, v0.2d, v4.2d \n\t" // Row 1.
329 " trn2 v19.2d, v8.2d, v12.2d \n\t"
330 " trn1 v20.2d, v1.2d, v5.2d \n\t" // Row 2.
331 " trn1 v21.2d, v9.2d, v13.2d \n\t"
332 " trn2 v22.2d, v1.2d, v5.2d \n\t" // Row 3.
333 " trn2 v23.2d, v9.2d, v13.2d \n\t"
334 " trn1 v24.2d, v2.2d, v6.2d \n\t" // Row 4.
335 " trn1 v25.2d, v10.2d, v14.2d \n\t"
336 " trn2 v26.2d, v2.2d, v6.2d \n\t" // Row 5.
337 " trn2 v27.2d, v10.2d, v14.2d \n\t"
338 " trn1 v28.2d, v3.2d, v7.2d \n\t" // Row 6.
339 " trn1 v29.2d, v11.2d, v15.2d \n\t"
340 " trn2 v30.2d, v3.2d, v7.2d \n\t" // Row 7.
341 " trn2 v31.2d, v11.2d, v15.2d \n\t"
342 // " ld1r {v14.2d}, [x4] \n\t" // Reload alpha & beta (value).
343 " ld1r {v15.2d}, [x8] \n\t"
344 " fcmp d15, #0.0 \n\t"
345 BEQ(ZERO_BETA_R)
346 DLOADC_4V_R_FWD(0,1,2,3,x1,0,x6)
347 DLOADC_4V_R_FWD(4,5,6,7,x1,0,x6)
348 DSCALEA8V(16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,15,0)
349 //
350 DLOADC_4V_R_FWD(0,1,2,3,x1,0,x6)
351 DLOADC_4V_R_FWD(4,5,6,7,x1,0,x6)
352 DSCALEA8V(24,25,26,27,28,29,30,31,0,1,2,3,4,5,6,7,15,0)
353 LABEL(ZERO_BETA_R)
354 //
355 DSTOREC_4V_R_FWD(16,17,18,19,x5,0,x6)
356 DSTOREC_4V_R_FWD(20,21,22,23,x5,0,x6)
357 DSTOREC_4V_R_FWD(24,25,26,27,x5,0,x6)
358 DSTOREC_4V_R_FWD(28,29,30,31,x5,0,x6)
359 //
360 // End of this microkernel.
361 LABEL(END_WRITE_MEM)
362 " \n\t"
363 " subs x12, x12, #1 \n\t"
364 BEQ(END_EXEC)
365 " \n\t"
366 " mov x8, #8 \n\t"
367 " madd x13, x6, x8, x13 \n\t" // Forward C's base address to the next logic panel.
368 " add x10, x10, x11 \n\t" // Forward A's base address to the next logic panel.
369 BRANCH(MILLIKER_MLOOP)
370 //
371 // End of execution.
372 LABEL(END_EXEC)
373 :
374 : [a] "m" (a),
375 [b] "m" (b),
376 [c] "m" (c),
377 [rs_a] "m" (rs_a),
378 [cs_a] "m" (cs_a),
379 [ps_a] "m" (ps_a),
380 [rs_b] "m" (rs_b),
381 [rs_c] "m" (rs_c),
382 [cs_c] "m" (cs_c),
383 [m_iter] "m" (m_iter),
384 [k_mker] "m" (k_mker),
385 [k_left] "m" (k_left),
386 [alpha] "m" (alpha),
387 [beta] "m" (beta)
388 : "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
389 "x8", "x9", "x10","x11","x12","x13","x14",
390 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
391 "v8", "v9", "v10","v11","v12","v13","v14","v15",
392 "v16","v17","v18","v19","v20","v21","v22","v23",
393 "v24","v25","v26","v27","v28","v29","v30","v31"
394 );
395
396 consider_edge_cases:
397 a = ( double* )a + m_iter * ps_a;
398 c = ( double* )c + m_iter * 8 * rs_c;
399 // Edge case is within 1 millikernel loop of THIS kernel.
400 // Regarding the 6x?m kernel, the panel stride should be always local.
401 auxinfo_t data_6xkm = *data;
402 bli_auxinfo_set_ps_a( 6 * rs_a, &data_6xkm );
403 if ( m_left )
404 {
405 bli_dgemmsup_rv_armv8a_int_6x4mn
406 (
407 conja, conjb, m_left, 4, k0,
408 alpha, a, rs_a0, cs_a0, b, rs_b0, cs_b0,
409 beta, c, rs_c0, cs_c0, &data_6xkm, cntx
410 );
411 }
412
413 // Issue prefetch instructions only after
414 // execution is done.
415 __asm__
416 (
417 " mov x0, %[a_next] \n\t"
418 " mov x1, %[b_next] \n\t"
419 " prfm PLDL1STRM, [x0, #16*0] \n\t"
420 " prfm PLDL1STRM, [x0, #16*1] \n\t"
421 " prfm PLDL1STRM, [x0, #16*2] \n\t"
422 " prfm PLDL1KEEP, [x1, #16*0] \n\t"
423 " prfm PLDL1KEEP, [x1, #16*1] \n\t"
424 " prfm PLDL1KEEP, [x1, #16*2] \n\t"
425 :
426 : [a_next] "r" (a_next),
427 [b_next] "r" (b_next)
428 : "x0", "x1"
429 );
430 }
431