File size: 2,249 Bytes
58ba6df | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | // 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).
#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);
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();
}
|