Add Unsigned Integer Support
Introduction
The Add Unsigned Integer Support skill is a specialized utility designed for PyTorch contributors and core developers. It streamlines the process of expanding operator type coverage to include unsigned integer types (uint16, uint32, and uint64).
In the PyTorch ecosystem, adding support for new dtypes often involves complex updates to C++ dispatch macros. This skill automates the heavy lifting by analyzing existing kernel implementations and applying the correct AT_DISPATCH_V2 transformations.
Key Features:
- Automatic V2 Conversion: Detects legacy
AT_DISPATCHmacros and upgrades them to the modernV2format before adding new types. - Intelligent Type Grouping: Automatically decides whether to use
AT_BAREBONES_UNSIGNED_TYPESor upgrade existing groups toAT_INTEGRAL_TYPES_V2. - Multi-Site Consistency: Identifies and updates all relevant dispatch sites (CPU, CUDA, etc.) within a file to ensure uniform type support.
- Semantic Validation: Ensures that unsigned types are only added to operators where they are mathematically and logically applicable.
Installation
To use this skill within your Claude Code environment, ensure you are working within the pytorch/pytorch repository.
- Configure the skill: Add the skill definition to your local
.claude/skillsdirectory or include it in your project instructions. - Verify environment: Ensure you have the necessary PyTorch development headers available, as the skill performs static analysis on C++ source files.
# Example: Adding the skill to your projectcp add-uint-support.md .claude/skills/Usage
This skill is triggered when you need to expand the functionality of PyTorch kernels. You can invoke it by describing the operator you want to update or by referencing specific “unsigned types” or “barebones” support.
Example Prompts:
- “Add unsigned integer support to the
min_valuesCUDA kernel.” - “Enable uint16 and uint32 for the element-wise addition operator.”
- “Check if
native_batch_norm.cppsupports barebones unsigned types and update if necessary.”
The Decision Workflow
The skill follows a structured logic to ensure code integrity:
- Check for V2: If a file uses the old
AT_DISPATCHmacro, it first runs theat-dispatch-v2skill. - Analyze Groups: It looks for
AT_INTEGRAL_TYPESorAT_ALL_TYPES. - Transform:
- If
AT_INTEGRAL_TYPESis present, it replaces it withAT_INTEGRAL_TYPES_V2. - Otherwise, it explicitly appends
AT_BAREBONES_UNSIGNED_TYPESto the dispatch list.
- If
Code Reference
Before Transformation:
AT_DISPATCH_V2(dtype, "op", AT_WRAP([&]() { kernel<scalar_t>();}), AT_EXPAND(AT_ALL_TYPES));After Transformation:
AT_DISPATCH_V2(dtype, "op", AT_WRAP([&]() { kernel<scalar_t>();}), AT_EXPAND(AT_ALL_TYPES), AT_EXPAND(AT_BAREBONES_UNSIGNED_TYPES));Note: This skill specifically targets
uint16,uint32, anduint64. Note thatkByte(uint8) is handled separately in PyTorch’s legacy type groups.
Constraints & Edge Cases
- Floating Point Only: The skill will skip operators that are semantically restricted to floating-point types (e.g., certain transcendental functions).
- Complex Types: Unsigned types are added alongside complex types without conflict.
- Manual Verification: While the skill automates the macro updates, developers are encouraged to run functional tests to ensure the underlying kernel logic handles unsigned overflows correctly.