okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-kv-default: with KV streaming on NVIDIA cards, the prompt's new K/V cells reach the host copy by one DMA copy per array6aae30348

main
1.9 KiB45 linesraw
1// The prompt path's K/V append under KV streaming (strata/core/kv_host_dma.hpp): CUDA copies the chunk's new cells to
2// the host copy by DMA by default, HIP keeps the kernel's own stores unless asked, STRATA_KV_HOST_DMA=1 / 0 forces
3// either way, and a layer without a staging pool always keeps the kernel's stores.
4#include "strata/core/kv_host_dma.hpp"
5
6#include <cstdio>
7
8using namespace strata::core;
9
10namespace {
11int failed = 0;
12#define CHECK(x) do { if (!(x)) { std::fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #x); ++failed; } } while (0)
13}  // namespace
14
15int main() {
16    // unset: the backend's default (CUDA true, HIP false)
17    CHECK(kv_host_dma_on(nullptr, true));
18    CHECK(!kv_host_dma_on(nullptr, false));
19    // "1" / "0" force it on both backends
20    CHECK(kv_host_dma_on("1", false));
21    CHECK(kv_host_dma_on("1", true));
22    CHECK(!kv_host_dma_on("0", true));
23    CHECK(!kv_host_dma_on("0", false));
24    // HIP as before this header: only a value that starts with '1' turns it on
25    CHECK(kv_host_dma_on("1yes", false));
26    CHECK(!kv_host_dma_on("", false));
27    CHECK(!kv_host_dma_on("yes", false));
28    CHECK(!kv_host_dma_on("2", false));
29    // CUDA: anything but a leading '0' keeps the default on
30    CHECK(kv_host_dma_on("", true));
31    CHECK(kv_host_dma_on("yes", true));
32    CHECK(!kv_host_dma_on("0n", true));
33    // one append: the switch, a streamed (staged) layer, and its staging pool; any one missing -> the kernel's stores
34    CHECK(kv_host_dma_use(true, true, true));
35    for (int on = 0; on < 2; ++on)
36        for (int staged = 0; staged < 2; ++staged)
37            for (int pool = 0; pool < 2; ++pool)
38                if (!(on && staged && pool)) CHECK(!kv_host_dma_use(on != 0, staged != 0, pool != 0));
39    if (failed) {
40        std::fprintf(stderr, "kv_host_dma_test: %d failed\n", failed);
41        return 1;
42    }
43    std::printf("kv_host_dma_test: ok\n");
44    return 0;
45}