restructured original into implexa 6-component format with explicit decision points, edge case handling, and added deployment context (auth, connections, validation steps).
Add Unsigned Integer (uint) Support to Operators
intent
add unsigned integer type support (uint16, uint32, uint64) to PyTorch operators by modifying their AT_DISPATCH_V2 macros. use this when an operator needs to accept unsigned integer tensors, when converting dispatch macros to V2 format with uint support, or when a user explicitly requests unsigned type support for a kernel or operator.
inputs
required context:
- target file path (cpp implementation file containing AT_DISPATCH macros)
- operator or kernel name that needs uint support
- current AT_DISPATCH macro format (old AT_DISPATCH or AT_DISPATCH_V2)
external connections:
- none (local code modification only)
setup:
- read access to pytorch source tree
- write access to target cpp file
- understanding of AT_DISPATCH macro syntax in pytorch codebase
edge cases to handle:
- file uses old AT_DISPATCH format (requires at-dispatch-v2 skill first)
- operator only supports floating point types (skip uint addition)
- uint support already present (identify via AT_INTEGRAL_TYPES_V2 or AT_BAREBONES_UNSIGNED_TYPES)
- multiple dispatch sites in same file need consistent updates
- rate limits: none (local operation)
- auth: none required
procedure
step 1: verify dispatch format
- input: target file path
- read the file and locate all AT_DISPATCH calls
- check if using AT_DISPATCH_V2 format
- output: list of dispatch sites and their current format
step 2: assess if v2 conversion needed
- input: dispatch format from step 1
- if using old AT_DISPATCH (AT_DISPATCH_ALL_TYPES, AT_DISPATCH_ALL_TYPES_AND2, etc.), flag that at-dispatch-v2 skill must run first
- if already AT_DISPATCH_V2, proceed to step 3
- output: decision to convert or continue
step 3: analyze type groups in current dispatch
- input: AT_DISPATCH_V2 macros from file
- for each dispatch site, identify type groups: AT_ALL_TYPES, AT_INTEGRAL_TYPES, AT_FLOATING_TYPES, AT_COMPLEX_TYPES, individual types (kHalf, kBFloat16, kBool)
- note which pattern matches (see common patterns below)
- output: categorized list of dispatch sites and their type coverage
step 4: determine uint addition method
- input: type groups from step 3
- if dispatch contains AT_EXPAND(AT_INTEGRAL_TYPES), choose method 2 (replace with AT_INTEGRAL_TYPES_V2)
- if dispatch contains AT_EXPAND(AT_ALL_TYPES) or individual types, choose method 1 (add AT_BAREBONES_UNSIGNED_TYPES)
- if operator only supports floating types, skip modification
- output: method selection per dispatch site
step 5: apply transformations
- input: method selection from step 4
- method 1: add
AT_EXPAND(AT_BAREBONES_UNSIGNED_TYPES) to the type list in each dispatch macro
- method 2: replace
AT_EXPAND(AT_INTEGRAL_TYPES) with AT_EXPAND(AT_INTEGRAL_TYPES_V2) in each dispatch macro
- maintain consistent formatting (commas, whitespace)
- output: modified cpp file with uint support added
step 6: verify all dispatch sites updated
- input: modified file from step 5
- scan file for any remaining dispatch macros that should have uint support but don't
- ensure each dispatch site that should support integers now includes unsigned types
- output: confirmation of complete coverage
step 7: validate syntax
- input: modified file
- check all AT_DISPATCH_V2 calls use correct syntax:
AT_DISPATCH_V2(dtype, "name", AT_WRAP([&]() { body }), type_groups)
- confirm AT_EXPAND() wraps type groups
- verify comma separation and formatting
- output: pass/fail validation
decision points
if file uses old AT_DISPATCH format (not V2):
- action: inform user that at-dispatch-v2 skill must run first before adding uint support
- do not proceed with uint additions until v2 conversion complete
if dispatch uses AT_EXPAND(AT_INTEGRAL_TYPES):
- use method 2: replace with
AT_EXPAND(AT_INTEGRAL_TYPES_V2)
- this is cleaner and more concise than adding explicit BAREBONES_UNSIGNED_TYPES
if dispatch uses AT_EXPAND(AT_ALL_TYPES):
- use method 1: add
AT_EXPAND(AT_BAREBONES_UNSIGNED_TYPES) to type list
- do not replace AT_ALL_TYPES; just append unsigned types
if operator only supports floating point types (AT_EXPAND(AT_FLOATING_TYPES) only):
- skip uint addition for that operator
- floating point operators have no unsigned integer variants
if uint support already present (AT_INTEGRAL_TYPES_V2 or AT_BAREBONES_UNSIGNED_TYPES already in dispatch):
- skip the file and inform user that uint support is already enabled
if multiple dispatch sites exist in same file:
- apply same method consistently across all sites
- do not mix methods within the same file
if complex types present (AT_EXPAND(AT_COMPLEX_TYPES)):
- add unsigned types alongside complex types
- order: integral (or integral_v2), floating, complex, then individual types
- no ordering conflict with unsigned
output contract
successful uint support addition produces:
- modified cpp file with all relevant dispatch macros updated
- each dispatch now includes unsigned integer types via:
- method 1: explicit
AT_EXPAND(AT_BAREBONES_UNSIGNED_TYPES) line, or
- method 2:
AT_EXPAND(AT_INTEGRAL_TYPES_V2) replacing AT_EXPAND(AT_INTEGRAL_TYPES)
- all syntax correct: proper commas, AT_EXPAND() wrapping, valid AT_DISPATCH_V2 format
- no incomplete modifications (all dispatch sites that need uint support have it)
- file is parseable cpp code
data format:
- cpp source file with AT_DISPATCH_V2 macros
- type groups wrapped in AT_EXPAND()
- barebones unsigned types: kUInt16, kUInt32, kUInt64 (8-bit kByte is signed, not included)
file location:
- same cpp implementation file (in-place modification)
outcome signal
user knows the skill worked when:
- operator accepts uint16, uint32, uint64 tensors at runtime (verified via functional test or inference)
- dispatch macros now include unsigned integer types in their type list
- file compiles without type errors related to unsigned integers
- operator kernels execute correctly for unsigned integer inputs
- no new compiler warnings or errors introduced
- changes shown to user clearly indicate where unsigned types were added (diff or before/after comparison)