// File: kernel.cpp
// Reference-scalar gemm w8a8ch (int8 activations + weights, per-output-channel dequant, no bias).
// 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 int8_t* A, float* output, const int8_t* B,
                            const float* weight_scales, int M)
{
    for (int m = 0; m < M; ++m) {
        const int8_t* a_row   = A + (long)m * K;
        float*        out_row = output + (long)m * N;
        for (int n = 0; n < N; ++n) {
            const int8_t* b_row = B + (long)n * K;
            int64_t acc = 0;
            for (int k = 0; k < K; ++k) {
                acc += (int64_t)a_row[k] * (int64_t)b_row[k];
            }
            double scale = (double)input_scale * (double)weight_scales[n];
            out_row[n] = (float)((double)acc * scale);
        }
    }
}