Skip to content

fix(das): never read outside the IQ data for out-of-range ALG1 samples - #4

Merged
jvoor merged 1 commit into
mainfrom
fix/das-alg1-oob-select
Oct 12, 2026
Merged

jvoor merged 1 commit into
mainfrom
fix/das-alg1-oob-select

Conversation

@jvoor

@jvoor jvoor commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

das_alg1_kernel zeroes the weight of a sample whose index falls outside [0, samples - 2], but still loads x[k] and x[k + 1] at that index. The load can land before or past the IQ buffer -- an illegal address for deep voxels whose offset + range exceeds the recording, and a NaN in the output whenever the value it returns is not finite (0 * NaN). Closes #2.

The guard is branch-free: the load index is clamped into the channel's row (k -> 0 when out of range) and the interpolated value is replaced by an exact zero through a select, so the warp keeps main's control flow and a NaN/Inf at the clamped sample cannot reach the accumulator. The second interpolation tap steps by 1, or by 0 for a 1-sample recording, so the clamped pair stays in range for every samples >= 1. Outputs are bit-identical to main whenever the data is finite. The sparse path shares the kernel and is covered too.

Tests: the reproduction from Issue #2; reads before the start and past the end of a NaN-padded buffer (float32 / complex64, batch 1 / 3 / 16, dense and sparse); NaN in the first or last sample of every row; a 1-sample recording.

das_alg1_kernel zeroes the weight of a sample whose index falls outside
[0, samples - 2], but still loads x[k] and x[k + 1] at that index. The load
can land before or past the IQ buffer -- an illegal address for deep voxels
whose offset + range exceeds the recording, and a NaN in the output whenever
the value it returns is not finite (0 * NaN). Closes #2.

The guard is branch-free: the load index is clamped into the channel's row
(k -> 0 when out of range) and the interpolated value is replaced by an exact
zero through a select, so the warp keeps main's control flow and a NaN/Inf at
the clamped sample cannot reach the accumulator. The second interpolation tap
steps by 1, or by 0 for a 1-sample recording, so the clamped pair stays in
range for every samples >= 1. Outputs are bit-identical to main whenever the
data is finite. The sparse path shares the kernel and is covered too.

Measured on a real 4D-TEE problem (192 channels, 16 diverging waves, 255
samples, 7.95 M voxels, locked 1200 MHz, Quadro RTX 6000): within +0.6 % of
main at batch 1-4, +1.1 % at batch 16-32 when every voxel fits the
recording, and 2.0-2.6 % faster than main at batch 4-32 when 15 % of the
voxels overshoot it. Branching around the load (#3) measured +1.9 % / +3.8 %.

Tests: the reproduction from #2; reads before the start and past the end of
a NaN-padded buffer (float32 / complex64, batch 1 / 3 / 16, dense and sparse);
NaN in the first or last sample of every row; a 1-sample recording.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U7SVxqLx9EQwHmAi1kK7JA
Copilot AI balanced review requested due to automatic review settings October 12, 2026 13:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused kernel fix correctly prevents invalid reads and is comprehensively covered by regression tests.

0 open findings

What changed in this PR

Prevents ALG1 from reading outside IQ buffers for invalid interpolation indices while preserving zero contribution behavior.

Changes:

  • Clamps invalid sample loads and safely handles one-sample recordings.
  • Adds dense, sparse, batched, real, complex, and NaN regression tests.
File Description
src/​das/​das_alg1_kernels.cuh Safely clamps ALG1 interpolation loads.
bindings/​python/​tests/​test_das.py Covers out-of-range and single-sample cases.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@luuk-verhoef

Copy link
Copy Markdown
Collaborator

Looks good.

@jvoor jvoor reopened this Oct 12, 2026
@jvoor
jvoor merged commit 43173e3 into main Oct 12, 2026
2 checks passed
@jvoor
jvoor deleted the fix/das-alg1-oob-select branch October 12, 2026 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

das_alg1 reads IQ out of bounds for deep voxels

3 participants