1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
|
/*
BLIS
An object-based framework for developing high-performance BLAS-like
libraries.
Copyright (C) 2014, The University of Texas at Austin
Copyright (C) 2018 - 2020, Advanced Micro Devices, Inc.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
- Neither the name(s) of the copyright holder(s) nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "blis.h"
// This array tracks whether a particular operation is implemented for each of
// the induced methods.
static bool bli_l3_ind_oper_impl[BLIS_NUM_IND_METHODS][BLIS_NUM_LEVEL3_OPS] =
{
/* gemm gemmt hemm herk her2k symm syrk syr2k trmm3 trmm trsm */
/* 1m */ { TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE },
/* nat */ { TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE }
};
//
// NOTE: "2" is used instead of BLIS_NUM_FP_TYPES/2.
//
// BLIS provides APIs to modify this state during runtime. So, it's possible for one
// application thread to modify the state before another starts the corresponding
// BLIS operation. This is solved by making the induced method status array local to
// threads.
static BLIS_THREAD_LOCAL
bool bli_l3_ind_oper_st[BLIS_NUM_IND_METHODS][BLIS_NUM_LEVEL3_OPS][2] =
{
/* gemm gemmt hemm herk her2k symm
syrk syr2k trmm3 trmm trsm */
/* c z */
/* 1m */ { {FALSE,FALSE}, {FALSE,FALSE}, {FALSE,FALSE}, {FALSE,FALSE}, {FALSE,FALSE}, {FALSE,FALSE},
{FALSE,FALSE}, {FALSE,FALSE}, {FALSE,FALSE}, {FALSE,FALSE}, {FALSE,FALSE} },
/* nat */ { {TRUE,TRUE}, {TRUE,TRUE}, {TRUE,TRUE}, {TRUE,TRUE}, {TRUE,TRUE}, {TRUE,TRUE},
{TRUE,TRUE}, {TRUE,TRUE}, {TRUE,TRUE}, {TRUE,TRUE}, {TRUE,TRUE} },
};
// -----------------------------------------------------------------------------
#undef GENFUNC
#define GENFUNC( opname, optype ) \
\
ind_t PASTEMAC(opname,ind_find_avail)( num_t dt ) \
{ \
return bli_l3_ind_oper_find_avail( optype, dt ); \
}
//bool PASTEMAC(opname,ind_has_avail)( num_t dt )
//{
// return bli_ind_oper_has_avail( optype, dt );
//}
GENFUNC( gemm, BLIS_GEMM )
GENFUNC( gemmt, BLIS_GEMMT )
GENFUNC( hemm, BLIS_HEMM )
GENFUNC( symm, BLIS_SYMM )
GENFUNC( trmm3, BLIS_TRMM3 )
GENFUNC( trmm, BLIS_TRMM )
GENFUNC( trsm, BLIS_TRSM )
// -----------------------------------------------------------------------------
#if 0
bool bli_l3_ind_oper_is_avail( opid_t oper, ind_t method, num_t dt )
{
bool enabled;
bool stat;
// If the datatype is real, it is never available.
if ( !bli_is_complex( dt ) ) return FALSE;
enabled = bli_l3_ind_oper_is_impl( oper, method );
stat = bli_l3_ind_oper_get_enable( oper, method, dt );
return ( enabled == TRUE && stat == TRUE );
}
#endif
// -----------------------------------------------------------------------------
ind_t bli_l3_ind_oper_find_avail( opid_t oper, num_t dt )
{
bli_init_once();
ind_t im;
// If the datatype is real, return native execution.
if ( !bli_is_complex( dt ) ) return BLIS_NAT;
// If the operation is not level-3, return native execution.
if ( !bli_opid_is_level3( oper ) ) return BLIS_NAT;
// Iterate over all induced methods and search for the first one
// that is available (ie: both implemented and enabled) for the
// current operation and datatype.
for ( im = 0; im < BLIS_NUM_IND_METHODS; ++im )
{
bool enabled = bli_l3_ind_oper_is_impl( oper, im );
bool stat = bli_l3_ind_oper_get_enable( oper, im, dt );
if ( enabled == TRUE &&
stat == TRUE ) return im;
}
// This return statement should never execute since the native index
// should be found even if all induced methods are unavailable. We
// include it simply to avoid a compiler warning.
return BLIS_NAT;
}
// -----------------------------------------------------------------------------
void bli_l3_ind_set_enable_dt( ind_t method, num_t dt, bool status )
{
opid_t iop;
if ( !bli_is_complex( dt ) ) return;
// Iterate over all level-3 operation ids.
for ( iop = 0; iop < BLIS_NUM_LEVEL3_OPS; ++iop )
{
bli_l3_ind_oper_set_enable( iop, method, dt, status );
}
}
// -----------------------------------------------------------------------------
void bli_l3_ind_oper_enable_only( opid_t oper, ind_t method, num_t dt )
{
ind_t im;
if ( !bli_is_complex( dt ) ) return;
if ( !bli_opid_is_level3( oper ) ) return;
for ( im = 0; im < BLIS_NUM_IND_METHODS; ++im )
{
// Native execution should always stay enabled.
if ( im == BLIS_NAT ) continue;
// When we come upon the requested method, enable it for the given
// operation and datatype. Otherwise, disable it.
if ( im == method )
bli_l3_ind_oper_set_enable( oper, im, dt, TRUE );
else
bli_l3_ind_oper_set_enable( oper, im, dt, FALSE );
}
}
void bli_l3_ind_oper_set_enable_all( opid_t oper, num_t dt, bool status )
{
ind_t im;
if ( !bli_is_complex( dt ) ) return;
if ( !bli_opid_is_level3( oper ) ) return;
for ( im = 0; im < BLIS_NUM_IND_METHODS; ++im )
{
// Native execution should always stay enabled.
if ( im != BLIS_NAT )
bli_l3_ind_oper_set_enable( oper, im, dt, status );
}
}
// -----------------------------------------------------------------------------
// A mutex to allow synchronous access to the bli_l3_ind_oper_st array.
static bli_pthread_mutex_t oper_st_mutex = BLIS_PTHREAD_MUTEX_INITIALIZER;
void bli_l3_ind_oper_set_enable( opid_t oper, ind_t method, num_t dt, bool status )
{
num_t idt;
if ( !bli_is_complex( dt ) ) return;
if ( !bli_opid_is_level3( oper ) ) return;
// Disallow changing status of native execution.
if ( method == BLIS_NAT ) return;
idt = bli_ind_map_cdt_to_index( dt );
// Acquire the mutex protecting bli_l3_ind_oper_st.
bli_pthread_mutex_lock( &oper_st_mutex );
// BEGIN CRITICAL SECTION
{
bli_l3_ind_oper_st[ method ][ oper ][ idt ] = status;
}
// END CRITICAL SECTION
// Release the mutex protecting bli_l3_ind_oper_st.
bli_pthread_mutex_unlock( &oper_st_mutex );
}
bool bli_l3_ind_oper_get_enable( opid_t oper, ind_t method, num_t dt )
{
num_t idt = bli_ind_map_cdt_to_index( dt );
bool r_val;
{
r_val = bli_l3_ind_oper_st[ method ][ oper ][ idt ];
}
return r_val;
}
// -----------------------------------------------------------------------------
bool bli_l3_ind_oper_is_impl( opid_t oper, ind_t method )
{
return bli_l3_ind_oper_impl[ method ][ oper ];
}
|