Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions config/rv64iv/bli_cntx_init_rv64iv.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
libraries.

Copyright (C) 2014, The University of Texas at Austin
Copyright (C) 2026, Yicheng Kang

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
Expand Down Expand Up @@ -51,21 +52,30 @@ void bli_cntx_init_rv64iv( cntx_t* cntx )

if ( v >= 4 )
{
const uint32_t mr_s = 4 * v;
// For VLEN = 256 (v == 8), sgemm uses the 2vx12 kernel: MR = 2*v,
// NR = 12 (12 FMAs per vector load of A). It is limited to VLEN 256,
// where it was measured: at VLEN >= 1024 its MR*NR tile would exceed
// the default BLIS_STACK_BUF_MAX_SIZE. Everything else keeps 4vx4.
const bool s2vx12 = v == 8;
const uint32_t mr_s = s2vx12 ? 2 * v : 4 * v;
const uint32_t nr_s = s2vx12 ? 12 : 4;
const uint32_t mc_s = s2vx12 ? bli_max( 1, 320 / mr_s ) * mr_s : 20 * mr_s;
const uint32_t kc_s = s2vx12 ? 512 : 640;
const uint32_t mr_d = 2 * v;
const uint32_t mr_c = 2 * v;
const uint32_t mr_z = v;

// TODO: Register different kernels based on the value
// of v to avoid MC becoming too big. (e.g. 2vx8)
// of v to avoid MC becoming too big for the other datatypes.

// Update the context with optimized native gemm micro-kernels.
bli_cntx_set_ukrs
(
cntx,

// level-3
BLIS_GEMM_UKR, BLIS_FLOAT, bli_sgemm_rviv_4vx4,
BLIS_GEMM_UKR, BLIS_FLOAT, s2vx12 ? bli_sgemm_rviv_2vx12
: bli_sgemm_rviv_4vx4,
BLIS_GEMM_UKR, BLIS_DOUBLE, bli_dgemm_rviv_4vx4,
BLIS_GEMM_UKR, BLIS_SCOMPLEX, bli_cgemm_rviv_4vx4,
BLIS_GEMM_UKR, BLIS_DCOMPLEX, bli_zgemm_rviv_4vx4,
Expand All @@ -90,9 +100,9 @@ void bli_cntx_init_rv64iv( cntx_t* cntx )
// Initialize level-3 blocksize objects with architecture-specific values.
// s d c z
bli_blksz_init_easy( &blkszs[ BLIS_MR ], mr_s, mr_d, mr_c, mr_z );
bli_blksz_init_easy( &blkszs[ BLIS_NR ], 4, 4, 4, 4 );
bli_blksz_init_easy( &blkszs[ BLIS_MC ], 20*mr_s, 20*mr_d, 60*mr_c, 30*mr_z );
bli_blksz_init_easy( &blkszs[ BLIS_KC ], 640, 320, 320, 160 );
bli_blksz_init_easy( &blkszs[ BLIS_NR ], nr_s, 4, 4, 4 );
bli_blksz_init_easy( &blkszs[ BLIS_MC ], mc_s, 20*mr_d, 60*mr_c, 30*mr_z );
bli_blksz_init_easy( &blkszs[ BLIS_KC ], kc_s, 320, 320, 160 );
bli_blksz_init_easy( &blkszs[ BLIS_NC ], 3072, 3072, 3072, 3072 );

// Update the context with the current architecture's register and cache
Expand Down
80 changes: 80 additions & 0 deletions kernels/rviv/3/bli_sgemm_rviv_2vx12.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*

BLIS
An object-based framework for developing high-performance BLAS-like
libraries.

Copyright (C) 2026, Yicheng Kang

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 "bli_rviv_utils.h"

void bli_sgemm_rviv_asm_2vx12
(
intptr_t k,
const void* alpha,
const void* a,
const void* b,
const void* beta,
void* c,
intptr_t cs_c
);

void bli_sgemm_rviv_2vx12
(
dim_t m,
dim_t n,
dim_t k,
const void* alpha,
const void* a,
const void* b,
const void* beta,
void* c, inc_t rs_c, inc_t cs_c,
const auxinfo_t* data,
const cntx_t* cntx
)
{
// The assembly kernel takes native machine-sized integer arguments.
bli_static_assert( sizeof(dim_t) <= sizeof(intptr_t) &&
sizeof(inc_t) <= sizeof(intptr_t) );

// mr = 2 * (VLEN / 32) is fixed when the context is initialized; nr = 12.
const inc_t mr = bli_cntx_get_blksz_def_dt( BLIS_FLOAT, BLIS_MR, cntx );
const inc_t nr = 12;

GEMM_UKR_SETUP_CT( s, mr, nr, false );

// The kernel assumes rs_c == 1, and the context should not deviate from it.
assert( rs_c == 1 );

bli_sgemm_rviv_asm_2vx12( k, alpha, a, b, beta, c, cs_c * sizeof(float) );

GEMM_UKR_FLUSH_CT( s );
}
Loading