← ClaudeAtlas

at-dispatch-v2listed

Convert PyTorch AT_DISPATCH macros to AT_DISPATCH_V2 format in ATen C++ code. Use when porting AT_DISPATCH_ALL_TYPES_AND*, AT_DISPATCH_FLOATING_TYPES*, or other dispatch macros to the new v2 API. For ATen kernel files, CUDA kernels, and native operator implementations.
aiskillstore/marketplace · ★ 329 · Data & Documents · score 79
Install: claude install-skill aiskillstore/marketplace
# AT_DISPATCH to AT_DISPATCH_V2 Converter This skill helps convert PyTorch's legacy AT_DISPATCH macros to the new AT_DISPATCH_V2 format, as defined in `aten/src/ATen/Dispatch_v2.h`. ## When to use this skill Use this skill when: - Converting AT_DISPATCH_* macros to AT_DISPATCH_V2 - Porting ATen kernels to use the new dispatch API - Working with files in `aten/src/ATen/native/` that use dispatch macros - User mentions "AT_DISPATCH", "dispatch v2", "Dispatch_v2.h", or macro conversion ## Quick reference **Old format:** ```cpp AT_DISPATCH_ALL_TYPES_AND3(kBFloat16, kHalf, kBool, dtype, "kernel_name", [&]() { // lambda body }); ``` **New format:** ```cpp AT_DISPATCH_V2(dtype, "kernel_name", AT_WRAP([&]() { // lambda body }), AT_EXPAND(AT_ALL_TYPES), kBFloat16, kHalf, kBool); ``` ## Key transformations 1. **Reorder arguments**: `scalar_type` and `name` come first, then lambda, then types 2. **Wrap the lambda**: Use `AT_WRAP(lambda)` to handle internal commas 3. **Expand type groups**: Use `AT_EXPAND(AT_ALL_TYPES)` instead of implicit expansion 4. **List individual types**: Add extra types (kHalf, kBFloat16, etc.) after expanded groups 5. **Add include**: `#include <ATen/Dispatch_v2.h>` near other Dispatch includes ## Instructions ### Step 1: Add the Dispatch_v2.h include Add the v2 header near the existing `#include <ATen/Dispatch.h>`: ```cpp #include <ATen/Dispatch.h> #include <ATen/Dispatch_v2.h> ``` Keep the old Dispatch.h include for now (other code may still n