]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - dense-linear-algebra-libraries/linalg.git/blob - blis/frame/3/gemm/bli_gemm_int.c
TI Linear Algebra Library (LINALG) Rlease 1.0.0
[dense-linear-algebra-libraries/linalg.git] / blis / frame / 3 / gemm / bli_gemm_int.c
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 gemm_fp
43 typedef void (*FUNCPTR_T)( obj_t*  a,
44                            obj_t*  b,
45                            obj_t*  c,
46                            gemm_t* cntl,
47                            gemm_thrinfo_t* thread );
49 static FUNCPTR_T vars[6][3] =
50 {
51     // unblocked          optimized unblocked   blocked
52     { NULL,               NULL,                 bli_gemm_blk_var1f },
53     { NULL,               bli_gemm_ker_var2,    bli_gemm_blk_var2f },
54     { NULL,               NULL,                 bli_gemm_blk_var3f },
55     { NULL,               NULL,                 NULL               },
56     { NULL,               NULL,                 NULL               },
57     { NULL,               NULL,                 NULL               }
58 };
60 void bli_gemm_int( obj_t*  alpha,
61                    obj_t*  a,
62                    obj_t*  b,
63                    obj_t*  beta,
64                    obj_t*  c,
65                    gemm_t* cntl,
66                    gemm_thrinfo_t* thread )
67 {
68         obj_t     a_local;
69         obj_t     b_local;
70         obj_t     c_local;
71         varnum_t  n;
72         impl_t    i;
73         FUNCPTR_T f;
74 #ifdef BLIS_ENABLE_CYCLE_COUNT_BLIS_GEMM_INT
75         volatile int counter_start;
76         volatile int counter_end;
77 #endif
79         // Extract the variant number and implementation type.
80         n = cntl_var_num( cntl );
81         i = cntl_impl_type( cntl );
83         // Check parameters.
84         if ( bli_error_checking_is_enabled() )
85                 bli_gemm_int_check( alpha, a, b, beta, c, cntl );
87         // If C has a zero dimension, return early.
88         if ( bli_obj_has_zero_dim( *c ) ) return;
90         // If A or B has a zero dimension, scale C by beta and return early.
91         if ( bli_obj_has_zero_dim( *a ) ||
92              bli_obj_has_zero_dim( *b ) )
93         {
94         if( thread_am_ochief( thread ) )
95                     bli_scalm( beta, c );
96         thread_obarrier( thread );
97                 return;
98         }
100         // If A or B is marked as being filled with zeros, scale C by beta and
101         // return early.
102         if ( bli_obj_is_zeros( *a ) ||
103              bli_obj_is_zeros( *b ) )
104         {
105         if( thread_am_ochief( thread ) )
106                     bli_scalm( beta, c );
107         thread_obarrier( thread );
108                 return;
109         }
111         // Alias A and B in case we need to update attached scalars.
112         bli_obj_alias_to( *a, a_local );
113         bli_obj_alias_to( *b, b_local );
115         // Alias C in case we need to induce a transposition.
116         bli_obj_alias_to( *c, c_local );
118         // If we are about to call a leaf-level implementation, and matrix C
119         // still needs a transposition, then we must induce one by swapping the
120         // strides and dimensions. Note that this transposition would normally
121         // be handled explicitly in the packing of C, but if C is not being
122         // packed, this is our last chance to handle the transposition.
123         if ( cntl_is_leaf( cntl ) && bli_obj_has_trans( *c ) )
124         {
125         //if( thread_am_ochief( thread ) ) {
126             bli_obj_induce_trans( c_local );
127             bli_obj_set_onlytrans( BLIS_NO_TRANSPOSE, c_local );
128        // }
129         }
131         // If alpha is non-unit, typecast and apply it to the scalar attached
132         // to B.
133         if ( !bli_obj_equals( alpha, &BLIS_ONE ) )
134         {
135         bli_obj_scalar_apply_scalar( alpha, &b_local );
136         }
139         // If beta is non-unit, typecast and apply it to the scalar attached
140         // to C.
141         if ( !bli_obj_equals( beta, &BLIS_ONE ) )
142         {
143         bli_obj_scalar_apply_scalar( beta, &c_local );
144         }
146         // Extract the variant number and implementation type.
147         n = cntl_var_num( cntl );
148         i = cntl_impl_type( cntl );
150         // Index into the variant array to extract the correct function pointer.
151         f = vars[n][i];
152         //printf("gemm_int %d %d\n", n, i);
154         // Invoke the variant.
155 #ifdef BLIS_ENABLE_CYCLE_COUNT_BLIS_GEMM_INT
156         TSCL = 0;
157         counter_start = TSCL;
158 #endif
159         f( &a_local,
160            &b_local,
161            &c_local,
162            cntl,
163        thread );
164 #ifdef BLIS_ENABLE_CYCLE_COUNT_BLIS_GEMM_INT
165        counter_end = TSCL;
166        if(CSL_chipReadDNUM()==0) printf("xxxxx bli_gemm_int %d %d %d\n", n, i, counter_end-counter_start);
167 #endif