hamer-p150 / code /hamer /kernels /cmm /help_prefetch.cpp
changh95's picture
Optimized build (2026-10-03): model call 3.49 ms, device 3.36 ms
58ba6df verified
Raw History Blame Contribute Delete
1.36 kB
// SPDX-FileCopyrightText: © 2026 Tenstorrent Inc.
// SPDX-License-Identifier: Apache-2.0
// Round 8: cross-op weight prefetch by the cores a cmm program leaves idle. Each helper copies its chunks of a LATER
// cmm's packed weight blocks from DRAM into the persistent L1 prefetch buffer of their owner (a top-row sender,
// tt_kernels.CmmPrefetch): DRAM -> local scratch CB 22 -> remote L1. 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) (fixed length).
#include <stdint.h>
#include "api/dataflow/dataflow_api.h"
void kernel_main() {
const uint32_t w_addr = get_arg_val<uint32_t>(0);
const uint32_t n = get_arg_val<uint32_t>(1);
const uint32_t buf = get_write_ptr(22);
for (uint32_t i = 0; i < n; ++i) {
const uint32_t a = 2 + 6 * i;
const uint32_t bank = get_arg_val<uint32_t>(a), off = get_arg_val<uint32_t>(a + 1);
const uint32_t dx = get_arg_val<uint32_t>(a + 2), dy = get_arg_val<uint32_t>(a + 3);
const uint32_t dst = get_arg_val<uint32_t>(a + 4), bytes = get_arg_val<uint32_t>(a + 5);
noc_async_read(get_noc_addr_from_bank_id<true>(bank, w_addr + off), buf, bytes);
noc_async_read_barrier();
noc_async_write(buf, get_noc_addr(dx, dy, dst), bytes);
noc_async_write_barrier();
}
}