Debian Codegraph @

kernels/power10/3/bli_i4gemm_power10_mma.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
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are
11 met:
12 - Redistributions of source code must retain the above copyright
13 notice, this list of conditions and the following disclaimer.
14 - Redistributions in binary form must reproduce the above copyright
15 notice, this list of conditions and the following disclaimer in the
16 documentation and/or other materials provided with the distribution.
17 - Neither the name(s) of the copyright holder(s) nor the names of its
18 contributors may be used to endorse or promote products derived
19 from this software without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 */
34
35 #ifdef BLIS_SANDBOX_POWER10
36
37 #include "vector_int_macros.h"
38
39 #define I4_ACCUMULATE \
40 __builtin_mma_xvi4ger8pp (&acc0, ca[0], rb[0]); \
41 __builtin_mma_xvi4ger8pp (&acc1, ca[0], rb[1]); \
42 __builtin_mma_xvi4ger8pp (&acc2, ca[0], rb[2]); \
43 __builtin_mma_xvi4ger8pp (&acc3, ca[0], rb[3]); \
44 __builtin_mma_xvi4ger8pp (&acc4, ca[1], rb[0]); \
45 __builtin_mma_xvi4ger8pp (&acc5, ca[1], rb[1]); \
46 __builtin_mma_xvi4ger8pp (&acc6, ca[1], rb[2]); \
47 __builtin_mma_xvi4ger8pp (&acc7, ca[1], rb[3]);
48
49 #define I4_INCREMENT \
50 A0+=32; \
51 B0+=64;
52
53 #define I4_AB_PRODUCT \
54 LOAD_VECTORS \
55 I4_INCREMENT \
56 I4_ACCUMULATE
57
58 void bli_i4gemm_power10_mma_8x16
59 (
60 dim_t m,
61 dim_t n,
62 dim_t k,
63 //const int32_t* alpha,
64 //const nibbles* a,
65 //const nibbles* b,
66 //const int32_t* beta,
67 // int32_t* c, inc_t rs_c0, inc_t cs_c0,
68 const void* alpha,
69 const void* a,
70 const void* b,
71 const void* beta,
72 void* c, inc_t rs_c0, inc_t cs_c0,
73 const auxinfo_t* data,
74 const cntx_t* cntx
75 )
76 {
77
78 uint64_t k_iter = (k-1) / 4;
79 uint64_t k_left = (k-1) % 4;
80
81 uint64_t rs_c = rs_c0;
82 //uint64_t cs_c = cs_c0;
83
84 const nibbles* restrict A0 = a;
85 const nibbles* restrict B0 = b;
86 int* restrict C0 = c;
87
88 int alpha_ = *((int32_t*)alpha),
89 beta_ = *((int32_t*)beta);
90
91 iv4sf_t result[4];
92 iv4sf_t *rowC;
93
94 // accumulators that will hold the matrix product
95 __vector_quad acc0, acc1, acc2, acc3,
96 acc4, acc5, acc6, acc7;
97
98 vec_t *ca = (vec_t *) A0;
99 vec_t *rb = (vec_t *) B0;
100
101 __builtin_mma_xvi4ger8 (&acc0, ca[0], rb[0]);
102 __builtin_mma_xvi4ger8 (&acc1, ca[0], rb[1]);
103 __builtin_mma_xvi4ger8 (&acc2, ca[0], rb[2]);
104 __builtin_mma_xvi4ger8 (&acc3, ca[0], rb[3]);
105 __builtin_mma_xvi4ger8 (&acc4, ca[1], rb[0]);
106 __builtin_mma_xvi4ger8 (&acc5, ca[1], rb[1]);
107 __builtin_mma_xvi4ger8 (&acc6, ca[1], rb[2]);
108 __builtin_mma_xvi4ger8 (&acc7, ca[1], rb[3]);
109
110 I4_INCREMENT
111
112 // k loop (unrolled by 4)
113 for (int k = 0; k<k_iter; k++)
114 {
115 I4_AB_PRODUCT
116 I4_AB_PRODUCT
117 I4_AB_PRODUCT
118 I4_AB_PRODUCT
119 }
120
121 // edge loop
122 for (int k = 0; k<k_left; k++)
123 {
124 I4_AB_PRODUCT
125 }
126
127 // handle beta cases
128 if (beta_ != 0.0)
129 {
130 SAVE_ACC(iv4sf_t, &acc0, rs_c, 0 );
131 SAVE_ACC(iv4sf_t, &acc1, rs_c, 4 );
132 SAVE_ACC(iv4sf_t, &acc2, rs_c, 8 );
133 SAVE_ACC(iv4sf_t, &acc3, rs_c, 12 );
134 SAVE_ACC(iv4sf_t, &acc4, rs_c, 4*rs_c);
135 SAVE_ACC(iv4sf_t, &acc5, rs_c, 4+4*rs_c);
136 SAVE_ACC(iv4sf_t, &acc6, rs_c, 8+4*rs_c);
137 SAVE_ACC(iv4sf_t, &acc7, rs_c, 12+4*rs_c);
138 }
139 else
140 {
141 SAVE_ACC_bz(iv4sf_t, &acc0, rs_c, 0 );
142 SAVE_ACC_bz(iv4sf_t, &acc1, rs_c, 4 );
143 SAVE_ACC_bz(iv4sf_t, &acc2, rs_c, 8 );
144 SAVE_ACC_bz(iv4sf_t, &acc3, rs_c, 12 );
145 SAVE_ACC_bz(iv4sf_t, &acc4, rs_c, 4*rs_c);
146 SAVE_ACC_bz(iv4sf_t, &acc5, rs_c, 4+4*rs_c);
147 SAVE_ACC_bz(iv4sf_t, &acc6, rs_c, 8+4*rs_c);
148 SAVE_ACC_bz(iv4sf_t, &acc7, rs_c, 12+4*rs_c);
149 }
150 }
151 #endif // BLIS_SANDBOX_POWER10