Merge branch 'f-021-iD' into f-021-int

This commit is contained in:
Niko1221 committed 2026-10-20 02:13:21 +02:00
commit 83027df587
12 files changed
+338 -16

No files matched your search

+4
View File
@@ -2112,6 +2112,10 @@ if(STRATA_BUILD_TESTS)
add_executable(pool_plan_test src/kernels/cpu/pool_plan_test.cpp)
target_include_directories(pool_plan_test PRIVATE include)
add_test(NAME pool_plan_test COMMAND pool_plan_test)
# #3204: when the HIP start-up warm-up of hipBLAS may run (pure policy, no GPU)
add_executable(warm_policy_test src/prefill/warm_policy_test.cpp)
target_include_directories(warm_policy_test PRIVATE include)
add_test(NAME warm_policy_test COMMAND warm_policy_test)
# issue #29: tiny batches with sleeping workers, as on a big-VRAM card; a hang fails it
add_executable(pool_stress src/kernels/cpu/pool_stress.cpp)
target_link_libraries(pool_stress PRIVATE strata_kernels_cpu)
+16 -1
View File
@@ -45,8 +45,23 @@ struct PoolPlanInput {
int e_cores = 0;
};
/// #3262: is a CPU an efficiency-class core? `pmu_core` / `pmu_atom` / `pmu_lowpower` are Intel's hybrid PMU lists
/// (/sys/devices/cpu_core/cpus, cpu_atom/cpus, cpu_lowpower/cpus; the last exists on Meteor Lake and Arrow Lake-H, where
/// the LP-E cores of the SoC tile are in neither of the other two). A CPU in the P list is a P-core; one in the atom
/// or low-power list is an E-core (the LP-E cores sort last by capacity). A CPU in no list falls back to its capacity
/// (an E-core under 90% of the largest). `pmu`: both the core and the atom list were read.
inline bool hybrid_cpu_is_efficiency(int cpu, long cap, long max_cap, bool pmu, const std::vector<int>& pmu_core,
const std::vector<int>& pmu_atom, const std::vector<int>& pmu_lowpower) {
auto in = [&](const std::vector<int>& v) { return std::find(v.begin(), v.end(), cpu) != v.end(); };
if (pmu) {
if (in(pmu_atom) || in(pmu_lowpower)) return true;
if (in(pmu_core)) return false;
}
return max_cap > 0 && cap > 0 && cap * 10 < max_cap * 9;
}
struct PoolPlan {
int workers = 1; ///< the default count of pool workers (the host thread works beside them)
int workers = 1; ///< the default count of pool workers (the host thread works beside them)
int cores = 0; ///< physical cores counted (all packages)
int cores_local = 0; ///< ... on the host's package
int packages = 1;
+17
View File
@@ -60,6 +60,23 @@ inline bool file_cache_keeps(uint64_t avail, uint64_t arena_bytes, uint64_t read
return room >= need;
}
/// #3237: with the room rule saying the file cache could keep the experts that come back, but holding only
/// `held_fraction` (< 0.5) of the read set: whether the unbuffered reads win, from a start-up timing of the drive both
/// ways (`direct_bps`: O_DIRECT preads on the I/O threads, `cached_bps`: first touches of a mapping's pages).
/// On a PCIe 5 NVMe (8.2 GB/s direct against 4.9 through the cache, the cache holding 13%) the cached path read prompts at
/// half the speed and decoded 3-4x slower than unbuffered reads (#3237). On a 1.7-2.5 GB/s NVMe (ext4, notes-021-iD) the
/// cache decoded 1.1-1.6x faster at 10-60% held while direct reads read prompts 1.1-1.4x faster, so a timing ratio alone
/// (2.0x there, 1.66x on the reporter's) cannot separate the two: a miss costs 1/bandwidth, and only on a fast drive is
/// a miss cheap enough that the cache's faults and read-ahead cost more than the hits save. Hence an absolute floor: the
/// direct path must run at 4 GB/s or more. Then a cache that holds under 30% needs the direct path 1.3x faster; up to
/// half, 1.5x.
inline bool file_tier_prefers_direct(double held_fraction, double direct_bps, double cached_bps) {
if (!(direct_bps > 0.0) || !(cached_bps > 0.0)) return false;
if (held_fraction >= 0.5 || direct_bps < 4.0e9) return false;
const double ratio = direct_bps / cached_bps;
return held_fraction < 0.3 ? ratio >= 1.3 : ratio >= 1.5;
}
/// Whether `advise_willneed` asks the OS for anything: not on Windows, nor with STRATA_READ_AHEAD=0.
bool read_ahead_enabled();
/// Asks the OS to start reading [p, p + bytes) of a file mapping, without waiting. Linux reads at most one
+30
View File
@@ -0,0 +1,30 @@
// include/strata/prefill/warm_policy.hpp - whether the HIP start-up warm-up of hipBLAS (prefill.cpp warm_gemm_libraries)
// may run. Pure, so it is unit tested without a GPU (warm_policy_test).
//
// #3204: on a layer split across a gfx1151 and a gfx1201 card, prompts read ~25% slower with the warm-up (1,250 against
// 1,710 tok/s at 64K; STRATA_PREFILL_WARM=0 restores it; hc read of the gfx1151 stage 2.7 -> 9.0 s a 32K block). The
// same warm-up on two cards of ONE architecture (2x R9700) costs nothing (021-iD, interleaved pairs). Cards of different
// architectures share one process-wide hipBLAS / hipBLASLt library state, and the warm-up of the second architecture runs
// before the first card's own tuned products resolve their solutions. So: no warm-up when the process sees more than one
// architecture (the first prompt pays the one-time 1-2.5 s load, as before 0.2.0), unless STRATA_PREFILL_WARM=1 asks.
#pragma once
#include <string>
#include <vector>
namespace strata::prefill {
/// `gcn_archs`: gcnArchName of every visible HIP device (a ":sramecc+:xnack-" feature suffix is ignored);
/// `env`: the value of STRATA_PREFILL_WARM or nullptr. "0" turns the warm-up off, "1" on whatever the cards are.
inline bool warm_gemm_wanted(const std::vector<std::string>& gcn_archs, const char* env) {
if (env != nullptr && env[0] == '0') return false;
if (env != nullptr && env[0] == '1') return true;
if (gcn_archs.empty()) return true;
const auto base = [](const std::string& a) { return a.substr(0, a.find(':')); };
const std::string first = base(gcn_archs.front());
for (const std::string& a : gcn_archs)
if (base(a) != first) return false;
return true;
}
} // namespace strata::prefill
+16 -10
View File
@@ -996,7 +996,7 @@ def linux_core_classes(sys_root: str = "/sys"):
one under 90% of the largest - Turbo Boost Max 3.0 gives the "favored" P-cores a slightly higher capacity (1024
against 1012), so "below the maximum" counted 2 of a Core Ultra 7 270K Plus's 8 P-cores."""
pmu = linux_hybrid_pmu(sys_root + "/devices")
seen = {}
seen, top = {}, 0
for cpu in sorted((Path(sys_root) / "devices" / "system" / "cpu").glob("cpu[0-9]*"), key=lambda p: int(p.name[3:])):
cap = cpu / "cpu_capacity"
pkg, core = cpu / "topology" / "physical_package_id", cpu / "topology" / "core_id"
@@ -1004,15 +1004,17 @@ def linux_core_classes(sys_root: str = "/sys"):
return None
key = (pkg.read_text(encoding="utf-8").strip(), core.read_text(encoding="utf-8").strip()) \
if pkg.exists() and core.exists() else cpu.name
if pmu is not None:
seen.setdefault(key, 0 if int(cpu.name[3:]) in pmu[1] else 1)
else:
seen.setdefault(key, int(cap.read_text(encoding="utf-8").strip()))
classes = list(seen.values())
if pmu is None:
top = max(classes, default=0)
classes = [1 if c * 10 >= top * 9 else 0 for c in classes]
return classes
num = int(cpu.name[3:])
capacity = int(cap.read_text(encoding="utf-8").strip()) if cap.exists() else 0
top = max(top, capacity)
if pmu is not None and num in pmu[1]:
seen.setdefault(key, None) # a listed E-core (the atom list and, #3262, the LP-E list)
elif pmu is not None and num in pmu[0]:
seen.setdefault(key, False) # a listed P-core
else: # in no list (or no lists at all): its capacity decides
seen.setdefault(key, capacity)
# an E-core is under 90% of the largest capacity; the PMU lists (None: E, False: P) decide where they say
return [0 if c is None else 1 if c is False else (1 if c * 10 >= top * 9 else 0) for c in seen.values()]
def cpulist(text: str) -> set:
@@ -1033,6 +1035,10 @@ def linux_hybrid_pmu(root: str = "/sys/devices"):
e = cpulist((Path(root) / "cpu_atom" / "cpus").read_text(encoding="utf-8"))
except OSError:
return None
try: # #3262: Meteor Lake / Arrow Lake-H list their LP-E cores in a third set, in neither of the two above
e |= cpulist((Path(root) / "cpu_lowpower" / "cpus").read_text(encoding="utf-8"))
except OSError:
pass
return (p, e) if p and e else None
+138
View File
@@ -511,6 +511,120 @@ void close_direct(void* h) {
#endif
}
#if defined(__linux__)
/// #3237: how fast this drive serves the experts' reads the two ways the file tier can take them - O_DIRECT preads of
/// 1 MiB at random places on 8 threads (the unbuffered tier's I/O threads) against first touches of the pages of random
/// 1 MiB pieces of a mapping on 3 threads (the cached tier: the pool's threads faulting the page cache in). Regions the
/// page cache already holds are skipped, and the probed ranges are dropped from the cache again. The best of two
/// rounds each; a few hundred MiB read, under two seconds per pass. Done once per process. false: not measurable.
struct TierProbeResult { bool done = false, ok = false; double direct_bps = 0, cached_bps = 0; };
bool file_tier_probe(const std::vector<std::string>& paths, double& direct_bps, double& cached_bps) {
static std::mutex mu;
static TierProbeResult memo;
std::lock_guard<std::mutex> lk(mu);
if (memo.done) { direct_bps = memo.direct_bps; cached_bps = memo.cached_bps; return memo.ok; }
memo.done = true;
const std::string* best = nullptr;
uint64_t size = 0;
for (const std::string& p : paths) {
struct stat st{};
if (::stat(p.c_str(), &st) == 0 && (uint64_t) st.st_size > size) { size = (uint64_t) st.st_size; best = &p; }
}
constexpr uint64_t kRegion = 1ull << 20;
constexpr int kPerPass = 96, kRounds = 2;
constexpr int kDirectThreads = 8, kCachedThreads = 3;
if (best == nullptr || size < 8ull * kPerPass * kRegion * 2) return false;
const int fd_d = ::open(best->c_str(), O_RDONLY | O_DIRECT | O_CLOEXEC);
const int fd_b = ::open(best->c_str(), O_RDONLY | O_CLOEXEC);
void* map = fd_b >= 0 ? mmap(nullptr, (size_t) size, PROT_READ, MAP_SHARED, fd_b, 0) : MAP_FAILED;
auto cleanup = [&] {
if (map != MAP_FAILED) munmap(map, (size_t) size);
if (fd_d >= 0) ::close(fd_d);
if (fd_b >= 0) ::close(fd_b);
};
if (fd_d < 0 || map == MAP_FAILED) { cleanup(); return false; }
const uint8_t* base = static_cast<const uint8_t*>(map);
uint64_t seed = (uint64_t) std::chrono::steady_clock::now().time_since_epoch().count() * 6364136223846793005ull + 1442695040888963407ull;
std::vector<uint64_t> used;
auto pick = [&](std::vector<uint64_t>& out) { // kPerPass distinct 1 MiB pieces the page cache does not hold
out.clear();
std::vector<unsigned char> vec(kRegion / 4096);
for (int tries = 0; (int) out.size() < kPerPass && tries < kPerPass * 40; ++tries) {
seed = seed * 6364136223846793005ull + 1442695040888963407ull;
const uint64_t off = ((seed >> 20) % (size / kRegion)) * kRegion;
if (std::find(used.begin(), used.end(), off) != used.end()) continue;
if (mincore((void*) (base + off), (size_t) kRegion, vec.data()) != 0) continue;
int res = 0;
for (unsigned char c : vec) res += c & 1;
if (res * 4 > (int) vec.size()) continue;
used.push_back(off);
out.push_back(off);
}
return (int) out.size() >= kPerPass / 2;
};
auto preadn = [&](uint8_t* dst, uint64_t off) {
uint64_t done = 0;
while (done < kRegion) {
const ssize_t r = ::pread(fd_d, dst + done, (size_t) (kRegion - done), (off_t) (off + done));
if (r < 0) { if (errno == EINTR) continue; return false; }
if (r == 0) return false;
done += (uint64_t) r;
}
return true;
};
double best_d = 0, best_c = 0;
bool ok = true;
for (int round = 0; round < kRounds && ok; ++round) {
for (int mode = 0; mode < 2 && ok; ++mode) { // 0: direct, 1: cached
std::vector<uint64_t> offs;
if (!pick(offs)) { ok = false; break; }
std::atomic<size_t> next{0};
std::atomic<uint64_t> bytes{0};
std::atomic<int> failed{0};
const auto t0 = std::chrono::steady_clock::now();
const auto deadline = t0 + std::chrono::milliseconds(1500);
std::vector<std::thread> th;
const int nthreads = mode == 0 ? kDirectThreads : kCachedThreads;
for (int t = 0; t < nthreads; ++t) {
th.emplace_back([&] {
void* buf = nullptr;
if (mode == 0 && posix_memalign(&buf, 4096, kRegion) != 0) { failed = 1; return; }
volatile uint8_t sink = 0;
for (;;) {
const size_t i = next.fetch_add(1);
if (i >= offs.size() || std::chrono::steady_clock::now() > deadline) break;
if (mode == 0) {
if (!preadn((uint8_t*) buf, offs[i])) { failed = 1; break; }
} else {
for (uint64_t pg = 0; pg < kRegion; pg += 4096) sink = (uint8_t) (sink + base[offs[i] + pg]);
}
bytes.fetch_add(kRegion);
}
std::free(buf);
});
}
for (std::thread& x : th) x.join();
const double secs = std::chrono::duration<double>(std::chrono::steady_clock::now() - t0).count();
if (failed.load() != 0 || bytes.load() == 0 || secs <= 0) { ok = false; break; }
const double bps = (double) bytes.load() / secs;
(mode == 0 ? best_d : best_c) = std::max(mode == 0 ? best_d : best_c, bps);
for (uint64_t off : offs) { // leave the page cache as it was
(void) madvise((void*) (base + off), (size_t) kRegion, MADV_DONTNEED);
(void) posix_fadvise(fd_b, (off_t) off, (off_t) kRegion, POSIX_FADV_DONTNEED);
}
}
}
cleanup();
memo.ok = ok && best_d > 0 && best_c > 0;
memo.direct_bps = best_d;
memo.cached_bps = best_c;
direct_bps = best_d;
cached_bps = best_c;
return memo.ok;
}
#endif
/// #286/#577: whether the file tier reads its `read_bytes` unbuffered, beside `arena_bytes` of RAM copy still to be
/// taken. Windows times probe reads too (experts_unbuffered); on Linux the same rule as its `cache_counts = false`
/// arm decides: whether the file cache could keep those bytes at all, from MemAvailable and the tightest cgroup
@@ -551,6 +665,30 @@ bool file_tier_unbuffered(const std::vector<std::string>& paths, uint64_t arena_
(double) avail / (1ull << 30), (double) arena_bytes / (1ull << 30), (double) read_bytes / (1ull << 30),
keepable ? "can" : "cannot");
why = msg;
// #3237: the room rule says the cache can keep the experts that come back, but when it holds under half of the read
// set, whether it pays depends on the drive: on a PCIe 5 NVMe (8 GB/s direct) the cached path read prompts at half
// the speed and decoded 3-4x slower than unbuffered reads, on a 1.7-2.5 GB/s NVMe the cache decodes faster. So time
// both paths once at start and read unbuffered only when the drive is fast and serves direct reads clearly faster
// (platform::file_tier_prefers_direct). STRATA_FILE_TIER_PROBE=0 keeps the room rule alone.
if (keepable && !old_rule && read_bytes > 0) {
const char* pe = std::getenv("STRATA_FILE_TIER_PROBE");
const uint64_t margin = 1ull << 30;
const double room = avail > arena_bytes + margin ? (double) (avail - arena_bytes - margin) : 0.0;
const double held = room / (double) read_bytes;
if (!(pe != nullptr && pe[0] == '0') && held < 0.5) {
double d = 0, c = 0;
char pm[256];
if (file_tier_probe(paths, d, c)) {
const bool direct = strata::platform::file_tier_prefers_direct(held, d, c);
std::snprintf(pm, sizeof pm, "; the cache holds %.0f%% of the read set, direct reads %.2f GB/s, cached-path reads "
"%.2f GB/s (%.2fx): %s", held * 100.0, d / 1e9, c / 1e9, d / c,
direct ? "the file tier reads unbuffered" : "the file cache stays");
why += pm;
return direct;
}
why += "; the drive probe could not run, the file cache stays";
}
}
return !keepable;
#else
(void) paths; (void) arena_bytes; (void) read_bytes;
+5 -3
View File
@@ -429,12 +429,14 @@ static CpuTopology detect_cpu_topology_impl(bool skip_first, PoolAffinity affini
// CPU is an E-core when its capacity is under 90% of the largest. Turbo Boost Max 3.0 gives the "favored"
// P-cores a slightly higher capacity (1024 against 1012 on a Core Ultra 7 270K Plus): "capacity == the maximum"
// counted 2 of its 8 P-cores and started 1 pool worker.
std::vector<int> pmu_core, pmu_atom;
// #3262: Meteor Lake and Arrow Lake-H list their LP-E cores (SoC tile, no L3, ~2.5 GHz) in a third set,
// /sys/devices/cpu_lowpower/cpus, that is in neither of the other two; they are E-cores too (and sort last).
std::vector<int> pmu_core, pmu_atom, pmu_lowpower;
const bool pmu = cpulist_read("/sys/devices/cpu_core/cpus", pmu_core) &&
cpulist_read("/sys/devices/cpu_atom/cpus", pmu_atom);
cpulist_read("/sys/devices/cpu_lowpower/cpus", pmu_lowpower);
auto is_e = [&](const CoreLinux& cl) {
if (pmu) return std::find(pmu_atom.begin(), pmu_atom.end(), cl.cpu) != pmu_atom.end();
return max_cap > 0 && cl.cap > 0 && cl.cap * 10 < max_cap * 9;
return hybrid_cpu_is_efficiency(cl.cpu, cl.cap, max_cap, pmu, pmu_core, pmu_atom, pmu_lowpower);
};
bool any_e = false, any_p = false;
for (const auto& cl : all_cpus) (is_e(cl) ? any_e : any_p) = true;
+23
View File
@@ -100,6 +100,29 @@ int main() {
expect(cpu::plan_pool_workers(h3).workers == 15, "8P+8E: not more E-cores than P-cores, every core but the host's");
}
// #3262: Core Ultra 7 255H (6P + 8E + 2 LP-E, no SMT). The LP-E cores (CPUs 14-15) are in cpu_lowpower/cpus, in
// neither the core nor the atom list; they are efficiency cores.
{
const std::vector<int> core = {0, 1, 2, 3, 4, 5}, atom = {6, 7, 8, 9, 10, 11, 12, 13}, lp = {14, 15};
int e = 0, p = 0;
for (int c = 0; c < 16; ++c) {
const long cap = c < 6 ? 1024 : c < 14 ? 774 : 312;
(cpu::hybrid_cpu_is_efficiency(c, cap, 1024, true, core, atom, lp) ? e : p)++;
}
expect(p == 6 && e == 10, "255H: 6 P-cores, 8 E + 2 LP-E counted as efficiency cores");
expect(cpu::hybrid_cpu_is_efficiency(14, 312, 1024, true, core, atom, lp), "LP-E core 14 is an E-core");
expect(!cpu::hybrid_cpu_is_efficiency(5, 1024, 1024, true, core, atom, lp), "P-core 5 stays a P-core");
// a CPU in the lists of no kind falls back to its capacity (312 < 90% of 1024: an E-core)
expect(cpu::hybrid_cpu_is_efficiency(14, 312, 1024, true, core, atom, {}), "LP-E core with no third list: capacity says E");
// a CPU in no list with a favoured-P capacity is a P-core
expect(!cpu::hybrid_cpu_is_efficiency(20, 1012, 1024, true, core, atom, lp), "unlisted CPU, capacity 1012/1024: P");
// the plan with the right counts: 6P + 10E -> 5 + 5 workers, not the 15 of "every core but the host's"
auto h = cpu_of(16, {16});
h.p_cores = 6;
h.e_cores = 10;
expect(cpu::plan_pool_workers(h).workers == 10, "255H -> 10 workers (the measured 9-13 are flat; 15 is -35%)");
}
// a container quota
const auto q = cpu_of(128, {64}, 4.0);
line("64c, container quota 4 CPUs", q);
+29 -1
View File
@@ -73,8 +73,36 @@ int file_cache_keeps_cases() {
}
} // namespace
// #3237: the drive probe's decision
int file_tier_prefers_direct_cases() {
using strata::platform::file_tier_prefers_direct;
struct Case { const char* what; double held, direct, cached; bool direct_wins; };
const Case cases[] = {
{"#3237: 13% held, 8.18 vs 4.93 GB/s", 0.13, 8.18e9, 4.93e9, true},
{"P1004 (measured): 1.65 vs 0.81 GB/s, 19% held: a slow drive keeps the cache", 0.19, 1.65e9, 0.81e9, false},
{"a fast drive, the same ratio as P1004 (8 vs 4 GB/s)", 0.19, 8.0e9, 4.0e9, true},
{"just under the 4 GB/s floor", 0.10, 3.9e9, 1.0e9, false},
{"a third held, direct 1.4x: not enough", 0.35, 5.6e9, 4.0e9, false},
{"a third held, direct 1.6x", 0.35, 6.4e9, 4.0e9, true},
{"under 30% held, direct 1.3x", 0.20, 5.2e9, 4.0e9, true},
{"under 30% held, direct 1.2x", 0.20, 4.8e9, 4.0e9, false},
{"half held or more: the cache, however fast the drive", 0.5, 9e9, 1e9, false},
{"no cached-path figure", 0.1, 5e9, 0.0, false},
{"no direct figure", 0.1, 0.0, 5e9, false},
{"a hard disk (direct 2x, under the floor): the cache", 0.1, 0.2e9, 0.1e9, false},
};
int fail = 0;
for (const Case& c : cases) {
const bool got = file_tier_prefers_direct(c.held, c.direct, c.cached);
std::printf("file_tier_prefers_direct %-62s -> %s%s\n", c.what, got ? "unbuffered" : "cache",
got == c.direct_wins ? "" : " <-- WRONG");
fail |= got != c.direct_wins;
}
return fail;
}
int main() {
int fail_keeps = file_cache_keeps_cases();
int fail_keeps = file_cache_keeps_cases() | file_tier_prefers_direct_cases();
const uint64_t bytes = 256ull << 20;
void* p = std::malloc(bytes);
if (p == nullptr) return 2;
+19
View File
@@ -1,6 +1,7 @@
// src/prefill/prefill.cpp - see include/strata/prefill/prefill.hpp.
#include "strata/kernels/fused_gr.hpp"
#include "strata/prefill/prefill.hpp"
#include "strata/prefill/warm_policy.hpp"
#include <atomic>
#if defined(__cpp_lib_atomic_wait)
#define STRATA_ATOMIC_WAIT 1 // #1488: std::atomic::wait / notify_all are a GCC 11 library feature; GCC 10 spins instead
@@ -1286,6 +1287,24 @@ void warm_gemm_libraries(int device) {
static const bool off = [] { const char* e = std::getenv("STRATA_PREFILL_WARM"); return e != nullptr && e[0] == '0'; }();
if (off) return;
#if defined(STRATA_USE_HIP)
// #3204: not when the process sees cards of more than one architecture (gfx1151 + gfx1201: prompts -25%); see
// warm_policy.hpp. STRATA_PREFILL_WARM=1 asks for it anyway.
static const bool arch_ok = [] {
std::vector<std::string> archs;
int n = 0;
if (cudaGetDeviceCount(&n) != cudaSuccess) { (void) cudaGetLastError(); return true; }
for (int i = 0; i < n && i < 32; ++i) {
cudaDeviceProp p{};
if (cudaGetDeviceProperties(&p, i) == cudaSuccess) archs.emplace_back(p.gcnArchName);
else (void) cudaGetLastError();
}
const bool wanted = warm_gemm_wanted(archs, std::getenv("STRATA_PREFILL_WARM"));
if (!wanted)
std::fprintf(stderr, "strata prefill: no hipBLAS warm-up: the cards are of more than one architecture "
"(it slows prompts there, #3204); the first prompt loads the libraries (STRATA_PREFILL_WARM=1 asks for it)\n");
return wanted;
}();
if (!arch_ok) return;
static std::mutex mu;
static unsigned done_mask = 0; // per device: each card loads its own code objects
if (device < 0 || device >= 32) return;
+31
View File
@@ -0,0 +1,31 @@
// warm_policy_test: when the HIP start-up warm-up of hipBLAS may run (include/strata/prefill/warm_policy.hpp). Pure.
#include "strata/prefill/warm_policy.hpp"
#include <cstdio>
using strata::prefill::warm_gemm_wanted;
static int g_fail = 0;
static void expect(bool ok, const char* what) {
if (!ok) {
++g_fail;
std::fprintf(stderr, "FAIL: %s\n", what);
}
}
int main() {
expect(warm_gemm_wanted({}, nullptr), "no device list: the warm-up runs");
expect(warm_gemm_wanted({"gfx1201"}, nullptr), "one R9700: on");
expect(warm_gemm_wanted({"gfx1201", "gfx1201"}, nullptr), "2x R9700 (same architecture): on (021-iD: no loss)");
expect(warm_gemm_wanted({"gfx1201:sramecc+:xnack-", "gfx1201"}, nullptr), "feature suffixes do not make a mixed pair");
expect(!warm_gemm_wanted({"gfx1151", "gfx1201"}, nullptr), "8060S + R9700 (#3204): off");
expect(!warm_gemm_wanted({"gfx1201", "gfx1151"}, nullptr), "the order does not matter");
expect(!warm_gemm_wanted({"gfx1100", "gfx1100", "gfx1030"}, nullptr), "any second architecture turns it off");
expect(!warm_gemm_wanted({"gfx1201"}, "0"), "STRATA_PREFILL_WARM=0: off");
expect(!warm_gemm_wanted({"gfx1201", "gfx1201"}, "0"), "STRATA_PREFILL_WARM=0 on two cards: off");
expect(warm_gemm_wanted({"gfx1151", "gfx1201"}, "1"), "STRATA_PREFILL_WARM=1 forces it on a mixed pair");
expect(!warm_gemm_wanted({"gfx1151", "gfx1201"}, ""), "an empty value is unset: a mixed pair stays off");
if (g_fail) { std::fprintf(stderr, "warm_policy_test: %d failure(s)\n", g_fail); return 1; }
std::printf("warm_policy_test: OK\n");
return 0;
}
+10 -1
View File
@@ -31,7 +31,7 @@ def fake_sys(root: Path, caps: list, pmu=None, smt=False) -> None:
(d / "cpu_capacity").write_text(str(cap))
n += 1
if pmu:
for name, lst in zip(("cpu_core", "cpu_atom"), pmu):
for name, lst in zip(("cpu_core", "cpu_atom", "cpu_lowpower"), pmu):
(root / "devices" / name).mkdir(parents=True)
(root / "devices" / name / "cpus").write_text(lst + "\n")
@@ -54,6 +54,15 @@ class LinuxCores(unittest.TestCase):
self.assertEqual(self.classes(caps, pmu=("0-7", "8-23")), (8, 16)) # by the PMU lists
self.assertEqual(setup.hybrid_pool_workers((8, 16)), 15)
def test_lp_e_cores_are_efficiency_cores(self):
"""#3262: Core Ultra 7 255H (6P + 8E + 2 LP-E): the LP-E cores are in /sys/devices/cpu_lowpower/cpus, in neither
of the other two lists; they were counted as P-cores (8P + 8E, so the engine's every-core default of 15 stayed)."""
caps = [1024] * 6 + [774] * 8 + [312] * 2
self.assertEqual(self.classes(caps, pmu=("0-5", "6-13", "14-15")), (6, 10))
self.assertEqual(self.classes(caps), (6, 10)) # no PMU lists: capacity says the same
self.assertEqual(setup.hybrid_pool_workers((6, 10)), 10) # not None (8, 8 gave every core: 15)
self.assertEqual(self.classes(caps, pmu=("0-5", "6-13")), (6, 10)) # a kernel without the third list: capacity
def test_plain_capacities_and_plain_cpus(self):
self.assertEqual(self.classes([1024] * 8 + [512] * 8), (8, 8))
self.assertIsNone(self.classes([1024] * 8)) # no E-cores