Skip to content

[REQ] Add support for tile slicing syntax, including fancy indexing #1176

@daedalus5

Description

@daedalus5

Feature Request: NumPy-Style Slicing for Warp Tiles

Problem

Warp tiles currently lack slicing syntax support. While tile_view() exists, it requires explicit offset and shape parameters rather than the familiar NumPy slicing notation that users expect.

Current approach with tile_view():

@wp.kernel
def process_tile(data: wp.array2d(dtype=float)):
    t = wp.tile_load(data, shape=(64, 64))
    
    # Extract rows 10-20
    subset = wp.tile_view(t, offset=(10, 0), shape=(10, 64))
    
    # Extract a single row — requires knowing the full shape
    row = wp.tile_view(t, offset=(5, 0), shape=(1, 64))

What we want:

@wp.kernel
def process_tile(data: wp.array2d(dtype=float)):
    t = wp.tile_load(data, shape=(64, 64))
    
    # NumPy-style slicing
    subset = t[10:20, :]
    row = t[5, :]
    cols = t[:, 0:32]
    strided = t[::2, ::2]

    # Slice assignment
    t[0:8, :] = wp.tile_ones(shape=(8, 64), dtype=float)

Additionally, there's no support for index array slicing (fancy indexing), which is essential for gathering non-contiguous elements:

@wp.kernel
def gather_elements(data: wp.array2d(dtype=float)):
    t = wp.tile_load(data, shape=(64, 64))
    
    # Gather specific rows by index
    indices = wp.tile_arange(0, 8, dtype=int) * 8  # [0, 8, 16, 24, 32, 40, 48, 56]
    selected_rows = t[indices, :]  # Not currently possible

Implementation Notes

Relationship to Existing APIs

  • tile_view(t, offset, shape) — Should remain as the explicit API; basic slice syntax (e.g., t[0:8, :]) compiles down to tile_view calls
  • tile_slice_indexed (new primitive) — Index array slicing (e.g., t[indices, :]) would require a new gather operation
  • tile_extract(t, i, j, ...) — Unchanged; extracts scalar elements
  • t[i] — Existing integer indexing unchanged; reduces dimensionality

Compile-Time vs Runtime

Slice bounds should be compile-time constants for optimal code generation, consistent with existing tile shape requirements. The compiler can verify bounds at compile time when constants are used.

Metadata

Metadata

Assignees

Labels

feature requestRequest for something to be added

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions