Repository navigation
[XPU] Fast static launcher 2/2: Add a fast vectorcall launcher for statically launched XPU kernels. - #200916
[XPU] Fast static launcher 2/2: Add a fast vectorcall launcher for statically launched XPU kernels.#200916etaf wants to merge 19 commits into
Conversation
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". ✅ AUTOMATED REVIEW - Ready for human review:
Reviewed commit: 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/200916
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 1 Unrelated FailureAs of commit d8599ef with merge base 0563a22 ( NEW FAILURE - The following job has failed:
NEW FAILURES SUPPRESSED BY AI (non-blocking) - The following job failed, but the AI CI Advisor judged the failure not to be evidence against this change:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
## Motivation `_StaticXpuLauncher._launch_kernel` re-derives everything but the argument values on every launch: * `PyArg_ParseTuple` over nine arguments. * A capsule tag comparison to get the kernel. * A `strlen` of `arg_tys` to count the arguments. * Per pointer argument: a python `data_ptr()` call, plus a `zeMemGetAllocProperties` validation whose result is discarded. * `StaticallyLaunchedXpuKernel.run` on top of that rebuilds the argument tuple and the `arg_tys` string to append the scratch arguments. None of it can change between launches of the same kernel. Median host time per launch (5 processes, bursts of 32 into a drained queue), through `run()` as inductor calls it today vs through the fast launcher: | kernel arguments | `run()` | fast | | --- | --- | --- | | 1 pointer | 4445 ns | 3204 ns | | 4 pointers | 5866 ns | 3771 ns | | 8 pointers | 7236 ns | 4001 ns | | 16 pointers | 9922 ns | 4708 ns | | 4 pointers + 4 scalars | 6376 ns | 4125 ns | The marginal cost per pointer argument drops from ~370 ns to ~100 ns. On densenet121 inference (bs16, 128x128, 342 launches per iteration, host bound), one compiled iteration goes from ~7.5 ms to ~6.5 ms, and the speedup over eager from ~1.21x to ~1.40x. ## Solution `_FastXpuLauncher`, the XPU sibling of `_FastCudaLauncher`: * Binds the loaded kernel, the work-group size, the argument layout and the shared memory size once. Its vectorcall (PEP 590) slot takes only the grid, the stream and the kernel arguments. * `CachingAutotuner` swaps it into the cached launcher after the first launch, so `run()` is bypassed too. * Pointer arguments are read with `THPVariable_Unpack` + `Tensor::data_ptr()` and are not validated. Inductor codegen guarantees the `'O'` arguments are tensors, as on CUDA; anything else falls back to the generic unpacking. * It holds a reference to the kernel capsule, which owns the `sycl::kernel`. CUDA bakes a raw `CUfunction` and relies on the python side to keep the owner alive; that would leave a use-after-free here, reachable by closing the static kernel. The PR below in this stack split `packKernelArg()` and `submitKernel()` out of the launch path for this, so `xpu.cpp` here is only new code. ## Test `TestFastCudaLauncher` becomes device-generic `TestFastLauncher`, so its CUDA cases cover XPU too, including the float16 / bfloat16 / float64 scalar bit reinterpretation. New cases there, for both devices: * A 2D grid, a `Parameter` and a raw address as pointer arguments, and two launches with different arguments. * Keyword arguments rejected, and the `tp_call` path non-vectorcall callers take. * `_build_fast_launcher` building a real launcher, and a launch through it. New XPU-only `TestFastXpuLauncher`: * A kernel whose shared memory is declared in the binary, which must not get a local accessor bound. Triton emits no XPU kernel that takes one, so neither launcher's bind-local branch has a kernel to exercise it. * Rejections: kernel argument count mismatch, launch metadata that would size the argument layout out of bounds, an object that is not a loaded kernel. * The kernel capsule outliving `StaticallyLaunchedXpuKernel.close()`, and being released when the launcher is. `_build_fast_launcher`'s device dispatch becomes one parametrized test over cuda and xpu, with both launcher types patched so that picking the wrong one fails. `TestFastCudaLauncherCompileResult.test_basic_compile` asserted that XPU never builds a fast launcher, which is no longer true; it now asserts what CUDA does and launches twice, so that the numerics of the swapped-in launcher are checked. It stays skipped on XPU: it was disabled there in #181491 and what failed is not known. This PR was authored with the assistance of an AI agent (Claude). Co-Authored-By: Claude Opus 5 <[email protected]> ghstack-source-id: da96f94 Pull-Request: #200916
…atically launched XPU kernels. `_StaticXpuLauncher._launch_kernel` re-derives everything but the argument values on every launch: * `PyArg_ParseTuple` over nine arguments. * A capsule tag comparison to get the kernel. * A `strlen` of `arg_tys` to count the arguments. * Per pointer argument: a python `data_ptr()` call, plus a `zeMemGetAllocProperties` validation whose result is discarded. * `StaticallyLaunchedXpuKernel.run` on top of that rebuilds the argument tuple and the `arg_tys` string to append the scratch arguments. None of it can change between launches of the same kernel. Median host time per launch (5 processes, bursts of 32 into a drained queue), through `run()` as inductor calls it today vs through the fast launcher: | kernel arguments | `run()` | fast | | --- | --- | --- | | 1 pointer | 4445 ns | 3204 ns | | 4 pointers | 5866 ns | 3771 ns | | 8 pointers | 7236 ns | 4001 ns | | 16 pointers | 9922 ns | 4708 ns | | 4 pointers + 4 scalars | 6376 ns | 4125 ns | The marginal cost per pointer argument drops from ~370 ns to ~100 ns. On densenet121 inference (bs16, 128x128, 342 launches per iteration, host bound), one compiled iteration goes from ~7.5 ms to ~6.5 ms, and the speedup over eager from ~1.21x to ~1.40x. `_FastXpuLauncher`, the XPU sibling of `_FastCudaLauncher`: * Binds the loaded kernel, num_warps, the argument layout and the shared memory size once. Its vectorcall (PEP 590) slot takes only the grid, the stream and the kernel arguments. * `CachingAutotuner` swaps it into the cached launcher after the first launch, so `run()` is bypassed too. * Pointer arguments are read with `THPVariable_Unpack` + `Tensor::data_ptr()` and are not validated. Inductor codegen guarantees the `'O'` arguments are tensors, as on CUDA; anything else falls back to the generic unpacking. * It holds a reference to the kernel capsule, which owns the `sycl::kernel`. CUDA bakes a raw `CUfunction` and relies on the python side to keep the owner alive; that would leave a use-after-free here, reachable by closing the static kernel. The PR below in this stack split `packKernelArg()` and `submitKernel()` out of the launch path for this, so `xpu.cpp` here is only new code. Note that the argument count check `submitKernel()` relies on lives in `launchKernel()`, which this launcher does not go through: it makes that check once, when it is built. `TestFastCudaLauncher` becomes device-generic `TestFastLauncher`, so its CUDA cases cover XPU too, including the float16 / bfloat16 / float64 scalar bit reinterpretation. New cases there, for both devices: * A 2D grid, a `Parameter` and a raw address as pointer arguments, and two launches with different arguments. * Keyword arguments rejected, and the `tp_call` path non-vectorcall callers take. * `_build_fast_launcher` building a real launcher, and a launch through it. New XPU-only `TestFastXpuLauncher`: * A kernel whose shared memory is declared in the binary, which must not get a local accessor bound. Triton emits no XPU kernel that takes one, so neither launcher's bind-local branch has a kernel to exercise it. * Rejections: kernel argument count mismatch, launch metadata that would size the argument layout out of bounds, an object that is not a loaded kernel. * The kernel capsule outliving `StaticallyLaunchedXpuKernel.close()`, and being released when the launcher is. `_build_fast_launcher`'s device dispatch becomes one parametrized test over cuda and xpu, with both launcher types patched so that picking the wrong one fails. `TestFastCudaLauncherCompileResult.test_basic_compile` asserted that XPU never builds a fast launcher, which is no longer true; it now asserts what CUDA does and launches twice, so that the numerics of the swapped-in launcher are checked. It stays skipped on XPU: it was disabled there in #181491 and what failed is not known. This PR was authored with the assistance of an AI agent (Claude). Co-Authored-By: Claude Opus 5 <[email protected]> ghstack-source-id: 530c2d1 Pull-Request: #200916
…atically launched XPU kernels. `_StaticXpuLauncher._launch_kernel` re-derives everything but the argument values on every launch: * `PyArg_ParseTuple` over nine arguments. * A capsule tag comparison to get the kernel. * A `strlen` of `arg_tys` to count the arguments. * Per pointer argument: a python `data_ptr()` call, plus a `zeMemGetAllocProperties` validation whose result is discarded. * `StaticallyLaunchedXpuKernel.run` on top of that rebuilds the argument tuple and the `arg_tys` string to append the scratch arguments. None of it can change between launches of the same kernel. Median host time per launch (5 processes, bursts of 32 into a drained queue), through `run()` as inductor calls it today vs through the fast launcher: | kernel arguments | `run()` | fast | | --- | --- | --- | | 1 pointer | 4445 ns | 3204 ns | | 4 pointers | 5866 ns | 3771 ns | | 8 pointers | 7236 ns | 4001 ns | | 16 pointers | 9922 ns | 4708 ns | | 4 pointers + 4 scalars | 6376 ns | 4125 ns | The marginal cost per pointer argument drops from ~370 ns to ~100 ns. On densenet121 inference (bs16, 128x128, 342 launches per iteration, host bound), one compiled iteration goes from ~7.5 ms to ~6.5 ms, and the speedup over eager from ~1.21x to ~1.40x. `_FastXpuLauncher`, the XPU sibling of `_FastCudaLauncher`: * Binds the loaded kernel, num_warps, the argument layout and the shared memory size once. Its vectorcall (PEP 590) slot takes only the grid, the stream and the kernel arguments. * `CachingAutotuner` swaps it into the cached launcher after the first launch, so `run()` is bypassed too. * Pointer arguments are read with `THPVariable_Unpack` + `Tensor::data_ptr()` and are not validated. Inductor codegen guarantees the `'O'` arguments are tensors, as on CUDA; anything else falls back to the generic unpacking. * It holds a reference to the kernel capsule, which owns the `sycl::kernel`. CUDA bakes a raw `CUfunction` and relies on the python side to keep the owner alive; that would leave a use-after-free here, reachable by closing the static kernel. The PR below in this stack split `packKernelArg()` and `submitKernel()` out of the launch path for this, so `xpu.cpp` here is only new code. Note that the argument count check `submitKernel()` relies on lives in `launchKernel()`, which this launcher does not go through: it makes that check once, when it is built. `TestFastCudaLauncher` becomes device-generic `TestFastLauncher`, so its CUDA cases cover XPU too, including the float16 / bfloat16 / float64 scalar bit reinterpretation. New cases there, for both devices: * A 2D grid, a `Parameter` and a raw address as pointer arguments, and two launches with different arguments. * Keyword arguments rejected, and the `tp_call` path non-vectorcall callers take. * `_build_fast_launcher` building a real launcher, and a launch through it. New XPU-only `TestFastXpuLauncher`: * A kernel whose shared memory is declared in the binary, which must not get a local accessor bound. Triton emits no XPU kernel that takes one, so neither launcher's bind-local branch has a kernel to exercise it. * Rejections: kernel argument count mismatch, launch metadata that would size the argument layout out of bounds, an object that is not a loaded kernel. * The kernel capsule outliving `StaticallyLaunchedXpuKernel.close()`, and being released when the launcher is. `_build_fast_launcher`'s device dispatch becomes one parametrized test over cuda and xpu, with both launcher types patched so that picking the wrong one fails. `TestFastCudaLauncherCompileResult.test_basic_compile` asserted that XPU never builds a fast launcher, which is no longer true; it now asserts what CUDA does and launches twice, so that the numerics of the swapped-in launcher are checked. It stays skipped on XPU: it was disabled there in #181491 and what failed is not known. This PR was authored with the assistance of an AI agent (Claude). Co-Authored-By: Claude Opus 5 <[email protected]> ghstack-source-id: bfa57c2 Pull-Request: #200916
…atically launched XPU kernels. `_StaticXpuLauncher._launch_kernel` re-derives everything but the argument values on every launch: * `PyArg_ParseTuple` over nine arguments. * A capsule tag comparison to get the kernel. * A `strlen` of `arg_tys` to count the arguments. * Per pointer argument: a python `data_ptr()` call, plus a `zeMemGetAllocProperties` validation whose result is discarded. * `StaticallyLaunchedXpuKernel.run` on top of that rebuilds the argument tuple and the `arg_tys` string to append the scratch arguments. None of it can change between launches of the same kernel. Median host time per launch (5 processes, bursts of 32 into a drained queue), through `run()` as inductor calls it today vs through the fast launcher: | kernel arguments | `run()` | fast | | --- | --- | --- | | 1 pointer | 4445 ns | 3204 ns | | 4 pointers | 5866 ns | 3771 ns | | 8 pointers | 7236 ns | 4001 ns | | 16 pointers | 9922 ns | 4708 ns | | 4 pointers + 4 scalars | 6376 ns | 4125 ns | The marginal cost per pointer argument drops from ~370 ns to ~100 ns. On densenet121 inference (bs16, 128x128, 342 launches per iteration, host bound), one compiled iteration goes from ~7.5 ms to ~6.5 ms, and the speedup over eager from ~1.21x to ~1.40x. `_FastXpuLauncher`, the XPU sibling of `_FastCudaLauncher`: * Binds the loaded kernel, num_warps, the argument layout and the shared memory size once. Its vectorcall (PEP 590) slot takes only the grid, the stream and the kernel arguments. * `CachingAutotuner` swaps it into the cached launcher after the first launch, so `run()` is bypassed too. * Pointer arguments are read with `THPVariable_Unpack` + `Tensor::data_ptr()` and are not validated. Inductor codegen guarantees the `'O'` arguments are tensors, as on CUDA; anything else falls back to the generic unpacking. * It holds a reference to the kernel capsule, which owns the `sycl::kernel`. CUDA bakes a raw `CUfunction` and relies on the python side to keep the owner alive; that would leave a use-after-free here, reachable by closing the static kernel. The PR below in this stack split `packKernelArg()` and `submitKernel()` out of the launch path for this, so `xpu.cpp` here is only new code. Note that the argument count check `submitKernel()` relies on lives in `launchKernel()`, which this launcher does not go through: it makes that check once, when it is built. `TestFastCudaLauncher` becomes device-generic `TestFastLauncher`, so its CUDA cases cover XPU too, including the float16 / bfloat16 / float64 scalar bit reinterpretation. New cases there, for both devices: * A 2D grid, a `Parameter` and a raw address as pointer arguments, and two launches with different arguments. * Keyword arguments rejected, and the `tp_call` path non-vectorcall callers take. * `_build_fast_launcher` building a real launcher, and a launch through it. New XPU-only `TestFastXpuLauncher`: * A kernel whose shared memory is declared in the binary, which must not get a local accessor bound. Triton emits no XPU kernel that takes one, so neither launcher's bind-local branch has a kernel to exercise it. * Rejections: kernel argument count mismatch, launch metadata that would size the argument layout out of bounds, an object that is not a loaded kernel. * The kernel capsule outliving `StaticallyLaunchedXpuKernel.close()`, and being released when the launcher is. `_build_fast_launcher`'s device dispatch becomes one parametrized test over cuda and xpu, with both launcher types patched so that picking the wrong one fails. `TestFastCudaLauncherCompileResult.test_basic_compile` asserted that XPU never builds a fast launcher, which is no longer true; it now asserts what CUDA does and launches twice, so that the numerics of the swapped-in launcher are checked. It stays skipped on XPU: it was disabled there in #181491 and what failed is not known. This PR was authored with the assistance of an AI agent (Claude). Co-Authored-By: Claude Opus 5 <[email protected]> ghstack-source-id: 55354a0 Pull-Request: #200916
Merge failedReason: HTTP Error 502: Bad Gateway Details for Dev Infra teamRaised by workflow job |
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: 1 jobs have failed, first few of them are: xpu / linux-noble-xpu-n-py3.11 / test (default, 8, 12, linux.idc.xpu) Details for Dev Infra teamRaised by workflow job |
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 2 checks: xpu / linux-noble-xpu-n-py3.11 / test (default, 10, 12, linux.idc.xpu) (#200916), xpu / linux-noble-xpu-n-py3.11 / test (default, 8, 12, linux.idc.xpu) (#200916) Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…the new launcher. (#201004) ## Motivation #200916 adds `_FastXpuLauncher`, a vectorcall launcher that binds a kernel's launch properties once instead of re-deriving them on every launch. Almost everything it still has to do per launch, `_StaticXpuLauncher` already does: pack each argument into an 8-byte slot according to its type code, and submit the kernel with those slots. The goal of this PR is to let the new launcher **reuse** that code rather than copy it. Without it, `_FastXpuLauncher` would carry its own copy of the 13-case packing switch and of the submit, and the two copies would drift apart. Splitting it out also keeps #200916 reviewable: with this landed, the `xpu.cpp` diff there is new code only. ## Solution No behavior change, except for the last point. * `packKernelArg()` packs one argument of one type code. The pointer resolution is a parameter, so each caller chooses how much it validates: the generic launcher keeps its `zeMemGetAllocProperties` check, the new one skips it. `parseKernelArgs()` is the loop over the argument tuple around it. * `submitKernel()` submits with an argument layout the caller resolved: the work-group size, the argument count, and whether to bind dynamic shared memory. `launchKernel()` derives those per launch, as before; the new launcher resolves them once, when it is built. * `kernelArgs`, the per-launch array of pointers into `argStorage`, is gone. It came over with the code this file was copied from: `cuLaunchKernel` takes the kernel arguments as a `void**` of argument *addresses* and copies from each one itself, so on CUDA that array has to exist for the driver to read. SYCL takes one `cgh.set_arg(i, value)` call per argument instead, so the submit loop reads each 8-byte slot directly. Nothing outside that loop ever looked at `kernelArgs[i]`, which was always `&argStorage[i]`. ## Test No new test: this is a refactor of the launch path that every static launcher test already exercises. Pull Request resolved: #201004 Approved by: https://github.com/guangyey
pytorch#200916 removed the module-level `import types` when it deleted TestFastLauncherDeviceSupport, its only user at the time. The new tests in this PR call `types.SimpleNamespace` and rely on that import, so once both landed, lint failed with F821 and this PR was auto-reverted. Restore the import. Test Plan: lintrunner is not installed in this environment. The changed files match the merge commit that CI linted (2d1918a) except for this line, and that lint run's only errors were the two F821s fixed here: ``` git diff 2d1918a -- test/inductor/test_triton_heuristics.py torch/_inductor/codegen/cpp_wrapper_gpu.py torch/_inductor/runtime/hints.py torch/_inductor/runtime/triton_heuristics.py torch/_inductor/runtime/triton_lazy_compile.py python3 -m py_compile test/inductor/test_triton_heuristics.py ``` Authored with an AI assistant (Claude Code).
…the new launcher. (pytorch#201004) ## Motivation pytorch#200916 adds `_FastXpuLauncher`, a vectorcall launcher that binds a kernel's launch properties once instead of re-deriving them on every launch. Almost everything it still has to do per launch, `_StaticXpuLauncher` already does: pack each argument into an 8-byte slot according to its type code, and submit the kernel with those slots. The goal of this PR is to let the new launcher **reuse** that code rather than copy it. Without it, `_FastXpuLauncher` would carry its own copy of the 13-case packing switch and of the submit, and the two copies would drift apart. Splitting it out also keeps pytorch#200916 reviewable: with this landed, the `xpu.cpp` diff there is new code only. ## Solution No behavior change, except for the last point. * `packKernelArg()` packs one argument of one type code. The pointer resolution is a parameter, so each caller chooses how much it validates: the generic launcher keeps its `zeMemGetAllocProperties` check, the new one skips it. `parseKernelArgs()` is the loop over the argument tuple around it. * `submitKernel()` submits with an argument layout the caller resolved: the work-group size, the argument count, and whether to bind dynamic shared memory. `launchKernel()` derives those per launch, as before; the new launcher resolves them once, when it is built. * `kernelArgs`, the per-launch array of pointers into `argStorage`, is gone. It came over with the code this file was copied from: `cuLaunchKernel` takes the kernel arguments as a `void**` of argument *addresses* and copies from each one itself, so on CUDA that array has to exist for the driver to read. SYCL takes one `cgh.set_arg(i, value)` call per argument instead, so the submit loop reads each 8-byte slot directly. Nothing outside that loop ever looked at `kernelArgs[i]`, which was always `&argStorage[i]`. ## Test No new test: this is a refactor of the launch path that every static launcher test already exercises. Pull Request resolved: pytorch#201004 Approved by: https://github.com/guangyey
…atically launched XPU kernels. (pytorch#200916) ## Motivation `_StaticXpuLauncher._launch_kernel` has some overhead on every launch: * `PyArg_ParseTuple` over nine arguments, a capsule tag comparison to get the kernel, and a `strlen` of `arg_tys`. * Per pointer argument: a python `data_ptr()` call, plus a `zeMemGetAllocProperties` validation whose result is discarded. * `StaticallyLaunchedXpuKernel.run` on top of that rebuilds the argument tuple and the `arg_tys` string to append the scratch arguments. None of it can change between launches of the same kernel. Median host time per launch (5 processes, bursts of 32 into a drained queue), through `run()` as inductor calls it today vs through the fast launcher: | kernel arguments | `run()` | fast | | --- | --- | --- | | 1 pointer | 4445 ns | 3204 ns | | 4 pointers | 5866 ns | 3771 ns | | 8 pointers | 7236 ns | 4001 ns | | 16 pointers | 9922 ns | 4708 ns | | 4 pointers + 4 scalars | 6376 ns | 4125 ns | The marginal cost per pointer argument drops from ~370 ns to ~100 ns. On densenet121 inference (bs16, 128x128, 342 launches per iteration, host bound), one compiled iteration goes from ~7.5 ms to ~6.5 ms, and the speedup over eager from ~1.21x to ~1.40x. ## Solution `_FastXpuLauncher`, the XPU sibling of `_FastCudaLauncher`: * Binds the loaded kernel, num_warps, the argument layout and the shared memory size once. Its vectorcall (PEP 590) slot takes only the grid, the stream and the kernel arguments. * `CachingAutotuner` swaps it into the cached launcher after the first launch, so `run()` is bypassed too. * Pointer arguments are read with `THPVariable_Unpack` + `Tensor::data_ptr()` and are not validated, as on CUDA: inductor codegen guarantees the `'O'` arguments are tensors, and anything else falls back to the generic unpacking. * It holds a reference to the kernel capsule, which owns the `sycl::kernel`. CUDA bakes a raw `CUfunction` and relies on the python side to keep the owner alive; doing that here would leave a use-after-free reachable by closing the static kernel. It reuses `packKernelArg()` and `submitKernel()`, which pytorch#201004 split out of the launch path, so `xpu.cpp` here is new code only. Pull Request resolved: pytorch#200916 Approved by: https://github.com/jansel ghstack dependencies: pytorch#201004
…r hw classes (#198439) ## Summary Make `TestFastLauncher` in `test/inductor/test_static_triton_launcher.py` hardware-classified and instantiated for both CUDA and XPU, keeping every test that ran before the split running after it. Split from #192893 (one test class per PR, zero overlap), rebased onto main after #200916 renamed `TestFastCudaLauncher` to `TestFastLauncher` and moved the shared helpers into `StaticLauncherTestMixin`. ## Changes - `TestFastLauncher` declares `hw_classification = HardwareClassification.ACCELERATOR` and is instantiated with `only_for=("cuda", "xpu"), allow_xpu=True` (the in-tree combination used by e.g. test_comparison_utils.py, test_gpu_trace.py, test/dynamo/test_after_aot.py). Five tests (`test_basic`, `test_multiple_tensor_args`, `test_zero_grid`, `test_wrong_arg_count`, `test_too_many_args_raises_value_error`) take the injected `device` argument; the remaining tests resolve `GPU_TYPE`, which equals the running device on the CUDA and XPU single-device-type CI runners. - The five XPU-specific tests (`test_xpu_static_shared_mem`, `test_xpu_fast_kernel_arg_count_mismatch`, `test_xpu_rejects_invalid_launch_metadata`, `test_xpu_rejects_unloaded_kernel`, `test_xpu_keeps_kernel_capsule_alive`) move to a new `TestFastLauncherXpuOnly` class: `hw_classification = HardwareClassification.XPU`, instantiated with `only_for="xpu", allow_xpu=True`, keeping their `@unittest.skipUnless(HAS_XPU_AND_TRITON)` guards. On non-XPU devices the class collects empty (the generic form is deleted by instantiation and no variant is generated). - The fast-launcher construction helpers (`_fast_launcher_cls`, `_make_fast_launcher`, `_stream`, `_store_sum_launcher`) move into a file-private `_FastLauncherMixin` shared by the two classes. `StaticLauncherTestMixin` is unchanged; its `_make_launcher`/`write_cubin_to_tmp` device-optional form stays byte-identical with the sibling #198437 so whichever lands first supplies them. Why `only_for=("cuda", "xpu")` instead of `except_for="cpu"`: the static launcher registry (`torch/_inductor/runtime/static_triton_launcher.py`) only has `cuda`/`hip`/`xpu` entries, so `except_for="cpu"` would generate MPS/PrivateUse1 variants that hard-error in `_make_launcher` instead of skipping; `cuda`+`xpu` is exactly the device set the pre-series `GPU_TYPE` gating covered. ## Notes - **Test IDs change for the whole class.** `TestFastLauncher.test_x` becomes `TestFastLauncherCUDA.test_x_cuda` (and a `TestFastLauncherXPU...._xpu` variant on XPU runners); the XPU-specific tests become `TestFastLauncherXpuOnlyXPU.test_xpu_*_xpu` there. No in-tree DISABLED/slow-test entries reference the old names (grepped `test/`, `.ci/`, `tools/`). - The `write_cubin_to_tmp` helper in this diff gains an `npubin` binary key alongside `zebin`/`cubin`/`hsaco` for the out-of-tree NPU backends that motivate this series; having the backend supply its binary key via `register_statically_launched_kernel` is a plausible follow-up. - MTIA coverage: previously `GPU_TYPE`-gated classes could resolve to MTIA on MTIA runners; no MTIA test base is registered here, so no MTIA variants are generated. A coverage note, not a regression on currently-tested devices. ## Motivation The static Triton launcher tests are gated by `@requires_gpu_and_triton` / `GPU_TYPE`, which only recognize in-tree devices (`cuda`/`mps`/`xpu`/`mtia`): out-of-tree accelerators registered via `PrivateUse1` never run them. Migrating each class to `instantiate_device_type_tests` + `hw_classification` makes the tests device-agnostic and classifiable by `--hw-classification` filtering. This PR makes that true for `TestFastLauncher` without dropping its existing XPU coverage. ## Test Plan CPU-only host (torch `2.16.0.dev20261102+cpu` wheel; no CUDA or XPU device available): ``` python -c "import ast; ast.parse(open('test/inductor/test_static_triton_launcher.py').read())" cd /tmp && python -I -m pytest <repo-checkout>/test/inductor/test_static_triton_launcher.py --collect-only -q cd /tmp && python -I -m pytest <repo-checkout>/test/inductor/test_static_triton_launcher.py -q uv run --python 3.11 --script tools/linter/adapters/pyfmt_linter.py -- test/inductor/test_static_triton_launcher.py uv run --python 3.10 --script tools/linter/adapters/ruff_linter.py -- test/inductor/test_static_triton_launcher.py python3 tools/linter/adapters/test_linter.py test/inductor/test_static_triton_launcher.py ``` - Collect: 60 tests on the rebased head (the pre-rebase head collected 58; the delta is entirely main-side: 3 unit-class ids removed by #198440's restructure and 5 main-added tests absent from the older base); no instantiated `TestFastLauncher*` variants on a CPU-only host, as designed. - Run: 22 passed, 36 skipped, 2 failed. Both failures are in the untouched `TestStaticTritonLauncherUnit` (the CPU wheel carries no `_FastXpuLauncher` extension, and without Triton/GPU compilation no cubin is produced) and reproduce identically on the unmodified current-main file in the same environment (wheel-vs-trunk drift), so this change is CPU-neutral. - Import probe: importing the module with a recording stub over `instantiate_device_type_tests` asserts both generic classes, their `hw_classification` values, the exact test placement (the 5 `test_xpu_*` tests only in `TestFastLauncherXpuOnly`), helper resolution through `_FastLauncherMixin`, the retained skip guards, and the instantiate kwargs; `filter_by_hw_classification` is exercised directly (`{ACCELERATOR}` keeps the shared class, `{XPU}` keeps `TestFastLauncherXpuOnly`). - Lint: pyfmt and CI-pinned ruff 0.14.4 (check + format) clean; `test_linter.py` reports nothing (the file is in its allowlist, like the precedent files above). CUDA and XPU on-device execution of the instantiated classes is delegated to CI; the authoring host has neither device. ## Agent details (if applicable) This description and the linked review replies were drafted with an AI assistant and reviewed against the diff by the author before posting. Rebase note (2026-11-16): rebased onto current main after #198440 landed. #198440 refactored the separate `TestFastLauncherCompileResult` class (untouched here) and gathered the file's `instantiate_device_type_tests` calls into a single trailing group; this PR's two instantiation calls now join that group and its two import lines dedup against main. The branch's three commits were squashed into one (head `d3924245614`); diff +61/-33 -> +57/-33; no scope change. Pull Request resolved: #198439 Approved by: https://github.com/lizhihai137, https://github.com/jansel
…r hw classes (pytorch#198439) ## Summary Make `TestFastLauncher` in `test/inductor/test_static_triton_launcher.py` hardware-classified and instantiated for both CUDA and XPU, keeping every test that ran before the split running after it. Split from pytorch#192893 (one test class per PR, zero overlap), rebased onto main after pytorch#200916 renamed `TestFastCudaLauncher` to `TestFastLauncher` and moved the shared helpers into `StaticLauncherTestMixin`. ## Changes - `TestFastLauncher` declares `hw_classification = HardwareClassification.ACCELERATOR` and is instantiated with `only_for=("cuda", "xpu"), allow_xpu=True` (the in-tree combination used by e.g. test_comparison_utils.py, test_gpu_trace.py, test/dynamo/test_after_aot.py). Five tests (`test_basic`, `test_multiple_tensor_args`, `test_zero_grid`, `test_wrong_arg_count`, `test_too_many_args_raises_value_error`) take the injected `device` argument; the remaining tests resolve `GPU_TYPE`, which equals the running device on the CUDA and XPU single-device-type CI runners. - The five XPU-specific tests (`test_xpu_static_shared_mem`, `test_xpu_fast_kernel_arg_count_mismatch`, `test_xpu_rejects_invalid_launch_metadata`, `test_xpu_rejects_unloaded_kernel`, `test_xpu_keeps_kernel_capsule_alive`) move to a new `TestFastLauncherXpuOnly` class: `hw_classification = HardwareClassification.XPU`, instantiated with `only_for="xpu", allow_xpu=True`, keeping their `@unittest.skipUnless(HAS_XPU_AND_TRITON)` guards. On non-XPU devices the class collects empty (the generic form is deleted by instantiation and no variant is generated). - The fast-launcher construction helpers (`_fast_launcher_cls`, `_make_fast_launcher`, `_stream`, `_store_sum_launcher`) move into a file-private `_FastLauncherMixin` shared by the two classes. `StaticLauncherTestMixin` is unchanged; its `_make_launcher`/`write_cubin_to_tmp` device-optional form stays byte-identical with the sibling pytorch#198437 so whichever lands first supplies them. Why `only_for=("cuda", "xpu")` instead of `except_for="cpu"`: the static launcher registry (`torch/_inductor/runtime/static_triton_launcher.py`) only has `cuda`/`hip`/`xpu` entries, so `except_for="cpu"` would generate MPS/PrivateUse1 variants that hard-error in `_make_launcher` instead of skipping; `cuda`+`xpu` is exactly the device set the pre-series `GPU_TYPE` gating covered. ## Notes - **Test IDs change for the whole class.** `TestFastLauncher.test_x` becomes `TestFastLauncherCUDA.test_x_cuda` (and a `TestFastLauncherXPU...._xpu` variant on XPU runners); the XPU-specific tests become `TestFastLauncherXpuOnlyXPU.test_xpu_*_xpu` there. No in-tree DISABLED/slow-test entries reference the old names (grepped `test/`, `.ci/`, `tools/`). - The `write_cubin_to_tmp` helper in this diff gains an `npubin` binary key alongside `zebin`/`cubin`/`hsaco` for the out-of-tree NPU backends that motivate this series; having the backend supply its binary key via `register_statically_launched_kernel` is a plausible follow-up. - MTIA coverage: previously `GPU_TYPE`-gated classes could resolve to MTIA on MTIA runners; no MTIA test base is registered here, so no MTIA variants are generated. A coverage note, not a regression on currently-tested devices. ## Motivation The static Triton launcher tests are gated by `@requires_gpu_and_triton` / `GPU_TYPE`, which only recognize in-tree devices (`cuda`/`mps`/`xpu`/`mtia`): out-of-tree accelerators registered via `PrivateUse1` never run them. Migrating each class to `instantiate_device_type_tests` + `hw_classification` makes the tests device-agnostic and classifiable by `--hw-classification` filtering. This PR makes that true for `TestFastLauncher` without dropping its existing XPU coverage. ## Test Plan CPU-only host (torch `2.16.0.dev20261102+cpu` wheel; no CUDA or XPU device available): ``` python -c "import ast; ast.parse(open('test/inductor/test_static_triton_launcher.py').read())" cd /tmp && python -I -m pytest <repo-checkout>/test/inductor/test_static_triton_launcher.py --collect-only -q cd /tmp && python -I -m pytest <repo-checkout>/test/inductor/test_static_triton_launcher.py -q uv run --python 3.11 --script tools/linter/adapters/pyfmt_linter.py -- test/inductor/test_static_triton_launcher.py uv run --python 3.10 --script tools/linter/adapters/ruff_linter.py -- test/inductor/test_static_triton_launcher.py python3 tools/linter/adapters/test_linter.py test/inductor/test_static_triton_launcher.py ``` - Collect: 60 tests on the rebased head (the pre-rebase head collected 58; the delta is entirely main-side: 3 unit-class ids removed by pytorch#198440's restructure and 5 main-added tests absent from the older base); no instantiated `TestFastLauncher*` variants on a CPU-only host, as designed. - Run: 22 passed, 36 skipped, 2 failed. Both failures are in the untouched `TestStaticTritonLauncherUnit` (the CPU wheel carries no `_FastXpuLauncher` extension, and without Triton/GPU compilation no cubin is produced) and reproduce identically on the unmodified current-main file in the same environment (wheel-vs-trunk drift), so this change is CPU-neutral. - Import probe: importing the module with a recording stub over `instantiate_device_type_tests` asserts both generic classes, their `hw_classification` values, the exact test placement (the 5 `test_xpu_*` tests only in `TestFastLauncherXpuOnly`), helper resolution through `_FastLauncherMixin`, the retained skip guards, and the instantiate kwargs; `filter_by_hw_classification` is exercised directly (`{ACCELERATOR}` keeps the shared class, `{XPU}` keeps `TestFastLauncherXpuOnly`). - Lint: pyfmt and CI-pinned ruff 0.14.4 (check + format) clean; `test_linter.py` reports nothing (the file is in its allowlist, like the precedent files above). CUDA and XPU on-device execution of the instantiated classes is delegated to CI; the authoring host has neither device. ## Agent details (if applicable) This description and the linked review replies were drafted with an AI assistant and reviewed against the diff by the author before posting. Rebase note (2026-11-16): rebased onto current main after pytorch#198440 landed. pytorch#198440 refactored the separate `TestFastLauncherCompileResult` class (untouched here) and gathered the file's `instantiate_device_type_tests` calls into a single trailing group; this PR's two instantiation calls now join that group and its two import lines dedup against main. The branch's three commits were squashed into one (head `d3924245614`); diff +61/-33 -> +57/-33; no scope change. Pull Request resolved: pytorch#198439 Approved by: https://github.com/lizhihai137, https://github.com/jansel
… into a CUDA-classified class (#203548) ## Summary Slice 1 of 4 of the static-launcher re-cut (original monolith #198437 at 505 lines; all slices independent, any merge order) per #198436's review request. Moves the Triton-gated autotuner unit test (`test_tensor_memory_autotuner_retries_without_pipelining`) out of `TestStaticTritonLauncherUnit` into a new **CUDA-classified, non-instantiated** class `TestStaticTritonLauncherUnitCuda`. The body exercises `CUDAAutotuner` / `StaticallyLaunchedCudaKernel` internals through mocks and is RoCm-skipped -- CUDA-family-specific, so device-variant instantiation (XPU/PrivateUse1 copies) would add noise, not coverage. The shared helpers (`_global_scratch_kernel`, `_can_statically_launch`) stay on the unit class and are delegated by reference (staticmethod-wrapped so signatures hold); nothing is copied. (+74/-52, one file) ## Test Plan - [x] cpu wheel venv: failure set identical to the untouched file (the 2 pre-existing wheel-vs-trunk artifacts) - [x] in-tree test linter + lintrunner clean - siblings: #203550 (RoCm scratch trio), #203551 (cubin metadata pair), #198437 (launcher migration) Rebase note (2026-11-06): replayed onto current main after #200916 touched the same file; slice content unchanged (+77/-54). ## Linked issue or supporting maintainer Part of #185590 (test case refactoring initiative) - hardware-decoupling slice. Pull Request resolved: #203548 Approved by: https://github.com/lizhihai137, https://github.com/jansel
Stack from ghstack (oldest at bottom):
Motivation
_StaticXpuLauncher._launch_kernelhas some overhead on every launch:PyArg_ParseTupleover nine arguments, a capsule tag comparison to get the kernel, and astrlenofarg_tys.data_ptr()call, plus azeMemGetAllocPropertiesvalidation whose result is discarded.StaticallyLaunchedXpuKernel.runon top of that rebuilds the argument tuple and thearg_tysstring to append the scratch arguments.None of it can change between launches of the same kernel. Median host time per launch (5 processes, bursts of 32 into a drained queue), through
run()as inductor calls it today vs through the fast launcher:run()The marginal cost per pointer argument drops from ~370 ns to ~100 ns. On densenet121 inference (bs16, 128x128, 342 launches per iteration, host bound), one compiled iteration goes from ~7.5 ms to ~6.5 ms, and the speedup over eager from ~1.21x to ~1.40x.
Solution
_FastXpuLauncher, the XPU sibling of_FastCudaLauncher:CachingAutotunerswaps it into the cached launcher after the first launch, sorun()is bypassed too.THPVariable_Unpack+Tensor::data_ptr()and are not validated, as on CUDA: inductor codegen guarantees the'O'arguments are tensors, and anything else falls back to the generic unpacking.sycl::kernel. CUDA bakes a rawCUfunctionand relies on the python side to keep the owner alive; doing that here would leave a use-after-free reachable by closing the static kernel.It reuses
packKernelArg()andsubmitKernel(), which #201004 split out of the launch path, soxpu.cpphere is new code only.cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo