// book_update.cu — MBP-10 snapshot apply.
//
// Replaces the per-block book state with the broadcast snapshot. The
// full top-10 image overwrites the previous state (MBP-10 semantics).
// One block per backtest; thread tid handles one of 10 levels per side
// (10 threads used out of 32 in the warp; remainder idle).
//
// Per feedback_no_atomicadd.md: no atomics — single-writer per level.
// Per spec §2: same snapshot broadcast to every backtest in v1.

#include "lob_state.cuh"

// Books are laid out [n_backtests, 4 fields × 10 levels].
// Field order: bid_px, bid_sz, ask_px, ask_sz (one contiguous Book per backtest).
extern "C" __global__ void book_update_apply_snapshot(
    const float* __restrict__ bid_px_in,   // [10] — broadcast
    const float* __restrict__ bid_sz_in,   // [10]
    const float* __restrict__ ask_px_in,   // [10]
    const float* __restrict__ ask_sz_in,   // [10]
    Book*        __restrict__ books_out,   // [n_backtests]
    int n_backtests
) {
    int b   = blockIdx.x;
    int tid = threadIdx.x;
    if (b >= n_backtests || tid >= 10) return;

    Book& bk = books_out[b];
    bk.bid_px[tid] = bid_px_in[tid];
    bk.bid_sz[tid] = bid_sz_in[tid];
    bk.ask_px[tid] = ask_px_in[tid];
    bk.ask_sz[tid] = ask_sz_in[tid];
}
