Download code/tt_rdt2/tt/kernels/pxf_mlp_reader.cpp from changh95/rdt2-base-p150: direct link, hf CLI and curl.
- Browser
- Download file 2.51 kB
-
https://huggingface.co/changh95/rdt2-base-p150/resolve/main/code/tt_rdt2/tt/kernels/pxf_mlp_reader.cpp
- Command line
-
hf download hf://changh95/rdt2-base-p150/code/tt_rdt2/tt/kernels/pxf_mlp_reader.cpp
-
curl -L -o pxf_mlp_reader.cpp https://huggingface.co/changh95/rdt2-base-p150/resolve/main/code/tt_rdt2/tt/kernels/pxf_mlp_reader.cpp
2.51 kB
| // SPDX-License-Identifier: Apache-2.0 | |
| // | |
| // RDT2-FM fused PREFIX op "swiglu_mm" (round 6 / prefix), weight reader (NCRISC, NoC 0): per K-block, the core's | |
| // 2 nc in1 tiles of each of the KBW K rows of W2 (gate / up interleaved per output column) -> MM_CB_IN1 laid out | |
| // [k][w] with row stride WMAX (the same block size on every core). W2 in tile pages (2 KB reads) or in row pages | |
| // (``pack_gu_rows``: one DRAM page per (K row, core), one read per K row). | |
| using namespace pxf; | |
| namespace { | |
| constexpr uint32_t KT = get_compile_time_arg_val(MM_CT_KT); | |
| constexpr uint32_t KBW = get_compile_time_arg_val(MM_CT_KBW); | |
| constexpr uint32_t NF = get_compile_time_arg_val(MM_CT_NF); | |
| constexpr uint32_t WMAX = get_compile_time_arg_val(MM_CT_WMAX); | |
| constexpr uint32_t NC = get_compile_time_arg_val(MM_CT_NC); | |
| constexpr uint32_t RP = get_compile_time_arg_val(MM_CT_RP); | |
| constexpr uint32_t NKB = KT / KBW; | |
| constexpr uint32_t NW = 2 * NF; // W2 column tiles | |
| constexpr auto acc_h = TensorAccessorArgs<MM_CT_ACC0>(); | |
| constexpr auto acc_w = TensorAccessorArgs<acc_h.next_compile_time_args_offset()>(); | |
| } // namespace | |
| void kernel_main() { | |
| const MmShare sh = mm_share(get_absolute_logical_x(), get_absolute_logical_y(), get_compile_time_arg_val(MM_CT_GX), | |
| get_compile_time_arg_val(MM_CT_NC), NF); | |
| const uint32_t w = 2 * sh.nc, col0 = 2 * sh.c0; | |
| const auto wa = TensorAccessor(acc_w, get_common_arg_val<uint32_t>(MM_C_W), RP ? WMAX * T16 : T16); | |
| for (uint32_t kb = 0; kb < NKB; ++kb) { | |
| cb_reserve_back(MM_CB_IN1, KBW * WMAX); | |
| const uint32_t l1 = get_write_ptr(MM_CB_IN1); | |
| { | |
| PXF_ZONE("MM_W"); | |
| for (uint32_t kk = 0; kk < KBW; ++kk) { | |
| const uint32_t dst = l1 + kk * WMAX * T16; | |
| if constexpr (RP) { // one read: the core's w tiles of this K row are one page | |
| noc_async_read(wa.get_noc_addr((kb * KBW + kk) * NC + sh.k), dst, w * T16); | |
| } else { | |
| const uint32_t page = (kb * KBW + kk) * NW + col0; | |
| for (uint32_t j = 0; j < w; ++j) { | |
| noc_async_read(wa.get_noc_addr(page + j), dst + j * T16, T16); | |
| } | |
| } | |
| } | |
| noc_async_read_barrier(); | |
| } | |
| cb_push_back(MM_CB_IN1, KBW * WMAX); | |
| } | |
| } | |