Skip to content

operators: propagate dtype into AIERuntimeArgSpec - #179

Open
atassis wants to merge 1 commit into
amd:develfrom
atassis:fix/argspec-dtype-not-propagated
Open

operators: propagate dtype into AIERuntimeArgSpec#179
atassis wants to merge 1 commit into
amd:develfrom
atassis:fix/argspec-dtype-not-propagated

Conversation

@atassis

@atassis atassis commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Problem

AIERuntimeArgSpec.dtype defaults to bfloat16, and none of the three get_arg_spec() implementations pass dtype=. So the spec reports bf16 regardless of what the design actually moves.

Concretely, GEMM(dtype_in='i8', dtype_out='i32') reports its C arg spec as bfloat16 -- 32768 bytes -- while the design DMAs int32, 65536 bytes. A caller sizing a host buffer from the spec under-allocates by 2x. The same 2x applies to StridedCopy and Repeat with a non-default dtype.

Two in-tree consumers size buffers off that value: test_utils.py's XRTTensor sizing and sequence.py's calculate_buffer_layout.

The defect is latent today -- a grep of every constructor call site in iron/ shows nothing currently passes a non-default dtype -- so this is a landmine rather than a live failure.

Fix

Pass the dtype through at the 7 call sites across 3 operator files: dtype=self.dtype for strided_copy and repeat, dtype=str_to_dtype(self.dtype_in/out) for gemm.

The two supporting commits are what the new test needs: comparison.py gains a strict comparison so exact equality is expressible, and conftest.py no longer aborts the whole session on an unparametrized test.

Test

New iron/tests/common/arg_spec_dtype.py, 6 device-free cases.

Verified red-then-green by hand rather than only after: 5 of 6 fail before the change, 6 of 6 pass after. (Run by importing the module and calling the test functions directly -- conftest.py resolves the device at collection time, so even pytest --collect-only would open the NPU.)

Both consumers confirmed to compute correct byte counts after the fix, and the change is a byte-for-byte no-op on every in-tree caller's default-dtype path.

black clean.

Known limitation

pr/strided-copy-transfer-size also rewrites get_arg_spec() for an unrelated shape bug. Whichever lands second will need a small reconcile.

strided_copy/repeat/gemm build AIERuntimeArgSpec without a dtype kwarg, so
every returned spec silently reports the dataclass default (bfloat16)
regardless of the operator's own dtype field(s). The two real consumers
(test_utils.py's XRTTensor(spec.shape, dtype=spec.dtype), sequence.py's
calculate_buffer_layout) size buffers off spec.dtype, so a non-default-dtype
caller under- or over-allocates by the itemsize ratio -- GEMM(dtype_in='i8',
dtype_out='i32') declared a 2-byte C buffer for an actual 4-byte int32
output. Latent: every in-tree caller uses the default today. Mirrors
dequant/op.py's existing correct pattern.
@atassis
atassis force-pushed the fix/argspec-dtype-not-propagated branch from 2db0521 to a8b0c95 Compare August 31, 2026 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant