MSE Loss Templates
mse.h implements the first trainable loss endpoint. It exposes two functions:
nnet::mse<CONFIG_T>(prediction, ground_truth, loss, loss_grad);
nnet::half_mse<CONFIG_T>(prediction, ground_truth, loss, loss_grad);
Both functions use the same mse_core implementation with compile-time shifts. The template intentionally avoids denominator division because the first supported scalings are powers of two.
Scalingβ
| Function | Scalar loss | Gradient seed |
|---|---|---|
mse | sum((y_hat - y)^2) | (y_hat - y) << 1 |
half_mse | sum((y_hat - y)^2) >> 1 | y_hat - y |
For the first hardware/software trace comparison, half_mse is the cleaner default because its output gradient is exactly the prediction error.
Config Contractβ
The generated config struct must provide:
n_out,data_in_t,ground_truth_t,loss_t,grad_out_t.
When trainable tracing is enabled, the writer must also emit trace names for prediction, ground truth, loss, and loss gradient.