[Pallas:Triton] Mask out-of-bounds memory accesses for unaligned blocks
When a BlockSpec dimension exceeds the underlying array dimension, does not
evenly divide the array dimension (`dim_size % dim_block_size != 0`), or has
unaligned start indices (`start_align % dim_block_size != 0`), Pallas Triton
lowering previously emitted unmasked `tt.load`, `tt.store`, and
`tt.atomic_rmw` instructions spanning the entire block. This caused
out-of-bounds reads and writes past the end of the allocated XLA buffer,
leading to silent memory corruption or hardware page faults
(`CUDA_ERROR_ILLEGAL_ADDRESS`) when the buffer is placed at the upper end of
the BFC arena.
- Compute `bounds_mask` (`dim_offsets < dim_size`) in
`_compute_offsets_from_indices` whenever `dim_size % dim_block_size != 0`
or `start_align % dim_block_size != 0`, and propagate it through
`_compute_pointers_from_indices` to load, swap, addupdate, and atomic RMW
lowering rules.
- Update `_is_contiguous_int4` and `_reinterpret_int4_as_uint8` to require an
even last dimension size and halve `block_shape[-1]` and
`start_indices_alignment[-1]`.
- Convert and broadcast scalar `val`/`value` arguments via
`_ensure_ir_value` and `_bcast_to` in swap, addupdate, and atomic RMW
lowering rules so scalar constants work with non-None `bounds_mask`.
- Fix `_atomic_lowering_rule` in `primitives.py` to check
`lowering._element_type(val.type)` instead of `val.type` when selecting
integer vs. floating-point atomic RMW ops for tensor arguments.
- Add `test_block_shape_larger_than_shape_masked` with Triton MLIR IR
verification and execution checks.
PiperOrigin-RevId: 983770835