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 #define FUNCPTR_T setd_fp
39 typedef void (*FUNCPTR_T)(
40 doff_t diagoffx,
41 dim_t m,
42 dim_t n,
43 void* beta,
44 void* x, inc_t rs_x, inc_t cs_x
45 );
47 // If some mixed datatype functions will not be compiled, we initialize
48 // the corresponding elements of the function array to NULL.
49 #ifdef BLIS_ENABLE_MIXED_PRECISION_SUPPORT
50 static FUNCPTR_T GENARRAY2_ALL(ftypes,setd_unb_var1);
51 #else
52 #ifdef BLIS_ENABLE_MIXED_DOMAIN_SUPPORT
53 static FUNCPTR_T GENARRAY2_EXT(ftypes,setd_unb_var1);
54 #else
55 static FUNCPTR_T GENARRAY2_MIN(ftypes,setd_unb_var1);
56 #endif
57 #endif
60 void bli_setd_unb_var1( obj_t* beta,
61 obj_t* x )
62 {
63 num_t dt_x = bli_obj_datatype( *x );
65 doff_t diagoffx = bli_obj_diag_offset( *x );
67 dim_t m = bli_obj_length( *x );
68 dim_t n = bli_obj_width( *x );
70 void* buf_x = bli_obj_buffer_at_off( *x );
71 inc_t rs_x = bli_obj_row_stride( *x );
72 inc_t cs_x = bli_obj_col_stride( *x );
74 void* buf_beta;
75 num_t dt_beta;
77 FUNCPTR_T f;
79 // If beta is a scalar constant, use dt_x to extract the address of the
80 // corresponding constant value; otherwise, use the datatype encoded
81 // within the beta object and extract the buffer at the beta offset.
82 bli_set_scalar_dt_buffer( beta, dt_x, dt_beta, buf_beta );
84 // Index into the type combination array to extract the correct
85 // function pointer.
86 f = ftypes[dt_beta][dt_x];
88 // Invoke the function.
89 f( diagoffx,
90 m,
91 n,
92 buf_beta,
93 buf_x, rs_x, cs_x );
94 }
97 #undef GENTFUNC2
98 #define GENTFUNC2( ctype_b, ctype_x, chb, chx, varname, kername ) \
99 \
100 void PASTEMAC2(chb,chx,varname)( \
101 doff_t diagoffx, \
102 dim_t m, \
103 dim_t n, \
104 void* beta, \
105 void* x, inc_t rs_x, inc_t cs_x \
106 ) \
107 { \
108 ctype_b* beta_cast = beta; \
109 ctype_x* x_cast = x; \
110 ctype_x* x1; \
111 dim_t n_elem; \
112 dim_t offx; \
113 inc_t incx; \
114 \
115 if ( bli_zero_dim2( m, n ) ) return; \
116 \
117 if ( bli_is_outside_diag( diagoffx, BLIS_NO_TRANSPOSE, m, n ) ) return; \
118 \
119 /* Determine the distance to the diagonal, the number of diagonal
120 elements, and the diagonal increment. */ \
121 bli_set_dims_incs_1d( diagoffx, \
122 m, n, rs_x, cs_x, \
123 offx, n_elem, incx ); \
124 \
125 x1 = x_cast + offx; \
126 \
127 PASTEMAC2(chb,chx,kername)( n_elem, \
128 beta_cast, \
129 x1, incx ); \
130 }
132 // Define the basic set of functions unconditionally, and then also some
133 // mixed datatype functions if requested.
134 INSERT_GENTFUNC2_BASIC( setd_unb_var1, SETV_KERNEL )
136 #ifdef BLIS_ENABLE_MIXED_DOMAIN_SUPPORT
137 INSERT_GENTFUNC2_MIX_D( setd_unb_var1, SETV_KERNEL )
138 #endif
140 #ifdef BLIS_ENABLE_MIXED_PRECISION_SUPPORT
141 INSERT_GENTFUNC2_MIX_P( setd_unb_var1, SETV_KERNEL )
142 #endif