// File: kernel.cpp
// Reference-scalar gemm (fc-style: C = A @ B^T).
// LLM target: replace this file with an optimised inner_gemm.
// All per-definition constants live in gemm_def:: (gemm.h).
#include "gemm.h"
using namespace gemm_def;

extern "C" void inner_gemm(const float* A, float* output, const float* B, int M)
{
    for (int m = 0; m < M; ++m) {
        const float* a_row = A + (long)m * K;
        float*       out_row = output + (long)m * N;
        for (int n = 0; n < N; ++n) {
            const float* b_row = B + (long)n * K;
            float sum = 0.0f;
            for (int k = 0; k < K; ++k) {
                sum += a_row[k] * b_row[k];
            }
            out_row[n] = sum;
        }
    }
}