Skip to content

Indexing: tile-grid scans, device mask packing, device folded offsets, repeat - #39

Open
AdvaitTahilyani wants to merge 9 commits into
scale/23-jit-param-limitfrom
scale/24-index-data-movement
Open

AdvaitTahilyani wants to merge 9 commits into
scale/23-jit-param-limitfrom
scale/24-index-data-movement

Conversation

@AdvaitTahilyani

@AdvaitTahilyani AdvaitTahilyani commented Nov 5, 2026 •

Copy link
Copy Markdown
  • EXPAND/COMPRESS/MASK_SCATTER row offsets now come from a two-level scan over the tile grid. This replaces the single coordinator that sorted every row segment.
  • Unaligned masks are packed on the device and sent as device messages, or via CUDA IPC within a node.
  • Folded (>3-D) fancy-indexing offsets are built on the device.
  • Scalar repeat with axis=None or 1-D input no longer builds an int64 index array (N-D input with an axis still gathers with arange(n*r) // r).
  • Device index arrays on >3-D arrays get one blocking min/max get for the bounds check, so out-of-range entries raise IndexError; non-integer repeat counts raise TypeError.
Case 1 GPU 4 GPUs
Unaligned compress, 8191² 472 → 11 ms 154 → 6 ms
Folded F[idx] (before the bounds check) 621 → 3 ms 701 → 6 ms

Adds test_index_scale (244 checks).

🤖 Generated with Claude Code

…, repeat

- Index ops: row offsets by a scan of the tile grid
- Unaligned masks: device pack and device message
- repeat: scalar counts without an index array, host counts on the device
- Folded arrays: index-array offsets built on the device
- test_index_scale: unaligned masks, tile-grid scans, repeat, folded index arrays
- COMPRESS / MASK_SCATTER / EXPAND elements: CUDA IPC to processes on the host
- Index ops review fixes: kind-first dispatch, procNum, folded basic keys

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@adityapb adityapb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verdict: approve with nits.

I checked two parts with NumPy models:

  • The frontend _folded_plan, copied verbatim, plus a model of the backend GATHER rules, compared with x[key] for 24 keys on 4-D and 5-D arrays: all match.
  • The row-offset scan on 300 random views with uneven tiles, offsets, steps and random message order: all correct.

Line numbers are at this PR's head.

  1. [minor, regression] Out-of-range device indices on >3-D arrays are now dropped instead of raising.
    • _folded_plan (indexing.py:633-634) now uses _wrap_device(..., oob). Before, _host_key fetched device index arrays and NumPy raised IndexError.
    • Example: x = cnp.asarray(np.zeros((2,3,4,5))); x[cnp.asarray([0, 2])] used to raise and now returns a block of zeros.
    • The folded.py docstring doesn't mention it, and test_index_scale.py:203 uses a host list, so the test doesn't cover it.
  2. [minor] The float device-repeats crash from #21 still reaches the new root abort (executor_indexing.cpp:1022). This PR added casting="safe" for host counts (indexing.py:946) but not for device counts.
  3. Nit: "scalar repeat no longer builds an int64 index array" only holds for axis=None or 1-D input. N-D input with an axis still builds arange(n*r) // r (indexing.py:940-943).
  4. Nit: there are no tests for:
    • a duplicate-index scatter on folded arrays;
    • out-of-range device indices on folded arrays;
    • float device repeats.

…ger repeats

Folded device index arrays (mode "raise") get one blocking min/max get, so an
out-of-range entry raises IndexError as before instead of being dropped. Device
repeats must cast safely to int64 (float counts aborted the server), as must
scalar repeats. Tests: OOB folded device indices, duplicate-index scatter on
folded arrays, float device repeats.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AdvaitTahilyani

Copy link
Copy Markdown
Author
  1. [minor, regression] OOB device indices on >3-D arrays are dropped: fixed in c4498c7 (one blocking min/max get per device index array in raise mode; folded.py docstring updated)
  2. [minor] float device repeats abort: fixed in c4498c7 (safe cast to int64 for device and scalar counts, TypeError like NumPy)
  3. repeat claim: description fixed (axis=None or 1-D only)
  4. missing tests: added in c4498c7 (duplicate-index scatter on folded arrays with device/host/mixed keys, OOB device indices for get/set including negative values, float device/scalar repeats)

Validated: CPU regress +p1/+p2 (orig 15/15, ports 25/25, ops 34/34, test_index_scale 244 checks).

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.

2 participants