// File: kernel.cpp
// Reference-scalar global average pooling.
// LLM target: replace this file with an optimised inner_pooling.
#include "pooling.h"

extern "C" void inner_pooling(const float* input, float* output,
                               int N, int C, int H, int W)
{
    for (int n = 0; n < N; ++n) {
        for (int c = 0; c < C; ++c) {
            const float* in_c = input + ((long)n * C + c) * H * W;
            float sum = 0.0f;
            for (int i = 0; i < H * W; ++i) {
                sum += in_c[i];
            }
            output[(long)n * C + c] = sum / (float)(H * W);
        }
    }
}