What problem does it solve?
PyTorch CUDA kernels can silently overflow when tensor sizes exceed 2^31 elements, producing wrong results or memory errors. This Skill classifies the overflow site and applies the correct fix pattern without unnecessarily inflating binary size or slowing hot loops.
Core Features & Use Cases
- Overflow Site Classification: Distinguishes one-time setup offsets, hot per-element indexing, grid-dimension overflow, and 32-bit-only algorithms.
- Canonical Utilities: Uses
canUse32BitIndexMath, AT_DISPATCH_INDEX_TYPES, and CUDA_KERNEL_LOOP_TYPE instead of ad hoc checks.
- Fix Patterns: Provides localized 64-bit casts, templated grid-stride kernels, strided TensorInfo dispatch, and early
TORCH_CHECK failure for size-limited ops.
- Binary-Size and Performance Tradeoffs: Guides when to template on
index_t versus a single local cast, with commands to measure object/library size and symbol multiplication.
- Regression Tests: Adds boundary-crossing tests guarded by
@largeTensorTest and validates with compute-sanitizer.
Quick Start
Review the failing CUDA kernel, identify the exact expression that overflows 32-bit indexing, and apply the matching fix pattern from this skill.