Download code/hamer/kernels/cmm/idle_prefetch.cpp from changh95/hamer-p150: direct link, hf CLI and curl.
- Browser
- Download file 2.25 kB
-
https://huggingface.co/changh95/hamer-p150/resolve/main/code/hamer/kernels/cmm/idle_prefetch.cpp
- Command line
-
hf download hf://changh95/hamer-p150/code/hamer/kernels/cmm/idle_prefetch.cpp
-
curl -L -o idle_prefetch.cpp https://huggingface.co/changh95/hamer-p150/resolve/main/code/hamer/kernels/cmm/idle_prefetch.cpp
2.25 kB
| // SPDX-FileCopyrightText: © 2026 Tenstorrent Inc. | |
| // SPDX-License-Identifier: Apache-2.0 | |
| // Round 11: cores a cmm program leaves idle copy the first K blocks of a LATER xmm's packed weight from DRAM into the | |
| // persistent L1 prefetch buffers of that xmm's weight senders (tt_kernels.XmmPrefetch): their own buffer directly, other | |
| // cores' through a local scratch CB 22 (DRAM -> scratch -> NoC write, two scratch halves so a write overlaps the next | |
| // read). No semaphores: the consumer is a later program. | |
| // runtime: w_addr, n, then n x (bank, bank offset, dst x, dst y, dst addr, bytes, local) (fixed length). | |
| void kernel_main() { | |
| const uint32_t w_addr = get_arg_val<uint32_t>(0); | |
| const uint32_t n = get_arg_val<uint32_t>(1); | |
| if (n == 0) { | |
| return; | |
| } | |
| const uint32_t scr = get_write_ptr(22); | |
| const uint32_t half = get_local_cb_interface(22).fifo_size / 2; | |
| // local entries first: plain reads into this core's own buffer | |
| for (uint32_t i = 0; i < n; ++i) { | |
| const uint32_t a = 2 + 7 * i; | |
| if (get_arg_val<uint32_t>(a + 6)) { | |
| noc_async_read(get_noc_addr_from_bank_id<true>(get_arg_val<uint32_t>(a), w_addr + get_arg_val<uint32_t>(a + 1)), | |
| get_arg_val<uint32_t>(a + 4), get_arg_val<uint32_t>(a + 5)); | |
| } | |
| } | |
| uint32_t k = 0; | |
| for (uint32_t i = 0; i < n; ++i) { | |
| const uint32_t a = 2 + 7 * i; | |
| if (get_arg_val<uint32_t>(a + 6)) { | |
| continue; | |
| } | |
| const uint32_t buf = scr + (k & 1) * half; | |
| const uint32_t bytes = get_arg_val<uint32_t>(a + 5); | |
| // this half was last the source of the write two remote entries ago: every issued write has left L1 (flushed) | |
| noc_async_writes_flushed(); | |
| noc_async_read(get_noc_addr_from_bank_id<true>(get_arg_val<uint32_t>(a), w_addr + get_arg_val<uint32_t>(a + 1)), | |
| buf, bytes); | |
| noc_async_read_barrier(); | |
| noc_async_write(buf, get_noc_addr(get_arg_val<uint32_t>(a + 2), get_arg_val<uint32_t>(a + 3), get_arg_val<uint32_t>(a + 4)), | |
| bytes); | |
| ++k; | |
| } | |
| noc_async_read_barrier(); | |
| noc_async_write_barrier(); | |
| } | |