mirror of
https://github.com/amd/blis.git
synced 2026-04-20 07:38:53 +00:00
Added a new 'gemmlike' sandbox.
Details:
- Added a new sandbox called 'gemmlike', which implements sequential and
multithreaded gemm in the style of gemmsup but also unconditionally
employs packing. The purpose of this sandbox is to
(1) avoid select abstractions, such as objects and control trees, in
order to allow readers to better understand how a real-world
implementation of high-performance gemm can be constructed;
(2) provide a starting point for expert users who wish to build
something that is gemm-like without "reinventing the wheel."
Thanks to Jeff Diamond, Tze Meng Low, Nicholai Tukanov, and Devangi
Parikh for requesting and inspiring this work.
- The functions defined in this sandbox currently use the "bls_" prefix
instead of "bli_" in order to avoid any symbol collisions in the main
library.
- The sandbox contains two variants, each of which implements gemm via a
block-panel algorithm. The only difference between the two is that
variant 1 calls the microkernel directly while variant 2 calls the
microkernel indirectly, via a function wrapper, which allows the edge
case handling to be abstracted away from the classic five loops.
- This sandbox implementation utilizes the conventional gemm microkernel
(not the skinny/unpacked gemmsup kernels).
- Updated some typos in the comments of a few files in the main
framework.
This commit is contained in:
@@ -57,7 +57,7 @@ void PASTEMAC(ch,opname) \
|
||||
} \
|
||||
else /* if ( will_pack == TRUE ) */ \
|
||||
{ \
|
||||
/* NOTE: This is "rounding up" of the last upanel is actually optional
|
||||
/* NOTE: This "rounding up" of the last upanel is actually optional
|
||||
for the rrc/crc cases, but absolutely necessary for the other cases
|
||||
since we NEED that last micropanel to have the same ldim (cs_p) as
|
||||
the other micropanels. Why? So that millikernels can use the same
|
||||
|
||||
@@ -57,7 +57,7 @@ void PASTEMAC(ch,opname) \
|
||||
} \
|
||||
else /* if ( will_pack == TRUE ) */ \
|
||||
{ \
|
||||
/* NOTE: This is "rounding up" of the last upanel is actually optional
|
||||
/* NOTE: This "rounding up" of the last upanel is actually optional
|
||||
for the rrc/crc cases, but absolutely necessary for the other cases
|
||||
since we NEED that last micropanel to have the same ldim (cs_p) as
|
||||
the other micropanels. Why? So that millikernels can use the same
|
||||
@@ -280,15 +280,15 @@ void PASTEMAC(ch,opname) \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
/* All other stor3_t ids: pack A to column-stored row-panels. */ \
|
||||
/* All other stor3_t ids: pack B to row-stored column-panels. */ \
|
||||
*rs_p = nr; \
|
||||
*cs_p = 1; \
|
||||
\
|
||||
*pd_p = nr; \
|
||||
*ps_p = k * nr; \
|
||||
\
|
||||
/* Set the schema to "packed row panels" to indicate packing to
|
||||
conventional column-stored row panels. */ \
|
||||
/* Set the schema to "packed column panels" to indicate packing to
|
||||
conventional row-stored column panels. */ \
|
||||
*schema = BLIS_PACKED_COL_PANELS; \
|
||||
} \
|
||||
\
|
||||
|
||||
@@ -128,6 +128,20 @@ arrayname[BLIS_NUM_FP_TYPES][BLIS_NUM_FP_TYPES] = \
|
||||
|
||||
|
||||
|
||||
// -- One-operand macro (with custom prefix) --
|
||||
|
||||
#define GENARRAY_PREF(arrayname,prefix,op) \
|
||||
\
|
||||
arrayname[BLIS_NUM_FP_TYPES] = \
|
||||
{ \
|
||||
PASTECH2(prefix,s,op), \
|
||||
PASTECH2(prefix,c,op), \
|
||||
PASTECH2(prefix,d,op), \
|
||||
PASTECH2(prefix,z,op) \
|
||||
}
|
||||
|
||||
|
||||
|
||||
// -- Two-operand macros --
|
||||
|
||||
|
||||
|
||||
@@ -1190,7 +1190,7 @@ BLIS_INLINE stor3_t bli_obj_stor3_from_strides( obj_t* c, obj_t* a, obj_t* b )
|
||||
// -- Initialization-related macros --
|
||||
|
||||
// Finish the initialization started by the matrix-specific static initializer
|
||||
// (e.g. BLIS_OBJECT_PREINITIALIZER)
|
||||
// (e.g. BLIS_OBJECT_INITIALIZER)
|
||||
// NOTE: This is intended only for use in the BLAS compatibility API and typed
|
||||
// BLIS API.
|
||||
|
||||
@@ -1223,7 +1223,7 @@ BLIS_INLINE void bli_obj_init_finish( num_t dt, dim_t m, dim_t n, void* p, inc_t
|
||||
}
|
||||
|
||||
// Finish the initialization started by the 1x1-specific static initializer
|
||||
// (e.g. BLIS_OBJECT_PREINITIALIZER_1X1)
|
||||
// (e.g. BLIS_OBJECT_INITIALIZER_1X1)
|
||||
// NOTE: This is intended only for use in the BLAS compatibility API and typed
|
||||
// BLIS API.
|
||||
|
||||
|
||||
88
sandbox/gemmlike/bli_gemmnat.c
Normal file
88
sandbox/gemmlike/bli_gemmnat.c
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
|
||||
BLIS
|
||||
An object-based framework for developing high-performance BLAS-like
|
||||
libraries.
|
||||
|
||||
Copyright (C) 2014, The University of Texas at Austin
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
// Given the current architecture of BLIS sandboxes, bli_gemmnat() is the
|
||||
// entry point to any sandbox implementation.
|
||||
|
||||
// NOTE: This function is implemented identically to the function that it
|
||||
// overrides in frame/ind/oapi/bli_l3_nat_oapi.c. This means that we are
|
||||
// forgoing the option of customizing the implementations that underlie
|
||||
// bli_gemm() and bli_?gemm(). Any new code defined in this sandbox
|
||||
// directory, however, will be included in the BLIS.
|
||||
|
||||
#include "blis.h"
|
||||
|
||||
#undef GENFRONT
|
||||
#define GENFRONT( opname, cname, imeth ) \
|
||||
\
|
||||
void PASTEMAC(opname,imeth) \
|
||||
( \
|
||||
obj_t* alpha, \
|
||||
obj_t* a, \
|
||||
obj_t* b, \
|
||||
obj_t* beta, \
|
||||
obj_t* c, \
|
||||
cntx_t* cntx, \
|
||||
rntm_t* rntm \
|
||||
) \
|
||||
{ \
|
||||
\
|
||||
/* A switch to easily toggle whether we use the sandbox implementation
|
||||
of bls_gemm() as the implementation for bli_gemm(). (This allows for
|
||||
easy testing of bls_gemm() via the testsuite.) */ \
|
||||
if ( 1 ) \
|
||||
{ \
|
||||
bls_gemm_ex( alpha, a, b, beta, c, cntx, rntm ); \
|
||||
return; \
|
||||
} \
|
||||
\
|
||||
bli_init_once(); \
|
||||
\
|
||||
/* Obtain a valid (native) context from the gks if necessary. */ \
|
||||
if ( cntx == NULL ) cntx = bli_gks_query_cntx(); \
|
||||
\
|
||||
/* Initialize a local runtime with global settings if necessary. Note
|
||||
that in the case that a runtime is passed in, we make a local copy. */ \
|
||||
rntm_t rntm_l; \
|
||||
if ( rntm == NULL ) { bli_rntm_init_from_global( &rntm_l ); rntm = &rntm_l; } \
|
||||
else { rntm_l = *rntm; rntm = &rntm_l; } \
|
||||
\
|
||||
/* Invoke the operation's front end. */ \
|
||||
PASTEMAC(opname,_front) \
|
||||
( \
|
||||
alpha, a, b, beta, c, cntx, rntm, NULL \
|
||||
); \
|
||||
}
|
||||
|
||||
GENFRONT( gemm, gemm, nat )
|
||||
56
sandbox/gemmlike/bli_sandbox.h
Normal file
56
sandbox/gemmlike/bli_sandbox.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
|
||||
BLIS
|
||||
An object-based framework for developing high-performance BLAS-like
|
||||
libraries.
|
||||
|
||||
Copyright (C) 2014, The University of Texas at Austin
|
||||
|
||||
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 of copyright holder(s) nor the names
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef BLIS_SANDBOX_H
|
||||
#define BLIS_SANDBOX_H
|
||||
|
||||
// NOTE: This header is the only header required to be present in the sandbox
|
||||
// implementation directory.
|
||||
|
||||
// This header should contain (or #include) any definitions that must be
|
||||
// folded into blis.h. Typically, it will remain empty since any header
|
||||
// definitions specific to the sandbox implementation will not need to be
|
||||
// made available to applications (or the framework) during compilation.
|
||||
|
||||
#include "bls_gemm.h"
|
||||
#include "bls_gemm_var.h"
|
||||
|
||||
#include "bls_l3_packm_a.h"
|
||||
#include "bls_l3_packm_b.h"
|
||||
#include "bls_l3_packm_var.h"
|
||||
|
||||
#include "bls_l3_decor.h"
|
||||
|
||||
|
||||
#endif
|
||||
304
sandbox/gemmlike/bls_gemm.c
Normal file
304
sandbox/gemmlike/bls_gemm.c
Normal file
@@ -0,0 +1,304 @@
|
||||
/*
|
||||
|
||||
BLIS
|
||||
An object-based framework for developing high-performance BLAS-like
|
||||
libraries.
|
||||
|
||||
Copyright (C) 2021, The University of Texas at Austin
|
||||
|
||||
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"
|
||||
|
||||
//
|
||||
// -- Define the gemm-like operation's object API ------------------------------
|
||||
//
|
||||
|
||||
void bls_gemm
|
||||
(
|
||||
obj_t* alpha,
|
||||
obj_t* a,
|
||||
obj_t* b,
|
||||
obj_t* beta,
|
||||
obj_t* c
|
||||
)
|
||||
{
|
||||
bls_gemm_ex
|
||||
(
|
||||
alpha,
|
||||
a,
|
||||
b,
|
||||
beta,
|
||||
c,
|
||||
NULL,
|
||||
NULL
|
||||
);
|
||||
}
|
||||
|
||||
void bls_gemm_ex
|
||||
(
|
||||
obj_t* alpha,
|
||||
obj_t* a,
|
||||
obj_t* b,
|
||||
obj_t* beta,
|
||||
obj_t* c,
|
||||
cntx_t* cntx,
|
||||
rntm_t* rntm
|
||||
)
|
||||
{
|
||||
bli_init_once();
|
||||
|
||||
// -- bli_gemmnat() --------------------------------------------------------
|
||||
|
||||
// Obtain a valid (native) context from the gks if necessary.
|
||||
// NOTE: This must be done before calling the _check() function, since
|
||||
// that function assumes the context pointer is valid.
|
||||
if ( cntx == NULL ) cntx = bli_gks_query_cntx();
|
||||
|
||||
// Initialize a local runtime with global settings if necessary. Note
|
||||
// that in the case that a runtime is passed in, we make a local copy.
|
||||
rntm_t rntm_l;
|
||||
if ( rntm == NULL ) { bli_rntm_init_from_global( &rntm_l ); rntm = &rntm_l; }
|
||||
else { rntm_l = *rntm; rntm = &rntm_l; }
|
||||
|
||||
// -- bli_gemm_front() -----------------------------------------------------
|
||||
|
||||
obj_t a_local;
|
||||
obj_t b_local;
|
||||
obj_t c_local;
|
||||
|
||||
// Check parameters.
|
||||
if ( bli_error_checking_is_enabled() )
|
||||
{
|
||||
bli_gemm_check( alpha, a, b, beta, c, cntx );
|
||||
}
|
||||
|
||||
// If C has a zero dimension, return early.
|
||||
if ( bli_obj_has_zero_dim( c ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// If alpha is zero, or if A or B has a zero dimension, scale C by beta
|
||||
// and return early.
|
||||
if ( bli_obj_equals( alpha, &BLIS_ZERO ) ||
|
||||
bli_obj_has_zero_dim( a ) ||
|
||||
bli_obj_has_zero_dim( b ) )
|
||||
{
|
||||
bli_scalm( beta, c );
|
||||
return;
|
||||
}
|
||||
|
||||
// Alias A, B, and C in case we need to apply transformations.
|
||||
bli_obj_alias_to( a, &a_local );
|
||||
bli_obj_alias_to( b, &b_local );
|
||||
bli_obj_alias_to( c, &c_local );
|
||||
|
||||
// Induce a transposition of A if it has its transposition property set.
|
||||
// Then clear the transposition bit in the object.
|
||||
if ( bli_obj_has_trans( &a_local ) )
|
||||
{
|
||||
bli_obj_induce_trans( &a_local );
|
||||
bli_obj_set_onlytrans( BLIS_NO_TRANSPOSE, &a_local );
|
||||
}
|
||||
|
||||
// Induce a transposition of B if it has its transposition property set.
|
||||
// Then clear the transposition bit in the object.
|
||||
if ( bli_obj_has_trans( &b_local ) )
|
||||
{
|
||||
bli_obj_induce_trans( &b_local );
|
||||
bli_obj_set_onlytrans( BLIS_NO_TRANSPOSE, &b_local );
|
||||
}
|
||||
|
||||
// An optimization: If C is stored by rows and the micro-kernel prefers
|
||||
// contiguous columns, or if C is stored by columns and the micro-kernel
|
||||
// prefers contiguous rows, transpose the entire operation to allow the
|
||||
// micro-kernel to access elements of C in its preferred manner.
|
||||
if ( bli_cntx_l3_vir_ukr_dislikes_storage_of( &c_local, BLIS_GEMM_UKR, cntx ) )
|
||||
{
|
||||
bli_obj_swap( &a_local, &b_local );
|
||||
|
||||
bli_obj_induce_trans( &a_local );
|
||||
bli_obj_induce_trans( &b_local );
|
||||
bli_obj_induce_trans( &c_local );
|
||||
|
||||
// NOTE: This is probably not needed within the sandbox.
|
||||
// We must also swap the pack schemas, which were set by bli_gemm_md()
|
||||
// or the inlined code above.
|
||||
//bli_obj_swap_pack_schemas( &a_local, &b_local );
|
||||
}
|
||||
|
||||
// Parse and interpret the contents of the rntm_t object to properly
|
||||
// set the ways of parallelism for each loop, and then make any
|
||||
// additional modifications necessary for the current operation.
|
||||
bli_rntm_set_ways_for_op
|
||||
(
|
||||
BLIS_GEMM,
|
||||
BLIS_LEFT, // ignored for gemm/hemm/symm
|
||||
bli_obj_length( &c_local ),
|
||||
bli_obj_width( &c_local ),
|
||||
bli_obj_width( &a_local ),
|
||||
rntm
|
||||
);
|
||||
|
||||
// Spawn threads (if applicable), where bls_gemm_int() is the thread entry
|
||||
// point function for each thread. This also begins the process of creating
|
||||
// the thrinfo_t tree, which contains thread communicators.
|
||||
bls_l3_thread_decorator
|
||||
(
|
||||
bls_gemm_int,
|
||||
BLIS_GEMM, // operation family id
|
||||
alpha,
|
||||
&a_local,
|
||||
&b_local,
|
||||
beta,
|
||||
&c_local,
|
||||
cntx,
|
||||
rntm
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// -- Define the gemm-like operation's thread entry point ----------------------
|
||||
//
|
||||
|
||||
void bls_gemm_int
|
||||
(
|
||||
obj_t* alpha,
|
||||
obj_t* a,
|
||||
obj_t* b,
|
||||
obj_t* beta,
|
||||
obj_t* c,
|
||||
cntx_t* cntx,
|
||||
rntm_t* rntm,
|
||||
thrinfo_t* thread
|
||||
)
|
||||
{
|
||||
// In this function, we choose the gemm implementation that is executed
|
||||
// on each thread.
|
||||
|
||||
#if 1
|
||||
// Call the block-panel algorithm that calls the kernel directly, which
|
||||
// exposes edge-case handling.
|
||||
bls_gemm_bp_var1
|
||||
(
|
||||
alpha,
|
||||
a,
|
||||
b,
|
||||
beta,
|
||||
c,
|
||||
cntx,
|
||||
rntm,
|
||||
thread
|
||||
);
|
||||
#else
|
||||
// Call the block-panel algorithm that calls the kernel indirectly via a
|
||||
// wrapper function, which hides edge-case handling.
|
||||
bls_gemm_bp_var2
|
||||
(
|
||||
alpha,
|
||||
a,
|
||||
b,
|
||||
beta,
|
||||
c,
|
||||
cntx,
|
||||
rntm,
|
||||
thread
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
// -- Define the gemm-like operation's typed API -------------------------------
|
||||
//
|
||||
|
||||
#undef GENTFUNC
|
||||
#define GENTFUNC( ctype, ch, opname ) \
|
||||
\
|
||||
void PASTECH2(bls_,ch,opname) \
|
||||
( \
|
||||
trans_t transa, \
|
||||
trans_t transb, \
|
||||
dim_t m, \
|
||||
dim_t n, \
|
||||
dim_t k, \
|
||||
ctype* alpha, \
|
||||
ctype* a, inc_t rs_a, inc_t cs_a, \
|
||||
ctype* b, inc_t rs_b, inc_t cs_b, \
|
||||
ctype* beta, \
|
||||
ctype* c, inc_t rs_c, inc_t cs_c \
|
||||
) \
|
||||
{ \
|
||||
bli_init_once(); \
|
||||
\
|
||||
/* Determine the datatype (e.g. BLIS_FLOAT, BLIS_DOUBLE, etc.) based on
|
||||
the macro parameter 'ch' (e.g. s, d, etc). */ \
|
||||
const num_t dt = PASTEMAC(ch,type); \
|
||||
\
|
||||
obj_t alphao, ao, bo, betao, co; \
|
||||
\
|
||||
dim_t m_a, n_a; \
|
||||
dim_t m_b, n_b; \
|
||||
\
|
||||
/* Adjust the dimensions of matrices A and B according to the transa and
|
||||
transb parameters. */ \
|
||||
bli_set_dims_with_trans( transa, m, k, &m_a, &n_a ); \
|
||||
bli_set_dims_with_trans( transb, k, n, &m_b, &n_b ); \
|
||||
\
|
||||
/* Create bufferless scalar objects and attach the provided scalar pointers
|
||||
to those scalar objects. */ \
|
||||
bli_obj_create_1x1_with_attached_buffer( dt, alpha, &alphao ); \
|
||||
bli_obj_create_1x1_with_attached_buffer( dt, beta, &betao ); \
|
||||
\
|
||||
/* Create bufferless matrix objects and attach the provided matrix pointers
|
||||
to those matrix objects. */ \
|
||||
bli_obj_create_with_attached_buffer( dt, m_a, n_a, a, rs_a, cs_a, &ao ); \
|
||||
bli_obj_create_with_attached_buffer( dt, m_b, n_b, b, rs_b, cs_b, &bo ); \
|
||||
bli_obj_create_with_attached_buffer( dt, m, n, c, rs_c, cs_c, &co ); \
|
||||
\
|
||||
/* Set the transposition/conjugation properties of the objects for matrices
|
||||
A and B. */ \
|
||||
bli_obj_set_conjtrans( transa, &ao ); \
|
||||
bli_obj_set_conjtrans( transb, &bo ); \
|
||||
\
|
||||
/* Call the object interface. */ \
|
||||
PASTECH(bls_,opname) \
|
||||
( \
|
||||
&alphao, \
|
||||
&ao, \
|
||||
&bo, \
|
||||
&betao, \
|
||||
&co \
|
||||
); \
|
||||
}
|
||||
|
||||
//INSERT_GENTFUNC_BASIC0( gemm )
|
||||
GENTFUNC( float, s, gemm )
|
||||
GENTFUNC( double, d, gemm )
|
||||
GENTFUNC( scomplex, c, gemm )
|
||||
GENTFUNC( dcomplex, z, gemm )
|
||||
|
||||
101
sandbox/gemmlike/bls_gemm.h
Normal file
101
sandbox/gemmlike/bls_gemm.h
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
|
||||
BLIS
|
||||
An object-based framework for developing high-performance BLAS-like
|
||||
libraries.
|
||||
|
||||
Copyright (C) 2021, The University of Texas at Austin
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
//
|
||||
// -- Prototype the gemm-like operation's object API ---------------------------
|
||||
//
|
||||
|
||||
void bls_gemm
|
||||
(
|
||||
obj_t* alpha,
|
||||
obj_t* a,
|
||||
obj_t* b,
|
||||
obj_t* beta,
|
||||
obj_t* c
|
||||
);
|
||||
|
||||
void bls_gemm_ex
|
||||
(
|
||||
obj_t* alpha,
|
||||
obj_t* a,
|
||||
obj_t* b,
|
||||
obj_t* beta,
|
||||
obj_t* c,
|
||||
cntx_t* cntx,
|
||||
rntm_t* rntm
|
||||
);
|
||||
|
||||
//
|
||||
// -- Prototype the gemm-like operation's thread entry point -------------------
|
||||
//
|
||||
|
||||
void bls_gemm_int
|
||||
(
|
||||
obj_t* alpha,
|
||||
obj_t* a,
|
||||
obj_t* b,
|
||||
obj_t* beta,
|
||||
obj_t* c,
|
||||
cntx_t* cntx,
|
||||
rntm_t* rntm,
|
||||
thrinfo_t* thread
|
||||
);
|
||||
|
||||
//
|
||||
// -- Prototype the gemm-like operation's typed API ----------------------------
|
||||
//
|
||||
|
||||
#undef GENTPROT
|
||||
#define GENTPROT( ctype, ch, opname ) \
|
||||
\
|
||||
void PASTECH2(bls_,ch,opname) \
|
||||
( \
|
||||
trans_t transa, \
|
||||
trans_t transb, \
|
||||
dim_t m, \
|
||||
dim_t n, \
|
||||
dim_t k, \
|
||||
ctype* alpha, \
|
||||
ctype* a, inc_t rs_a, inc_t cs_a, \
|
||||
ctype* b, inc_t rs_b, inc_t cs_b, \
|
||||
ctype* beta, \
|
||||
ctype* c, inc_t rs_c, inc_t cs_c \
|
||||
);
|
||||
|
||||
//INSERT_GENTPROT_BASIC0( gemm )
|
||||
GENTPROT( float, s, gemm )
|
||||
GENTPROT( double, d, gemm )
|
||||
GENTPROT( scomplex, c, gemm )
|
||||
GENTPROT( dcomplex, z, gemm )
|
||||
|
||||
518
sandbox/gemmlike/bls_gemm_bp_var1.c
Normal file
518
sandbox/gemmlike/bls_gemm_bp_var1.c
Normal file
@@ -0,0 +1,518 @@
|
||||
/*
|
||||
|
||||
BLIS
|
||||
An object-based framework for developing high-performance BLAS-like
|
||||
libraries.
|
||||
|
||||
Copyright (C) 2021, The University of Texas at Austin
|
||||
|
||||
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"
|
||||
|
||||
#define FUNCPTR_T gemm_fp
|
||||
|
||||
typedef void (*FUNCPTR_T)
|
||||
(
|
||||
conj_t conja,
|
||||
conj_t conjb,
|
||||
dim_t m,
|
||||
dim_t n,
|
||||
dim_t k,
|
||||
void* restrict alpha,
|
||||
void* restrict a, inc_t rs_a, inc_t cs_a,
|
||||
void* restrict b, inc_t rs_b, inc_t cs_b,
|
||||
void* restrict beta,
|
||||
void* restrict c, inc_t rs_c, inc_t cs_c,
|
||||
cntx_t* restrict cntx,
|
||||
rntm_t* restrict rntm,
|
||||
thrinfo_t* restrict thread
|
||||
);
|
||||
|
||||
//
|
||||
// -- gemm-like block-panel algorithm (object interface) -----------------------
|
||||
//
|
||||
|
||||
// Define a function pointer array named ftypes and initialize its contents with
|
||||
// the addresses of the typed functions defined below, bls_?gemm_bp_var1().
|
||||
static FUNCPTR_T GENARRAY_PREF(ftypes,bls_,gemm_bp_var1);
|
||||
|
||||
void bls_gemm_bp_var1
|
||||
(
|
||||
obj_t* alpha,
|
||||
obj_t* a,
|
||||
obj_t* b,
|
||||
obj_t* beta,
|
||||
obj_t* c,
|
||||
cntx_t* cntx,
|
||||
rntm_t* rntm,
|
||||
thrinfo_t* thread
|
||||
)
|
||||
{
|
||||
const num_t dt = bli_obj_dt( c );
|
||||
|
||||
const conj_t conja = bli_obj_conj_status( a );
|
||||
const conj_t conjb = bli_obj_conj_status( b );
|
||||
|
||||
const dim_t m = bli_obj_length( c );
|
||||
const dim_t n = bli_obj_width( c );
|
||||
const dim_t k = bli_obj_width( a );
|
||||
|
||||
void* restrict buf_a = bli_obj_buffer_at_off( a );
|
||||
const inc_t rs_a = bli_obj_row_stride( a );
|
||||
const inc_t cs_a = bli_obj_col_stride( a );
|
||||
|
||||
void* restrict buf_b = bli_obj_buffer_at_off( b );
|
||||
const inc_t rs_b = bli_obj_row_stride( b );
|
||||
const inc_t cs_b = bli_obj_col_stride( b );
|
||||
|
||||
void* restrict buf_c = bli_obj_buffer_at_off( c );
|
||||
const inc_t rs_c = bli_obj_row_stride( c );
|
||||
const inc_t cs_c = bli_obj_col_stride( c );
|
||||
|
||||
void* restrict buf_alpha = bli_obj_buffer_for_1x1( dt, alpha );
|
||||
void* restrict buf_beta = bli_obj_buffer_for_1x1( dt, beta );
|
||||
|
||||
// Index into the function pointer array to extract the correct
|
||||
// typed function pointer based on the chosen datatype.
|
||||
FUNCPTR_T f = ftypes[dt];
|
||||
|
||||
// Invoke the function.
|
||||
f
|
||||
(
|
||||
conja,
|
||||
conjb,
|
||||
m,
|
||||
n,
|
||||
k,
|
||||
buf_alpha,
|
||||
buf_a, rs_a, cs_a,
|
||||
buf_b, rs_b, cs_b,
|
||||
buf_beta,
|
||||
buf_c, rs_c, cs_c,
|
||||
cntx,
|
||||
rntm,
|
||||
thread
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// -- gemm-like block-panel algorithm (typed interface) ------------------------
|
||||
//
|
||||
|
||||
#undef GENTFUNC
|
||||
#define GENTFUNC( ctype, ch, varname ) \
|
||||
\
|
||||
void PASTECH2(bls_,ch,varname) \
|
||||
( \
|
||||
conj_t conja, \
|
||||
conj_t conjb, \
|
||||
dim_t m, \
|
||||
dim_t n, \
|
||||
dim_t k, \
|
||||
void* restrict alpha, \
|
||||
void* restrict a, inc_t rs_a, inc_t cs_a, \
|
||||
void* restrict b, inc_t rs_b, inc_t cs_b, \
|
||||
void* restrict beta, \
|
||||
void* restrict c, inc_t rs_c, inc_t cs_c, \
|
||||
cntx_t* restrict cntx, \
|
||||
rntm_t* restrict rntm, \
|
||||
thrinfo_t* restrict thread \
|
||||
) \
|
||||
{ \
|
||||
const num_t dt = PASTEMAC(ch,type); \
|
||||
\
|
||||
/* Query the context for various blocksizes. */ \
|
||||
const dim_t NR = bli_cntx_get_blksz_def_dt( dt, BLIS_NR, cntx ); \
|
||||
const dim_t MR = bli_cntx_get_blksz_def_dt( dt, BLIS_MR, cntx ); \
|
||||
const dim_t NC = bli_cntx_get_blksz_def_dt( dt, BLIS_NC, cntx ); \
|
||||
const dim_t MC = bli_cntx_get_blksz_def_dt( dt, BLIS_MC, cntx ); \
|
||||
const dim_t KC = bli_cntx_get_blksz_def_dt( dt, BLIS_KC, cntx ); \
|
||||
\
|
||||
/* Query the context for the microkernel address and cast it to its
|
||||
function pointer type. */ \
|
||||
PASTECH(ch,gemm_ukr_ft) \
|
||||
gemm_ukr = bli_cntx_get_l3_nat_ukr_dt( dt, BLIS_GEMM_UKR, cntx ); \
|
||||
\
|
||||
/* Temporary C buffer for edge cases. Note that the strides of this
|
||||
temporary buffer are set so that they match the storage of the
|
||||
original C matrix. For example, if C is column-stored, ct will be
|
||||
column-stored as well. */ \
|
||||
ctype ct[ BLIS_STACK_BUF_MAX_SIZE \
|
||||
/ sizeof( ctype ) ] \
|
||||
__attribute__((aligned(BLIS_STACK_BUF_ALIGN_SIZE))); \
|
||||
const bool col_pref = bli_cntx_l3_nat_ukr_prefers_cols_dt( dt, BLIS_GEMM_UKR, cntx ); \
|
||||
const inc_t rs_ct = ( col_pref ? 1 : NR ); \
|
||||
const inc_t cs_ct = ( col_pref ? MR : 1 ); \
|
||||
\
|
||||
/* Compute partitioning step values for each matrix of each loop. */ \
|
||||
const inc_t jcstep_c = cs_c; \
|
||||
const inc_t jcstep_b = cs_b; \
|
||||
\
|
||||
const inc_t pcstep_a = cs_a; \
|
||||
const inc_t pcstep_b = rs_b; \
|
||||
\
|
||||
const inc_t icstep_c = rs_c; \
|
||||
const inc_t icstep_a = rs_a; \
|
||||
\
|
||||
const inc_t jrstep_c = cs_c * NR; \
|
||||
\
|
||||
const inc_t irstep_c = rs_c * MR; \
|
||||
\
|
||||
ctype* restrict a_00 = a; \
|
||||
ctype* restrict b_00 = b; \
|
||||
ctype* restrict c_00 = c; \
|
||||
ctype* restrict alpha_cast = alpha; \
|
||||
ctype* restrict beta_cast = beta; \
|
||||
\
|
||||
/* Make local copies of the scalars to prevent any unnecessary sharing of
|
||||
cache lines between the cores' caches. */ \
|
||||
ctype alpha_local = *alpha_cast; \
|
||||
ctype beta_local = *beta_cast; \
|
||||
ctype one_local = *PASTEMAC(ch,1); \
|
||||
ctype zero_local = *PASTEMAC(ch,0); \
|
||||
\
|
||||
auxinfo_t aux; \
|
||||
\
|
||||
/* Initialize a mem_t entry for A and B. Strictly speaking, this is only
|
||||
needed for the matrix we will be packing (if any), but we do it
|
||||
unconditionally to be safe. */ \
|
||||
mem_t mem_a = BLIS_MEM_INITIALIZER; \
|
||||
mem_t mem_b = BLIS_MEM_INITIALIZER; \
|
||||
\
|
||||
/* Define an array of bszid_t ids, which will act as our substitute for
|
||||
the cntl_t tree. */ \
|
||||
bszid_t bszids[8] = { BLIS_NC, /* 5th loop */ \
|
||||
BLIS_KC, /* 4th loop */ \
|
||||
BLIS_NO_PART, /* pack B */ \
|
||||
BLIS_MC, /* 3rd loop */ \
|
||||
BLIS_NO_PART, /* pack A */ \
|
||||
BLIS_NR, /* 2nd loop */ \
|
||||
BLIS_MR, /* 1st loop */ \
|
||||
BLIS_KR }; /* microkernel loop */ \
|
||||
\
|
||||
bszid_t* restrict bszids_jc = &bszids[0]; \
|
||||
bszid_t* restrict bszids_pc = &bszids[1]; \
|
||||
/*bszid_t* restrict bszids_pb = &bszids[2];*/ \
|
||||
bszid_t* restrict bszids_ic = &bszids[3]; \
|
||||
/*bszid_t* restrict bszids_pa = &bszids[4];*/ \
|
||||
bszid_t* restrict bszids_jr = &bszids[5]; \
|
||||
/*bszid_t* restrict bszids_ir = &bszids[6];*/ \
|
||||
\
|
||||
thrinfo_t* restrict thread_jc = NULL; \
|
||||
thrinfo_t* restrict thread_pc = NULL; \
|
||||
thrinfo_t* restrict thread_pb = NULL; \
|
||||
thrinfo_t* restrict thread_ic = NULL; \
|
||||
thrinfo_t* restrict thread_pa = NULL; \
|
||||
thrinfo_t* restrict thread_jr = NULL; \
|
||||
thrinfo_t* restrict thread_ir = NULL; \
|
||||
\
|
||||
/* Identify the current thrinfo_t node and then grow the tree. */ \
|
||||
thread_jc = thread; \
|
||||
bli_thrinfo_sup_grow( rntm, bszids_jc, thread_jc ); \
|
||||
\
|
||||
/* Compute the JC loop thread range for the current thread. */ \
|
||||
dim_t jc_start, jc_end; \
|
||||
bli_thread_range_sub( thread_jc, n, NR, FALSE, &jc_start, &jc_end ); \
|
||||
const dim_t n_local = jc_end - jc_start; \
|
||||
\
|
||||
/* Compute number of primary and leftover components of the JC loop. */ \
|
||||
/*const dim_t jc_iter = ( n_local + NC - 1 ) / NC;*/ \
|
||||
const dim_t jc_left = n_local % NC; \
|
||||
\
|
||||
/* Loop over the n dimension (NC rows/columns at a time). */ \
|
||||
for ( dim_t jj = jc_start; jj < jc_end; jj += NC ) \
|
||||
{ \
|
||||
/* Calculate the thread's current JC block dimension. */ \
|
||||
const dim_t nc_cur = ( NC <= jc_end - jj ? NC : jc_left ); \
|
||||
\
|
||||
ctype* restrict b_jc = b_00 + jj * jcstep_b; \
|
||||
ctype* restrict c_jc = c_00 + jj * jcstep_c; \
|
||||
\
|
||||
/* Identify the current thrinfo_t node and then grow the tree. */ \
|
||||
thread_pc = bli_thrinfo_sub_node( thread_jc ); \
|
||||
bli_thrinfo_sup_grow( rntm, bszids_pc, thread_pc ); \
|
||||
\
|
||||
/* Compute the PC loop thread range for the current thread. */ \
|
||||
const dim_t pc_start = 0, pc_end = k; \
|
||||
const dim_t k_local = k; \
|
||||
\
|
||||
/* Compute number of primary and leftover components of the PC loop. */ \
|
||||
/*const dim_t pc_iter = ( k_local + KC - 1 ) / KC;*/ \
|
||||
const dim_t pc_left = k_local % KC; \
|
||||
\
|
||||
/* Loop over the k dimension (KC rows/columns at a time). */ \
|
||||
for ( dim_t pp = pc_start; pp < pc_end; pp += KC ) \
|
||||
{ \
|
||||
/* Calculate the thread's current PC block dimension. */ \
|
||||
const dim_t kc_cur = ( KC <= pc_end - pp ? KC : pc_left ); \
|
||||
\
|
||||
ctype* restrict a_pc = a_00 + pp * pcstep_a; \
|
||||
ctype* restrict b_pc = b_jc + pp * pcstep_b; \
|
||||
\
|
||||
/* Only apply beta to the first iteration of the pc loop. */ \
|
||||
ctype* restrict beta_use = ( pp == 0 ? &beta_local : &one_local ); \
|
||||
\
|
||||
ctype* b_use; \
|
||||
inc_t rs_b_use, cs_b_use, ps_b_use; \
|
||||
\
|
||||
/* Identify the current thrinfo_t node. Note that the thrinfo_t
|
||||
node will have already been created by a previous call to
|
||||
bli_thrinfo_sup_grow() since bszid_t values of BLIS_NO_PART
|
||||
cause the tree to grow by two (e.g. to the next bszid that is
|
||||
a normal bszid_t value). */ \
|
||||
thread_pb = bli_thrinfo_sub_node( thread_pc ); \
|
||||
/*bli_thrinfo_sup_grow( rntm, bszids_pb, thread_pb );*/ \
|
||||
\
|
||||
/* Determine the packing buffer and related parameters for matrix
|
||||
B. Then call the packm implementation. */ \
|
||||
PASTECH2(bls_,ch,packm_b) \
|
||||
( \
|
||||
conjb, \
|
||||
KC, NC, \
|
||||
kc_cur, nc_cur, NR, \
|
||||
&one_local, \
|
||||
b_pc, rs_b, cs_b, \
|
||||
&b_use, &rs_b_use, &cs_b_use, \
|
||||
&ps_b_use, \
|
||||
cntx, \
|
||||
rntm, \
|
||||
&mem_b, \
|
||||
thread_pb \
|
||||
); \
|
||||
\
|
||||
/* Alias b_use so that it's clear this is our current block of
|
||||
matrix B. */ \
|
||||
ctype* restrict b_pc_use = b_use; \
|
||||
\
|
||||
/* Identify the current thrinfo_t node and then grow the tree. */ \
|
||||
thread_ic = bli_thrinfo_sub_node( thread_pb ); \
|
||||
bli_thrinfo_sup_grow( rntm, bszids_ic, thread_ic ); \
|
||||
\
|
||||
/* Compute the IC loop thread range for the current thread. */ \
|
||||
dim_t ic_start, ic_end; \
|
||||
bli_thread_range_sub( thread_ic, m, MR, FALSE, &ic_start, &ic_end ); \
|
||||
const dim_t m_local = ic_end - ic_start; \
|
||||
\
|
||||
/* Compute number of primary and leftover components of the IC loop. */ \
|
||||
/*const dim_t ic_iter = ( m_local + MC - 1 ) / MC;*/ \
|
||||
const dim_t ic_left = m_local % MC; \
|
||||
\
|
||||
/* Loop over the m dimension (MC rows at a time). */ \
|
||||
for ( dim_t ii = ic_start; ii < ic_end; ii += MC ) \
|
||||
{ \
|
||||
/* Calculate the thread's current IC block dimension. */ \
|
||||
const dim_t mc_cur = ( MC <= ic_end - ii ? MC : ic_left ); \
|
||||
\
|
||||
ctype* restrict a_ic = a_pc + ii * icstep_a; \
|
||||
ctype* restrict c_ic = c_jc + ii * icstep_c; \
|
||||
\
|
||||
ctype* a_use; \
|
||||
inc_t rs_a_use, cs_a_use, ps_a_use; \
|
||||
\
|
||||
/* Identify the current thrinfo_t node. Note that the thrinfo_t
|
||||
node will have already been created by a previous call to
|
||||
bli_thrinfo_sup_grow() since bszid_t values of BLIS_NO_PART
|
||||
cause the tree to grow by two (e.g. to the next bszid that is
|
||||
a normal bszid_t value). */ \
|
||||
thread_pa = bli_thrinfo_sub_node( thread_ic ); \
|
||||
/*bli_thrinfo_sup_grow( rntm, bszids_pa, thread_pa );*/ \
|
||||
\
|
||||
/* Determine the packing buffer and related parameters for matrix
|
||||
A. Then call the packm implementation. */ \
|
||||
PASTECH2(bls_,ch,packm_a) \
|
||||
( \
|
||||
conja, \
|
||||
MC, KC, \
|
||||
mc_cur, kc_cur, MR, \
|
||||
&one_local, \
|
||||
a_ic, rs_a, cs_a, \
|
||||
&a_use, &rs_a_use, &cs_a_use, \
|
||||
&ps_a_use, \
|
||||
cntx, \
|
||||
rntm, \
|
||||
&mem_a, \
|
||||
thread_pa \
|
||||
); \
|
||||
\
|
||||
/* Alias a_use so that it's clear this is our current block of
|
||||
matrix A. */ \
|
||||
ctype* restrict a_ic_use = a_use; \
|
||||
\
|
||||
/* Identify the current thrinfo_t node and then grow the tree. */ \
|
||||
thread_jr = bli_thrinfo_sub_node( thread_pa ); \
|
||||
bli_thrinfo_sup_grow( rntm, bszids_jr, thread_jr ); \
|
||||
\
|
||||
/* Query the number of threads and thread ids for the JR loop.
|
||||
NOTE: These values are only needed when computing the next
|
||||
micropanel of B. */ \
|
||||
const dim_t jr_nt = bli_thread_n_way( thread_jr ); \
|
||||
const dim_t jr_tid = bli_thread_work_id( thread_jr ); \
|
||||
\
|
||||
/* Compute number of primary and leftover components of the JR loop. */ \
|
||||
dim_t jr_iter = ( nc_cur + NR - 1 ) / NR; \
|
||||
dim_t jr_left = nc_cur % NR; \
|
||||
\
|
||||
/* Compute the JR loop thread range for the current thread. */ \
|
||||
dim_t jr_start, jr_end; \
|
||||
bli_thread_range_sub( thread_jr, jr_iter, 1, FALSE, &jr_start, &jr_end ); \
|
||||
\
|
||||
/* Loop over the n dimension (NR columns at a time). */ \
|
||||
for ( dim_t j = jr_start; j < jr_end; j += 1 ) \
|
||||
{ \
|
||||
const dim_t nr_cur \
|
||||
= ( bli_is_not_edge_f( j, jr_iter, jr_left ) ? NR : jr_left ); \
|
||||
\
|
||||
ctype* restrict b_jr = b_pc_use + j * ps_b_use; \
|
||||
ctype* restrict c_jr = c_ic + j * jrstep_c; \
|
||||
\
|
||||
/* Assume for now that our next panel of B to be the current panel
|
||||
of B. */ \
|
||||
ctype* restrict b2 = b_jr; \
|
||||
\
|
||||
/* Identify the current thrinfo_t node. */ \
|
||||
thread_ir = bli_thrinfo_sub_node( thread_jr ); \
|
||||
\
|
||||
/* Query the number of threads and thread ids for the IR loop.
|
||||
NOTE: These values are only needed when computing the next
|
||||
micropanel of A. */ \
|
||||
const dim_t ir_nt = bli_thread_n_way( thread_ir ); \
|
||||
const dim_t ir_tid = bli_thread_work_id( thread_ir ); \
|
||||
\
|
||||
/* Compute number of primary and leftover components of the IR loop. */ \
|
||||
dim_t ir_iter = ( mc_cur + MR - 1 ) / MR; \
|
||||
dim_t ir_left = mc_cur % MR; \
|
||||
\
|
||||
/* Compute the IR loop thread range for the current thread. */ \
|
||||
dim_t ir_start, ir_end; \
|
||||
bli_thread_range_sub( thread_ir, ir_iter, 1, FALSE, &ir_start, &ir_end ); \
|
||||
\
|
||||
/* Loop over the m dimension (MR rows at a time). */ \
|
||||
for ( dim_t i = ir_start; i < ir_end; i += 1 ) \
|
||||
{ \
|
||||
const dim_t mr_cur \
|
||||
= ( bli_is_not_edge_f( i, ir_iter, ir_left ) ? MR : ir_left ); \
|
||||
\
|
||||
ctype* restrict a_ir = a_ic_use + i * ps_a_use; \
|
||||
ctype* restrict c_ir = c_jr + i * irstep_c; \
|
||||
\
|
||||
ctype* restrict a2; \
|
||||
\
|
||||
/* Compute the addresses of the next micropanels of A and B. */ \
|
||||
a2 = bli_gemm_get_next_a_upanel( a_ir, ps_a_use, 1 ); \
|
||||
if ( bli_is_last_iter( i, ir_end, ir_tid, ir_nt ) ) \
|
||||
{ \
|
||||
a2 = a_ic_use; \
|
||||
b2 = bli_gemm_get_next_b_upanel( b_jr, ps_b_use, 1 ); \
|
||||
if ( bli_is_last_iter( j, jr_end, jr_tid, jr_nt ) ) \
|
||||
b2 = b_pc_use; \
|
||||
} \
|
||||
\
|
||||
/* Save the addresses of next micropanels of A and B to the
|
||||
auxinfo_t object. */ \
|
||||
bli_auxinfo_set_next_a( a2, &aux ); \
|
||||
bli_auxinfo_set_next_b( b2, &aux ); \
|
||||
\
|
||||
/* Handle interior and edge cases separately. */ \
|
||||
if ( mr_cur == MR && nr_cur == NR ) \
|
||||
{ \
|
||||
/* Invoke the gemm microkernel. */ \
|
||||
gemm_ukr \
|
||||
( \
|
||||
kc_cur, \
|
||||
&alpha_local, \
|
||||
a_ir, \
|
||||
b_jr, \
|
||||
beta_use, \
|
||||
c_ir, rs_c, cs_c, \
|
||||
&aux, \
|
||||
cntx \
|
||||
); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
/* Invoke the gemm microkernel. */ \
|
||||
gemm_ukr \
|
||||
( \
|
||||
kc_cur, \
|
||||
&alpha_local, \
|
||||
a_ir, \
|
||||
b_jr, \
|
||||
&zero_local, \
|
||||
ct, rs_ct, cs_ct, \
|
||||
&aux, \
|
||||
cntx \
|
||||
); \
|
||||
\
|
||||
/* Scale the bottom edge of C and add the result from above. */ \
|
||||
PASTEMAC(ch,xpbys_mxn) \
|
||||
( \
|
||||
mr_cur, \
|
||||
nr_cur, \
|
||||
ct, rs_ct, cs_ct, \
|
||||
beta_use, \
|
||||
c_ir, rs_c, cs_c \
|
||||
); \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
/* This barrier is needed to prevent threads from starting to pack
|
||||
the next row panel of B before the current row panel is fully
|
||||
computed upon. */ \
|
||||
bli_thread_barrier( thread_pb ); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
/* Release any memory that was acquired for packing matrices A and B. */ \
|
||||
PASTECH2(bls_,ch,packm_finalize_mem_a) \
|
||||
( \
|
||||
rntm, \
|
||||
&mem_a, \
|
||||
thread_pa \
|
||||
); \
|
||||
PASTECH2(bls_,ch,packm_finalize_mem_b) \
|
||||
( \
|
||||
rntm, \
|
||||
&mem_b, \
|
||||
thread_pb \
|
||||
); \
|
||||
\
|
||||
/*
|
||||
PASTEMAC(ch,fprintm)( stdout, "gemm_bp_var1: a1_packed", mr_cur, kc_cur, a_ir, rs_a_use, cs_a_use, "%5.2f", "" ); \
|
||||
PASTEMAC(ch,fprintm)( stdout, "gemm_bp_var1: b1_packed", kc_cur, nr_cur, b_jr, rs_b_use, cs_b_use, "%5.2f", "" ); \
|
||||
PASTEMAC(ch,fprintm)( stdout, "gemm_bp_var1: c ", mr_cur, nr_cur, c_ir, rs_c, cs_c, "%5.2f", "" ); \
|
||||
*/ \
|
||||
}
|
||||
|
||||
//INSERT_GENTFUNC_BASIC0( gemm_bp_var1 )
|
||||
GENTFUNC( float, s, gemm_bp_var1 )
|
||||
GENTFUNC( double, d, gemm_bp_var1 )
|
||||
GENTFUNC( scomplex, c, gemm_bp_var1 )
|
||||
GENTFUNC( dcomplex, z, gemm_bp_var1 )
|
||||
|
||||
590
sandbox/gemmlike/bls_gemm_bp_var2.c
Normal file
590
sandbox/gemmlike/bls_gemm_bp_var2.c
Normal file
@@ -0,0 +1,590 @@
|
||||
/*
|
||||
|
||||
BLIS
|
||||
An object-based framework for developing high-performance BLAS-like
|
||||
libraries.
|
||||
|
||||
Copyright (C) 2021, The University of Texas at Austin
|
||||
|
||||
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"
|
||||
|
||||
#define FUNCPTR_T gemm_fp
|
||||
|
||||
typedef void (*FUNCPTR_T)
|
||||
(
|
||||
conj_t conja,
|
||||
conj_t conjb,
|
||||
dim_t m,
|
||||
dim_t n,
|
||||
dim_t k,
|
||||
void* restrict alpha,
|
||||
void* restrict a, inc_t rs_a, inc_t cs_a,
|
||||
void* restrict b, inc_t rs_b, inc_t cs_b,
|
||||
void* restrict beta,
|
||||
void* restrict c, inc_t rs_c, inc_t cs_c,
|
||||
cntx_t* restrict cntx,
|
||||
rntm_t* restrict rntm,
|
||||
thrinfo_t* restrict thread
|
||||
);
|
||||
|
||||
//
|
||||
// -- gemm-like block-panel algorithm (object interface) -----------------------
|
||||
//
|
||||
|
||||
// Define a function pointer array named ftypes and initialize its contents with
|
||||
// the addresses of the typed functions defined below, bls_?gemm_bp_var2().
|
||||
static FUNCPTR_T GENARRAY_PREF(ftypes,bls_,gemm_bp_var2);
|
||||
|
||||
void bls_gemm_bp_var2
|
||||
(
|
||||
obj_t* alpha,
|
||||
obj_t* a,
|
||||
obj_t* b,
|
||||
obj_t* beta,
|
||||
obj_t* c,
|
||||
cntx_t* cntx,
|
||||
rntm_t* rntm,
|
||||
thrinfo_t* thread
|
||||
)
|
||||
{
|
||||
const num_t dt = bli_obj_dt( c );
|
||||
|
||||
const conj_t conja = bli_obj_conj_status( a );
|
||||
const conj_t conjb = bli_obj_conj_status( b );
|
||||
|
||||
const dim_t m = bli_obj_length( c );
|
||||
const dim_t n = bli_obj_width( c );
|
||||
const dim_t k = bli_obj_width( a );
|
||||
|
||||
void* restrict buf_a = bli_obj_buffer_at_off( a );
|
||||
const inc_t rs_a = bli_obj_row_stride( a );
|
||||
const inc_t cs_a = bli_obj_col_stride( a );
|
||||
|
||||
void* restrict buf_b = bli_obj_buffer_at_off( b );
|
||||
const inc_t rs_b = bli_obj_row_stride( b );
|
||||
const inc_t cs_b = bli_obj_col_stride( b );
|
||||
|
||||
void* restrict buf_c = bli_obj_buffer_at_off( c );
|
||||
const inc_t rs_c = bli_obj_row_stride( c );
|
||||
const inc_t cs_c = bli_obj_col_stride( c );
|
||||
|
||||
void* restrict buf_alpha = bli_obj_buffer_for_1x1( dt, alpha );
|
||||
void* restrict buf_beta = bli_obj_buffer_for_1x1( dt, beta );
|
||||
|
||||
// Index into the function pointer array to extract the correct
|
||||
// typed function pointer based on the chosen datatype.
|
||||
FUNCPTR_T f = ftypes[dt];
|
||||
|
||||
// Invoke the function.
|
||||
f
|
||||
(
|
||||
conja,
|
||||
conjb,
|
||||
m,
|
||||
n,
|
||||
k,
|
||||
buf_alpha,
|
||||
buf_a, rs_a, cs_a,
|
||||
buf_b, rs_b, cs_b,
|
||||
buf_beta,
|
||||
buf_c, rs_c, cs_c,
|
||||
cntx,
|
||||
rntm,
|
||||
thread
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// -- gemm-like block-panel algorithm (typed interface) ------------------------
|
||||
//
|
||||
|
||||
#undef GENTFUNC
|
||||
#define GENTFUNC( ctype, ch, varname ) \
|
||||
\
|
||||
void PASTECH2(bls_,ch,varname) \
|
||||
( \
|
||||
conj_t conja, \
|
||||
conj_t conjb, \
|
||||
dim_t m, \
|
||||
dim_t n, \
|
||||
dim_t k, \
|
||||
void* restrict alpha, \
|
||||
void* restrict a, inc_t rs_a, inc_t cs_a, \
|
||||
void* restrict b, inc_t rs_b, inc_t cs_b, \
|
||||
void* restrict beta, \
|
||||
void* restrict c, inc_t rs_c, inc_t cs_c, \
|
||||
cntx_t* restrict cntx, \
|
||||
rntm_t* restrict rntm, \
|
||||
thrinfo_t* restrict thread \
|
||||
) \
|
||||
{ \
|
||||
const num_t dt = PASTEMAC(ch,type); \
|
||||
\
|
||||
/* Query the context for various blocksizes. */ \
|
||||
const dim_t NR = bli_cntx_get_blksz_def_dt( dt, BLIS_NR, cntx ); \
|
||||
const dim_t MR = bli_cntx_get_blksz_def_dt( dt, BLIS_MR, cntx ); \
|
||||
const dim_t NC = bli_cntx_get_blksz_def_dt( dt, BLIS_NC, cntx ); \
|
||||
const dim_t MC = bli_cntx_get_blksz_def_dt( dt, BLIS_MC, cntx ); \
|
||||
const dim_t KC = bli_cntx_get_blksz_def_dt( dt, BLIS_KC, cntx ); \
|
||||
\
|
||||
/* Query the context for the microkernel address and cast it to its
|
||||
function pointer type. */ \
|
||||
/*
|
||||
PASTECH(ch,gemm_ukr_ft) \
|
||||
gemm_ukr = bli_cntx_get_l3_nat_ukr_dt( dt, BLIS_GEMM_UKR, cntx ); \
|
||||
*/ \
|
||||
\
|
||||
/* Temporary C buffer for edge cases. Note that the strides of this
|
||||
temporary buffer are set so that they match the storage of the
|
||||
original C matrix. For example, if C is column-stored, ct will be
|
||||
column-stored as well. */ \
|
||||
/*
|
||||
ctype ct[ BLIS_STACK_BUF_MAX_SIZE \
|
||||
/ sizeof( ctype ) ] \
|
||||
__attribute__((aligned(BLIS_STACK_BUF_ALIGN_SIZE))); \
|
||||
const bool col_pref = bli_cntx_l3_nat_ukr_prefers_cols_dt( dt, BLIS_GEMM_UKR, cntx ); \
|
||||
const inc_t rs_ct = ( col_pref ? 1 : NR ); \
|
||||
const inc_t cs_ct = ( col_pref ? MR : 1 ); \
|
||||
*/ \
|
||||
\
|
||||
/* Compute partitioning step values for each matrix of each loop. */ \
|
||||
const inc_t jcstep_c = cs_c; \
|
||||
const inc_t jcstep_b = cs_b; \
|
||||
\
|
||||
const inc_t pcstep_a = cs_a; \
|
||||
const inc_t pcstep_b = rs_b; \
|
||||
\
|
||||
const inc_t icstep_c = rs_c; \
|
||||
const inc_t icstep_a = rs_a; \
|
||||
\
|
||||
const inc_t jrstep_c = cs_c * NR; \
|
||||
\
|
||||
const inc_t irstep_c = rs_c * MR; \
|
||||
\
|
||||
ctype* restrict a_00 = a; \
|
||||
ctype* restrict b_00 = b; \
|
||||
ctype* restrict c_00 = c; \
|
||||
ctype* restrict alpha_cast = alpha; \
|
||||
ctype* restrict beta_cast = beta; \
|
||||
\
|
||||
/* Make local copies of the scalars to prevent any unnecessary sharing of
|
||||
cache lines between the cores' caches. */ \
|
||||
ctype alpha_local = *alpha_cast; \
|
||||
ctype beta_local = *beta_cast; \
|
||||
ctype one_local = *PASTEMAC(ch,1); \
|
||||
/*ctype zero_local = *PASTEMAC(ch,0);*/ \
|
||||
\
|
||||
auxinfo_t aux; \
|
||||
\
|
||||
/* Initialize a mem_t entry for A and B. Strictly speaking, this is only
|
||||
needed for the matrix we will be packing (if any), but we do it
|
||||
unconditionally to be safe. */ \
|
||||
mem_t mem_a = BLIS_MEM_INITIALIZER; \
|
||||
mem_t mem_b = BLIS_MEM_INITIALIZER; \
|
||||
\
|
||||
/* Define an array of bszid_t ids, which will act as our substitute for
|
||||
the cntl_t tree. */ \
|
||||
bszid_t bszids[8] = { BLIS_NC, /* 5th loop */ \
|
||||
BLIS_KC, /* 4th loop */ \
|
||||
BLIS_NO_PART, /* pack B */ \
|
||||
BLIS_MC, /* 3rd loop */ \
|
||||
BLIS_NO_PART, /* pack A */ \
|
||||
BLIS_NR, /* 2nd loop */ \
|
||||
BLIS_MR, /* 1st loop */ \
|
||||
BLIS_KR }; /* microkernel loop */ \
|
||||
\
|
||||
bszid_t* restrict bszids_jc = &bszids[0]; \
|
||||
bszid_t* restrict bszids_pc = &bszids[1]; \
|
||||
/*bszid_t* restrict bszids_pb = &bszids[2];*/ \
|
||||
bszid_t* restrict bszids_ic = &bszids[3]; \
|
||||
/*bszid_t* restrict bszids_pa = &bszids[4];*/ \
|
||||
bszid_t* restrict bszids_jr = &bszids[5]; \
|
||||
/*bszid_t* restrict bszids_ir = &bszids[6];*/ \
|
||||
\
|
||||
thrinfo_t* restrict thread_jc = NULL; \
|
||||
thrinfo_t* restrict thread_pc = NULL; \
|
||||
thrinfo_t* restrict thread_pb = NULL; \
|
||||
thrinfo_t* restrict thread_ic = NULL; \
|
||||
thrinfo_t* restrict thread_pa = NULL; \
|
||||
thrinfo_t* restrict thread_jr = NULL; \
|
||||
thrinfo_t* restrict thread_ir = NULL; \
|
||||
\
|
||||
/* Identify the current thrinfo_t node and then grow the tree. */ \
|
||||
thread_jc = thread; \
|
||||
bli_thrinfo_sup_grow( rntm, bszids_jc, thread_jc ); \
|
||||
\
|
||||
/* Compute the JC loop thread range for the current thread. */ \
|
||||
dim_t jc_start, jc_end; \
|
||||
bli_thread_range_sub( thread_jc, n, NR, FALSE, &jc_start, &jc_end ); \
|
||||
const dim_t n_local = jc_end - jc_start; \
|
||||
\
|
||||
/* Compute number of primary and leftover components of the JC loop. */ \
|
||||
/*const dim_t jc_iter = ( n_local + NC - 1 ) / NC;*/ \
|
||||
const dim_t jc_left = n_local % NC; \
|
||||
\
|
||||
/* Loop over the n dimension (NC rows/columns at a time). */ \
|
||||
for ( dim_t jj = jc_start; jj < jc_end; jj += NC ) \
|
||||
{ \
|
||||
/* Calculate the thread's current JC block dimension. */ \
|
||||
const dim_t nc_cur = ( NC <= jc_end - jj ? NC : jc_left ); \
|
||||
\
|
||||
ctype* restrict b_jc = b_00 + jj * jcstep_b; \
|
||||
ctype* restrict c_jc = c_00 + jj * jcstep_c; \
|
||||
\
|
||||
/* Identify the current thrinfo_t node and then grow the tree. */ \
|
||||
thread_pc = bli_thrinfo_sub_node( thread_jc ); \
|
||||
bli_thrinfo_sup_grow( rntm, bszids_pc, thread_pc ); \
|
||||
\
|
||||
/* Compute the PC loop thread range for the current thread. */ \
|
||||
const dim_t pc_start = 0, pc_end = k; \
|
||||
const dim_t k_local = k; \
|
||||
\
|
||||
/* Compute number of primary and leftover components of the PC loop. */ \
|
||||
/*const dim_t pc_iter = ( k_local + KC - 1 ) / KC;*/ \
|
||||
const dim_t pc_left = k_local % KC; \
|
||||
\
|
||||
/* Loop over the k dimension (KC rows/columns at a time). */ \
|
||||
for ( dim_t pp = pc_start; pp < pc_end; pp += KC ) \
|
||||
{ \
|
||||
/* Calculate the thread's current PC block dimension. */ \
|
||||
const dim_t kc_cur = ( KC <= pc_end - pp ? KC : pc_left ); \
|
||||
\
|
||||
ctype* restrict a_pc = a_00 + pp * pcstep_a; \
|
||||
ctype* restrict b_pc = b_jc + pp * pcstep_b; \
|
||||
\
|
||||
/* Only apply beta to the first iteration of the pc loop. */ \
|
||||
ctype* restrict beta_use = ( pp == 0 ? &beta_local : &one_local ); \
|
||||
\
|
||||
ctype* b_use; \
|
||||
inc_t rs_b_use, cs_b_use, ps_b_use; \
|
||||
\
|
||||
/* Identify the current thrinfo_t node. Note that the thrinfo_t
|
||||
node will have already been created by a previous call to
|
||||
bli_thrinfo_sup_grow() since bszid_t values of BLIS_NO_PART
|
||||
cause the tree to grow by two (e.g. to the next bszid that is
|
||||
a normal bszid_t value). */ \
|
||||
thread_pb = bli_thrinfo_sub_node( thread_pc ); \
|
||||
/*bli_thrinfo_sup_grow( rntm, bszids_pb, thread_pb );*/ \
|
||||
\
|
||||
/* Determine the packing buffer and related parameters for matrix
|
||||
B. Then call the packm implementation. */ \
|
||||
PASTECH2(bls_,ch,packm_b) \
|
||||
( \
|
||||
conjb, \
|
||||
KC, NC, \
|
||||
kc_cur, nc_cur, NR, \
|
||||
&one_local, \
|
||||
b_pc, rs_b, cs_b, \
|
||||
&b_use, &rs_b_use, &cs_b_use, \
|
||||
&ps_b_use, \
|
||||
cntx, \
|
||||
rntm, \
|
||||
&mem_b, \
|
||||
thread_pb \
|
||||
); \
|
||||
\
|
||||
/* Alias b_use so that it's clear this is our current block of
|
||||
matrix B. */ \
|
||||
ctype* restrict b_pc_use = b_use; \
|
||||
\
|
||||
/* Identify the current thrinfo_t node and then grow the tree. */ \
|
||||
thread_ic = bli_thrinfo_sub_node( thread_pb ); \
|
||||
bli_thrinfo_sup_grow( rntm, bszids_ic, thread_ic ); \
|
||||
\
|
||||
/* Compute the IC loop thread range for the current thread. */ \
|
||||
dim_t ic_start, ic_end; \
|
||||
bli_thread_range_sub( thread_ic, m, MR, FALSE, &ic_start, &ic_end ); \
|
||||
const dim_t m_local = ic_end - ic_start; \
|
||||
\
|
||||
/* Compute number of primary and leftover components of the IC loop. */ \
|
||||
/*const dim_t ic_iter = ( m_local + MC - 1 ) / MC;*/ \
|
||||
const dim_t ic_left = m_local % MC; \
|
||||
\
|
||||
/* Loop over the m dimension (MC rows at a time). */ \
|
||||
for ( dim_t ii = ic_start; ii < ic_end; ii += MC ) \
|
||||
{ \
|
||||
/* Calculate the thread's current IC block dimension. */ \
|
||||
const dim_t mc_cur = ( MC <= ic_end - ii ? MC : ic_left ); \
|
||||
\
|
||||
ctype* restrict a_ic = a_pc + ii * icstep_a; \
|
||||
ctype* restrict c_ic = c_jc + ii * icstep_c; \
|
||||
\
|
||||
ctype* a_use; \
|
||||
inc_t rs_a_use, cs_a_use, ps_a_use; \
|
||||
\
|
||||
/* Identify the current thrinfo_t node. Note that the thrinfo_t
|
||||
node will have already been created by a previous call to
|
||||
bli_thrinfo_sup_grow() since bszid_t values of BLIS_NO_PART
|
||||
cause the tree to grow by two (e.g. to the next bszid that is
|
||||
a normal bszid_t value). */ \
|
||||
thread_pa = bli_thrinfo_sub_node( thread_ic ); \
|
||||
/*bli_thrinfo_sup_grow( rntm, bszids_pa, thread_pa );*/ \
|
||||
\
|
||||
/* Determine the packing buffer and related parameters for matrix
|
||||
A. Then call the packm implementation. */ \
|
||||
PASTECH2(bls_,ch,packm_a) \
|
||||
( \
|
||||
conja, \
|
||||
MC, KC, \
|
||||
mc_cur, kc_cur, MR, \
|
||||
&one_local, \
|
||||
a_ic, rs_a, cs_a, \
|
||||
&a_use, &rs_a_use, &cs_a_use, \
|
||||
&ps_a_use, \
|
||||
cntx, \
|
||||
rntm, \
|
||||
&mem_a, \
|
||||
thread_pa \
|
||||
); \
|
||||
\
|
||||
/* Alias a_use so that it's clear this is our current block of
|
||||
matrix A. */ \
|
||||
ctype* restrict a_ic_use = a_use; \
|
||||
\
|
||||
/* Identify the current thrinfo_t node and then grow the tree. */ \
|
||||
thread_jr = bli_thrinfo_sub_node( thread_pa ); \
|
||||
bli_thrinfo_sup_grow( rntm, bszids_jr, thread_jr ); \
|
||||
\
|
||||
/* Query the number of threads and thread ids for the JR loop.
|
||||
NOTE: These values are only needed when computing the next
|
||||
micropanel of B. */ \
|
||||
const dim_t jr_nt = bli_thread_n_way( thread_jr ); \
|
||||
const dim_t jr_tid = bli_thread_work_id( thread_jr ); \
|
||||
\
|
||||
/* Compute number of primary and leftover components of the JR loop. */ \
|
||||
dim_t jr_iter = ( nc_cur + NR - 1 ) / NR; \
|
||||
dim_t jr_left = nc_cur % NR; \
|
||||
\
|
||||
/* Compute the JR loop thread range for the current thread. */ \
|
||||
dim_t jr_start, jr_end; \
|
||||
bli_thread_range_sub( thread_jr, jr_iter, 1, FALSE, &jr_start, &jr_end ); \
|
||||
\
|
||||
/* Loop over the n dimension (NR columns at a time). */ \
|
||||
for ( dim_t j = jr_start; j < jr_end; j += 1 ) \
|
||||
{ \
|
||||
const dim_t nr_cur \
|
||||
= ( bli_is_not_edge_f( j, jr_iter, jr_left ) ? NR : jr_left ); \
|
||||
\
|
||||
ctype* restrict b_jr = b_pc_use + j * ps_b_use; \
|
||||
ctype* restrict c_jr = c_ic + j * jrstep_c; \
|
||||
\
|
||||
/* Assume for now that our next panel of B to be the current panel
|
||||
of B. */ \
|
||||
ctype* restrict b2 = b_jr; \
|
||||
\
|
||||
/* Identify the current thrinfo_t node. */ \
|
||||
thread_ir = bli_thrinfo_sub_node( thread_jr ); \
|
||||
\
|
||||
/* Query the number of threads and thread ids for the IR loop.
|
||||
NOTE: These values are only needed when computing the next
|
||||
micropanel of A. */ \
|
||||
const dim_t ir_nt = bli_thread_n_way( thread_ir ); \
|
||||
const dim_t ir_tid = bli_thread_work_id( thread_ir ); \
|
||||
\
|
||||
/* Compute number of primary and leftover components of the IR loop. */ \
|
||||
dim_t ir_iter = ( mc_cur + MR - 1 ) / MR; \
|
||||
dim_t ir_left = mc_cur % MR; \
|
||||
\
|
||||
/* Compute the IR loop thread range for the current thread. */ \
|
||||
dim_t ir_start, ir_end; \
|
||||
bli_thread_range_sub( thread_ir, ir_iter, 1, FALSE, &ir_start, &ir_end ); \
|
||||
\
|
||||
/* Loop over the m dimension (MR rows at a time). */ \
|
||||
for ( dim_t i = ir_start; i < ir_end; i += 1 ) \
|
||||
{ \
|
||||
const dim_t mr_cur \
|
||||
= ( bli_is_not_edge_f( i, ir_iter, ir_left ) ? MR : ir_left ); \
|
||||
\
|
||||
ctype* restrict a_ir = a_ic_use + i * ps_a_use; \
|
||||
ctype* restrict c_ir = c_jr + i * irstep_c; \
|
||||
\
|
||||
ctype* restrict a2; \
|
||||
\
|
||||
/* Compute the addresses of the next micropanels of A and B. */ \
|
||||
a2 = bli_gemm_get_next_a_upanel( a_ir, ps_a_use, 1 ); \
|
||||
if ( bli_is_last_iter( i, ir_end, ir_tid, ir_nt ) ) \
|
||||
{ \
|
||||
a2 = a_ic_use; \
|
||||
b2 = bli_gemm_get_next_b_upanel( b_jr, ps_b_use, 1 ); \
|
||||
if ( bli_is_last_iter( j, jr_end, jr_tid, jr_nt ) ) \
|
||||
b2 = b_pc_use; \
|
||||
} \
|
||||
\
|
||||
/* Save the addresses of next micropanels of A and B to the
|
||||
auxinfo_t object. */ \
|
||||
bli_auxinfo_set_next_a( a2, &aux ); \
|
||||
bli_auxinfo_set_next_b( b2, &aux ); \
|
||||
\
|
||||
/* Call a wrapper to the kernel (which handles edge cases). */ \
|
||||
PASTECH2(bls_,ch,gemm_kernel) \
|
||||
( \
|
||||
MR, \
|
||||
NR, \
|
||||
mr_cur, \
|
||||
nr_cur, \
|
||||
kc_cur, \
|
||||
&alpha_local, \
|
||||
a_ir, rs_a_use, cs_a_use, \
|
||||
b_jr, rs_b_use, cs_b_use, \
|
||||
beta_use, \
|
||||
c_ir, rs_c, cs_c, \
|
||||
&aux, \
|
||||
cntx \
|
||||
); \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
/* This barrier is needed to prevent threads from starting to pack
|
||||
the next row panel of B before the current row panel is fully
|
||||
computed upon. */ \
|
||||
bli_thread_barrier( thread_pb ); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
/* Release any memory that was acquired for packing matrices A and B. */ \
|
||||
PASTECH2(bls_,ch,packm_finalize_mem_a) \
|
||||
( \
|
||||
rntm, \
|
||||
&mem_a, \
|
||||
thread_pa \
|
||||
); \
|
||||
PASTECH2(bls_,ch,packm_finalize_mem_b) \
|
||||
( \
|
||||
rntm, \
|
||||
&mem_b, \
|
||||
thread_pb \
|
||||
); \
|
||||
\
|
||||
/*
|
||||
PASTEMAC(ch,fprintm)( stdout, "gemm_bp_var2: a1_packed", mr_cur, kc_cur, a_ir, rs_a_use, cs_a_use, "%5.2f", "" ); \
|
||||
PASTEMAC(ch,fprintm)( stdout, "gemm_bp_var2: b1_packed", kc_cur, nr_cur, b_jr, rs_b_use, cs_b_use, "%5.2f", "" ); \
|
||||
PASTEMAC(ch,fprintm)( stdout, "gemm_bp_var2: c ", mr_cur, nr_cur, c_ir, rs_c, cs_c, "%5.2f", "" ); \
|
||||
*/ \
|
||||
}
|
||||
|
||||
//INSERT_GENTFUNC_BASIC0( gemm_bp_var2 )
|
||||
GENTFUNC( float, s, gemm_bp_var2 )
|
||||
GENTFUNC( double, d, gemm_bp_var2 )
|
||||
GENTFUNC( scomplex, c, gemm_bp_var2 )
|
||||
GENTFUNC( dcomplex, z, gemm_bp_var2 )
|
||||
|
||||
//
|
||||
// -- gemm-like microkernel wrapper --------------------------------------------
|
||||
//
|
||||
|
||||
#undef GENTFUNC
|
||||
#define GENTFUNC( ctype, ch, varname ) \
|
||||
\
|
||||
void PASTECH2(bls_,ch,varname) \
|
||||
( \
|
||||
const dim_t MR, \
|
||||
const dim_t NR, \
|
||||
dim_t mr_cur, \
|
||||
dim_t nr_cur, \
|
||||
dim_t kc_cur, \
|
||||
ctype* restrict alpha, \
|
||||
ctype* restrict a, inc_t rs_a, inc_t cs_a, \
|
||||
ctype* restrict b, inc_t rs_b, inc_t cs_b, \
|
||||
ctype* restrict beta, \
|
||||
ctype* restrict c, inc_t rs_c, inc_t cs_c, \
|
||||
auxinfo_t* restrict aux, \
|
||||
cntx_t* restrict cntx \
|
||||
) \
|
||||
{ \
|
||||
/* Infer the datatype from the ctype. */ \
|
||||
const num_t dt = PASTEMAC(ch,type); \
|
||||
\
|
||||
/* Query the context for the microkernel address and cast it to its
|
||||
function pointer type. */ \
|
||||
PASTECH(ch,gemm_ukr_ft) \
|
||||
gemm_ukr = bli_cntx_get_l3_nat_ukr_dt( dt, BLIS_GEMM_UKR, cntx ); \
|
||||
\
|
||||
/* Temporary C buffer for edge cases. Note that the strides of this
|
||||
temporary buffer are set so that they match the storage of the
|
||||
original C matrix. For example, if C is column-stored, ct will be
|
||||
column-stored as well. */ \
|
||||
ctype ct[ BLIS_STACK_BUF_MAX_SIZE \
|
||||
/ sizeof( ctype ) ] \
|
||||
__attribute__((aligned(BLIS_STACK_BUF_ALIGN_SIZE))); \
|
||||
const bool col_pref = bli_cntx_l3_nat_ukr_prefers_cols_dt( dt, BLIS_GEMM_UKR, cntx ); \
|
||||
const inc_t rs_ct = ( col_pref ? 1 : NR ); \
|
||||
const inc_t cs_ct = ( col_pref ? MR : 1 ); \
|
||||
\
|
||||
ctype zero = *PASTEMAC(ch,0); \
|
||||
\
|
||||
/* Handle interior and edge cases separately. */ \
|
||||
if ( mr_cur == MR && nr_cur == NR ) \
|
||||
{ \
|
||||
/* Invoke the gemm microkernel. */ \
|
||||
gemm_ukr \
|
||||
( \
|
||||
kc_cur, \
|
||||
alpha, \
|
||||
a, \
|
||||
b, \
|
||||
beta, \
|
||||
c, rs_c, cs_c, \
|
||||
aux, \
|
||||
cntx \
|
||||
); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
/* Invoke the gemm microkernel. */ \
|
||||
gemm_ukr \
|
||||
( \
|
||||
kc_cur, \
|
||||
alpha, \
|
||||
a, \
|
||||
b, \
|
||||
&zero, \
|
||||
ct, rs_ct, cs_ct, \
|
||||
aux, \
|
||||
cntx \
|
||||
); \
|
||||
\
|
||||
/* Scale the bottom edge of C and add the result from above. */ \
|
||||
PASTEMAC(ch,xpbys_mxn) \
|
||||
( \
|
||||
mr_cur, \
|
||||
nr_cur, \
|
||||
ct, rs_ct, cs_ct, \
|
||||
beta, \
|
||||
c, rs_c, cs_c \
|
||||
); \
|
||||
} \
|
||||
}
|
||||
|
||||
//INSERT_GENTFUNC_BASIC0( gemm_kernel )
|
||||
GENTFUNC( float, s, gemm_kernel )
|
||||
GENTFUNC( double, d, gemm_kernel )
|
||||
GENTFUNC( scomplex, c, gemm_kernel )
|
||||
GENTFUNC( dcomplex, z, gemm_kernel )
|
||||
|
||||
124
sandbox/gemmlike/bls_gemm_var.h
Normal file
124
sandbox/gemmlike/bls_gemm_var.h
Normal file
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
|
||||
BLIS
|
||||
An object-based framework for developing high-performance BLAS-like
|
||||
libraries.
|
||||
|
||||
Copyright (C) 2021, The University of Texas at Austin
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
//
|
||||
// Prototype the object-based variant interfaces.
|
||||
//
|
||||
|
||||
#undef GENPROT
|
||||
#define GENPROT( opname ) \
|
||||
\
|
||||
void PASTECH(bls_,opname) \
|
||||
( \
|
||||
obj_t* alpha, \
|
||||
obj_t* a, \
|
||||
obj_t* b, \
|
||||
obj_t* beta, \
|
||||
obj_t* c, \
|
||||
cntx_t* cntx, \
|
||||
rntm_t* rntm, \
|
||||
thrinfo_t* thread \
|
||||
);
|
||||
|
||||
GENPROT( gemm_bp_var1 )
|
||||
GENPROT( gemm_bp_var2 )
|
||||
|
||||
|
||||
//
|
||||
// Prototype the typed variant interfaces.
|
||||
//
|
||||
|
||||
#undef GENTPROT
|
||||
#define GENTPROT( ctype, ch, varname ) \
|
||||
\
|
||||
void PASTECH2(bls_,ch,varname) \
|
||||
( \
|
||||
conj_t conja, \
|
||||
conj_t conjb, \
|
||||
dim_t m, \
|
||||
dim_t n, \
|
||||
dim_t k, \
|
||||
void* restrict alpha, \
|
||||
void* restrict a, inc_t rs_a, inc_t cs_a, \
|
||||
void* restrict b, inc_t rs_b, inc_t cs_b, \
|
||||
void* restrict beta, \
|
||||
void* restrict c, inc_t rs_c, inc_t cs_c, \
|
||||
cntx_t* restrict cntx, \
|
||||
rntm_t* restrict rntm, \
|
||||
thrinfo_t* restrict thread \
|
||||
);
|
||||
|
||||
//INSERT_GENTPROT_BASIC0( gemm_bp_var1 )
|
||||
GENTPROT( float, s, gemm_bp_var1 )
|
||||
GENTPROT( double, d, gemm_bp_var1 )
|
||||
GENTPROT( scomplex, c, gemm_bp_var1 )
|
||||
GENTPROT( dcomplex, z, gemm_bp_var1 )
|
||||
|
||||
//INSERT_GENTPROT_BASIC0( gemm_bp_var2 )
|
||||
GENTPROT( float, s, gemm_bp_var2 )
|
||||
GENTPROT( double, d, gemm_bp_var2 )
|
||||
GENTPROT( scomplex, c, gemm_bp_var2 )
|
||||
GENTPROT( dcomplex, z, gemm_bp_var2 )
|
||||
|
||||
|
||||
//
|
||||
// Prototype the typed kernel interfaces.
|
||||
//
|
||||
|
||||
#undef GENTPROT
|
||||
#define GENTPROT( ctype, ch, varname ) \
|
||||
\
|
||||
void PASTECH2(bls_,ch,varname) \
|
||||
( \
|
||||
const dim_t MR, \
|
||||
const dim_t NR, \
|
||||
dim_t mr_cur, \
|
||||
dim_t nr_cur, \
|
||||
dim_t k, \
|
||||
ctype* restrict alpha, \
|
||||
ctype* restrict a, inc_t rs_a, inc_t cs_a, \
|
||||
ctype* restrict b, inc_t rs_b, inc_t cs_b, \
|
||||
ctype* restrict beta, \
|
||||
ctype* restrict c, inc_t rs_c, inc_t cs_c, \
|
||||
auxinfo_t* restrict aux, \
|
||||
cntx_t* restrict cntx \
|
||||
);
|
||||
|
||||
//INSERT_GENTPROT_BASIC0( gemm_kernel )
|
||||
GENTPROT( float, s, gemm_kernel )
|
||||
GENTPROT( double, d, gemm_kernel )
|
||||
GENTPROT( scomplex, c, gemm_kernel )
|
||||
GENTPROT( dcomplex, z, gemm_kernel )
|
||||
|
||||
328
sandbox/gemmlike/bls_l3_packm_a.c
Normal file
328
sandbox/gemmlike/bls_l3_packm_a.c
Normal file
@@ -0,0 +1,328 @@
|
||||
/*
|
||||
|
||||
BLIS
|
||||
An object-based framework for developing high-performance BLAS-like
|
||||
libraries.
|
||||
|
||||
Copyright (C) 2021, The University of Texas at Austin
|
||||
|
||||
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"
|
||||
|
||||
#undef GENTFUNC
|
||||
#define GENTFUNC( ctype, ch, opname ) \
|
||||
\
|
||||
void PASTECH2(bls_,ch,opname) \
|
||||
( \
|
||||
dim_t m, \
|
||||
dim_t k, \
|
||||
dim_t mr, \
|
||||
cntx_t* restrict cntx, \
|
||||
rntm_t* restrict rntm, \
|
||||
mem_t* restrict mem, \
|
||||
thrinfo_t* restrict thread \
|
||||
) \
|
||||
{ \
|
||||
/* Set the pack buffer type so that we are obtaining memory blocks from
|
||||
the pool dedicated to blocks of A. */ \
|
||||
const packbuf_t pack_buf_type = BLIS_BUFFER_FOR_A_BLOCK; \
|
||||
\
|
||||
/* NOTE: This "rounding up" of the last upanel is absolutely necessary since
|
||||
we NEED that last micropanel to have the same ldim (cs_p) as the other
|
||||
micropanels. Why? Because the microkernel assumes that the register (MR,
|
||||
NR) AND storage (PACKMR, PACKNR) blocksizes do not change. */ \
|
||||
const dim_t m_pack = ( m / mr + ( m % mr ? 1 : 0 ) ) * mr; \
|
||||
const dim_t k_pack = k; \
|
||||
\
|
||||
/* Barrier to make sure all threads are caught up and ready to begin the
|
||||
packm stage. */ \
|
||||
bli_thread_barrier( thread ); \
|
||||
\
|
||||
/* Compute the size of the memory block eneded. */ \
|
||||
siz_t size_needed = sizeof( ctype ) * m_pack * k_pack; \
|
||||
\
|
||||
/* Check the mem_t entry provided by the caller. If it is unallocated,
|
||||
then we need to acquire a block from the memory broker. */ \
|
||||
if ( bli_mem_is_unalloc( mem ) ) \
|
||||
{ \
|
||||
if ( bli_thread_am_ochief( thread ) ) \
|
||||
{ \
|
||||
/* Acquire directly to the chief thread's mem_t that was passed in.
|
||||
It needs to be that mem_t struct, and not a local (temporary)
|
||||
mem_t, since there is no barrier until after packing is finished,
|
||||
which could allow a race condition whereby the chief thread exits
|
||||
the current function before the other threads have a chance to
|
||||
copy from it. (A barrier would fix that race condition, but then
|
||||
again, I prefer to keep barriers to a minimum.) */ \
|
||||
bli_membrk_acquire_m \
|
||||
( \
|
||||
rntm, \
|
||||
size_needed, \
|
||||
pack_buf_type, \
|
||||
mem \
|
||||
); \
|
||||
} \
|
||||
\
|
||||
/* Broadcast the address of the chief thread's passed-in mem_t to all
|
||||
threads. */ \
|
||||
mem_t* mem_p = bli_thread_broadcast( thread, mem ); \
|
||||
\
|
||||
/* Non-chief threads: Copy the contents of the chief thread's
|
||||
passed-in mem_t to the passed-in mem_t for this thread. (The
|
||||
chief thread already has the mem_t, so it does not need to
|
||||
perform any copy.) */ \
|
||||
if ( !bli_thread_am_ochief( thread ) ) \
|
||||
{ \
|
||||
*mem = *mem_p; \
|
||||
} \
|
||||
} \
|
||||
else /* if ( bli_mem_is_alloc( mem ) ) */ \
|
||||
{ \
|
||||
/* If the mem_t entry provided by the caller does NOT contain a NULL
|
||||
buffer, then a block has already been acquired from the memory
|
||||
broker and cached by the caller. */ \
|
||||
\
|
||||
/* As a sanity check, we should make sure that the mem_t object isn't
|
||||
associated with a block that is too small compared to the size of
|
||||
the packed matrix buffer that is needed, according to the value
|
||||
computed above. */ \
|
||||
siz_t mem_size = bli_mem_size( mem ); \
|
||||
\
|
||||
if ( mem_size < size_needed ) \
|
||||
{ \
|
||||
if ( bli_thread_am_ochief( thread ) ) \
|
||||
{ \
|
||||
/* The chief thread releases the existing block associated
|
||||
with the mem_t, and then re-acquires a new block, saving
|
||||
the associated mem_t to its passed-in mem_t. (See coment
|
||||
above for why the acquisition needs to be directly to
|
||||
the chief thread's passed-in mem_t and not a local
|
||||
(temporary) mem_t. */ \
|
||||
bli_membrk_release \
|
||||
( \
|
||||
rntm, \
|
||||
mem \
|
||||
); \
|
||||
bli_membrk_acquire_m \
|
||||
( \
|
||||
rntm, \
|
||||
size_needed, \
|
||||
pack_buf_type, \
|
||||
mem \
|
||||
); \
|
||||
} \
|
||||
\
|
||||
/* Broadcast the address of the chief thread's passed-in mem_t
|
||||
to all threads. */ \
|
||||
mem_t* mem_p = bli_thread_broadcast( thread, mem ); \
|
||||
\
|
||||
/* Non-chief threads: Copy the contents of the chief thread's
|
||||
passed-in mem_t to the passed-in mem_t for this thread. (The
|
||||
chief thread already has the mem_t, so it does not need to
|
||||
perform any copy.) */ \
|
||||
if ( !bli_thread_am_ochief( thread ) ) \
|
||||
{ \
|
||||
*mem = *mem_p; \
|
||||
} \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
/* If the mem_t entry is already allocated and sufficiently large,
|
||||
then we use it as-is. No action is needed. */ \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
//INSERT_GENTFUNC_BASIC0( packm_init_mem_a )
|
||||
GENTFUNC( float, s, packm_init_mem_a )
|
||||
GENTFUNC( double, d, packm_init_mem_a )
|
||||
GENTFUNC( scomplex, c, packm_init_mem_a )
|
||||
GENTFUNC( dcomplex, z, packm_init_mem_a )
|
||||
|
||||
|
||||
#undef GENTFUNC
|
||||
#define GENTFUNC( ctype, ch, opname ) \
|
||||
\
|
||||
void PASTECH2(bls_,ch,opname) \
|
||||
( \
|
||||
rntm_t* restrict rntm, \
|
||||
mem_t* restrict mem, \
|
||||
thrinfo_t* restrict thread \
|
||||
) \
|
||||
{ \
|
||||
if ( thread != NULL ) \
|
||||
if ( bli_thread_am_ochief( thread ) ) \
|
||||
{ \
|
||||
/* Check the mem_t entry provided by the caller. Only proceed if it
|
||||
is allocated, which it should be. */ \
|
||||
if ( bli_mem_is_alloc( mem ) ) \
|
||||
{ \
|
||||
bli_membrk_release \
|
||||
( \
|
||||
rntm, \
|
||||
mem \
|
||||
); \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
//INSERT_GENTFUNC_BASIC0( packm_finalize_mem_a )
|
||||
GENTFUNC( float, s, packm_finalize_mem_a )
|
||||
GENTFUNC( double, d, packm_finalize_mem_a )
|
||||
GENTFUNC( scomplex, c, packm_finalize_mem_a )
|
||||
GENTFUNC( dcomplex, z, packm_finalize_mem_a )
|
||||
|
||||
|
||||
#undef GENTFUNC
|
||||
#define GENTFUNC( ctype, ch, opname ) \
|
||||
\
|
||||
void PASTECH2(bls_,ch,opname) \
|
||||
( \
|
||||
pack_t* restrict schema, \
|
||||
dim_t m, \
|
||||
dim_t k, \
|
||||
dim_t mr, \
|
||||
dim_t* restrict m_max, \
|
||||
dim_t* restrict k_max, \
|
||||
ctype** p, inc_t* restrict rs_p, inc_t* restrict cs_p, \
|
||||
dim_t* restrict pd_p, inc_t* restrict ps_p, \
|
||||
mem_t* restrict mem \
|
||||
) \
|
||||
{ \
|
||||
/* NOTE: This "rounding up" of the last upanel is absolutely necessary since
|
||||
we NEED that last micropanel to have the same ldim (cs_p) as the other
|
||||
micropanels. Why? Because the microkernel assumes that the register (MR,
|
||||
NR) AND storage (PACKMR, PACKNR) blocksizes do not change. */ \
|
||||
*m_max = ( m / mr + ( m % mr ? 1 : 0 ) ) * mr; \
|
||||
*k_max = k; \
|
||||
\
|
||||
/* Determine the dimensions and strides for the packed matrix A. */ \
|
||||
{ \
|
||||
/* Pack A to column-stored row-panels. */ \
|
||||
*rs_p = 1; \
|
||||
*cs_p = mr; \
|
||||
\
|
||||
*pd_p = mr; \
|
||||
*ps_p = mr * k; \
|
||||
\
|
||||
/* Set the schema to "packed row panels" to indicate packing to
|
||||
conventional column-stored row panels. */ \
|
||||
*schema = BLIS_PACKED_ROW_PANELS; \
|
||||
} \
|
||||
\
|
||||
/* Set the buffer address provided by the caller to point to the memory
|
||||
associated with the mem_t entry acquired from the memory pool. */ \
|
||||
*p = bli_mem_buffer( mem ); \
|
||||
}
|
||||
|
||||
//INSERT_GENTFUNC_BASIC0( packm_init_a )
|
||||
GENTFUNC( float, s, packm_init_a )
|
||||
GENTFUNC( double, d, packm_init_a )
|
||||
GENTFUNC( scomplex, c, packm_init_a )
|
||||
GENTFUNC( dcomplex, z, packm_init_a )
|
||||
|
||||
|
||||
//
|
||||
// Define BLAS-like interfaces to the variant chooser.
|
||||
//
|
||||
|
||||
#undef GENTFUNC
|
||||
#define GENTFUNC( ctype, ch, opname ) \
|
||||
\
|
||||
void PASTECH2(bls_,ch,opname) \
|
||||
( \
|
||||
conj_t conj, \
|
||||
dim_t m_alloc, \
|
||||
dim_t k_alloc, \
|
||||
dim_t m, \
|
||||
dim_t k, \
|
||||
dim_t mr, \
|
||||
ctype* restrict kappa, \
|
||||
ctype* restrict a, inc_t rs_a, inc_t cs_a, \
|
||||
ctype** restrict p, inc_t* restrict rs_p, inc_t* restrict cs_p, \
|
||||
inc_t* restrict ps_p, \
|
||||
cntx_t* restrict cntx, \
|
||||
rntm_t* restrict rntm, \
|
||||
mem_t* restrict mem, \
|
||||
thrinfo_t* restrict thread \
|
||||
) \
|
||||
{ \
|
||||
pack_t schema; \
|
||||
dim_t m_max; \
|
||||
dim_t k_max; \
|
||||
dim_t pd_p; \
|
||||
\
|
||||
/* Prepare the packing destination buffer. */ \
|
||||
PASTECH2(bls_,ch,packm_init_mem_a) \
|
||||
( \
|
||||
m_alloc, k_alloc, mr, \
|
||||
cntx, \
|
||||
rntm, \
|
||||
mem, \
|
||||
thread \
|
||||
); \
|
||||
\
|
||||
/* Determine the packing buffer and related parameters for matrix A. */ \
|
||||
PASTECH2(bls_,ch,packm_init_a) \
|
||||
( \
|
||||
&schema, \
|
||||
m, k, mr, \
|
||||
&m_max, &k_max, \
|
||||
p, rs_p, cs_p, \
|
||||
&pd_p, ps_p, \
|
||||
mem \
|
||||
); \
|
||||
\
|
||||
/* Pack matrix A to the destination buffer chosen above. Here, the packed
|
||||
matrix is stored to column-stored MR x k micropanels. */ \
|
||||
PASTECH2(bls_,ch,packm_var1) \
|
||||
( \
|
||||
conj, \
|
||||
schema, \
|
||||
m, \
|
||||
k, \
|
||||
m_max, \
|
||||
k_max, \
|
||||
kappa, \
|
||||
a, rs_a, cs_a, \
|
||||
*p, *rs_p, *cs_p, \
|
||||
pd_p, *ps_p, \
|
||||
cntx, \
|
||||
thread \
|
||||
); \
|
||||
\
|
||||
/* Barrier so that packing is done before computation. */ \
|
||||
bli_thread_barrier( thread ); \
|
||||
}
|
||||
|
||||
//INSERT_GENTFUNC_BASIC0( packm_a )
|
||||
GENTFUNC( float, s, packm_a )
|
||||
GENTFUNC( double, d, packm_a )
|
||||
GENTFUNC( scomplex, c, packm_a )
|
||||
GENTFUNC( dcomplex, z, packm_a )
|
||||
|
||||
122
sandbox/gemmlike/bls_l3_packm_a.h
Normal file
122
sandbox/gemmlike/bls_l3_packm_a.h
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
|
||||
BLIS
|
||||
An object-based framework for developing high-performance BLAS-like
|
||||
libraries.
|
||||
|
||||
Copyright (C) 2021, The University of Texas at Austin
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
#undef GENTPROT
|
||||
#define GENTPROT( ctype, ch, opname ) \
|
||||
\
|
||||
void PASTECH2(bls_,ch,opname) \
|
||||
( \
|
||||
dim_t m, \
|
||||
dim_t k, \
|
||||
dim_t mr, \
|
||||
cntx_t* restrict cntx, \
|
||||
rntm_t* restrict rntm, \
|
||||
mem_t* restrict mem, \
|
||||
thrinfo_t* restrict thread \
|
||||
); \
|
||||
|
||||
//INSERT_GENTPROT_BASIC0( packm_init_mem_a )
|
||||
GENTPROT( float, s, packm_init_mem_a )
|
||||
GENTPROT( double, d, packm_init_mem_a )
|
||||
GENTPROT( scomplex, c, packm_init_mem_a )
|
||||
GENTPROT( dcomplex, z, packm_init_mem_a )
|
||||
|
||||
|
||||
#undef GENTPROT
|
||||
#define GENTPROT( ctype, ch, opname ) \
|
||||
\
|
||||
void PASTECH2(bls_,ch,opname) \
|
||||
( \
|
||||
rntm_t* restrict rntm, \
|
||||
mem_t* restrict mem, \
|
||||
thrinfo_t* restrict thread \
|
||||
); \
|
||||
|
||||
//INSERT_GENTPROT_BASIC0( packm_finalize_mem_a )
|
||||
GENTPROT( float, s, packm_finalize_mem_a )
|
||||
GENTPROT( double, d, packm_finalize_mem_a )
|
||||
GENTPROT( scomplex, c, packm_finalize_mem_a )
|
||||
GENTPROT( dcomplex, z, packm_finalize_mem_a )
|
||||
|
||||
|
||||
#undef GENTPROT
|
||||
#define GENTPROT( ctype, ch, opname ) \
|
||||
\
|
||||
void PASTECH2(bls_,ch,opname) \
|
||||
( \
|
||||
pack_t* restrict schema, \
|
||||
dim_t m, \
|
||||
dim_t k, \
|
||||
dim_t mr, \
|
||||
dim_t* restrict m_max, \
|
||||
dim_t* restrict k_max, \
|
||||
ctype** p, inc_t* restrict rs_p, inc_t* restrict cs_p, \
|
||||
dim_t* restrict pd_p, inc_t* restrict ps_p, \
|
||||
mem_t* restrict mem \
|
||||
); \
|
||||
|
||||
//INSERT_GENTPROT_BASIC0( packm_init_a )
|
||||
GENTPROT( float, s, packm_init_a )
|
||||
GENTPROT( double, d, packm_init_a )
|
||||
GENTPROT( scomplex, c, packm_init_a )
|
||||
GENTPROT( dcomplex, z, packm_init_a )
|
||||
|
||||
|
||||
#undef GENTPROT
|
||||
#define GENTPROT( ctype, ch, opname ) \
|
||||
\
|
||||
void PASTECH2(bls_,ch,opname) \
|
||||
( \
|
||||
conj_t conj, \
|
||||
dim_t m_alloc, \
|
||||
dim_t k_alloc, \
|
||||
dim_t m, \
|
||||
dim_t k, \
|
||||
dim_t mr, \
|
||||
ctype* restrict kappa, \
|
||||
ctype* restrict a, inc_t rs_a, inc_t cs_a, \
|
||||
ctype** restrict p, inc_t* restrict rs_p, inc_t* restrict cs_p, \
|
||||
inc_t* restrict ps_p, \
|
||||
cntx_t* restrict cntx, \
|
||||
rntm_t* restrict rntm, \
|
||||
mem_t* restrict mem, \
|
||||
thrinfo_t* restrict thread \
|
||||
); \
|
||||
|
||||
//INSERT_GENTPROT_BASIC0( packm_a )
|
||||
GENTPROT( float, s, packm_a )
|
||||
GENTPROT( double, d, packm_a )
|
||||
GENTPROT( scomplex, c, packm_a )
|
||||
GENTPROT( dcomplex, z, packm_a )
|
||||
|
||||
328
sandbox/gemmlike/bls_l3_packm_b.c
Normal file
328
sandbox/gemmlike/bls_l3_packm_b.c
Normal file
@@ -0,0 +1,328 @@
|
||||
/*
|
||||
|
||||
BLIS
|
||||
An object-based framework for developing high-performance BLAS-like
|
||||
libraries.
|
||||
|
||||
Copyright (C) 2021, The University of Texas at Austin
|
||||
|
||||
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"
|
||||
|
||||
#undef GENTFUNC
|
||||
#define GENTFUNC( ctype, ch, opname ) \
|
||||
\
|
||||
void PASTECH2(bls_,ch,opname) \
|
||||
( \
|
||||
dim_t k, \
|
||||
dim_t n, \
|
||||
dim_t nr, \
|
||||
cntx_t* restrict cntx, \
|
||||
rntm_t* restrict rntm, \
|
||||
mem_t* restrict mem, \
|
||||
thrinfo_t* restrict thread \
|
||||
) \
|
||||
{ \
|
||||
/* Set the pack buffer type so that we are obtaining memory blocks from
|
||||
the pool dedicated to panels of B. */ \
|
||||
const packbuf_t pack_buf_type = BLIS_BUFFER_FOR_B_PANEL; \
|
||||
\
|
||||
/* NOTE: This "rounding up" of the last upanel is absolutely necessary since
|
||||
we NEED that last micropanel to have the same ldim (cs_p) as the other
|
||||
micropanels. Why? Because the microkernel assumes that the register (MR,
|
||||
NR) AND storage (PACKMR, PACKNR) blocksizes do not change. */ \
|
||||
const dim_t k_pack = k; \
|
||||
const dim_t n_pack = ( n / nr + ( n % nr ? 1 : 0 ) ) * nr; \
|
||||
\
|
||||
/* Barrier to make sure all threads are caught up and ready to begin the
|
||||
packm stage. */ \
|
||||
bli_thread_barrier( thread ); \
|
||||
\
|
||||
/* Compute the size of the memory block eneded. */ \
|
||||
siz_t size_needed = sizeof( ctype ) * k_pack * n_pack; \
|
||||
\
|
||||
/* Check the mem_t entry provided by the caller. If it is unallocated,
|
||||
then we need to acquire a block from the memory broker. */ \
|
||||
if ( bli_mem_is_unalloc( mem ) ) \
|
||||
{ \
|
||||
if ( bli_thread_am_ochief( thread ) ) \
|
||||
{ \
|
||||
/* Acquire directly to the chief thread's mem_t that was passed in.
|
||||
It needs to be that mem_t struct, and not a local (temporary)
|
||||
mem_t, since there is no barrier until after packing is finished,
|
||||
which could allow a race condition whereby the chief thread exits
|
||||
the current function before the other threads have a chance to
|
||||
copy from it. (A barrier would fix that race condition, but then
|
||||
again, I prefer to keep barriers to a minimum.) */ \
|
||||
bli_membrk_acquire_m \
|
||||
( \
|
||||
rntm, \
|
||||
size_needed, \
|
||||
pack_buf_type, \
|
||||
mem \
|
||||
); \
|
||||
} \
|
||||
\
|
||||
/* Broadcast the address of the chief thread's passed-in mem_t to all
|
||||
threads. */ \
|
||||
mem_t* mem_p = bli_thread_broadcast( thread, mem ); \
|
||||
\
|
||||
/* Non-chief threads: Copy the contents of the chief thread's
|
||||
passed-in mem_t to the passed-in mem_t for this thread. (The
|
||||
chief thread already has the mem_t, so it does not need to
|
||||
perform any copy.) */ \
|
||||
if ( !bli_thread_am_ochief( thread ) ) \
|
||||
{ \
|
||||
*mem = *mem_p; \
|
||||
} \
|
||||
} \
|
||||
else /* if ( bli_mem_is_alloc( mem ) ) */ \
|
||||
{ \
|
||||
/* If the mem_t entry provided by the caller does NOT contain a NULL
|
||||
buffer, then a block has already been acquired from the memory
|
||||
broker and cached by the caller. */ \
|
||||
\
|
||||
/* As a sanity check, we should make sure that the mem_t object isn't
|
||||
associated with a block that is too small compared to the size of
|
||||
the packed matrix buffer that is needed, according to the value
|
||||
computed above. */ \
|
||||
siz_t mem_size = bli_mem_size( mem ); \
|
||||
\
|
||||
if ( mem_size < size_needed ) \
|
||||
{ \
|
||||
if ( bli_thread_am_ochief( thread ) ) \
|
||||
{ \
|
||||
/* The chief thread releases the existing block associated
|
||||
with the mem_t, and then re-acquires a new block, saving
|
||||
the associated mem_t to its passed-in mem_t. (See coment
|
||||
above for why the acquisition needs to be directly to
|
||||
the chief thread's passed-in mem_t and not a local
|
||||
(temporary) mem_t. */ \
|
||||
bli_membrk_release \
|
||||
( \
|
||||
rntm, \
|
||||
mem \
|
||||
); \
|
||||
bli_membrk_acquire_m \
|
||||
( \
|
||||
rntm, \
|
||||
size_needed, \
|
||||
pack_buf_type, \
|
||||
mem \
|
||||
); \
|
||||
} \
|
||||
\
|
||||
/* Broadcast the address of the chief thread's passed-in mem_t
|
||||
to all threads. */ \
|
||||
mem_t* mem_p = bli_thread_broadcast( thread, mem ); \
|
||||
\
|
||||
/* Non-chief threads: Copy the contents of the chief thread's
|
||||
passed-in mem_t to the passed-in mem_t for this thread. (The
|
||||
chief thread already has the mem_t, so it does not need to
|
||||
perform any copy.) */ \
|
||||
if ( !bli_thread_am_ochief( thread ) ) \
|
||||
{ \
|
||||
*mem = *mem_p; \
|
||||
} \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
/* If the mem_t entry is already allocated and sufficiently large,
|
||||
then we use it as-is. No action is needed. */ \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
//INSERT_GENTFUNC_BASIC0( packm_init_mem_b )
|
||||
GENTFUNC( float, s, packm_init_mem_b )
|
||||
GENTFUNC( double, d, packm_init_mem_b )
|
||||
GENTFUNC( scomplex, c, packm_init_mem_b )
|
||||
GENTFUNC( dcomplex, z, packm_init_mem_b )
|
||||
|
||||
|
||||
#undef GENTFUNC
|
||||
#define GENTFUNC( ctype, ch, opname ) \
|
||||
\
|
||||
void PASTECH2(bls_,ch,opname) \
|
||||
( \
|
||||
rntm_t* restrict rntm, \
|
||||
mem_t* restrict mem, \
|
||||
thrinfo_t* restrict thread \
|
||||
) \
|
||||
{ \
|
||||
if ( thread != NULL ) \
|
||||
if ( bli_thread_am_ochief( thread ) ) \
|
||||
{ \
|
||||
/* Check the mem_t entry provided by the caller. Only proceed if it
|
||||
is allocated, which it should be. */ \
|
||||
if ( bli_mem_is_alloc( mem ) ) \
|
||||
{ \
|
||||
bli_membrk_release \
|
||||
( \
|
||||
rntm, \
|
||||
mem \
|
||||
); \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
//INSERT_GENTFUNC_BASIC0( packm_finalize_mem_b )
|
||||
GENTFUNC( float, s, packm_finalize_mem_b )
|
||||
GENTFUNC( double, d, packm_finalize_mem_b )
|
||||
GENTFUNC( scomplex, c, packm_finalize_mem_b )
|
||||
GENTFUNC( dcomplex, z, packm_finalize_mem_b )
|
||||
|
||||
|
||||
#undef GENTFUNC
|
||||
#define GENTFUNC( ctype, ch, opname ) \
|
||||
\
|
||||
void PASTECH2(bls_,ch,opname) \
|
||||
( \
|
||||
pack_t* restrict schema, \
|
||||
dim_t k, \
|
||||
dim_t n, \
|
||||
dim_t nr, \
|
||||
dim_t* restrict k_max, \
|
||||
dim_t* restrict n_max, \
|
||||
ctype** p, inc_t* restrict rs_p, inc_t* restrict cs_p, \
|
||||
dim_t* restrict pd_p, inc_t* restrict ps_p, \
|
||||
mem_t* restrict mem \
|
||||
) \
|
||||
{ \
|
||||
/* NOTE: This "rounding up" of the last upanel is absolutely necessary since
|
||||
we NEED that last micropanel to have the same ldim (cs_p) as the other
|
||||
micropanels. Why? Because the microkernel assumes that the register (MR,
|
||||
NR) AND storage (PACKMR, PACKNR) blocksizes do not change. */ \
|
||||
*k_max = k; \
|
||||
*n_max = ( n / nr + ( n % nr ? 1 : 0 ) ) * nr; \
|
||||
\
|
||||
/* Determine the dimensions and strides for the packed matrix B. */ \
|
||||
{ \
|
||||
/* Pack B to row-stored column-panels. */ \
|
||||
*rs_p = nr; \
|
||||
*cs_p = 1; \
|
||||
\
|
||||
*pd_p = nr; \
|
||||
*ps_p = k * nr; \
|
||||
\
|
||||
/* Set the schema to "packed column panels" to indicate packing to
|
||||
conventional row-stored column panels. */ \
|
||||
*schema = BLIS_PACKED_COL_PANELS; \
|
||||
} \
|
||||
\
|
||||
/* Set the buffer address provided by the caller to point to the memory
|
||||
associated with the mem_t entry acquired from the memory pool. */ \
|
||||
*p = bli_mem_buffer( mem ); \
|
||||
}
|
||||
|
||||
//INSERT_GENTFUNC_BASIC0( packm_init_b )
|
||||
GENTFUNC( float, s, packm_init_b )
|
||||
GENTFUNC( double, d, packm_init_b )
|
||||
GENTFUNC( scomplex, c, packm_init_b )
|
||||
GENTFUNC( dcomplex, z, packm_init_b )
|
||||
|
||||
|
||||
//
|
||||
// Define BLAS-like interfaces to the variant chooser.
|
||||
//
|
||||
|
||||
#undef GENTFUNC
|
||||
#define GENTFUNC( ctype, ch, opname ) \
|
||||
\
|
||||
void PASTECH2(bls_,ch,opname) \
|
||||
( \
|
||||
conj_t conj, \
|
||||
dim_t k_alloc, \
|
||||
dim_t n_alloc, \
|
||||
dim_t k, \
|
||||
dim_t n, \
|
||||
dim_t nr, \
|
||||
ctype* restrict kappa, \
|
||||
ctype* restrict b, inc_t rs_b, inc_t cs_b, \
|
||||
ctype** restrict p, inc_t* restrict rs_p, inc_t* restrict cs_p, \
|
||||
inc_t* restrict ps_p, \
|
||||
cntx_t* restrict cntx, \
|
||||
rntm_t* restrict rntm, \
|
||||
mem_t* restrict mem, \
|
||||
thrinfo_t* restrict thread \
|
||||
) \
|
||||
{ \
|
||||
pack_t schema; \
|
||||
dim_t k_max; \
|
||||
dim_t n_max; \
|
||||
dim_t pd_p; \
|
||||
\
|
||||
/* Prepare the packing destination buffer. */ \
|
||||
PASTECH2(bls_,ch,packm_init_mem_b) \
|
||||
( \
|
||||
k_alloc, n_alloc, nr, \
|
||||
cntx, \
|
||||
rntm, \
|
||||
mem, \
|
||||
thread \
|
||||
); \
|
||||
\
|
||||
/* Determine the packing buffer and related parameters for matrix B. */ \
|
||||
PASTECH2(bls_,ch,packm_init_b) \
|
||||
( \
|
||||
&schema, \
|
||||
k, n, nr, \
|
||||
&k_max, &n_max, \
|
||||
p, rs_p, cs_p, \
|
||||
&pd_p, ps_p, \
|
||||
mem \
|
||||
); \
|
||||
\
|
||||
/* Pack matrix B to the destination buffer chosen above. Here, the packed
|
||||
matrix is stored to row-stored k x NR micropanels. */ \
|
||||
PASTECH2(bls_,ch,packm_var1) \
|
||||
( \
|
||||
conj, \
|
||||
schema, \
|
||||
k, \
|
||||
n, \
|
||||
k_max, \
|
||||
n_max, \
|
||||
kappa, \
|
||||
b, rs_b, cs_b, \
|
||||
*p, *rs_p, *cs_p, \
|
||||
pd_p, *ps_p, \
|
||||
cntx, \
|
||||
thread \
|
||||
); \
|
||||
\
|
||||
/* Barrier so that packing is done before computation. */ \
|
||||
bli_thread_barrier( thread ); \
|
||||
}
|
||||
|
||||
//INSERT_GENTFUNC_BASIC0( packm_b )
|
||||
GENTFUNC( float, s, packm_b )
|
||||
GENTFUNC( double, d, packm_b )
|
||||
GENTFUNC( scomplex, c, packm_b )
|
||||
GENTFUNC( dcomplex, z, packm_b )
|
||||
|
||||
122
sandbox/gemmlike/bls_l3_packm_b.h
Normal file
122
sandbox/gemmlike/bls_l3_packm_b.h
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
|
||||
BLIS
|
||||
An object-based framework for developing high-performance BLAS-like
|
||||
libraries.
|
||||
|
||||
Copyright (C) 2021, The University of Texas at Austin
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
#undef GENTPROT
|
||||
#define GENTPROT( ctype, ch, opname ) \
|
||||
\
|
||||
void PASTECH2(bls_,ch,opname) \
|
||||
( \
|
||||
dim_t k, \
|
||||
dim_t n, \
|
||||
dim_t nr, \
|
||||
cntx_t* restrict cntx, \
|
||||
rntm_t* restrict rntm, \
|
||||
mem_t* restrict mem, \
|
||||
thrinfo_t* restrict thread \
|
||||
); \
|
||||
|
||||
//INSERT_GENTPROT_BASIC0( packm_init_mem_b )
|
||||
GENTPROT( float, s, packm_init_mem_b )
|
||||
GENTPROT( double, d, packm_init_mem_b )
|
||||
GENTPROT( scomplex, c, packm_init_mem_b )
|
||||
GENTPROT( dcomplex, z, packm_init_mem_b )
|
||||
|
||||
|
||||
#undef GENTPROT
|
||||
#define GENTPROT( ctype, ch, opname ) \
|
||||
\
|
||||
void PASTECH2(bls_,ch,opname) \
|
||||
( \
|
||||
rntm_t* restrict rntm, \
|
||||
mem_t* restrict mem, \
|
||||
thrinfo_t* restrict thread \
|
||||
); \
|
||||
|
||||
//INSERT_GENTPROT_BASIC0( packm_finalize_mem_b )
|
||||
GENTPROT( float, s, packm_finalize_mem_b )
|
||||
GENTPROT( double, d, packm_finalize_mem_b )
|
||||
GENTPROT( scomplex, c, packm_finalize_mem_b )
|
||||
GENTPROT( dcomplex, z, packm_finalize_mem_b )
|
||||
|
||||
|
||||
#undef GENTPROT
|
||||
#define GENTPROT( ctype, ch, opname ) \
|
||||
\
|
||||
void PASTECH2(bls_,ch,opname) \
|
||||
( \
|
||||
pack_t* restrict schema, \
|
||||
dim_t k, \
|
||||
dim_t n, \
|
||||
dim_t nr, \
|
||||
dim_t* restrict k_max, \
|
||||
dim_t* restrict n_max, \
|
||||
ctype** p, inc_t* restrict rs_p, inc_t* restrict cs_p, \
|
||||
dim_t* restrict pd_p, inc_t* restrict ps_p, \
|
||||
mem_t* restrict mem \
|
||||
); \
|
||||
|
||||
//INSERT_GENTPROT_BASIC0( packm_init_b )
|
||||
GENTPROT( float, s, packm_init_b )
|
||||
GENTPROT( double, d, packm_init_b )
|
||||
GENTPROT( scomplex, c, packm_init_b )
|
||||
GENTPROT( dcomplex, z, packm_init_b )
|
||||
|
||||
|
||||
#undef GENTPROT
|
||||
#define GENTPROT( ctype, ch, opname ) \
|
||||
\
|
||||
void PASTECH2(bls_,ch,opname) \
|
||||
( \
|
||||
conj_t conj, \
|
||||
dim_t k_alloc, \
|
||||
dim_t n_alloc, \
|
||||
dim_t k, \
|
||||
dim_t n, \
|
||||
dim_t nr, \
|
||||
ctype* restrict kappa, \
|
||||
ctype* restrict b, inc_t rs_b, inc_t cs_b, \
|
||||
ctype** restrict p, inc_t* restrict rs_p, inc_t* restrict cs_p, \
|
||||
inc_t* restrict ps_p, \
|
||||
cntx_t* restrict cntx, \
|
||||
rntm_t* restrict rntm, \
|
||||
mem_t* restrict mem, \
|
||||
thrinfo_t* restrict thread \
|
||||
); \
|
||||
|
||||
//INSERT_GENTPROT_BASIC0( packm_b )
|
||||
GENTPROT( float, s, packm_b )
|
||||
GENTPROT( double, d, packm_b )
|
||||
GENTPROT( scomplex, c, packm_b )
|
||||
GENTPROT( dcomplex, z, packm_b )
|
||||
|
||||
198
sandbox/gemmlike/bls_l3_packm_var.c
Normal file
198
sandbox/gemmlike/bls_l3_packm_var.c
Normal file
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
|
||||
BLIS
|
||||
An object-based framework for developing high-performance BLAS-like
|
||||
libraries.
|
||||
|
||||
Copyright (C) 2021, The University of Texas at Austin
|
||||
|
||||
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"
|
||||
|
||||
//
|
||||
// Define BLAS-like interfaces to the variants.
|
||||
//
|
||||
|
||||
#undef GENTFUNC
|
||||
#define GENTFUNC( ctype, ch, varname ) \
|
||||
\
|
||||
void PASTECH2(bls_,ch,varname) \
|
||||
( \
|
||||
trans_t transc, \
|
||||
pack_t schema, \
|
||||
dim_t m, \
|
||||
dim_t n, \
|
||||
dim_t m_max, \
|
||||
dim_t n_max, \
|
||||
ctype* restrict kappa, \
|
||||
ctype* restrict c, inc_t rs_c, inc_t cs_c, \
|
||||
ctype* restrict p, inc_t rs_p, inc_t cs_p, \
|
||||
dim_t pd_p, inc_t ps_p, \
|
||||
cntx_t* restrict cntx, \
|
||||
thrinfo_t* restrict thread \
|
||||
) \
|
||||
{ \
|
||||
ctype* restrict kappa_cast = kappa; \
|
||||
ctype* restrict c_cast = c; \
|
||||
ctype* restrict p_cast = p; \
|
||||
\
|
||||
dim_t iter_dim; \
|
||||
dim_t n_iter; \
|
||||
dim_t it, ic; \
|
||||
dim_t ic0; \
|
||||
doff_t ic_inc; \
|
||||
dim_t panel_len_full; \
|
||||
dim_t panel_len_i; \
|
||||
dim_t panel_len_max; \
|
||||
dim_t panel_len_max_i; \
|
||||
dim_t panel_dim_i; \
|
||||
dim_t panel_dim_max; \
|
||||
inc_t vs_c; \
|
||||
inc_t ldc; \
|
||||
inc_t ldp; \
|
||||
conj_t conjc; \
|
||||
\
|
||||
\
|
||||
/* Extract the conjugation bit from the transposition argument. */ \
|
||||
conjc = bli_extract_conj( transc ); \
|
||||
\
|
||||
/* Create flags to incidate row or column storage. Note that the
|
||||
schema bit that encodes row or column is describing the form of
|
||||
micro-panel, not the storage in the micro-panel. Hence the
|
||||
mismatch in "row" and "column" semantics. */ \
|
||||
bool row_stored = bli_is_col_packed( schema ); \
|
||||
/*bool col_stored = bli_is_row_packed( schema );*/ \
|
||||
\
|
||||
/* If the row storage flag indicates row storage, then we are packing
|
||||
to column panels; otherwise, if the strides indicate column storage,
|
||||
we are packing to row panels. */ \
|
||||
if ( row_stored ) \
|
||||
{ \
|
||||
/* Prepare to pack to row-stored column panels. */ \
|
||||
iter_dim = n; \
|
||||
panel_len_full = m; \
|
||||
panel_len_max = m_max; \
|
||||
panel_dim_max = pd_p; \
|
||||
vs_c = cs_c; \
|
||||
ldc = rs_c; \
|
||||
ldp = rs_p; \
|
||||
} \
|
||||
else /* if ( col_stored ) */ \
|
||||
{ \
|
||||
/* Prepare to pack to column-stored row panels. */ \
|
||||
iter_dim = m; \
|
||||
panel_len_full = n; \
|
||||
panel_len_max = n_max; \
|
||||
panel_dim_max = pd_p; \
|
||||
vs_c = rs_c; \
|
||||
ldc = cs_c; \
|
||||
ldp = cs_p; \
|
||||
} \
|
||||
\
|
||||
/* Compute the total number of iterations we'll need. */ \
|
||||
n_iter = iter_dim / panel_dim_max + ( iter_dim % panel_dim_max ? 1 : 0 ); \
|
||||
\
|
||||
/* Set the initial values and increments for indices related to C and P
|
||||
based on whether reverse iteration was requested. */ \
|
||||
{ \
|
||||
ic0 = 0; \
|
||||
ic_inc = panel_dim_max; \
|
||||
} \
|
||||
\
|
||||
ctype* restrict p_begin = p_cast; \
|
||||
\
|
||||
/* Query the number of threads and thread ids from the current thread's
|
||||
packm thrinfo_t node. */ \
|
||||
const dim_t nt = bli_thread_n_way( thread ); \
|
||||
const dim_t tid = bli_thread_work_id( thread ); \
|
||||
\
|
||||
/* Suppress warnings in case tid isn't used (ie: as in slab partitioning). */ \
|
||||
( void )nt; \
|
||||
( void )tid; \
|
||||
\
|
||||
dim_t it_start, it_end, it_inc; \
|
||||
\
|
||||
/* Determine the thread range and increment using the current thread's
|
||||
packm thrinfo_t node. NOTE: The definition of bli_thread_range_jrir()
|
||||
will depend on whether slab or round-robin partitioning was requested
|
||||
at configure-time. */ \
|
||||
bli_thread_range_jrir( thread, n_iter, 1, FALSE, &it_start, &it_end, &it_inc ); \
|
||||
\
|
||||
/* Iterate over every logical micropanel in the source matrix. */ \
|
||||
for ( ic = ic0, it = 0; it < n_iter; \
|
||||
ic += ic_inc, it += 1 ) \
|
||||
{ \
|
||||
panel_dim_i = bli_min( panel_dim_max, iter_dim - ic ); \
|
||||
\
|
||||
ctype* restrict c_begin = c_cast + (ic )*vs_c; \
|
||||
\
|
||||
ctype* restrict c_use = c_begin; \
|
||||
ctype* restrict p_use = p_begin; \
|
||||
\
|
||||
panel_len_i = panel_len_full; \
|
||||
panel_len_max_i = panel_len_max; \
|
||||
\
|
||||
/* The definition of bli_packm_my_iter() will depend on whether slab
|
||||
or round-robin partitioning was requested at configure-time. (The
|
||||
default is slab.) */ \
|
||||
if ( bli_packm_my_iter( it, it_start, it_end, tid, nt ) ) \
|
||||
{ \
|
||||
PASTEMAC(ch,packm_cxk) \
|
||||
( \
|
||||
conjc, \
|
||||
schema, \
|
||||
panel_dim_i, \
|
||||
panel_dim_max, \
|
||||
panel_len_i, \
|
||||
panel_len_max_i, \
|
||||
kappa_cast, \
|
||||
c_use, vs_c, ldc, \
|
||||
p_use, ldp, \
|
||||
cntx \
|
||||
); \
|
||||
} \
|
||||
\
|
||||
p_begin += ps_p; \
|
||||
\
|
||||
/*
|
||||
if ( row_stored ) \
|
||||
PASTEMAC(ch,fprintm)( stdout, "packm_sup_var1: b packed", panel_len_max, panel_dim_max, \
|
||||
p_use, rs_p, cs_p, "%5.2f", "" ); \
|
||||
if ( !row_stored ) \
|
||||
PASTEMAC(ch,fprintm)( stdout, "packm_sup_var1: a packed", panel_dim_max, panel_len_max, \
|
||||
p_use, rs_p, cs_p, "%5.2f", "" ); \
|
||||
*/ \
|
||||
} \
|
||||
}
|
||||
|
||||
//INSERT_GENTFUNC_BASIC0( packm_var1 )
|
||||
GENTFUNC( float, s, packm_var1 )
|
||||
GENTFUNC( double, d, packm_var1 )
|
||||
GENTFUNC( scomplex, c, packm_var1 )
|
||||
GENTFUNC( dcomplex, z, packm_var1 )
|
||||
|
||||
63
sandbox/gemmlike/bls_l3_packm_var.h
Normal file
63
sandbox/gemmlike/bls_l3_packm_var.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
|
||||
BLIS
|
||||
An object-based framework for developing high-performance BLAS-like
|
||||
libraries.
|
||||
|
||||
Copyright (C) 2021, The University of Texas at Austin
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
//
|
||||
// Prototype BLAS-like interfaces to the variants.
|
||||
//
|
||||
|
||||
#undef GENTPROT
|
||||
#define GENTPROT( ctype, ch, varname ) \
|
||||
\
|
||||
void PASTECH2(bls_,ch,varname) \
|
||||
( \
|
||||
trans_t transc, \
|
||||
pack_t schema, \
|
||||
dim_t m, \
|
||||
dim_t n, \
|
||||
dim_t m_max, \
|
||||
dim_t n_max, \
|
||||
ctype* restrict kappa, \
|
||||
ctype* restrict c, inc_t rs_c, inc_t cs_c, \
|
||||
ctype* restrict p, inc_t rs_p, inc_t cs_p, \
|
||||
dim_t pd_p, inc_t ps_p, \
|
||||
cntx_t* restrict cntx, \
|
||||
thrinfo_t* restrict thread \
|
||||
);
|
||||
|
||||
//INSERT_GENTPROT_BASIC0( packm_var1 )
|
||||
GENTPROT( float, s, packm_var1 )
|
||||
GENTPROT( double, d, packm_var1 )
|
||||
GENTPROT( scomplex, c, packm_var1 )
|
||||
GENTPROT( dcomplex, z, packm_var1 )
|
||||
|
||||
73
sandbox/gemmlike/thread/bls_l3_decor.h
Normal file
73
sandbox/gemmlike/thread/bls_l3_decor.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
|
||||
BLIS
|
||||
An object-based framework for developing high-performance BLAS-like
|
||||
libraries.
|
||||
|
||||
Copyright (C) 2021, The University of Texas at Austin
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef BLIS_SBX_L3_DECOR_H
|
||||
#define BLIS_SBX_L3_DECOR_H
|
||||
|
||||
// -- sup definitions ----------------------------------------------------------
|
||||
|
||||
// Level-3 sup internal function type.
|
||||
typedef void (*l3sbxint_t)
|
||||
(
|
||||
obj_t* alpha,
|
||||
obj_t* a,
|
||||
obj_t* b,
|
||||
obj_t* beta,
|
||||
obj_t* c,
|
||||
cntx_t* cntx,
|
||||
rntm_t* rntm,
|
||||
thrinfo_t* thread
|
||||
);
|
||||
|
||||
// Level-3 sup thread decorator prototype.
|
||||
void bls_l3_thread_decorator
|
||||
(
|
||||
l3sbxint_t func,
|
||||
opid_t family,
|
||||
obj_t* alpha,
|
||||
obj_t* a,
|
||||
obj_t* b,
|
||||
obj_t* beta,
|
||||
obj_t* c,
|
||||
cntx_t* cntx,
|
||||
rntm_t* rntm
|
||||
);
|
||||
|
||||
// Include definitions specific to the method of multithreading.
|
||||
#include "bls_l3_decor_single.h"
|
||||
#include "bls_l3_decor_openmp.h"
|
||||
#include "bls_l3_decor_pthreads.h"
|
||||
|
||||
#endif
|
||||
|
||||
138
sandbox/gemmlike/thread/bls_l3_decor_openmp.c
Normal file
138
sandbox/gemmlike/thread/bls_l3_decor_openmp.c
Normal file
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
|
||||
BLIS
|
||||
An object-based framework for developing high-performance BLAS-like
|
||||
libraries.
|
||||
|
||||
Copyright (C) 2021, The University of Texas at Austin
|
||||
|
||||
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"
|
||||
|
||||
#ifdef BLIS_ENABLE_OPENMP
|
||||
|
||||
// Define a dummy thread entry function, which is needed in the pthreads
|
||||
// version, so that when building Windows DLLs (with OpenMP enabled or with
|
||||
// no multithreading) we don't risk having an unresolved symbol.
|
||||
void* bls_l3_thread_entry( void* data_void ) { return NULL; }
|
||||
|
||||
//#define PRINT_THRINFO
|
||||
|
||||
void bls_l3_thread_decorator
|
||||
(
|
||||
l3sbxint_t func,
|
||||
opid_t family,
|
||||
obj_t* alpha,
|
||||
obj_t* a,
|
||||
obj_t* b,
|
||||
obj_t* beta,
|
||||
obj_t* c,
|
||||
cntx_t* cntx,
|
||||
rntm_t* rntm
|
||||
)
|
||||
{
|
||||
// Query the total number of threads from the rntm_t object.
|
||||
const dim_t n_threads = bli_rntm_num_threads( rntm );
|
||||
|
||||
// NOTE: The sba was initialized in bli_init().
|
||||
|
||||
// Check out an array_t from the small block allocator. This is done
|
||||
// with an internal lock to ensure only one application thread accesses
|
||||
// the sba at a time. bli_sba_checkout_array() will also automatically
|
||||
// resize the array_t, if necessary.
|
||||
array_t* restrict array = bli_sba_checkout_array( n_threads );
|
||||
|
||||
// Access the pool_t* for thread 0 and embed it into the rntm. We do
|
||||
// this up-front only so that we have the rntm_t.sba_pool field
|
||||
// initialized and ready for the global communicator creation below.
|
||||
bli_sba_rntm_set_pool( 0, array, rntm );
|
||||
|
||||
// Set the packing block allocator field of the rntm. This will be
|
||||
// inherited by all of the child threads when they make local copies of
|
||||
// the rntm below.
|
||||
bli_membrk_rntm_set_membrk( rntm );
|
||||
|
||||
// Allcoate a global communicator for the root thrinfo_t structures.
|
||||
thrcomm_t* restrict gl_comm = bli_thrcomm_create( rntm, n_threads );
|
||||
|
||||
|
||||
_Pragma( "omp parallel num_threads(n_threads)" )
|
||||
{
|
||||
// Create a thread-local copy of the master thread's rntm_t. This is
|
||||
// necessary since we want each thread to be able to track its own
|
||||
// small block pool_t as it executes down the function stack.
|
||||
rntm_t rntm_l = *rntm;
|
||||
rntm_t* restrict rntm_p = &rntm_l;
|
||||
|
||||
// Query the thread's id from OpenMP.
|
||||
const dim_t tid = omp_get_thread_num();
|
||||
|
||||
// Check for a somewhat obscure OpenMP thread-mistmatch issue.
|
||||
// NOTE: This calls the same function used for the conventional/large
|
||||
// code path.
|
||||
bli_l3_thread_decorator_thread_check( n_threads, tid, gl_comm, rntm_p );
|
||||
|
||||
// Use the thread id to access the appropriate pool_t* within the
|
||||
// array_t, and use it to set the sba_pool field within the rntm_t.
|
||||
// If the pool_t* element within the array_t is NULL, it will first
|
||||
// be allocated/initialized.
|
||||
bli_sba_rntm_set_pool( tid, array, rntm_p );
|
||||
|
||||
thrinfo_t* thread = NULL;
|
||||
|
||||
// Create the root node of the thread's thrinfo_t structure.
|
||||
bli_l3_sup_thrinfo_create_root( tid, gl_comm, rntm_p, &thread );
|
||||
|
||||
func
|
||||
(
|
||||
alpha,
|
||||
a,
|
||||
b,
|
||||
beta,
|
||||
c,
|
||||
cntx,
|
||||
rntm_p,
|
||||
thread
|
||||
);
|
||||
|
||||
// Free the current thread's thrinfo_t structure.
|
||||
bli_l3_sup_thrinfo_free( rntm_p, thread );
|
||||
}
|
||||
|
||||
// We shouldn't free the global communicator since it was already freed
|
||||
// by the global communicator's chief thread in bli_l3_thrinfo_free()
|
||||
// (called from the thread entry function).
|
||||
|
||||
// Check the array_t back into the small block allocator. Similar to the
|
||||
// check-out, this is done using a lock embedded within the sba to ensure
|
||||
// mutual exclusion.
|
||||
bli_sba_checkin_array( array );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
44
sandbox/gemmlike/thread/bls_l3_decor_openmp.h
Normal file
44
sandbox/gemmlike/thread/bls_l3_decor_openmp.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
|
||||
BLIS
|
||||
An object-based framework for developing high-performance BLAS-like
|
||||
libraries.
|
||||
|
||||
Copyright (C) 2021, The University of Texas at Austin
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef BLIS_SBX_L3_DECOR_OPENMP_H
|
||||
#define BLIS_SBX_L3_DECOR_OPENMP_H
|
||||
|
||||
// Definitions specific to situations when OpenMP multithreading is enabled.
|
||||
#ifdef BLIS_ENABLE_OPENMP
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
213
sandbox/gemmlike/thread/bls_l3_decor_pthreads.c
Normal file
213
sandbox/gemmlike/thread/bls_l3_decor_pthreads.c
Normal file
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
|
||||
BLIS
|
||||
An object-based framework for developing high-performance BLAS-like
|
||||
libraries.
|
||||
|
||||
Copyright (C) 2021, The University of Texas at Austin
|
||||
|
||||
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"
|
||||
|
||||
#ifdef BLIS_ENABLE_PTHREADS
|
||||
|
||||
// A data structure to assist in passing operands to additional threads.
|
||||
typedef struct thread_data
|
||||
{
|
||||
l3sbxint_t func;
|
||||
opid_t family;
|
||||
obj_t* alpha;
|
||||
obj_t* a;
|
||||
obj_t* b;
|
||||
obj_t* beta;
|
||||
obj_t* c;
|
||||
cntx_t* cntx;
|
||||
rntm_t* rntm;
|
||||
dim_t tid;
|
||||
thrcomm_t* gl_comm;
|
||||
array_t* array;
|
||||
} thread_data_t;
|
||||
|
||||
// Entry point function for additional threads.
|
||||
void* bls_l3_thread_entry( void* data_void )
|
||||
{
|
||||
thread_data_t* data = data_void;
|
||||
|
||||
l3sbxint_t func = data->func;
|
||||
opid_t family = data->family;
|
||||
obj_t* alpha = data->alpha;
|
||||
obj_t* a = data->a;
|
||||
obj_t* b = data->b;
|
||||
obj_t* beta = data->beta;
|
||||
obj_t* c = data->c;
|
||||
cntx_t* cntx = data->cntx;
|
||||
rntm_t* rntm = data->rntm;
|
||||
dim_t tid = data->tid;
|
||||
array_t* array = data->array;
|
||||
thrcomm_t* gl_comm = data->gl_comm;
|
||||
|
||||
( void )family;
|
||||
|
||||
// Create a thread-local copy of the master thread's rntm_t. This is
|
||||
// necessary since we want each thread to be able to track its own
|
||||
// small block pool_t as it executes down the function stack.
|
||||
rntm_t rntm_l = *rntm;
|
||||
rntm_t* restrict rntm_p = &rntm_l;
|
||||
|
||||
// Use the thread id to access the appropriate pool_t* within the
|
||||
// array_t, and use it to set the sba_pool field within the rntm_t.
|
||||
// If the pool_t* element within the array_t is NULL, it will first
|
||||
// be allocated/initialized.
|
||||
bli_sba_rntm_set_pool( tid, array, rntm_p );
|
||||
|
||||
thrinfo_t* thread = NULL;
|
||||
|
||||
// Create the root node of the current thread's thrinfo_t structure.
|
||||
bli_l3_sup_thrinfo_create_root( tid, gl_comm, rntm_p, &thread );
|
||||
|
||||
func
|
||||
(
|
||||
alpha,
|
||||
a,
|
||||
b,
|
||||
beta,
|
||||
c,
|
||||
cntx,
|
||||
rntm_p,
|
||||
thread
|
||||
);
|
||||
|
||||
// Free the current thread's thrinfo_t structure.
|
||||
bli_l3_sup_thrinfo_free( rntm_p, thread );
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void bls_l3_thread_decorator
|
||||
(
|
||||
l3sbxint_t func,
|
||||
opid_t family,
|
||||
obj_t* alpha,
|
||||
obj_t* a,
|
||||
obj_t* b,
|
||||
obj_t* beta,
|
||||
obj_t* c,
|
||||
cntx_t* cntx,
|
||||
rntm_t* rntm
|
||||
)
|
||||
{
|
||||
// Query the total number of threads from the context.
|
||||
const dim_t n_threads = bli_rntm_num_threads( rntm );
|
||||
|
||||
// NOTE: The sba was initialized in bli_init().
|
||||
|
||||
// Check out an array_t from the small block allocator. This is done
|
||||
// with an internal lock to ensure only one application thread accesses
|
||||
// the sba at a time. bli_sba_checkout_array() will also automatically
|
||||
// resize the array_t, if necessary.
|
||||
array_t* restrict array = bli_sba_checkout_array( n_threads );
|
||||
|
||||
// Access the pool_t* for thread 0 and embed it into the rntm. We do
|
||||
// this up-front only so that we have the rntm_t.sba_pool field
|
||||
// initialized and ready for the global communicator creation below.
|
||||
bli_sba_rntm_set_pool( 0, array, rntm );
|
||||
|
||||
// Set the packing block allocator field of the rntm. This will be
|
||||
// inherited by all of the child threads when they make local copies of
|
||||
// the rntm below.
|
||||
bli_membrk_rntm_set_membrk( rntm );
|
||||
|
||||
// Allocate a global communicator for the root thrinfo_t structures.
|
||||
thrcomm_t* restrict gl_comm = bli_thrcomm_create( rntm, n_threads );
|
||||
|
||||
// Allocate an array of pthread objects and auxiliary data structs to pass
|
||||
// to the thread entry functions.
|
||||
|
||||
#ifdef BLIS_ENABLE_MEM_TRACING
|
||||
printf( "bli_l3_thread_decorator().pth: " );
|
||||
#endif
|
||||
bli_pthread_t* pthreads = bli_malloc_intl( sizeof( bli_pthread_t ) * n_threads );
|
||||
|
||||
#ifdef BLIS_ENABLE_MEM_TRACING
|
||||
printf( "bli_l3_thread_decorator().pth: " );
|
||||
#endif
|
||||
thread_data_t* datas = bli_malloc_intl( sizeof( thread_data_t ) * n_threads );
|
||||
|
||||
// NOTE: We must iterate backwards so that the chief thread (thread id 0)
|
||||
// can spawn all other threads before proceeding with its own computation.
|
||||
for ( dim_t tid = n_threads - 1; 0 <= tid; tid-- )
|
||||
{
|
||||
// Set up thread data for additional threads (beyond thread 0).
|
||||
datas[tid].func = func;
|
||||
datas[tid].family = family;
|
||||
datas[tid].alpha = alpha;
|
||||
datas[tid].a = a;
|
||||
datas[tid].b = b;
|
||||
datas[tid].beta = beta;
|
||||
datas[tid].c = c;
|
||||
datas[tid].cntx = cntx;
|
||||
datas[tid].rntm = rntm;
|
||||
datas[tid].tid = tid;
|
||||
datas[tid].gl_comm = gl_comm;
|
||||
datas[tid].array = array;
|
||||
|
||||
// Spawn additional threads for ids greater than 1.
|
||||
if ( tid != 0 )
|
||||
bli_pthread_create( &pthreads[tid], NULL, &bls_l3_thread_entry, &datas[tid] );
|
||||
else
|
||||
bls_l3_thread_entry( ( void* )(&datas[0]) );
|
||||
}
|
||||
|
||||
// We shouldn't free the global communicator since it was already freed
|
||||
// by the global communicator's chief thread in bli_l3_thrinfo_free()
|
||||
// (called from the thread entry function).
|
||||
|
||||
// Thread 0 waits for additional threads to finish.
|
||||
for ( dim_t tid = 1; tid < n_threads; tid++ )
|
||||
{
|
||||
bli_pthread_join( pthreads[tid], NULL );
|
||||
}
|
||||
|
||||
// Check the array_t back into the small block allocator. Similar to the
|
||||
// check-out, this is done using a lock embedded within the sba to ensure
|
||||
// mutual exclusion.
|
||||
bli_sba_checkin_array( array );
|
||||
|
||||
#ifdef BLIS_ENABLE_MEM_TRACING
|
||||
printf( "bli_l3_thread_decorator().pth: " );
|
||||
#endif
|
||||
bli_free_intl( pthreads );
|
||||
|
||||
#ifdef BLIS_ENABLE_MEM_TRACING
|
||||
printf( "bli_l3_thread_decorator().pth: " );
|
||||
#endif
|
||||
bli_free_intl( datas );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
47
sandbox/gemmlike/thread/bls_l3_decor_pthreads.h
Normal file
47
sandbox/gemmlike/thread/bls_l3_decor_pthreads.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
|
||||
BLIS
|
||||
An object-based framework for developing high-performance BLAS-like
|
||||
libraries.
|
||||
|
||||
Copyright (C) 2021, The University of Texas at Austin
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef BLIS_SBX_L3_DECOR_PTHREADS_H
|
||||
#define BLIS_SBX_L3_DECOR_PTHREADS_H
|
||||
|
||||
// Definitions specific to situations when POSIX multithreading is enabled.
|
||||
#ifdef BLIS_ENABLE_PTHREADS
|
||||
|
||||
// Thread entry point prototype.
|
||||
void* bls_l3_thread_entry( void* data_void );
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
141
sandbox/gemmlike/thread/bls_l3_decor_single.c
Normal file
141
sandbox/gemmlike/thread/bls_l3_decor_single.c
Normal file
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
|
||||
BLIS
|
||||
An object-based framework for developing high-performance BLAS-like
|
||||
libraries.
|
||||
|
||||
Copyright (C) 2021, The University of Texas at Austin
|
||||
|
||||
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"
|
||||
|
||||
#ifndef BLIS_ENABLE_MULTITHREADING
|
||||
|
||||
#define SKIP_THRINFO_TREE
|
||||
|
||||
void bls_l3_thread_decorator
|
||||
(
|
||||
l3sbxint_t func,
|
||||
opid_t family,
|
||||
//pack_t schema_a,
|
||||
//pack_t schema_b,
|
||||
obj_t* alpha,
|
||||
obj_t* a,
|
||||
obj_t* b,
|
||||
obj_t* beta,
|
||||
obj_t* c,
|
||||
cntx_t* cntx,
|
||||
rntm_t* rntm
|
||||
)
|
||||
{
|
||||
// For sequential execution, we use only one thread.
|
||||
const dim_t n_threads = 1;
|
||||
|
||||
// NOTE: The sba was initialized in bli_init().
|
||||
|
||||
// Check out an array_t from the small block allocator. This is done
|
||||
// with an internal lock to ensure only one application thread accesses
|
||||
// the sba at a time. bli_sba_checkout_array() will also automatically
|
||||
// resize the array_t, if necessary.
|
||||
array_t* restrict array = bli_sba_checkout_array( n_threads );
|
||||
|
||||
// Access the pool_t* for thread 0 and embed it into the rntm.
|
||||
bli_sba_rntm_set_pool( 0, array, rntm );
|
||||
|
||||
// Set the packing block allocator field of the rntm.
|
||||
bli_membrk_rntm_set_membrk( rntm );
|
||||
|
||||
#ifndef SKIP_THRINFO_TREE
|
||||
// Allcoate a global communicator for the root thrinfo_t structures.
|
||||
thrcomm_t* restrict gl_comm = bli_thrcomm_create( rntm, n_threads );
|
||||
#endif
|
||||
|
||||
|
||||
{
|
||||
// NOTE: We don't need to create another copy of the rntm_t since
|
||||
// it was already copied in one of the high-level oapi functions.
|
||||
rntm_t* restrict rntm_p = rntm;
|
||||
|
||||
// There is only one thread id (for the thief thread).
|
||||
const dim_t tid = 0;
|
||||
|
||||
// Use the thread id to access the appropriate pool_t* within the
|
||||
// array_t, and use it to set the sba_pool field within the rntm_t.
|
||||
// If the pool_t* element within the array_t is NULL, it will first
|
||||
// be allocated/initialized.
|
||||
// NOTE: This is commented out because, in the single-threaded case,
|
||||
// this is redundant since it's already been done above.
|
||||
//bli_sba_rntm_set_pool( tid, array, rntm_p );
|
||||
|
||||
#ifndef SKIP_THRINFO_TREE
|
||||
thrinfo_t* thread = NULL;
|
||||
|
||||
// Create the root node of the thread's thrinfo_t structure.
|
||||
bli_l3_sup_thrinfo_create_root( tid, gl_comm, rntm_p, &thread );
|
||||
#else
|
||||
// This optimization allows us to use one of the global thrinfo_t
|
||||
// objects for single-threaded execution rather than grow one from
|
||||
// scratch. The key is that bli_thrinfo_sup_grow(), which is called
|
||||
// from within the variants, will immediately return if it detects
|
||||
// that the thrinfo_t* passed into it is either
|
||||
// &BLIS_GEMM_SINGLE_THREADED or &BLIS_PACKM_SINGLE_THREADED.
|
||||
thrinfo_t* thread = &BLIS_GEMM_SINGLE_THREADED;
|
||||
|
||||
( void )tid;
|
||||
#endif
|
||||
|
||||
func
|
||||
(
|
||||
alpha,
|
||||
a,
|
||||
b,
|
||||
beta,
|
||||
c,
|
||||
cntx,
|
||||
rntm_p,
|
||||
thread
|
||||
);
|
||||
|
||||
#ifndef SKIP_THRINFO_TREE
|
||||
// Free the current thread's thrinfo_t structure.
|
||||
bli_l3_sup_thrinfo_free( rntm_p, thread );
|
||||
#endif
|
||||
}
|
||||
|
||||
// We shouldn't free the global communicator since it was already freed
|
||||
// by the global communicator's chief thread in bli_l3_thrinfo_free()
|
||||
// (called above).
|
||||
|
||||
// Check the array_t back into the small block allocator. Similar to the
|
||||
// check-out, this is done using a lock embedded within the sba to ensure
|
||||
// mutual exclusion.
|
||||
bli_sba_checkin_array( array );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
44
sandbox/gemmlike/thread/bls_l3_decor_single.h
Normal file
44
sandbox/gemmlike/thread/bls_l3_decor_single.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
|
||||
BLIS
|
||||
An object-based framework for developing high-performance BLAS-like
|
||||
libraries.
|
||||
|
||||
Copyright (C) 2021, The University of Texas at Austin
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef BLIS_SBX_L3_DECOR_SINGLE_H
|
||||
#define BLIS_SBX_L3_DECOR_SINGLE_H
|
||||
|
||||
// Definitions specific to situations when multithreading is disabled.
|
||||
#ifndef BLIS_ENABLE_MULTITHREADING
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -32,7 +32,14 @@
|
||||
|
||||
*/
|
||||
|
||||
// This file is needed for the BLIS build system.
|
||||
// Given the current architecture of BLIS sandboxes, bli_gemmnat() is the
|
||||
// entry point to any sandbox implementation.
|
||||
|
||||
// NOTE: This function is implemented identically to the function that it
|
||||
// overrides in frame/ind/oapi/bli_l3_nat_oapi.c. This means that we are
|
||||
// forgoing the option of customizing the implementations that underlie
|
||||
// bli_gemm() and bli_?gemm(). Any new code defined in this sandbox
|
||||
// directory, however, will be included in the BLIS.
|
||||
|
||||
#include "blis.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user