HPL_dgemm(3)
π HPL_dgemm β the HPL Library Functions girlies' guide to matrix-matrix slay π
okay so bestie, you're in the HPL Library Functions section of the manual and this one is a banger. it's HPL_dgemm(3), it does matrix-matrix math, and it absolutely ate. let's get into it π«Ά
β¨ NAME β¨
HPL_dgemm β literally just this: C := alpha * op(A) * op(B) + beta * C. that's the whole vibe. no cap.
πΈ SYNOPSIS πΈ
#include "hpl.h"
void HPL_dgemm( const enum HPL_ORDER ORDER, const enum HPL_TRANS TRANSA,
const enum HPL_TRANS TRANSB, const int M, const int N, const int K,
const double ALPHA, const double * A, const int LDA, const double * B,
const int LDB, const double BETA, double * C, const int LDC );
look at her. eleven arguments. main character energy fr fr π
π¦ DESCRIPTION π¦
HPL_dgemm performs one of the matrix-matrix operations
C := alpha * op( A ) * op( B ) + beta * C
where op( X ) is one of
op( X ) = X or op( X ) = X^T.
Alpha and beta are scalars, and A, B and C are matrices, with op(A) an m by k matrix, op(B) a k by n matrix and C an m by n matrix.
so like. you're scaling, you're multiplying, you're adding. it's giving linear algebra but make it fashion π
π ARGUMENTS π
the whole cast, one by one
ORDER(local input)const enum HPL_ORDERβ On entry,ORDERspecifies the storage format of the operands as follows:ORDER = HplRowMajor,ORDER = HplColumnMajor.
TRANSA(local input)const enum HPL_TRANSβ On entry,TRANSAspecifies the form ofop(A)to be used in the matrix-matrix operation follows:TRANSA==HplNoTrans:op( A ) = A,TRANSA==HplTrans:op( A ) = A^T,TRANSA==HplConjTrans:op( A ) = A^T.
TRANSB(local input)const enum HPL_TRANSβ On entry,TRANSBspecifies the form ofop(B)to be used in the matrix-matrix operation follows:TRANSB==HplNoTrans:op( B ) = B,TRANSB==HplTrans:op( B ) = B^T,TRANSB==HplConjTrans:op( B ) = B^T.
M(local input)const intβ On entry,Mspecifies the number of rows of the matrixop(A)and of the matrixC.Mmust be at least zero. (zero is allowed bestie, we don't judge β¨)N(local input)const intβ On entry,Nspecifies the number of columns of the matrixop(B)and the number of columns of the matrixC.Nmust be at least zero.K(local input)const intβ On entry,Kspecifies the number of columns of the matrixop(A)and the number of rows of the matrixop(B).Kmust be be at least zero. (yes, the original says "be be" β iconic typo, we're keeping it, character for character π)ALPHA(local input)const doubleβ On entry,ALPHAspecifies the scalar alpha. WhenALPHAis supplied as zero then the elements of the matricesAandBneed not be set on input. so like, if alpha is 0 you literally don't have to fill in A and B. free real estate πA(local input)const double *β On entry,Ais an array of dimension(LDA,ka), where ka is k whenTRANSA==HplNoTrans, and is m otherwise. Before entry withTRANSA==HplNoTrans, the leading m by k part of the arrayAmust contain the matrixA, otherwise the leading k by m part of the arrayAmust contain the matrixA.LDA(local input)const intβ On entry,LDAspecifies the first dimension ofAas declared in the calling (sub) program. WhenTRANSA==HplNoTransthenLDAmust be at leastmax(1,m), otherwiseLDAmust be at leastmax(1,k).B(local input)const double *β On entry,Bis an array of dimension(LDB,kb), where kb is n whenTRANSB==HplNoTrans, and is k otherwise. Before entry withTRANSB==HplNoTrans, the leading k by n part of the arrayBmust contain the matrixB, otherwise the leading n by k part of the arrayBmust contain the matrixB.LDB(local input)const intβ On entry,LDBspecifies the first dimension ofBas declared in the calling (sub) program. WhenTRANSB==HplNoTransthenLDBmust be at leastmax(1,k), otherwiseLDBmust be at leastmax(1,n).BETA(local input)const doubleβ On entry,BETAspecifies the scalar beta. WhenBETAis supplied as zero then the elements of the matrixCneed not be set on input. same deal as ALPHA, zero beta means C can be a mystery, no one's checking πC(local input/output)double *β On entry,Cis an array of dimension(LDC,n). Before entry, the leading m by n part of the arrayCmust contain the matrixC, except when beta is zero, in which caseCneed not be set on entry. On exit, the arrayCis overwritten by the m by n matrix( alpha*op( A )*op( B ) + beta*C ). she's input AND output. multitalented. we love a double threat πLDC(local input)const intβ On entry,LDCspecifies the first dimension ofCas declared in the calling (sub) program.LDCmust be at leastmax(1,m).
π EXAMPLE π
here's the moment you've been waiting for. actual working code, copy it, run it, slay it:
#include "hpl.h"
int main(int argc, char *argv[])
{
double a[2*2], b[2*2], c[2*2];
a[0] = 1.0; a[1] = 2.0; a[2] = 3.0; a[3] = 3.0;
b[0] = 2.0; b[1] = 1.0; b[2] = 1.0; b[3] = 2.0;
c[0] = 4.0; c[1] = 3.0; c[2] = 2.0; c[3] = 1.0;
HPL_dgemm( HplColumnMajor, HplNoTrans, HplNoTrans,
2, 2, 2, 2.0, a, 2, b, 2, -1.0, c, 2 );
printf(" [%f,%f]\n", c[0], c[2]);
printf("c=[%f,%f]\n", c[1], c[3]);
exit(0); return(0);
}
two-by-two everything, alpha is 2.0, beta is -1.0, and she prints her little results. adorable. obsessed. π
π SEE ALSO π
HPL_dtrsm (3).
that's the sibling, go say hi.
lowkey important reminder bestie: the arguments marked local input are the ones you hand over, and C is the one that gets rewritten on exit. no surprises, just math. β¨
and that's the whole page, gorgeous. this was HPL 2.2, dated February 24, 2016 β old but she still serves π go forth and multiply (matrices) π¦β¨
π¦ where this page comes from
- fedora 43: hpl-doc 2.2-22.fc43 Β· LicenseRef-Callaway-BSD-with-advertising
- fedora 44: hpl-doc 2.2-23.fc44 Β· LicenseRef-Callaway-BSD-with-advertising
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms