4.7.9. Sample Application 1 - 5.2 English - 57404

AOCL User Guide (57404)

Document ID
57404
Release Date
2025-12-29
Version
5.2 English

The following sample application is to use the LPGEMM APIs without post-ops:

/*
$gcc test_lpgemm.c -o ./test_lpgemm.x -I/aocl-blis_install_directory/include/amdzen/
-L/aocl-blis_install_directory/lib/amdzen/ -lblis-mt -lm

Note: Export blis library path to LD_LIBRARY_PATH before running the
executable ./test_lpgem.x
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "blis.h"

// Example program to demonstrate LPGEMM API usage.
// aocl_gemm_f32f32f32of32 (A:float, B:float, C:float) used here.
int main()
{
    dim_t m = 1024;
    dim_t n = 1024;
    dim_t k = 1024;

    // Leading dimensions for row major matrices.
    dim_t lda = k;
    dim_t ldb = n;
    dim_t ldc = n;

    err_t err = BLIS_SUCCESS;
    float *a = (float *)bli_malloc_user(sizeof(float) * m * k, &err);
    if (err != BLIS_SUCCESS) { goto bailout; }

    float *b = (float *)bli_malloc_user(sizeof(float) * n * k, &err);
    if (err != BLIS_SUCCESS) { goto bailout; }

    float *c = (float *)bli_malloc_user(sizeof(float) * m * n, &err);
    if (err != BLIS_SUCCESS) { goto bailout; }

    // Functions to fill the matrices with data can be added here.
    float alpha = 2.2;
    float beta = 9.15;
    char storage = 'r'; // Row major. Use 'c' for column major.
    char transa = 'n'; // No transpose. Transpose not supported for all API's.
    char transb = 'n';
    char reordera = 'n';
    char reorderb = 'n';

    aocl_gemm_f32f32f32of32(storage, transa, transb,
                          m, n, k,
                          alpha,
                          a, lda, reordera,
                          b, ldb, reorderb,
                          beta,
                          c, ldc,
                          NULL);

bailout:

    if (a != NULL)
    {
        bli_free_user(a);
    }
    if (b != NULL)
    {
        bli_free_user(b);
    }
    if (c != NULL)
    {
        bli_free_user(c);
    }

    return 0;
}