Skip to content

Commit

Permalink
Added support for logging gemm input values.
Browse files Browse the repository at this point in the history
Added BLIS specific extension to AOCL DTL, in this
added support to print the input matrix sizes from BLIS
library.

AMD Internal: [CPUPL-806]

Change-Id: I80ed779d65f9b1c48466137fc2f05629fa2fb561
  • Loading branch information
dzambare committed Jun 15, 2020
1 parent dad7e2f commit 80b3127
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 15 deletions.
6 changes: 0 additions & 6 deletions aocl_dtl/aocldtl.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,19 +229,13 @@ void DTL_Trace(
if ((ui8LogLevel >= AOCL_DTL_LEVEL_TRACE_1) &&
(ui8LogLevel <= AOCL_DTL_LEVEL_TRACE_8))
{
fprintf(pOutFile, "%d ", (ui8LogLevel - AOCL_DTL_LEVEL_TRACE_1)+1);
/* this loop is for formating the output log file */
for (i = 0; i < (ui8LogLevel - AOCL_DTL_LEVEL_TRACE_1); i++)
{
/* print tabs in the output file */
fprintf(pOutFile, "\t");
}
}
else
{
/* For non call traces we will just start the line with astrix */
fprintf(pOutFile, "* \t");
}

switch (ui8LogType)
{
Expand Down
46 changes: 46 additions & 0 deletions aocl_dtl/aocldtl_blis.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*===================================================================
* File Name : aocldtl_blis.c
*
* Description : BLIS library specific debug helpes.
*
* Copyright (C) 2020, Advanced Micro Devices, Inc
*
*==================================================================*/


#include "blis.h"

#if AOCL_DTL_LOG_ENABLE
void AOCL_DTL_log_gemm_sizes(int8 loglevel,
obj_t* alpha,
obj_t* a,
obj_t* b,
obj_t* beta,
obj_t* c,
const char* filename,
const char* function_name,
int line)
{
char buffer[256];
gint_t m = bli_obj_length( c );
gint_t n = bli_obj_width( c );
gint_t k = bli_obj_length( b );
guint_t csa = bli_obj_col_stride( a );
guint_t csb = bli_obj_col_stride( b );
guint_t csc = bli_obj_col_stride( c );
guint_t rsa = bli_obj_row_stride( a );
guint_t rsb = bli_obj_row_stride( b );
guint_t rsc = bli_obj_row_stride( c );
const num_t dt_exec = bli_obj_dt( c );
float* alpha_cast = bli_obj_buffer_for_1x1( dt_exec, alpha );
float* beta_cast = bli_obj_buffer_for_1x1( dt_exec, beta );

sprintf(buffer, "%ld %ld %ld %lu %lu %lu %lu %lu %lu %f %f",
m, k, n,
csa, csb, csc,
rsa, rsb, rsc,
*alpha_cast, *beta_cast);

DTL_Trace(loglevel, TRACE_TYPE_LOG, function_name, function_name, line, buffer);
}
#endif
34 changes: 34 additions & 0 deletions aocl_dtl/aocldtl_blis.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*===================================================================
* File Name : aocldtl_blis.h
*
* Description : BLIS library specific debug helpes.
*
* Copyright (C) 2020, Advanced Micro Devices, Inc
*
*==================================================================*/


#ifndef __AOCLDTL_BLIS_H
#define __AOCLDTL_BLIS_H

#include "blis.h"

#if AOCL_DTL_LOG_ENABLE
void AOCL_DTL_log_gemm_sizes(int8 loglevel,
obj_t* alpha,
obj_t* a,
obj_t* b,
obj_t* beta,
obj_t* c,
const char* filename,
const char* functionn_name,
int line);

#define AOCL_DTL_LOG_GEMM_INPUTS(loglevel, alpha, a, b, beta, c) \
AOCL_DTL_log_gemm_sizes(loglevel, alpha, a, b, beta, c, __FILE__, __FUNCTION__, __LINE__);
#else
#define AOCL_DTL_LOG_GEMM_INPUTS(loglevel, alpha, a, b, beta, c)
#endif

#endif

1 change: 1 addition & 0 deletions frame/3/bli_l3_oapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ void PASTEMAC(opname,EX_SUF) \
bli_init_once(); \
\
BLIS_OAPI_EX_DECLS \
AOCL_DTL_LOG_GEMM_INPUTS(AOCL_DTL_LEVEL_TRACE_2, alpha, a, b, beta, c); \
\
/* If C has a zero dimension, return early. */ \
if ( bli_obj_has_zero_dim( c ) ) {\
Expand Down
25 changes: 21 additions & 4 deletions frame/3/bli_l3_sup.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,31 @@ err_t bli_gemmsup
rntm_t* rntm
)
{
AOCL_DTL_TRACE_ENTRY(AOCL_DTL_LEVEL_TRACE_2);
AOCL_DTL_LOG_GEMM_INPUTS(AOCL_DTL_LEVEL_TRACE_2, alpha, a, b, beta, c);

// Return early if small matrix handling is disabled at configure-time.
#ifdef BLIS_DISABLE_SUP_HANDLING
AOCL_DTL_TRACE_EXIT_ERR(AOCL_DTL_LEVEL_TRACE_2, "SUP is Disabled.");
return BLIS_FAILURE;
#endif

// Return early if this is a mixed-datatype computation.
if ( bli_obj_dt( c ) != bli_obj_dt( a ) ||
bli_obj_dt( c ) != bli_obj_dt( b ) ||
bli_obj_comp_prec( c ) != bli_obj_prec( c ) ) return BLIS_FAILURE;
bli_obj_comp_prec( c ) != bli_obj_prec( c ) ) {
AOCL_DTL_TRACE_EXIT_ERR(AOCL_DTL_LEVEL_TRACE_2, "SUP doesn't support Mixed datatypes.");
return BLIS_FAILURE;
}


const stor3_t stor_id = bli_obj_stor3_from_strides( c, a, b );

/*General stride is not yet supported in sup*/
if(BLIS_XXX==stor_id)
if(BLIS_XXX==stor_id) {
AOCL_DTL_TRACE_EXIT_ERR(AOCL_DTL_LEVEL_TRACE_2, "SUP doesn't support general stride.");
return BLIS_FAILURE;
}

const dim_t m = bli_obj_length( c );
const dim_t n = bli_obj_width( c );
Expand All @@ -74,6 +83,7 @@ err_t bli_gemmsup
|| ((transb == BLIS_CONJ_NO_TRANSPOSE) || (transb == BLIS_CONJ_TRANSPOSE))
)){
//printf(" gemmsup: Returning with for un-supported storage types and conjugate property in cgemmsup \n");
AOCL_DTL_TRACE_EXIT_ERR(AOCL_DTL_LEVEL_TRACE_2, "SUP - Unsuppported storage type for cgemm");
return BLIS_FAILURE;
}

Expand All @@ -84,6 +94,7 @@ err_t bli_gemmsup
|| ((transb == BLIS_CONJ_NO_TRANSPOSE) || (transb == BLIS_CONJ_TRANSPOSE))
)){
//printf(" gemmsup: Returning with for un-supported storage types and conjugate property in zgemmsup \n");
AOCL_DTL_TRACE_EXIT_ERR(AOCL_DTL_LEVEL_TRACE_2, "SUP - Unsuppported storage type for zgemm.");
return BLIS_FAILURE;
}

Expand All @@ -103,16 +114,20 @@ err_t bli_gemmsup

// Pass in m and n reversed, which simulates a transposition of the
// entire operation pursuant to the microkernel storage preference.
if ( !bli_cntx_l3_sup_thresh_is_met( dt, n, m, k, cntx ) )
if ( !bli_cntx_l3_sup_thresh_is_met( dt, n, m, k, cntx ) ) {
AOCL_DTL_TRACE_EXIT_ERR(AOCL_DTL_LEVEL_TRACE_2, "SUP - Traspostion results in unsupported storage for matrix C.");
return BLIS_FAILURE;
}
}
else // ukr_prefers_storage_of( c, ... )
{
const num_t dt = bli_obj_dt( c );
const dim_t k = bli_obj_width_after_trans( a );

if ( !bli_cntx_l3_sup_thresh_is_met( dt, m, n, k, cntx ) )
if ( !bli_cntx_l3_sup_thresh_is_met( dt, m, n, k, cntx ) ) {
AOCL_DTL_TRACE_EXIT_ERR(AOCL_DTL_LEVEL_TRACE_2, "SUP - Unsupported storage for matrix C.");
return BLIS_FAILURE;
}
}

// Initialize a local runtime with global settings if necessary. Note
Expand Down Expand Up @@ -158,6 +173,8 @@ printf( "dims: %d %d %d (threshs: %d %d %d)\n",
cntx,
rntm
);

AOCL_DTL_TRACE_EXIT(AOCL_DTL_LEVEL_TRACE_2);
}


9 changes: 8 additions & 1 deletion frame/3/bli_l3_sup_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ err_t bli_gemmsup_int
thrinfo_t* thread
)
{
AOCL_DTL_TRACE_ENTRY(AOCL_DTL_LEVEL_TRACE_4);
AOCL_DTL_LOG_GEMM_INPUTS(AOCL_DTL_LEVEL_TRACE_4, alpha, a, b, beta, c);

#if 0
//bli_gemmsup_ref_var2
//bli_gemmsup_ref_var1
Expand Down Expand Up @@ -80,7 +83,10 @@ err_t bli_gemmsup_int

// Don't use the small/unpacked implementation if one of the matrices
// uses general stride.
if ( stor_id == BLIS_XXX ) return BLIS_FAILURE;
if ( stor_id == BLIS_XXX ) {
AOCL_DTL_TRACE_EXIT_ERR(AOCL_DTL_LEVEL_TRACE_4, "SUP doesn't support general stide.");
return BLIS_FAILURE;
}

const bool_t is_rrr_rrc_rcr_crr = ( stor_id == BLIS_RRR ||
stor_id == BLIS_RRC ||
Expand Down Expand Up @@ -237,6 +243,7 @@ err_t bli_gemmsup_int
}

// Return success so that the caller knows that we computed the solution.
AOCL_DTL_TRACE_EXIT(AOCL_DTL_LEVEL_TRACE_4)
return BLIS_SUCCESS;
}

10 changes: 9 additions & 1 deletion frame/3/bli_l3_sup_packm_a.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ void PASTEMAC(ch,opname) \
thrinfo_t* restrict thread \
) \
{ \
/* Inspect whether we are going to be packing matrix A. */ \
AOCL_DTL_TRACE_ENTRY(AOCL_DTL_LEVEL_TRACE_5); \
/* Inspect whether we are going to be packing matrix A. */ \
if ( will_pack == FALSE ) \
{ \
} \
Expand Down Expand Up @@ -164,6 +165,7 @@ void PASTEMAC(ch,opname) \
} \
} \
} \
AOCL_DTL_TRACE_EXIT(AOCL_DTL_LEVEL_TRACE_5);\
}

INSERT_GENTFUNC_BASIC0( packm_sup_init_mem_a )
Expand All @@ -180,6 +182,7 @@ void PASTEMAC(ch,opname) \
thrinfo_t* restrict thread \
) \
{ \
AOCL_DTL_TRACE_ENTRY(AOCL_DTL_LEVEL_TRACE_5);\
/* Inspect whether we previously packed matrix A. */ \
if ( did_pack == FALSE ) \
{ \
Expand All @@ -202,6 +205,7 @@ void PASTEMAC(ch,opname) \
} \
} \
} \
AOCL_DTL_TRACE_EXIT(AOCL_DTL_LEVEL_TRACE_5);\
}

INSERT_GENTFUNC_BASIC0( packm_sup_finalize_mem_a )
Expand All @@ -228,6 +232,7 @@ void PASTEMAC(ch,opname) \
thrinfo_t* restrict thread \
) \
{ \
AOCL_DTL_TRACE_ENTRY(AOCL_DTL_LEVEL_TRACE_5);\
/* Inspect whether we are going to be packing matrix A. */ \
if ( will_pack == FALSE ) \
{ \
Expand Down Expand Up @@ -297,6 +302,7 @@ void PASTEMAC(ch,opname) \
broker. */ \
*p = bli_mem_buffer( mem ); \
} \
AOCL_DTL_TRACE_EXIT(AOCL_DTL_LEVEL_TRACE_5);\
}

INSERT_GENTFUNC_BASIC0( packm_sup_init_a )
Expand Down Expand Up @@ -335,6 +341,7 @@ void PASTEMAC(ch,opname) \
dim_t k_max; \
dim_t pd_p; \
\
AOCL_DTL_TRACE_ENTRY(AOCL_DTL_LEVEL_TRACE_5);\
/* Prepare the packing destination buffer. If packing is not requested,
this function will reduce to a no-op. */ \
PASTEMAC(ch,packm_sup_init_mem_a) \
Expand Down Expand Up @@ -424,6 +431,7 @@ void PASTEMAC(ch,opname) \
/* Barrier so that packing is done before computation. */ \
bli_thread_barrier( thread ); \
} \
AOCL_DTL_TRACE_EXIT(AOCL_DTL_LEVEL_TRACE_5);\
}

INSERT_GENTFUNC_BASIC0( packm_sup_a )
Expand Down
8 changes: 8 additions & 0 deletions frame/3/bli_l3_sup_packm_b.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void PASTEMAC(ch,opname) \
thrinfo_t* restrict thread \
) \
{ \
AOCL_DTL_TRACE_ENTRY(AOCL_DTL_LEVEL_TRACE_5);\
/* Inspect whether we are going to be packing matrix B. */ \
if ( will_pack == FALSE ) \
{ \
Expand Down Expand Up @@ -164,6 +165,7 @@ void PASTEMAC(ch,opname) \
} \
} \
} \
AOCL_DTL_TRACE_EXIT(AOCL_DTL_LEVEL_TRACE_5);\
}

INSERT_GENTFUNC_BASIC0( packm_sup_init_mem_b )
Expand All @@ -180,6 +182,7 @@ void PASTEMAC(ch,opname) \
thrinfo_t* restrict thread \
) \
{ \
AOCL_DTL_TRACE_ENTRY(AOCL_DTL_LEVEL_TRACE_5); \
/* Inspect whether we previously packed matrix A. */ \
if ( did_pack == FALSE ) \
{ \
Expand All @@ -202,6 +205,7 @@ void PASTEMAC(ch,opname) \
} \
} \
} \
AOCL_DTL_TRACE_EXIT(AOCL_DTL_LEVEL_TRACE_5); \
}

INSERT_GENTFUNC_BASIC0( packm_sup_finalize_mem_b )
Expand All @@ -228,6 +232,7 @@ void PASTEMAC(ch,opname) \
thrinfo_t* restrict thread \
) \
{ \
AOCL_DTL_TRACE_ENTRY(AOCL_DTL_LEVEL_TRACE_5);\
/* Inspect whether we are going to be packing matrix B. */ \
if ( will_pack == FALSE ) \
{ \
Expand Down Expand Up @@ -297,6 +302,7 @@ void PASTEMAC(ch,opname) \
broker. */ \
*p = bli_mem_buffer( mem ); \
} \
AOCL_DTL_TRACE_EXIT(AOCL_DTL_LEVEL_TRACE_5);\
}

INSERT_GENTFUNC_BASIC0( packm_sup_init_b )
Expand Down Expand Up @@ -330,6 +336,7 @@ void PASTEMAC(ch,opname) \
thrinfo_t* restrict thread \
) \
{ \
AOCL_DTL_TRACE_ENTRY(AOCL_DTL_LEVEL_TRACE_5); \
pack_t schema; \
dim_t k_max; \
dim_t n_max; \
Expand Down Expand Up @@ -424,6 +431,7 @@ void PASTEMAC(ch,opname) \
/* Barrier so that packing is done before computation. */ \
bli_thread_barrier( thread ); \
} \
AOCL_DTL_TRACE_EXIT(AOCL_DTL_LEVEL_TRACE_5); \
}

INSERT_GENTFUNC_BASIC0( packm_sup_b )
Expand Down
4 changes: 4 additions & 0 deletions frame/3/bli_l3_sup_var1n2m.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ void bli_gemmsup_ref_var1n
thrinfo_t* thread
)
{
AOCL_DTL_TRACE_ENTRY(AOCL_DTL_LEVEL_TRACE_5);
#if 0
obj_t at, bt;

Expand Down Expand Up @@ -227,6 +228,7 @@ void bli_gemmsup_ref_var1n
thread
);
}
AOCL_DTL_TRACE_EXIT(AOCL_DTL_LEVEL_TRACE_5);
}


Expand Down Expand Up @@ -724,6 +726,7 @@ void bli_gemmsup_ref_var2m
thrinfo_t* thread
)
{
AOCL_DTL_TRACE_ENTRY(AOCL_DTL_LEVEL_TRACE_5);
#if 0
obj_t at, bt;

Expand Down Expand Up @@ -875,6 +878,7 @@ void bli_gemmsup_ref_var2m
thread
);
}
AOCL_DTL_TRACE_EXIT(AOCL_DTL_LEVEL_TRACE_5);
}


Expand Down
1 change: 1 addition & 0 deletions frame/3/gemm/bli_gemm_front.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ void bli_gemm_front
)
{
AOCL_DTL_TRACE_ENTRY(AOCL_DTL_LEVEL_TRACE_3);
AOCL_DTL_LOG_GEMM_INPUTS(AOCL_DTL_LEVEL_TRACE_3, alpha, a, b, beta, c);
bli_init_once();

obj_t a_local;
Expand Down
Loading

0 comments on commit 80b3127

Please sign in to comment.