at-dispatch-v2
Automated conversion tool for migrating PyTorch ATen C++ code from legacy AT_DISPATCH macros to the modern AT_DISPATCH_V2 API.
Introduction
This skill provides a systematic framework for migrating PyTorch ATen C++ operator implementations from legacy dispatch macros to the modern AT_DISPATCH_V2 architecture. Designed for PyTorch kernel developers and systems engineers, this tool streamlines the porting process by providing standardized transformation rules, argument reordering logic, and macro expansion guidelines defined in the Dispatch_v2.h header file. It targets files within the aten/src/ATen/native directory, ensuring that legacy codebases remain compatible with evolving PyTorch dispatch requirements.
-
Automates the migration of legacy patterns such as AT_DISPATCH_ALL_TYPES_AND* and AT_DISPATCH_FLOATING_TYPES_AND* to the unified AT_DISPATCH_V2 format.
-
Provides clear mapping tables for type group expansion, ensuring correct usage of AT_EXPAND() for base type sets like AT_ALL_TYPES, AT_INTEGRAL_TYPES, and AT_FLOATING_TYPES.
-
Encapsulates lambda expressions using AT_WRAP to handle complex C++ code blocks containing internal commas or multi-line logic.
-
Standardizes header management by integrating #include <ATen/Dispatch_v2.h> alongside existing dispatch dependencies.
-
Supports granular control over type lists, allowing developers to append specific types like kBFloat16, kHalf, or kBool after applying broad type group macros.
-
Identify legacy dispatch macros in kernel implementations, including ATen native operators and CUDA kernels.
-
Replace macros systematically by reordering arguments to place the scalar_type and operator name at the beginning of the call.
-
Wrap lambda bodies using AT_WRAP to maintain correct C++ macro parsing during pre-processing.
-
Apply the correct AT_EXPAND macro for the specific type category involved, such as AT_ALL_TYPES_AND_COMPLEX or AT_BAREBONES_UNSIGNED_TYPES.
-
Verify the final transformation against the required signature: AT_DISPATCH_V2(scalar_type, name, lambda, type_groups, individual_types).
-
Ensure that individual types follow the type groups without being wrapped in AT_EXPAND, as per the API specification.
Repository Stats
- Stars
- 181
- Forks
- 24
- Open Issues
- 4
- Language
- Python
- Default Branch
- main
- Sync Status
- Idle
- Last Synced
- Apr 29, 2026, 02:12 PM