A question regarding an iterative use of gemm

7 views
Skip to first unread message

Ilkhom Abdurakhmanov

unread,
Nov 24, 2025, 9:48:51 PM11/24/25
to SLATE User
Hello we are new to SLATE,

we are considering using GEMM routine from SLATE library iteratively. At each iteration we need to perform matrix-matrix multiplication. 
First iteration: C_1=A x B_1, A=C_1. 
Second iteration: C_2=A x B_2. A=C_2
...
N'th iteration:  C_N=A x B_N
Do we need to retile matrix elements of matrix A in certain way at each iteration for SLATE's input? If we need to do that at every iteration wouldn't that kill the performance on the GPU?

Kind regards,
Ilkhom  

Mark Gates

unread,
Nov 24, 2025, 10:58:12 PM11/24/25
to Ilkhom Abdurakhmanov, SLATE User
Hi Ilkhom,

There's no need to retile A. In fact, I'm not exactly sure what you mean by "retile".

Are you using square tiles for A, B, and C (aside from rectangular tiles on the right and bottom edges)? It's possible to use rectangular tiles, but that complicates lots of things — the tiles of A, B, and C have to be conformant in order to multiply them. The GPU implementation is more complicated and less efficient if they aren't square. 

Be aware that SLATE does shallow copies, so after this:

    A = C;

A and C refer to exactly the same underlying object. If you modify C, then A reflects the same changes. This will not do what you want:

    for (int i = 0; i < N; ++i) {
        slate::multiply( A, B, C );
        A = C;  // Not what you want — A and C now refer to the same object.
    }

On the 2nd and subsequent iterations, it would effectively be doing:

    slate::multiply( C, B, C );

Instead, you may want to swap their contents (which just swaps pointers and metadata, so it's cheap):

    for (int i = 0; i < N; ++i) {
        slate::multiply( A, B, C );
        swap( A, C );
    }

I'm inferring that A and C are the same size, m-by-n, and B is n-by-n. Possibly m = n, so they're all square, but that's not required by your statement.

Mark

Interim Director, Innovative Computing Laboratory (ICL)
Research Assistant Professor, University of Tennessee, Knoxville

Reply all
Reply to author
Forward
0 new messages