mirror of
https://github.com/amd/blis.git
synced 2026-04-19 23:28:52 +00:00
Parallelized Pack and Compute Extension APIs
1. OpenMP based multi-threading parallelism is added for BLAS
extension APIs of Pack and Compute
2. Both pack and compute APIs are parallelized.
3. Multi-threading of pack and compute APIs done with different
number of threads can lead to inconsistent results due to
output difference of the full packed matrix buffer when packed
with different number of threads.
4. In multi-threaded execution, we ensure output of packed buffer
is exactly the same as in single threaded execution.
5. Similarly for compute API, read of packed buffer in multi-
threaded execution is exactly the same as in single-threaded
execution.
6. Routines are added to compute the offsets for thread workload
distribution for MT execution.
1. The offsets are calculated in such a way that it resembles
the reorder buffer traversal in single threaded reordering.
2. The panel boundaries (KCxNC) remain as it is accessed in
single thread, and as a consequence a thread with jc_start
inside the panel cannot consider NC range for reorder.
3. It has to work with NC' < NC, and the offset is calulated
using prev NC panels spanning k dim + cur NC panel spaning
pc loop cur iteration + (NC - NC') spanning current
kc0 (<= KC).
7. Routines to ensure the same are added for MT execution
1. frame/base/bli_pack_compute_utils.c
2. frame/base/bli_pack_compute_utils.h
AMD-Internal: [CPUPL-3560]
Change-Id: I0dad33e0062519de807c32f6071e61fba976d9ac
This commit is contained in:
@@ -278,7 +278,6 @@ int main( int argc, char** argv )
|
||||
bli_printm( "b", &b, "%4.6f", "" );
|
||||
bli_printm( "c", &c, "%4.6f", "" );
|
||||
#endif
|
||||
dtime = bli_clock();
|
||||
|
||||
#ifdef BLIS
|
||||
|
||||
@@ -374,6 +373,8 @@ int main( int argc, char** argv )
|
||||
ap, lda,
|
||||
aBuffer );
|
||||
|
||||
dtime = bli_clock();
|
||||
|
||||
cblas_sgemm_compute( cblas_order,
|
||||
CblasPacked,
|
||||
cblas_transb,
|
||||
@@ -385,6 +386,8 @@ int main( int argc, char** argv )
|
||||
*betap,
|
||||
cp, ldc );
|
||||
|
||||
dtime_save = bli_clock_min_diff( dtime_save, dtime );
|
||||
|
||||
bli_free_user(aBuffer);
|
||||
}
|
||||
else if ( !packA && packB )
|
||||
@@ -406,6 +409,8 @@ int main( int argc, char** argv )
|
||||
bp, ldb,
|
||||
bBuffer );
|
||||
|
||||
dtime = bli_clock();
|
||||
|
||||
cblas_sgemm_compute( cblas_order,
|
||||
cblas_transa,
|
||||
CblasPacked,
|
||||
@@ -417,6 +422,9 @@ int main( int argc, char** argv )
|
||||
*betap,
|
||||
cp, ldc );
|
||||
|
||||
dtime_save = bli_clock_min_diff( dtime_save, dtime );
|
||||
|
||||
|
||||
bli_free_user(bBuffer);
|
||||
}
|
||||
else if ( packA && packB )
|
||||
@@ -454,6 +462,8 @@ int main( int argc, char** argv )
|
||||
bp, ldb,
|
||||
bBuffer );
|
||||
|
||||
dtime = bli_clock();
|
||||
|
||||
cblas_sgemm_compute( cblas_order,
|
||||
CblasPacked,
|
||||
CblasPacked,
|
||||
@@ -465,12 +475,17 @@ int main( int argc, char** argv )
|
||||
*betap,
|
||||
cp, ldc );
|
||||
|
||||
dtime_save = bli_clock_min_diff( dtime_save, dtime );
|
||||
|
||||
bli_free_user(aBuffer);
|
||||
bli_free_user(bBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Neither A nor B is pre-packed.
|
||||
|
||||
dtime = bli_clock();
|
||||
|
||||
cblas_sgemm_compute( cblas_order,
|
||||
cblas_transa,
|
||||
cblas_transb,
|
||||
@@ -481,6 +496,8 @@ int main( int argc, char** argv )
|
||||
bp, ldb,
|
||||
*betap,
|
||||
cp, ldc );
|
||||
|
||||
dtime_save = bli_clock_min_diff( dtime_save, dtime );
|
||||
}
|
||||
#else // -- BLAS API --
|
||||
float* aBuffer;
|
||||
@@ -505,6 +522,8 @@ int main( int argc, char** argv )
|
||||
(f77_int*)&lda,
|
||||
aBuffer );
|
||||
|
||||
dtime = bli_clock();
|
||||
|
||||
sgemm_compute_( &f77_packed,
|
||||
&f77_transb,
|
||||
&mm,
|
||||
@@ -515,6 +534,8 @@ int main( int argc, char** argv )
|
||||
betap,
|
||||
cp, (f77_int*)&ldc );
|
||||
|
||||
dtime_save = bli_clock_min_diff( dtime_save, dtime );
|
||||
|
||||
bli_free_user( aBuffer );
|
||||
}
|
||||
else if ( !packA && packB )
|
||||
@@ -536,6 +557,8 @@ int main( int argc, char** argv )
|
||||
(f77_int*)&ldb,
|
||||
bBuffer );
|
||||
|
||||
dtime = bli_clock();
|
||||
|
||||
sgemm_compute_( &f77_transa,
|
||||
&f77_packed,
|
||||
&mm,
|
||||
@@ -546,6 +569,8 @@ int main( int argc, char** argv )
|
||||
betap,
|
||||
cp, (f77_int*)&ldc );
|
||||
|
||||
dtime_save = bli_clock_min_diff( dtime_save, dtime );
|
||||
|
||||
bli_free_user( bBuffer );
|
||||
}
|
||||
else if ( packA && packB )
|
||||
@@ -585,6 +610,8 @@ int main( int argc, char** argv )
|
||||
(f77_int*)&ldb,
|
||||
bBuffer );
|
||||
|
||||
dtime = bli_clock();
|
||||
|
||||
sgemm_compute_( &f77_packed,
|
||||
&f77_packed,
|
||||
&mm,
|
||||
@@ -595,12 +622,17 @@ int main( int argc, char** argv )
|
||||
betap,
|
||||
cp, (f77_int*)&ldc );
|
||||
|
||||
dtime_save = bli_clock_min_diff( dtime_save, dtime );
|
||||
|
||||
bli_free_user(aBuffer);
|
||||
bli_free_user(bBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Neither A nor B is reordered.
|
||||
|
||||
dtime = bli_clock();
|
||||
|
||||
sgemm_compute_( &f77_transa,
|
||||
&f77_transb,
|
||||
&mm,
|
||||
@@ -610,6 +642,8 @@ int main( int argc, char** argv )
|
||||
bp, (f77_int*)&ldb,
|
||||
betap,
|
||||
cp, (f77_int*)&ldc );
|
||||
|
||||
dtime_save = bli_clock_min_diff( dtime_save, dtime );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -649,6 +683,8 @@ int main( int argc, char** argv )
|
||||
ap, lda,
|
||||
aBuffer );
|
||||
|
||||
dtime = bli_clock();
|
||||
|
||||
cblas_dgemm_compute( cblas_order,
|
||||
CblasPacked,
|
||||
cblas_transb,
|
||||
@@ -660,6 +696,8 @@ int main( int argc, char** argv )
|
||||
*betap,
|
||||
cp, ldc );
|
||||
|
||||
dtime_save = bli_clock_min_diff( dtime_save, dtime );
|
||||
|
||||
bli_free_user(aBuffer);
|
||||
}
|
||||
else if ( !packA && packB )
|
||||
@@ -680,6 +718,8 @@ int main( int argc, char** argv )
|
||||
bp, ldb,
|
||||
bBuffer );
|
||||
|
||||
dtime = bli_clock();
|
||||
|
||||
cblas_dgemm_compute( cblas_order,
|
||||
cblas_transa,
|
||||
CblasPacked,
|
||||
@@ -691,6 +731,8 @@ int main( int argc, char** argv )
|
||||
*betap,
|
||||
cp, ldc );
|
||||
|
||||
dtime_save = bli_clock_min_diff( dtime_save, dtime );
|
||||
|
||||
bli_free_user(bBuffer);
|
||||
}
|
||||
else if ( packA && packB )
|
||||
@@ -728,6 +770,8 @@ int main( int argc, char** argv )
|
||||
bp, ldb,
|
||||
bBuffer );
|
||||
|
||||
dtime = bli_clock();
|
||||
|
||||
cblas_dgemm_compute( cblas_order,
|
||||
CblasPacked,
|
||||
CblasPacked,
|
||||
@@ -739,12 +783,17 @@ int main( int argc, char** argv )
|
||||
*betap,
|
||||
cp, ldc );
|
||||
|
||||
dtime_save = bli_clock_min_diff( dtime_save, dtime );
|
||||
|
||||
bli_free_user(aBuffer);
|
||||
bli_free_user(bBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Neither A nor B is pre-packed.
|
||||
|
||||
dtime = bli_clock();
|
||||
|
||||
cblas_dgemm_compute( cblas_order,
|
||||
cblas_transa,
|
||||
cblas_transb,
|
||||
@@ -755,6 +804,8 @@ int main( int argc, char** argv )
|
||||
bp, ldb,
|
||||
*betap,
|
||||
cp, ldc );
|
||||
|
||||
dtime_save = bli_clock_min_diff( dtime_save, dtime );
|
||||
}
|
||||
|
||||
#else // -- BLAS API --
|
||||
@@ -780,6 +831,8 @@ int main( int argc, char** argv )
|
||||
(f77_int*)&lda,
|
||||
aBuffer );
|
||||
|
||||
dtime = bli_clock();
|
||||
|
||||
dgemm_compute_( &f77_packed,
|
||||
&f77_transb,
|
||||
&mm,
|
||||
@@ -790,6 +843,8 @@ int main( int argc, char** argv )
|
||||
betap,
|
||||
cp, (f77_int*)&ldc );
|
||||
|
||||
dtime_save = bli_clock_min_diff( dtime_save, dtime );
|
||||
|
||||
bli_free_user( aBuffer );
|
||||
}
|
||||
else if ( !packA && packB )
|
||||
@@ -811,6 +866,8 @@ int main( int argc, char** argv )
|
||||
(f77_int*)&ldb,
|
||||
bBuffer );
|
||||
|
||||
dtime = bli_clock();
|
||||
|
||||
dgemm_compute_( &f77_transa,
|
||||
&f77_packed,
|
||||
&mm,
|
||||
@@ -821,6 +878,8 @@ int main( int argc, char** argv )
|
||||
betap,
|
||||
cp, (f77_int*)&ldc );
|
||||
|
||||
dtime_save = bli_clock_min_diff( dtime_save, dtime );
|
||||
|
||||
bli_free_user( bBuffer );
|
||||
}
|
||||
else if ( packA && packB )
|
||||
@@ -858,6 +917,8 @@ int main( int argc, char** argv )
|
||||
(f77_int*)&ldb,
|
||||
bBuffer );
|
||||
|
||||
dtime = bli_clock();
|
||||
|
||||
dgemm_compute_( &f77_packed,
|
||||
&f77_packed,
|
||||
&mm,
|
||||
@@ -868,12 +929,17 @@ int main( int argc, char** argv )
|
||||
betap,
|
||||
cp, (f77_int*)&ldc );
|
||||
|
||||
dtime_save = bli_clock_min_diff( dtime_save, dtime );
|
||||
|
||||
bli_free_user(aBuffer);
|
||||
bli_free_user(bBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Neither A nor B is reordered.
|
||||
|
||||
dtime = bli_clock();
|
||||
|
||||
dgemm_compute_( &f77_transa,
|
||||
&f77_transb,
|
||||
&mm,
|
||||
@@ -883,6 +949,8 @@ int main( int argc, char** argv )
|
||||
bp, (f77_int*)&ldb,
|
||||
betap,
|
||||
cp, (f77_int*)&ldc );
|
||||
|
||||
dtime_save = bli_clock_min_diff( dtime_save, dtime );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -891,8 +959,6 @@ int main( int argc, char** argv )
|
||||
#ifdef PRINT
|
||||
bli_printm( "c compute", &c, "%4.6f", "" );
|
||||
#endif
|
||||
|
||||
dtime_save = bli_clock_min_diff( dtime_save, dtime );
|
||||
}
|
||||
|
||||
gflops = ( 2.0 * m * k * n ) / ( dtime_save * 1.0e9 );
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
*/
|
||||
|
||||
#include "blis.h"
|
||||
#include "../../base/bli_pack_compute_utils.h"
|
||||
|
||||
void bli_pack_full_init
|
||||
(
|
||||
@@ -238,11 +239,6 @@ void PASTEMAC(ch,tfuncname) \
|
||||
/* 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; \
|
||||
\
|
||||
inc_t rs_b_use, cs_b_use, ps_b_use; \
|
||||
\
|
||||
@@ -251,12 +247,59 @@ void PASTEMAC(ch,tfuncname) \
|
||||
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 ); \
|
||||
dim_t nc_cur = ( NC <= ( jc_end - jj ) ? NC : ( jc_end - jj ) ); \
|
||||
\
|
||||
const inc_t pcstep_b_use = ( ( nc_cur + NR - 1 ) / NR ) * NR; \
|
||||
dim_t jc_cur_loop = jj;\
|
||||
dim_t jc_cur_loop_rem = 0;\
|
||||
dim_t n_sub_updated = 0;\
|
||||
\
|
||||
/* This function returns the offsets that are computed for */ \
|
||||
/* thread workload distribution in MT execution. */ \
|
||||
get_B_panel_reordered_start_offset_width \
|
||||
( \
|
||||
jj, n, NC, NR, \
|
||||
&jc_cur_loop, &jc_cur_loop_rem, \
|
||||
&nc_cur, &n_sub_updated \
|
||||
); \
|
||||
\
|
||||
/* The offsets are calculated in such a way that it resembles */ \
|
||||
/* the reorder buffer traversal in single threaded reordering. */ \
|
||||
/* The panel boundaries (KCxNC) remain as it is accessed in */ \
|
||||
/* single thread, and as a consequence a thread with jc_start */ \
|
||||
/* inside the panel cannot consider NC range for reorder. It */ \
|
||||
/* has to work with NC' < NC, and the offset is calulated using */ \
|
||||
/* prev NC panels spanning k dim + cur NC panel spaning pc loop */ \
|
||||
/* cur iteration + (NC - NC') spanning current kc0 (<= KC). */ \
|
||||
/* */ \
|
||||
/* Eg: Consider the following reordered buffer diagram: */ \
|
||||
/* t1 t2 */ \
|
||||
/* | | */ \
|
||||
/* | |..NC..| */ \
|
||||
/* | | | */ \
|
||||
/* |.NC. |.NC. |NC'|NC" */ \
|
||||
/* pc=0-+-----+-----+---+--+ */ \
|
||||
/* KC| | | | | */ \
|
||||
/* | 1 | 3 | 5 | */ \
|
||||
/* pc=KC-+-----+-----+---st-+ */ \
|
||||
/* KC| | | | | */ \
|
||||
/* | 2 | 4 | 6 | 7| */ \
|
||||
/* pc=k=2KC-+-----+-----+---+--+ */ \
|
||||
/* |jc=0 |jc=NC|jc=2NC| */ \
|
||||
/* */ \
|
||||
/* The numbers 1,2..6,7 denotes the order in which reordered */ \
|
||||
/* KCxNC blocks are stored in memory, ie: block 1 followed by 2 */ \
|
||||
/* followed by 3, etc. Given two threads t1 and t2, and t2 needs */ \
|
||||
/* to acces point st in the reorder buffer to write the data: */ \
|
||||
/* The offset calulation logic will be: */ \
|
||||
/* jc_cur_loop = 2NC, jc_cur_loop_rem = NC', pc = KC, */ \
|
||||
/* n_sub_updated = NC, k = 2KC, kc0_updated = KC */ \
|
||||
/* */ \
|
||||
/* st = ( jc_cur_loop * k ) <traverse blocks 1,2,3,4> */ \
|
||||
/* + ( n_sub_updated * pc ) <traverse block 5> */ \
|
||||
/* + ( NC' * kc0_updated) <traverse block 6> */ \
|
||||
\
|
||||
ctype* restrict b_jc = src + jj * jcstep_b; \
|
||||
ctype* restrict b_jc_use = dest + jj * jcstep_b_use; \
|
||||
ctype* restrict b_jc_use = dest + jc_cur_loop * jcstep_b_use; \
|
||||
\
|
||||
/* Compute the PC loop thread range for the current thread. */ \
|
||||
const dim_t pc_start = 0, pc_end = k; \
|
||||
@@ -271,10 +314,10 @@ void PASTEMAC(ch,tfuncname) \
|
||||
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 ); \
|
||||
const dim_t kc_cur = ( KC <= ( pc_end - pp ) ? KC : pc_left ); \
|
||||
\
|
||||
ctype* restrict b_pc = b_jc + pp * pcstep_b; \
|
||||
ctype* restrict b_pc_use = b_jc_use + pp * pcstep_b_use; \
|
||||
ctype* restrict b_pc_use = b_jc_use + pp * n_sub_updated + jc_cur_loop_rem * kc_cur; \
|
||||
\
|
||||
/* Packing is parallelized only at JC loop */ \
|
||||
thread_pb = &BLIS_GEMM_SINGLE_THREADED; \
|
||||
@@ -307,6 +350,9 @@ void PASTEMAC(ch,tfuncname) \
|
||||
); \
|
||||
\
|
||||
} \
|
||||
\
|
||||
adjust_B_panel_reordered_jc( &jj, jc_cur_loop ); \
|
||||
\
|
||||
} \
|
||||
\
|
||||
} \
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
*/
|
||||
|
||||
#include "blis.h"
|
||||
#include "../base/bli_pack_compute_utils.h"
|
||||
|
||||
void bli_gemm_compute_init
|
||||
(
|
||||
@@ -77,9 +78,6 @@ void bli_gemm_compute_init
|
||||
// bli_nthreads_optimum(a, b, c, BLIS_GEMM, rntm );
|
||||
#endif
|
||||
|
||||
// Explicitly set n_threads=1 and update rntm since only ST supported.
|
||||
dim_t n_threads = 1;
|
||||
bli_rntm_set_num_threads( n_threads, rntm );
|
||||
bli_rntm_set_ways_from_rntm_sup
|
||||
(
|
||||
bli_obj_length( c ),
|
||||
@@ -362,22 +360,32 @@ void PASTEMAC( ch, varname ) \
|
||||
/* 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 = 0; jj < jc_iter; jj += 1 )*/ \
|
||||
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 ); \
|
||||
const inc_t pcstep_b_use = ( ( nc_cur + NR - 1 ) / NR ) * NR; \
|
||||
dim_t nc_cur = ( NC <= ( jc_end - jj ) ? NC : ( jc_end - jj ) ); \
|
||||
\
|
||||
/* For MT correctness- to ensure full packing order of packed buffer */ \
|
||||
/* for Single and Multi Threaded executions are same. */ \
|
||||
dim_t jc_cur_loop = jj;\
|
||||
dim_t jc_cur_loop_rem = 0;\
|
||||
dim_t n_sub_updated = 0;\
|
||||
\
|
||||
if ( packedb ) \
|
||||
{ \
|
||||
get_B_panel_reordered_start_offset_width \
|
||||
( \
|
||||
jj, n, NC, NR, \
|
||||
&jc_cur_loop, &jc_cur_loop_rem, \
|
||||
&nc_cur, &n_sub_updated \
|
||||
); \
|
||||
} \
|
||||
\
|
||||
ctype* restrict b_jc = b_00 + jj * jcstep_b; \
|
||||
ctype* restrict b_jc_use = b_00 + jj * jcstep_b_use; \
|
||||
ctype* restrict b_jc_use = b_00 + jc_cur_loop * jcstep_b_use; \
|
||||
ctype* restrict c_jc = c_00 + jj * jcstep_c; \
|
||||
\
|
||||
/* Grow the thrinfo_t tree. */ \
|
||||
@@ -398,7 +406,7 @@ void PASTEMAC( ch, varname ) \
|
||||
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 ); \
|
||||
const dim_t kc_cur = ( KC <= ( pc_end - pp ) ? KC : pc_left ); \
|
||||
const inc_t icstep_a_use = kc_cur; \
|
||||
\
|
||||
ctype* restrict a_pc = a_00 + pp * pcstep_a; \
|
||||
@@ -440,7 +448,7 @@ void PASTEMAC( ch, varname ) \
|
||||
rs_b_use = NR; \
|
||||
cs_b_use = 1; \
|
||||
ps_b_use = kc_cur * NR; \
|
||||
b_pc_use = b_jc_use + pp * pcstep_b_use; \
|
||||
b_pc_use = b_jc_use + pp * n_sub_updated + jc_cur_loop_rem * kc_cur; \
|
||||
} else \
|
||||
{ \
|
||||
PASTEMAC(ch,packm_sup_b) \
|
||||
@@ -615,6 +623,10 @@ void PASTEMAC( ch, varname ) \
|
||||
that matrix is packed within the pc loop of this variant). */ \
|
||||
if ( packb ) bli_thread_barrier( thread_pb ); \
|
||||
} \
|
||||
if ( packedb ) \
|
||||
{ \
|
||||
adjust_B_panel_reordered_jc( &jj, jc_cur_loop ); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
/* Release any memory that was acquired for packing matrices A and B. */ \
|
||||
@@ -634,4 +646,4 @@ void PASTEMAC( ch, varname ) \
|
||||
); \
|
||||
}
|
||||
|
||||
INSERT_GENTFUNC_BASIC0_SD( gemm_compute )
|
||||
INSERT_GENTFUNC_BASIC0_SD( gemm_compute )
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
##Copyright (C) 2021, Advanced Micro Devices, Inc. All rights reserved.##
|
||||
##Copyright (C) 2021-2023, Advanced Micro Devices, Inc. All rights reserved.##
|
||||
|
||||
target_sources("${PROJECT_NAME}"
|
||||
PUBLIC
|
||||
@@ -39,6 +39,7 @@ target_sources("${PROJECT_NAME}"
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/bli_setri.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/bli_string.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/bli_winsys.c
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/bli_pack_compute_utils.c
|
||||
)
|
||||
|
||||
#Add all subdirectories
|
||||
|
||||
112
frame/base/bli_pack_compute_utils.c
Normal file
112
frame/base/bli_pack_compute_utils.c
Normal file
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
|
||||
BLIS
|
||||
An object-based framework for developing high-performance BLAS-like
|
||||
libraries.
|
||||
|
||||
Copyright (C) 2023, Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
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"
|
||||
|
||||
// Utility function to compute the offset for K dimension traversal
|
||||
// such that it is a multiple of NR.
|
||||
dim_t get_Bpanel_width_for_kdim_traversal
|
||||
(
|
||||
dim_t jc,
|
||||
dim_t n,
|
||||
dim_t NC,
|
||||
dim_t NR
|
||||
)
|
||||
{
|
||||
dim_t n_mod_NR = n % NR;
|
||||
dim_t n_sub_updated = NC;
|
||||
|
||||
if ( ( n % NC ) != 0 )
|
||||
{
|
||||
// Only applicable to final NC part of jc loop where jc + remaining
|
||||
// elements is less than NC; or when n < NC in which case panel width
|
||||
// is atmost n.
|
||||
dim_t n_last_loop = ( n / NC ) * NC;
|
||||
if ( jc >= n_last_loop )
|
||||
{
|
||||
n_sub_updated = n - n_last_loop;
|
||||
if ( n_mod_NR != 0 )
|
||||
{
|
||||
n_sub_updated += ( NR - n_mod_NR );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return n_sub_updated;
|
||||
}
|
||||
|
||||
void get_B_panel_reordered_start_offset_width
|
||||
(
|
||||
dim_t jc,
|
||||
dim_t n,
|
||||
dim_t NC,
|
||||
dim_t NR,
|
||||
dim_t* panel_start,
|
||||
dim_t* panel_offset,
|
||||
dim_t* panel_width,
|
||||
dim_t* panel_width_kdim_trav
|
||||
)
|
||||
{
|
||||
// Since n dimension is split across threads in units of NR blocks,
|
||||
// it could happen that B matrix chunk for a thread may be part of
|
||||
// two separate NCxKC panels. In this case nc0 is updated such that
|
||||
// the jr loop only accesses the remaining portion of current NCxKC
|
||||
// panel, with the next jc iteration taking care of the other panel.
|
||||
// This ensures that jr loop does not cross panel boundaries.
|
||||
( *panel_start ) = ( jc / NC ) * NC;
|
||||
( *panel_offset ) = jc - ( *panel_start );
|
||||
|
||||
// Check if jc + current_panel_width (nc0) crosses panel boundaries.
|
||||
if ( ( jc + ( *panel_width ) ) > ( ( *panel_start ) + NC ) )
|
||||
{
|
||||
( *panel_width ) = NC - ( *panel_offset );
|
||||
}
|
||||
|
||||
( *panel_width_kdim_trav ) = get_Bpanel_width_for_kdim_traversal
|
||||
(
|
||||
jc, n, NC, NR
|
||||
);
|
||||
}
|
||||
|
||||
void adjust_B_panel_reordered_jc( dim_t* jc, dim_t panel_start )
|
||||
{
|
||||
// Since n dimension is split across threads in units of NR blocks,
|
||||
// it could happen that B matrix chunk for a thread may be part of
|
||||
// two separate NCxKC panels. In this case jc is reset to immediate
|
||||
// previous panel offset so that in the next iteration, the
|
||||
// following panel belonging to the B chunk is accessed. This
|
||||
// ensures that jr loop does not cross panel boundaries.
|
||||
( *jc ) = panel_start;
|
||||
}
|
||||
|
||||
|
||||
65
frame/base/bli_pack_compute_utils.h
Normal file
65
frame/base/bli_pack_compute_utils.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
|
||||
BLIS
|
||||
An object-based framework for developing high-performance BLAS-like
|
||||
libraries.
|
||||
|
||||
Copyright (C) 2023, Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
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 PACK_COMPUTE_UTILS_H
|
||||
#define PACK_COMPUTE_UTILS_H
|
||||
|
||||
dim_t get_Bpanel_width_for_kdim_traversal
|
||||
(
|
||||
dim_t jc,
|
||||
dim_t n,
|
||||
dim_t NC,
|
||||
dim_t NR
|
||||
);
|
||||
|
||||
void get_B_panel_reordered_start_offset_width
|
||||
(
|
||||
dim_t jc,
|
||||
dim_t n,
|
||||
dim_t NC,
|
||||
dim_t NR,
|
||||
dim_t* panel_start,
|
||||
dim_t* panel_offset,
|
||||
dim_t* panel_width,
|
||||
dim_t* panel_width_kdim_trav
|
||||
);
|
||||
|
||||
void adjust_B_panel_reordered_jc( dim_t* jc, dim_t panel_start );
|
||||
|
||||
#endif //PACK_COMPUTE_UTILS_H
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
Copyright (C) 2014, The University of Texas at Austin
|
||||
Copyright (C) 2016, Hewlett Packard Enterprise Development LP
|
||||
Copyright (C) 2018 - 2022, Advanced Micro Devices, Inc.
|
||||
Copyright (C) 2018 - 2023, Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
|
||||
@@ -32,10 +32,6 @@
|
||||
|
||||
*/
|
||||
|
||||
// @note: Presently MT is not supported, so n_threads have been explicitly
|
||||
// initialized to 1 while intializing. Thus, even if BLIS is build with OpenMP
|
||||
// support, the compute APIs work as an ST implementation.
|
||||
|
||||
#include "blis.h"
|
||||
|
||||
#ifdef BLIS_ENABLE_OPENMP
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
#include "blis.h"
|
||||
|
||||
#ifndef BLIS_ENABLE_MULTITHREADING
|
||||
#if !defined (BLIS_ENABLE_MULTITHREADING) || defined (BLIS_ENABLE_PTHREADS)
|
||||
|
||||
err_t bli_l3_compute_thread_decorator
|
||||
(
|
||||
|
||||
@@ -54,11 +54,7 @@ void bli_pack_full_thread_decorator
|
||||
/* Ensure n_threads is always greater than or equal to 1 */
|
||||
/* Passing BLIS_IC_NT and BLIS_JC_NT for pack can lead to n_threads */
|
||||
/* becoming negative. In that case, packing is done using 1 thread */
|
||||
// n_threads = ( n_threads > 0 ) ? n_threads : 1;
|
||||
|
||||
// Explicitly setting n_threads = 1 to force packing with only a single
|
||||
// thread.
|
||||
n_threads = 1;
|
||||
n_threads = ( n_threads > 0 ) ? n_threads : 1;
|
||||
|
||||
_Pragma( "omp parallel num_threads(n_threads)" )
|
||||
{
|
||||
|
||||
@@ -34,9 +34,7 @@
|
||||
|
||||
#include "blis.h"
|
||||
|
||||
#ifndef BLIS_ENABLE_OPENMP
|
||||
|
||||
#define SKIP_THRINFO_TREE
|
||||
#if !defined (BLIS_ENABLE_MULTITHREADING) || defined (BLIS_ENABLE_PTHREADS)
|
||||
|
||||
void* bli_pack_full_thread_entry( void* data_void ) { return NULL; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user