Documented tree replacement (the history has no git-subtree metadata): 3-way merge of the old subtree (570201a:engine/strata) against upstream 41cf05a06a25dd29103b7b27a2279a3f60c21876 (2026-10-25), merge base = the old pin d9ab8435 (tree-identical to upstream 5b734e42; d9ab8435 is not an ancestor of upstream main). Local patches re-applied by hand where they conflicted (15 files): STRATA_CUDA_STATIC profile, experimental KAR experts and KAR PLE arms, keyless V-only arm (now beside upstream's K8V4 hybrid KV and fused norm+rope). Details, conflict table and left-out files are in docs/upstream.md. Left out (weights, captures, logs, media): new bench/results (2022 files), binary media and app assets (61), docs/work/evidence (24), *.bin / *.gguf data files, and the 7 files the first import already left out. scripts/build-cpu.sh: build the 11 CPU tests upstream registered since the old pin (they ran as "Not Run"). Checked: build-cpu.sh 16/16 ctest in WSL; sm_86 CUDA objects of the patched files compile, also with the KAR macros on. No GPU run, no quality gate. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
68 lines
2.2 KiB
C++
68 lines
2.2 KiB
C++
// Linux/x86 CUDA reproducer for #1975. Run "lazy" and "warm" as separate processes.
|
|
// See bench/results/2026-10-11-rtx-5090-callback-affinity/README.md for the build command.
|
|
#include <cuda_runtime_api.h>
|
|
#include <sched.h>
|
|
#include <unistd.h>
|
|
|
|
#include <algorithm>
|
|
#include <atomic>
|
|
#include <chrono>
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
#include <vector>
|
|
|
|
struct State {
|
|
std::atomic<bool> done{false};
|
|
cpu_set_t mask{};
|
|
};
|
|
|
|
static void callback(void* p) {
|
|
auto* s = (State*) p;
|
|
sched_getaffinity(0, sizeof s->mask, &s->mask);
|
|
s->done.store(true, std::memory_order_release);
|
|
}
|
|
|
|
static void check(cudaError_t e) {
|
|
if (e != cudaSuccess) {
|
|
std::fprintf(stderr, "%s\n", cudaGetErrorString(e));
|
|
std::exit(1);
|
|
}
|
|
}
|
|
|
|
int main(int argc, char** argv) {
|
|
const bool warm = argc > 1 && std::strcmp(argv[1], "warm") == 0;
|
|
cudaStream_t stream;
|
|
check(cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking));
|
|
State state;
|
|
if (warm) {
|
|
check(cudaLaunchHostFunc(stream, callback, &state));
|
|
check(cudaStreamSynchronize(stream));
|
|
}
|
|
cpu_set_t host;
|
|
CPU_ZERO(&host);
|
|
CPU_SET(0, &host);
|
|
if (sched_setaffinity(0, sizeof host, &host) != 0) {
|
|
std::perror("sched_setaffinity");
|
|
return 1;
|
|
}
|
|
std::vector<double> times;
|
|
for (int i = 0; i < 200; ++i) {
|
|
state.done.store(false, std::memory_order_release);
|
|
const auto start = std::chrono::steady_clock::now();
|
|
check(cudaLaunchHostFunc(stream, callback, &state));
|
|
while (!state.done.load(std::memory_order_acquire)) {
|
|
asm volatile("pause");
|
|
if (std::chrono::steady_clock::now() - start > std::chrono::seconds(5)) return 2;
|
|
}
|
|
times.push_back(std::chrono::duration<double, std::micro>(std::chrono::steady_clock::now() - start).count());
|
|
}
|
|
std::sort(times.begin(), times.end());
|
|
std::printf("%s: callback affinity:", warm ? "before pin warm-up" : "after pin lazy creation");
|
|
for (int i = 0; i < CPU_SETSIZE; ++i)
|
|
if (CPU_ISSET(i, &state.mask)) std::printf(" %d", i);
|
|
std::printf("; median %.2f us, p95 %.2f us\n", times[100], times[190]);
|
|
check(cudaStreamSynchronize(stream));
|
|
check(cudaStreamDestroy(stream));
|
|
}
|