1 /*
3 BLIS
4 An object-based framework for developing high-performance BLAS-like
5 libraries.
7 Copyright (C) 2014, The University of Texas at Austin
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 of The University of Texas at Austin nor the names
18 of its contributors may be used to endorse or promote products
19 derived from this software without specific prior written permission.
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.
33 */
35 #include "blis.h"
37 #ifdef BLIS_ENABLE_C66X_BUILD
38 //#define BLIS_ENABLE_CYCLE_COUNT_BLIS_GEMM_INT
39 #endif
41 #define FUNCPTR_T herk_fp
43 typedef void (*FUNCPTR_T)( obj_t* a,
44 obj_t* ah,
45 obj_t* c,
46 gemm_t* cntl,
47 herk_thrinfo_t* thread );
49 static FUNCPTR_T vars[2][4][3] =
50 {
51 // lower
52 {
53 // unblocked optimized unblocked blocked
54 { NULL, NULL, bli_herk_blk_var1f },
55 { NULL, bli_herk_l_ker_var2, bli_herk_blk_var2f },
56 { NULL, NULL, bli_herk_blk_var3f },
57 { NULL, NULL, NULL },
58 },
59 // upper
60 {
61 // unblocked optimized unblocked blocked
62 { NULL, NULL, bli_herk_blk_var1f },
63 { NULL, bli_herk_u_ker_var2, bli_herk_blk_var2f },
64 { NULL, NULL, bli_herk_blk_var3f },
65 { NULL, NULL, NULL },
66 }
67 };
69 void bli_herk_int( obj_t* alpha,
70 obj_t* a,
71 obj_t* ah,
72 obj_t* beta,
73 obj_t* c,
74 gemm_t* cntl,
75 herk_thrinfo_t* thread )
76 {
77 obj_t a_local;
78 obj_t ah_local;
79 obj_t c_local;
80 varnum_t n;
81 impl_t i;
82 bool_t uplo;
83 FUNCPTR_T f;
84 #ifdef BLIS_ENABLE_CYCLE_COUNT_BLIS_GEMM_INT
85 volatile int counter_start;
86 volatile int counter_end;
87 #endif
89 // Check parameters.
90 if ( bli_error_checking_is_enabled() )
91 bli_herk_int_check( alpha, a, ah, beta, c, cntl );
93 // If C has a zero dimension, return early.
94 if ( bli_obj_has_zero_dim( *c ) ) return;
96 // If A or A' has a zero dimension, scale C by beta and return early.
97 if ( bli_obj_has_zero_dim( *a ) ||
98 bli_obj_has_zero_dim( *ah ) )
99 {
100 if( thread_am_ochief( thread ) )
101 bli_scalm( beta, c );
102 thread_obarrier( thread );
103 return;
104 }
106 // Alias A and A' in case we need to update attached scalars.
107 bli_obj_alias_to( *a, a_local );
108 bli_obj_alias_to( *ah, ah_local );
110 // Alias C in case we need to induce a transposition.
111 bli_obj_alias_to( *c, c_local );
113 // If we are about to call a leaf-level implementation, and matrix C
114 // still needs a transposition, then we must induce one by swapping the
115 // strides and dimensions. Note that this transposition would normally
116 // be handled explicitly in the packing of C, but if C is not being
117 // packed, this is our last chance to handle the transposition.
118 if ( cntl_is_leaf( cntl ) && bli_obj_has_trans( *c ) )
119 {
120 bli_obj_induce_trans( c_local );
121 bli_obj_set_onlytrans( BLIS_NO_TRANSPOSE, c_local );
122 }
124 // If alpha is non-unit, typecast and apply it to the scalar
125 // attached to A'.
126 if ( !bli_obj_equals( alpha, &BLIS_ONE ) )
127 {
128 bli_obj_scalar_apply_scalar( alpha, &ah_local );
129 }
131 // If beta is non-unit, typecast and apply it to the scalar
132 // attached to C.
133 if ( !bli_obj_equals( beta, &BLIS_ONE ) )
134 {
135 bli_obj_scalar_apply_scalar( beta, &c_local );
136 }
138 // Set a bool based on the uplo field of C's root object.
139 if ( bli_obj_root_is_lower( c_local ) ) uplo = 0;
140 else uplo = 1;
142 // Extract the variant number and implementation type.
143 n = cntl_var_num( cntl );
144 i = cntl_impl_type( cntl );
146 // Index into the variant array to extract the correct function pointer.
147 f = vars[uplo][n][i];
148 #ifdef BLIS_ENABLE_CYCLE_COUNT_BLIS_GEMM_INT
149 TSCL = 0;
150 counter_start = TSCL;
151 #endif
152 // Invoke the variant.
153 f( &a_local,
154 &ah_local,
155 &c_local,
156 cntl,
157 thread );
158 #ifdef BLIS_ENABLE_CYCLE_COUNT_BLIS_GEMM_INT
159 counter_end = TSCL;
160 if(CSL_chipReadDNUM ()==0) printf("xxxxx bli_gemm_int \t %d %d %d \t %d\n", uplo, n, i, counter_end-counter_start);
161 #endif
162 }