/* xe2_couple.cpp -- the linear-MTP coupling ops (`--draft-coupling on`) on the card. * * `mtp_couple_propose` and `mtp_couple_verify` (docs/OPS.md) through the spechub plugin's own row * helpers (plugin/spechub/spechub.h over abi/rad_spechub.h) and argument readers, one work-item a * row: the rows are a step's sampled positions (at most the draft window), and the sampler's * candidate plane holds ~top_k live entries, so the serial walks are short. The arithmetic is the * host reference's, in its order, in FP64 (libxe2 builds with -ffp-contract=off). */ #include "xe2_common.h" #include "xe2_ops.h" #include "../plugin/spechub/spechub.cpp" namespace xe2 { int mtp_couple_propose(const RadArgs* a, RadStream st) { RadMtpCoupleProposeCall c{}; if (int rc = rad_mtp_couple_propose_args(a, &c); rc != RAD_OK) return rc; if (c.M <= 0) return RAD_OK; sycl::queue* q = queue_of(st); if (!q) return RAD_E_DEVICE; return submit([&] { q->parallel_for(sycl::range<1>{(size_t)c.M}, [=](sycl::id<1> i) { rad_mtp_couple_propose_row(c, (int64_t)i[0]); }); }); } int mtp_couple_verify(const RadArgs* a, RadStream st) { RadMtpCoupleVerifyCall c{}; if (int rc = rad_mtp_couple_verify_args(a, &c); rc != RAD_OK) return rc; if (c.M <= 0) return RAD_OK; sycl::queue* q = queue_of(st); if (!q) return RAD_E_DEVICE; if (c.n_cand > 4096) return submit([&] { q->parallel_for(sycl::range<1>{(size_t)c.M}, [=](sycl::id<1> i) { rad_mtp_couple_verify_row(c, (int64_t)i[0]); }); }); /* A row's candidates (n_cand 1024, mostly pads behind top_k) staged in local memory by a * work-group first: the helper's walk over them from global memory was a dependent load a * step. The helper then reads the staged row (its row pitch 0), arithmetic unchanged. */ constexpr size_t wg = 256; const int64_t n = c.n_cand; return submit([&] { q->submit([&](sycl::handler& h) { sycl::local_accessor sid(sycl::range<1>((size_t)n), h); sycl::local_accessor sv(sycl::range<1>((size_t)n), h); h.parallel_for(sycl::nd_range<1>{(size_t)c.M * wg, wg}, [=](sycl::nd_item<1> it) { const int64_t row = (int64_t)it.get_group(0); const int64_t lane = (int64_t)it.get_local_id(0); for (int64_t i = lane; i < n; i += (int64_t)wg) { sid[i] = c.idx[row * c.ld[0] + i]; sv[i] = c.val[row * c.ld[1] + i]; } sycl::group_barrier(it.get_group()); if (lane != 0) return; RadMtpCoupleVerifyCall cc = c; cc.idx = sid.template get_multi_ptr().get(); cc.val = sv.template get_multi_ptr().get(); cc.ld[0] = cc.ld[1] = 0; rad_mtp_couple_verify_row(cc, row); }); }); }); } } // namespace xe2