split: price each stage's prompt loan on its own card (#5722)

Prefill::bytes_needed answers for the current device (prefill.cpp fused_ring
decides the fused layout per card), and part_slots / ring_room priced every
participant of a layer split with whatever device was current, CUDA0's. On an
RTX 5080 + RTX 4090 split the 4090's loan was 2882 MiB for buffers that take
3014 MiB there, and its prompt path stepped down to small chunks.

New helper split_ring.hpp split_part_figure(on_device, dev, fn) evaluates
fn() with the participant's device current (OnDevice, put back after);
generate.cpp part_slots and ring_room's bytes_needed_no_ring go through it.
CUDA0's own part (dev -1) is priced as before. On like cards every device
gives the same figure, so the numbers are unchanged.

Test: tests/program/split_part_price_test.cpp (cpu-check, faked devices).
With the old pricing: CUDA1 lent 2880 MiB for 3014 MiB of buffers, reads
6144-token chunks (fail); now lent 3016 MiB, reads 8192; 2 and 4 like cards
give identical slot counts over the 256..32768 chunk grid. No mixed-card
machine was available: no real mixed-card run backs this.
This commit is contained in:
Niko1221 committed 2026-11-10 18:30:45 +01:00
1 parent e008709d77
commit 7ee50cc8c7
4 files changed
+130 -2

No files matched your search

+7 -2
View File
@@ -10770,8 +10770,11 @@ int main(int argc, char** argv) {
return strata::program::split_lend_slots(xc.slots(), xc.bytes(), xc.slot_offsets(),
(uint64_t) strata::kernels::cpu::expert_layout().max_blob, need);
};
auto on_part_device = [](int dev) { return strata::core::OnDevice(dev); };
auto part_slots = [&](const PfPart& p, int64_t c) -> int64_t {
return cache_slots_for(*p.cache, strata::prefill::Prefill::bytes_needed(g, *p.ses, c, srcp != nullptr));
return cache_slots_for(*p.cache, strata::program::split_part_figure(on_part_device, p.dev, [&] {
return strata::prefill::Prefill::bytes_needed(g, *p.ses, c, srcp != nullptr);
}));
};
auto part_bytes = [&](const PfPart& p, int32_t first) -> uint64_t {
strata::core::ExpertCache& xc = *p.cache;
@@ -10835,7 +10838,9 @@ int main(int argc, char** argv) {
const int64_t budget = std::max<int64_t>(0, std::min(p.cache->slots() - g_lend_keep,
kAutoLendPct * p.cache->slots() / 100));
const uint64_t avail = part_bytes(p, (int32_t) (p.cache->slots() - budget));
const uint64_t nonring = strata::prefill::Prefill::bytes_needed_no_ring(g, *p.ses, c, srcp != nullptr);
const uint64_t nonring = strata::program::split_part_figure(on_part_device, p.dev, [&] {
return strata::prefill::Prefill::bytes_needed_no_ring(g, *p.ses, c, srcp != nullptr);
});
room = std::min(room, (int64_t) ((avail - std::min(avail, nonring)) / (uint64_t) kBlob));
}
return room;