Guard KAR CUDA smoke against shared GPU memory pressure

This commit is contained in:
Pavlo Ratushnyi
2026-10-03 08:29:12 +02:00
parent bca18dee91
commit 60f60d331b
2 changed files with 33 additions and 5 deletions
+2
View File
@@ -28,4 +28,6 @@ provenance and is not a serving loader.
The smoke program validates the KAR container and payload CRCs, reserves a chosen tensor's compressed level prefix in VRAM, decodes it on a CUDA stream, and reports a warm kernel median over the requested iterations. Compare `output_fnv1a64` with the native CPU command above using the selected archive, tensor, and level. This is a **kernel smoke measurement**, not an end-to-end inference comparison or a model quality result. It does not yet link the decoder into Strata's serving path. Use the original model digest, archive digest, driver/CUDA versions, GPU, tensor, cache state, and iteration count when recording results.
Before any CUDA allocation, the smoke program checks the selected prefix, F32 output, and optional row ID against currently free VRAM. It leaves at least 512 MiB or one sixteenth of total VRAM free, whichever is larger, and refuses the run if that reserve would be crossed. This admission check protects shared GPU experiments; another process can still allocate memory afterward, so CUDA allocation errors remain possible. It is not an inference scheduler.
`--row ROW_ID` selects the CUDA row-gather decoder for one row of a compressed record. The row ID is local to the selected KAR part, so `--row 0` on a split PLE part addresses that part's first row. This mode stages the same complete compressed level prefix with `kar_reserve`, then allocates and writes only one F32 row. It reports `mode=row` and the one-row output checksum. Compare a real-model result with `model checksum-kar-row` on the selected archive and part name; that CPU command verifies the complete archive before bounded range decoding. The one-row synthetic fixture above has the same checksum as its full-tensor decode. Row mode does not reduce the initial PCIe transfer of that part and does not make the full model fit in VRAM.
+31 -5
View File
@@ -143,8 +143,15 @@ int main(int argc, char** argv) {
std::cerr << "smoke tensor must contain 1..100 million elements\n";
return 1;
}
if (row_mode && (tensor->storage_class == KAR_RAW || !tensor->row_words ||
row_id >= tensor->row_count)) {
if (tensor->storage_class == KAR_RAW) {
std::cerr << "smoke requires a compressed KAR record\n";
return 1;
}
if (level < tensor->planes_min || level > tensor->planes_max) {
std::cerr << "level outside the selected record's declared dial\n";
return 1;
}
if (row_mode && (!tensor->row_words || row_id >= tensor->row_count)) {
std::cerr << "row mode requires a compressed record with an addressable row ID\n";
return 1;
}
@@ -155,6 +162,28 @@ int main(int argc, char** argv) {
!cuda_ok(cudaRuntimeGetVersion(&runtime), "cudaRuntimeGetVersion")) {
return 1;
}
const size_t output_elements =
row_mode ? tensor->row_len : static_cast<size_t>(tensor->n_elements);
const size_t output_bytes = output_elements * sizeof(float);
const kar_cost cost = row_mode
? kar_decode_rows_cost(archive, static_cast<uint32_t>(index), level, 1)
: kar_decode_cost(archive, static_cast<uint32_t>(index), level);
if (cost.resident_bytes == 0 || cost.output_bytes != output_bytes ||
cost.resident_bytes > std::numeric_limits<uint64_t>::max() - cost.output_bytes -
(row_mode ? sizeof(row_id) : 0)) {
std::cerr << "selected KAR level has invalid GPU memory geometry\n";
return 1;
}
const uint64_t required_bytes = cost.resident_bytes + cost.output_bytes +
(row_mode ? sizeof(row_id) : 0);
size_t free_bytes = 0, total_bytes = 0;
if (!cuda_ok(cudaMemGetInfo(&free_bytes, &total_bytes), "cudaMemGetInfo")) return 1;
const uint64_t headroom = std::max<uint64_t>(512ull << 20, total_bytes / 16);
if (free_bytes <= headroom || required_bytes > free_bytes - headroom) {
std::cerr << "insufficient GPU memory for isolated KAR smoke: required=" << required_bytes
<< " free=" << free_bytes << " reserved_headroom=" << headroom << '\n';
return 1;
}
cudaStream_t stream = nullptr;
cudaEvent_t start = nullptr, stop = nullptr;
float* output = nullptr;
@@ -164,9 +193,6 @@ int main(int argc, char** argv) {
if (!cuda_ok(cudaStreamCreate(&stream), "cudaStreamCreate") ||
!cuda_ok(cudaEventCreate(&start), "cudaEventCreate") ||
!cuda_ok(cudaEventCreate(&stop), "cudaEventCreate")) break;
const size_t output_elements =
row_mode ? tensor->row_len : static_cast<size_t>(tensor->n_elements);
const size_t output_bytes = output_elements * sizeof(float);
if (!cuda_ok(cudaMalloc(&output, output_bytes), "cudaMalloc")) break;
if (row_mode &&
(!cuda_ok(cudaMalloc(&device_row_id, sizeof(row_id)), "cudaMalloc row ID") ||