Skip to content

perf(kernels): let triton_op kernels assume TensorRT's tensor alignment - #4875

Open
narendasan wants to merge 1 commit into
mainfrom
narendasan/triton-op-alignment
Open

narendasan wants to merge 1 commit into
mainfrom
narendasan/triton-op-alignment

Conversation

@narendasan

@narendasan narendasan commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • compile_triton_to_ptx built Triton's ASTSource without attrs, so AOT-compiled triton_op kernels treated every pointer parameter as possibly unaligned. Under the JIT, a tensor whose data_ptr() is 16-byte aligned gets tt.divisibility=16, and that specialization is what allows vectorized global loads and stores; the AOT path silently lost it.
  • Specialize every pointer parameter as 16-byte aligned, keyed by its position in the kernel's full parameter list (constexprs included). This is TensorRT's contract: addresses passed to IExecutionContext::setTensorAddress must be at least 256-byte aligned, and TensorRT allocates the engine's internal tensors itself. Integer arguments stay unspecialized, since nothing guarantees their divisibility.
  • Effect: an NVFP4 GEMV that unpacks uint8 weights compiled to ld.global.b8 and averaged 14.0 us per call inside the engine vs 9.5 us under the JIT. With this change it matches the JIT, and a 4B-parameter decode step (Nemotron-Labs Dory, RTX 5090) drops from 5.21 ms to 4.13 ms.

Tests

  • pytest tests/py/kernels: 247 passed, 34 skipped.
  • New test_pointer_args_specialized_as_aligned (stub: exactly the pointer parameters are marked, at their positions in the full signature) and test_aot_ptx_uses_vector_loads (real compile: an unmasked copy emits ld.global.v4). Both fail without the change.
  • The ISA-capping stub tests now pass a _FakeKernel with real argument names instead of object(), because the attrs are computed from kernel.arg_names.
  • Independent of fix(plugins): lower floor division in generated plugin output shapes #4876 and fix(kernels): reject triton_op kernels needing more than 48 KiB of shared memory #4877 (the other fixes from the same work) and landable in any order: with all three merged onto main, pytest tests/py/kernels tests/py/dynamo/automatic_plugin/test_automatic_plugin_shape_exprs.py gives 250 passed, 34 skipped.
  • Run on an RTX 5090 with TensorRT 11.3 and Triton 3.8: main's Python against a locally built runtime.

🤖 Generated with Claude Code

`compile_triton_to_ptx` built its `ASTSource` without `attrs`, so Triton
compiled every pointer parameter as possibly unaligned. Under the JIT, any
tensor whose `data_ptr()` is 16-byte aligned gets `tt.divisibility=16`, and
that specialization is what allows vectorized global loads and stores; the AOT
path silently lost it. Memory-bound kernels pay for it: an NVFP4 GEMV that
unpacks uint8 weights compiled to `ld.global.b8` and ran ~1.5x slower inside
the engine (14.0 us average per call) than the same kernel under the JIT
(9.5 us); with this change it matches the JIT, taking a 4B-parameter decode
step from 5.21 ms to 4.13 ms on an RTX 5090.

The specialization is safe because it is TensorRT's contract: addresses passed
to `IExecutionContext::setTensorAddress` must be at least 256-byte aligned, and
TensorRT allocates the engine's internal tensors itself. Integer arguments are
left unspecialized since nothing guarantees their divisibility.

Tests: the ISA-capping stubs now pass a kernel with real argument names (the
attrs are keyed by position in the full parameter list, constexprs included),
a stub test asserts exactly the pointer parameters are marked, and a real
compile asserts an unmasked copy emits `ld.global.v4`. Both new tests fail
without the change. `pytest tests/py/kernels`: 247 passed, 34 skipped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@narendasan
narendasan force-pushed the narendasan/triton-op-alignment branch from d623644 to 36a5d91 Compare November 23, 2026 23:06
@narendasan
narendasan requested a review from bowang007 November 23, 2026 23:24
@narendasan narendasan added this to the v2.16.0 milestone Nov 23, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signed component: api [Python] Issues re: Python API component: tests Issues re: Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant