mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-04 07:18:50 +00:00
perf(inkling2/cuda): Windows pins the host expert arena up to min(16 GiB, 35% of the available RAM) (was 8 GB), with an 8 GiB floor and STRATA_INK_PIN_GB
A pinned arena lets the card read the cold experts itself: the exact lane stages inside the CUDA graph instead of copying through a pageable arena + bounce ring with one host sync per visit. On the owner PC (RTX 5070, x16) SQ-10 at an 8 GiB plan goes from 30 to 49 tok/s in that lane, SQ-20 from 8 to 15; the launch probe still picks the lane (pinned exact against the CPU lane). The rule is a pure function (core/ink_pin_rule.hpp, tested by ink_pin_rule_test): Windows cap min(16 GiB, 35% of the available RAM), and an arena that would leave under 8 GiB of RAM available is not pinned; STRATA_INK_PIN_GB=<n> sets the cap in GiB (both platforms), =0 turns pinning off; Linux keeps its rule (under 45% of the available RAM). When the rule says no, or cudaHostAlloc fails, the arena is pageable as before, with one INFO line saying why; the start never fails on this.
This commit is contained in:
1 parent
0b58d83200
commit
2612ae5c0e
4 files changed
+114
-3
No files matched your search
@@ -337,6 +337,10 @@ if(STRATA_BUILD_TESTS)
|
||||
add_executable(ink_expert_policy_test tests/core/ink_expert_policy_test.cpp)
|
||||
target_include_directories(ink_expert_policy_test PRIVATE include)
|
||||
add_test(NAME ink_expert_policy_test COMMAND ink_expert_policy_test)
|
||||
# the pinned host arena rule of strata-inkling (cap, floor, override, no GPU)
|
||||
add_executable(ink_pin_rule_test tests/core/ink_pin_rule_test.cpp)
|
||||
target_include_directories(ink_pin_rule_test PRIVATE include)
|
||||
add_test(NAME ink_pin_rule_test COMMAND ink_pin_rule_test)
|
||||
# #6762 / #6784 / #6717: the DSpark drafter GGUF's tensors reach every backend as "dspark.<name>" (no GPU)
|
||||
add_executable(ink_names_test tests/core/ink_names_test.cpp)
|
||||
target_include_directories(ink_names_test PRIVATE include)
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
// Inkling 2 Mini host expert arena: may it be pinned (page-locked)? A pinned arena lets the card read the cold experts itself (the exact lane's in-graph
|
||||
// staging, the PCIe streaming of prefill), a pageable one goes through a bounce ring and a CPU copy. Pure function, no GPU, tested by ink_pin_rule_test.
|
||||
//
|
||||
// Windows (owner decision 11-23): the cap is min(16 GiB, 35% of the available RAM); STRATA_INK_PIN_GB=<n> replaces it by n GiB, =0 turns pinning off;
|
||||
// whatever the cap, an arena that would leave less than 8 GiB of RAM available is not pinned (the desktop keeps its memory). Linux keeps its rule
|
||||
// (the arena is pinned when it is under 45% of the available RAM, no size cap, no floor); STRATA_INK_PIN_GB applies to it as the cap in GiB, =0 turns it off.
|
||||
// An unknown available RAM (0) pins up to 8 GiB on Windows and always on Linux, as before. The caller falls back to the pageable path with one INFO line
|
||||
// when this says no, or when the allocation fails.
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace strata {
|
||||
|
||||
struct InkPinRule {
|
||||
bool pin = false;
|
||||
uint64_t cap = 0; // the size cap that applied (0: none)
|
||||
const char* why = ""; // the reason of a "no" / what decided a "yes"
|
||||
};
|
||||
|
||||
inline InkPinRule ink_pin_rule(bool windows, uint64_t bytes, uint64_t avail, const char* env_gib) noexcept {
|
||||
constexpr uint64_t GiB = 1ull << 30;
|
||||
constexpr uint64_t kFloor = 8 * GiB; // available RAM that must remain after pinning (Windows)
|
||||
InkPinRule r;
|
||||
if (env_gib != nullptr && env_gib[0] != 0) {
|
||||
const double n = std::atof(env_gib);
|
||||
if (!(n > 0.0)) { r.why = "STRATA_INK_PIN_GB=0 turns pinning off"; return r; }
|
||||
r.cap = (uint64_t)(n * (double)GiB);
|
||||
if (bytes > r.cap) { r.why = "larger than STRATA_INK_PIN_GB"; return r; }
|
||||
if (windows && avail != 0 && avail < bytes + kFloor) { r.why = "would leave less than 8 GiB of RAM available"; return r; }
|
||||
r.pin = true;
|
||||
r.why = "STRATA_INK_PIN_GB";
|
||||
return r;
|
||||
}
|
||||
if (windows) {
|
||||
r.cap = (avail != 0) ? std::min<uint64_t>(16 * GiB, (uint64_t)(0.35 * (double)avail)) : 8 * GiB;
|
||||
if (bytes > r.cap) { r.why = "larger than min(16 GiB, 35% of the available RAM)"; return r; }
|
||||
if (avail != 0 && avail < bytes + kFloor) { r.why = "would leave less than 8 GiB of RAM available"; return r; }
|
||||
r.pin = true;
|
||||
r.why = "within min(16 GiB, 35% of the available RAM)";
|
||||
return r;
|
||||
}
|
||||
if (avail == 0 || (double)bytes < 0.45 * (double)avail) { r.pin = true; r.why = "under 45% of the available RAM"; return r; }
|
||||
r.why = "larger than 45% of the available RAM";
|
||||
return r;
|
||||
}
|
||||
|
||||
} // namespace strata
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "../ink_host_avx2.h"
|
||||
#include "strata/core/moe_wave_plan.hpp"
|
||||
#include "strata/core/ink_expert_policy.hpp"
|
||||
#include "strata/core/ink_pin_rule.hpp"
|
||||
#include "strata/quant/act.hpp"
|
||||
#include "strata/quant/dequant.hpp"
|
||||
#include "strata/quant/dot.hpp"
|
||||
@@ -1511,17 +1512,26 @@ struct InkHybridEngine {
|
||||
if (numa_mask) std::fprintf(stderr, "[InkHybrid] host expert arena: pages interleaved over the NUMA nodes (mask 0x%lx)\n", numa_mask);
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
const bool try_pin = (bytes <= (8ull << 30)) && (avail == 0 || (double)bytes < 0.35 * (double)avail);
|
||||
constexpr bool kWindows = true;
|
||||
#else
|
||||
const bool try_pin = (avail == 0 || (double)bytes < 0.45 * (double)avail);
|
||||
constexpr bool kWindows = false;
|
||||
#endif
|
||||
if (try_pin) {
|
||||
// may the arena be page-locked? (core/ink_pin_rule.hpp: Windows min(16 GiB, 35% of the available RAM) and 8 GiB must stay available, Linux 45%;
|
||||
// STRATA_INK_PIN_GB=<n> sets the cap in GiB, =0 turns pinning off.) Whatever happens, the start continues on the pageable path.
|
||||
const strata::InkPinRule pin_rule = strata::ink_pin_rule(kWindows, (uint64_t)bytes, avail, std::getenv("STRATA_INK_PIN_GB"));
|
||||
if (pin_rule.pin) {
|
||||
if (cudaHostAlloc(&h_sec4_pinned, bytes, cudaHostAllocDefault) == cudaSuccess) {
|
||||
sec4_is_pinned = true;
|
||||
std::fprintf(stderr, "[InkHybrid] host expert arena %.2f GB pinned (%s; available RAM %.1f GB): the card reads the cold experts itself\n",
|
||||
(double)bytes / 1e9, pin_rule.why, (double)avail / 1e9);
|
||||
return h_sec4_pinned;
|
||||
}
|
||||
(void)cudaGetLastError();
|
||||
h_sec4_pinned = nullptr;
|
||||
std::fprintf(stderr, "[InkHybrid] host expert arena %.2f GB: pinning failed (cudaHostAlloc), using pageable memory\n", (double)bytes / 1e9);
|
||||
} else {
|
||||
std::fprintf(stderr, "[InkHybrid] host expert arena %.2f GB not pinned (%s; available RAM %.1f GB): pageable memory with a pinned bounce ring\n",
|
||||
(double)bytes / 1e9, pin_rule.why, (double)avail / 1e9);
|
||||
}
|
||||
sec4_is_pinned = false;
|
||||
#ifdef _WIN32
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
// engine/tests/core/ink_pin_rule_test.cpp - the pinned host arena rule of Inkling 2 Mini (cap, floor, override, fallback). No GPU.
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#include "strata/core/ink_pin_rule.hpp"
|
||||
|
||||
using strata::ink_pin_rule;
|
||||
|
||||
static int fails = 0;
|
||||
#define CHECK(c) do { if (!(c)) { std::printf("FAIL line %d: %s\n", __LINE__, #c); ++fails; } } while (0)
|
||||
|
||||
int main() {
|
||||
constexpr uint64_t GiB = 1ull << 30;
|
||||
// Windows, default: cap = min(16 GiB, 35% of the available RAM), and 8 GiB must stay available
|
||||
CHECK(ink_pin_rule(true, 8 * GiB, 64 * GiB, nullptr).pin); // 8 of 64: cap min(16, 22.4) = 16
|
||||
CHECK(ink_pin_rule(true, 16 * GiB, 64 * GiB, nullptr).pin); // exactly the cap
|
||||
CHECK(!ink_pin_rule(true, 16 * GiB + 1, 64 * GiB, nullptr).pin); // over 16 GiB
|
||||
CHECK(ink_pin_rule(true, 8 * GiB, 24 * GiB, nullptr).pin); // 35% of 24 = 8.4
|
||||
CHECK(!ink_pin_rule(true, 9 * GiB, 24 * GiB, nullptr).pin); // over 35%
|
||||
CHECK(!ink_pin_rule(true, 8 * GiB, 20 * GiB, nullptr).pin); // 35% of 20 = 7: over
|
||||
CHECK(ink_pin_rule(true, 14 * GiB, 42 * GiB, nullptr).pin); // Q4_K_XL-like arena, 35% of 42 = 14.7, leaves 28
|
||||
CHECK(!ink_pin_rule(true, 14 * GiB, 39 * GiB, nullptr).pin); // 35% of 39 = 13.65: over
|
||||
CHECK(ink_pin_rule(true, 8 * GiB, 0, nullptr).pin); // available RAM unknown: up to 8 GiB
|
||||
CHECK(!ink_pin_rule(true, 8 * GiB + 1, 0, nullptr).pin);
|
||||
// the floor: with the override the 35% share no longer applies, the 8 GiB that must remain does
|
||||
CHECK(!ink_pin_rule(true, 10 * GiB, 17 * GiB, "16").pin); // leaves 7 GiB
|
||||
CHECK(ink_pin_rule(true, 10 * GiB, 18 * GiB, "16").pin); // leaves exactly 8 GiB
|
||||
// override: n GiB, 0 = off
|
||||
CHECK(!ink_pin_rule(true, 8 * GiB + 1, 64 * GiB, "8").pin); // lower cap than the default
|
||||
CHECK(ink_pin_rule(true, 8 * GiB, 64 * GiB, "8").pin);
|
||||
CHECK(ink_pin_rule(true, 20 * GiB, 64 * GiB, "24").pin); // higher cap than the default (35% of 64 = 22.4 would also allow: 20 < 22.4)
|
||||
CHECK(ink_pin_rule(true, 20 * GiB, 64 * GiB, "20").pin);
|
||||
CHECK(!ink_pin_rule(true, 1 * GiB, 64 * GiB, "0").pin);
|
||||
CHECK(!ink_pin_rule(false, 1 * GiB, 64 * GiB, "0").pin);
|
||||
CHECK(std::strstr(ink_pin_rule(true, 1 * GiB, 64 * GiB, "0").why, "off") != nullptr);
|
||||
CHECK(std::strstr(ink_pin_rule(true, 20 * GiB, 64 * GiB, nullptr).why, "16 GiB") != nullptr);
|
||||
CHECK(std::strstr(ink_pin_rule(true, 10 * GiB, 17 * GiB, nullptr).why, "35%") != nullptr || std::strstr(ink_pin_rule(true, 10 * GiB, 17 * GiB, nullptr).why, "8 GiB") != nullptr);
|
||||
// Linux keeps its rule: under 45% of the available RAM, no size cap, no floor
|
||||
CHECK(ink_pin_rule(false, 20 * GiB, 64 * GiB, nullptr).pin); // 31% of 64
|
||||
CHECK(ink_pin_rule(false, 28 * GiB, 64 * GiB, nullptr).pin); // 43.75%
|
||||
CHECK(!ink_pin_rule(false, 30 * GiB, 64 * GiB, nullptr).pin); // 46.9%
|
||||
CHECK(ink_pin_rule(false, 100 * GiB, 0, nullptr).pin); // unknown: always
|
||||
CHECK(ink_pin_rule(false, 15 * GiB, 20 * GiB - 1, nullptr).pin == false); // 75%: no
|
||||
CHECK(!ink_pin_rule(false, 9 * GiB, 64 * GiB, "8").pin); // the override as a cap in GiB applies on Linux too
|
||||
CHECK(ink_pin_rule(false, 8 * GiB, 10 * GiB, "8").pin); // and replaces the 45% share (no floor on Linux)
|
||||
if (fails == 0) std::printf("ink_pin_rule_test: ok\n");
|
||||
return fails == 0 ? 0 : 1;
|
||||
}
|
||||
Reference in new issue
Block a user