Initialize mem_t structures safely and handle NULL communicator in threading

- Explicitly initialize all fields of mem_t structures in bli_znormfv_unb_var1 and bli_dnormfv_unb_var1 to prevent undefined behavior when memory is not allocated.

- Add a NULL check after bli_thread_broadcast() in bli_thrinfo_sup_create_for_cntl to ensure that the communicator is valid, and call bli_abort() if broadcast fails.
This commit is contained in:
S, Hari Govind
2025-09-18 18:44:33 +05:30
committed by GitHub
parent e14ffbea8b
commit 748ba373e1
2 changed files with 50 additions and 4 deletions

View File

@@ -192,7 +192,7 @@ thrinfo_t* bli_thrinfo_sup_create_for_cntl
// communicator is divisible by the number of new sub-groups.
if ( parent_nt_in % parent_n_way != 0 )
{
printf( "Assertion failed: parent_nt_in <mod> parent_n_way != 0\n" );
bli_print_msg( "Assertion failed: parent_nt_in <mod> parent_n_way != 0.", __FILE__, __LINE__ );
bli_abort();
}
@@ -231,6 +231,13 @@ thrinfo_t* bli_thrinfo_sup_create_for_cntl
// communicator.
new_comms = bli_thread_broadcast( thread_par, new_comms );
// Check if broadcast failed (can happen when parent communicator is NULL)
if ( new_comms == NULL )
{
bli_print_msg( "Broadcast failed if parent communicator is NULL.", __FILE__, __LINE__ );
bli_abort();
}
// Chiefs in the child communicator allocate the communicator
// object and store it in the array element corresponding to the
// parent's work id.

View File

@@ -573,8 +573,21 @@ void bli_znormfv_unb_var1
an allocated memory if created or a NULL .
*/
mem_t mem_buf_X = { 0 };
mem_t mem_buf_X;
inc_t incx_buf = incx;
/*
Initialize mem pool buffer to NULL and size to 0
"buf" and "size" fields are assigned once memory
is allocated from the pool in bli_pba_acquire_m().
This will ensure bli_mem_is_alloc() will be passed on
an allocated memory if created or a NULL .
*/
mem_buf_X.pblk.buf = NULL;
mem_buf_X.pblk.block_size = 0;
mem_buf_X.buf_type = 0;
mem_buf_X.size = 0;
mem_buf_X.pool = NULL;
// Packing for non-unit strided vector x.
// In order to get the buffer from pool via rntm access to memory broker
@@ -655,7 +668,20 @@ void bli_znormfv_unb_var1
the local results will finally be reduced as per the mandate.
*/
mem_t mem_buf_norm = { 0 };
mem_t mem_buf_norm;
/*
Initialize mem pool buffer to NULL and size to 0
"buf" and "size" fields are assigned once memory
is allocated from the pool in bli_pba_acquire_m().
This will ensure bli_mem_is_alloc() will be passed on
an allocated memory if created or a NULL .
*/
mem_buf_norm.pblk.buf = NULL;
mem_buf_norm.pblk.block_size = 0;
mem_buf_norm.buf_type = 0;
mem_buf_norm.size = 0;
mem_buf_norm.pool = NULL;
double *norm_per_thread = NULL;
@@ -1203,9 +1229,22 @@ void bli_dnormfv_unb_var1
an allocated memory if created or a NULL .
*/
mem_t mem_buf_X = { 0 };
mem_t mem_buf_X;
inc_t incx_buf = incx;
/*
Initialize mem pool buffer to NULL and size to 0
"buf" and "size" fields are assigned once memory
is allocated from the pool in bli_pba_acquire_m().
This will ensure bli_mem_is_alloc() will be passed on
an allocated memory if created or a NULL .
*/
mem_buf_X.pblk.buf = NULL;
mem_buf_X.pblk.block_size = 0;
mem_buf_X.buf_type = 0;
mem_buf_X.size = 0;
mem_buf_X.pool = NULL;
// Packing for non-unit strided vector x.
// In order to get the buffer from pool via rntm access to memory broker
// is needed. Following are initializations for rntm.