Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gemmt fills output matrix in wrong corner for upper row-major #4905

Closed
david-cortes opened this issue Sep 26, 2024 · 2 comments · Fixed by #4929
Closed

gemmt fills output matrix in wrong corner for upper row-major #4905

david-cortes opened this issue Sep 26, 2024 · 2 comments · Fixed by #4929

Comments

@david-cortes
Copy link

In function cblas_?gemmt, if I pass CblasRowMajor + CblasUplo to MKL's function with that name, the output ends up being filled in the upper corner (in row-major order), but in OpenBLAS's version of cblas_?gemmt, the output ends up being filled in the lower corner instead.

Example code:

#include <iostream>
#include "cblas.h"

extern "C" void cblas_dgemmt(OPENBLAS_CONST enum CBLAS_ORDER Order, OPENBLAS_CONST enum CBLAS_UPLO Uplo, OPENBLAS_CONST enum CBLAS_TRANSPOSE TransA, OPENBLAS_CONST enum CBLAS_TRANSPOSE TransB, OPENBLAS_CONST blasint M, OPENBLAS_CONST blasint K,
         OPENBLAS_CONST double alpha, OPENBLAS_CONST double *A, OPENBLAS_CONST blasint lda, OPENBLAS_CONST double *B, OPENBLAS_CONST blasint ldb, OPENBLAS_CONST double beta, double *C, OPENBLAS_CONST blasint ldc);


int main()
{
    const double A[] = {
        2., 3.,
        0., 4.
    };
    double B[4] = {0.};

    cblas_dgemmt(
        CblasRowMajor, CblasUpper, CblasTrans, CblasNoTrans,
        2, 2,
        1., A, 2,
        A, 2,
        0., B, 2
    );

    std::cout << "B:" << std::endl;
    std::cout << "[ " << B[0] << ", " << B[1] << "]" << std::endl;
    std::cout << "[ " << B[2] << ", " << B[3] << "]" << std::endl;

    return 0;
}

If I run the example with OpenBLAS, the output is:

B:
[ 4, 0]
[ 6, 25]

Whereas with MKL, the output is:

B:
[ 4, 6]
[ 0, 25]

Version: OpenBLAS 0.3.28, OpenMP variant, installed from source.

@XiWeiGu
Copy link
Contributor

XiWeiGu commented Oct 8, 2024

Yes, I encountered the same issue. The reason might be here:

OpenBLAS/interface/gemmt.c

Lines 314 to 323 in 73c1882

if (order == CblasRowMajor) {
a = (void *)B;
b = (void *)A;
lda = LDB;
ldb = LDA;
if (Uplo == CblasUpper) uplo = 0;
if (Uplo == CblasLower) uplo = 1;

Make the following revisions to the code on lines 322 and 323 (opposite to CblasColMajor instead of consistent):

 	if (Uplo == CblasUpper) uplo = 1; 
 	if (Uplo == CblasLower) uplo = 0; 

@martin-frbg
Copy link
Collaborator

Indeed this is a copy/paste blunder, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants