From a01bb47a0ccc19bcfb8145ea50f625808f928ddf Mon Sep 17 00:00:00 2001 From: PyTorch MergeBot Date: Fri, 16 Jan 2026 16:41:03 +0000 Subject: [PATCH] Revert "[xpu][static_launcher] 2/4: Refactor static cuda launcher to static triton launcher. (#169121)" This reverts commit 84646f716d0c2c0dabfd9b4eff7501a6e9bc6318. Reverted https://github.com/pytorch/pytorch/pull/169121 on behalf of https://github.com/yangw-dev due to break internal system, and casued SEV, please reachout internal staff for more details ([comment](https://github.com/pytorch/pytorch/pull/169121#issuecomment-3760882742)) --- build_variables.bzl | 2 +- ...uncher.py => test_static_cuda_launcher.py} | 4 +- torch/_C/__init__.pyi.in | 2 +- ...on_launcher.py => static_cuda_launcher.py} | 37 +++++-------------- torch/_inductor/runtime/triton_heuristics.py | 11 ++---- torch/csrc/Module.cpp | 2 +- .../cuda.cpp => static_cuda_launcher.cpp} | 2 +- .../cuda.h => static_cuda_launcher.h} | 0 8 files changed, 18 insertions(+), 42 deletions(-) rename test/inductor/{test_static_triton_launcher.py => test_static_cuda_launcher.py} (99%) rename torch/_inductor/runtime/{static_triton_launcher.py => static_cuda_launcher.py} (91%) rename torch/csrc/inductor/{static_launcher/cuda.cpp => static_cuda_launcher.cpp} (99%) rename torch/csrc/inductor/{static_launcher/cuda.h => static_cuda_launcher.h} (100%) diff --git a/build_variables.bzl b/build_variables.bzl index cb182d5c2235..32ce997241b0 100644 --- a/build_variables.bzl +++ b/build_variables.bzl @@ -954,7 +954,7 @@ libtorch_python_core_sources = [ "torch/csrc/inductor/aoti_eager/kernel_holder.cpp", "torch/csrc/inductor/aoti_eager/kernel_meta_info.cpp", "torch/csrc/inductor/resize_storage_bytes.cpp", - "torch/csrc/inductor/static_launcher/cuda.cpp", + "torch/csrc/inductor/static_cuda_launcher.cpp", "torch/csrc/jit/backends/backend_init.cpp", "torch/csrc/jit/python/init.cpp", "torch/csrc/jit/passes/onnx.cpp", diff --git a/test/inductor/test_static_triton_launcher.py b/test/inductor/test_static_cuda_launcher.py similarity index 99% rename from test/inductor/test_static_triton_launcher.py rename to test/inductor/test_static_cuda_launcher.py index 3f1f739eceb7..a8e11c2b3db6 100644 --- a/test/inductor/test_static_triton_launcher.py +++ b/test/inductor/test_static_cuda_launcher.py @@ -8,7 +8,7 @@ import torch from torch._dynamo.device_interface import get_interface_for_device from torch._inductor.codecache import PyCodeCache from torch._inductor.runtime import triton_helpers -from torch._inductor.runtime.static_triton_launcher import StaticallyLaunchedCudaKernel +from torch._inductor.runtime.static_cuda_launcher import StaticallyLaunchedCudaKernel from torch._inductor.runtime.triton_compat import CompiledKernel, tl, triton from torch._inductor.runtime.triton_helpers import libdevice from torch._inductor.test_case import TestCase @@ -492,7 +492,7 @@ class TestStaticTritonCompileResult(TestCase): self.assertEqual(eager_result, compiled_result) @skipIfRocm - def test_disable_static_triton_launcher(self): + def test_disable_static_cuda_launcher(self): @torch.compile def fn(x, y): return torch.cat(((x * 4), y + 10)) diff --git a/torch/_C/__init__.pyi.in b/torch/_C/__init__.pyi.in index 6af17aa6409e..fd0d994711f9 100644 --- a/torch/_C/__init__.pyi.in +++ b/torch/_C/__init__.pyi.in @@ -2839,7 +2839,7 @@ class _NodeIter(Iterator[FxNode]): def __iter__(self) -> Self: ... def __next__(self) -> FxNode: ... -# Defined in torch/csrc/inductor/static_launcher/cuda.cpp +# Defined in torch/csrc/inductor/static_cuda_launcher.cpp class _StaticCudaLauncher: @staticmethod def _load_kernel( diff --git a/torch/_inductor/runtime/static_triton_launcher.py b/torch/_inductor/runtime/static_cuda_launcher.py similarity index 91% rename from torch/_inductor/runtime/static_triton_launcher.py rename to torch/_inductor/runtime/static_cuda_launcher.py index dc12c818f92a..399c6bbb4c58 100644 --- a/torch/_inductor/runtime/static_triton_launcher.py +++ b/torch/_inductor/runtime/static_cuda_launcher.py @@ -1,6 +1,5 @@ import functools import os -from functools import cached_property from typing import Any from typing_extensions import Unpack @@ -8,7 +7,7 @@ from .triton_compat import ASTSource, CompiledKernel, knobs as triton_knobs from .triton_helpers import get_constexprs -class StaticallyLaunchedTritonKernel: +class StaticallyLaunchedCudaKernel: """ Parses the metadata of a CompiledKernel from Triton into a structure that can launch the cuda kernel directly. Only works for triton kernels compiled to cubin. @@ -21,13 +20,13 @@ class StaticallyLaunchedTritonKernel: Workflow: Compile time: 1. Compile a kernel with triton and get a CompiledKernel - 2. Instantiate kernel = StaticallyLaunchedTritonKernel(triton_kernel) + 2. Instantiate kernel = StaticallyLaunchedCudaKernel(triton_kernel) 3. Write to a cubin file: kernel.write_cubin_to_file(filepath) 4. Call kernel.load_kernel() (CUDA should be initialized by this point) to load the cubin Runtime: 5. Call kernel.run(grid, stream, args) to launch the kernel - Note that after step 3, StaticallyLaunchedTritonKernel is fully pickleable/serializable. + Note that after step 3, StaticallyLaunchedCudaKernel is fully pickleable/serializable. This allows it to be cached by FXGraphCache/TritonBundler, as well as sent from the worker to the parent process in inductor. @@ -35,10 +34,6 @@ class StaticallyLaunchedTritonKernel: to how it handles constants in 3.3, so there's some special logic necessary to handle both versions. """ - @cached_property - def C_impl(self): - raise NotImplementedError - def __init__(self, kernel: CompiledKernel) -> None: # pyrefly: ignore [missing-attribute] self.name = kernel.src.fn.__name__ @@ -136,12 +131,14 @@ class StaticallyLaunchedTritonKernel: return self.cubin_path def load_kernel(self, device: int) -> None: + from torch._C import _StaticCudaLauncher + if self.function is not None: return assert hasattr(self, "cubin_path") assert self.cubin_path is not None - (self.function, self.n_regs, self.n_spills) = self.C_impl._load_kernel( + (self.function, self.n_regs, self.n_spills) = _StaticCudaLauncher._load_kernel( self.cubin_path, self.name, self.shared, device ) # Don't need the cubin path anymore now that we've loaded @@ -181,7 +178,7 @@ class StaticallyLaunchedTritonKernel: return "O" elif ty == "nvTmaDesc": raise NotImplementedError("nvTmaDesc kernels are not yet supported") - return StaticallyLaunchedTritonKernel.type_mappings()[ty] + return StaticallyLaunchedCudaKernel.type_mappings()[ty] def arg_ty_from_signature(self, src: ASTSource) -> str: def index_key(i: Any) -> int: @@ -238,6 +235,7 @@ class StaticallyLaunchedTritonKernel: *args: Unpack[tuple[object, ...]], ) -> None: """Actually run the kernel at runtime. This function is the hot codepath.""" + from torch._C import _StaticCudaLauncher # Assert load_kernel() has been called and args match assert self.function is not None @@ -258,7 +256,7 @@ class StaticallyLaunchedTritonKernel: # TODO: can handle grid functions here or in C++, so # that we don't need the grid handler above. - self.C_impl._launch_kernel( + _StaticCudaLauncher._launch_kernel( self.function, grid_x, grid_y, @@ -269,20 +267,3 @@ class StaticallyLaunchedTritonKernel: args, stream, ) - - -class StaticallyLaunchedCudaKernel(StaticallyLaunchedTritonKernel): - @cached_property - def C_impl(self): - from torch._C import _StaticCudaLauncher - - return _StaticCudaLauncher - - -def statically_launched_kernel_by_device( - kernel: CompiledKernel, device_type: str = "cuda" -) -> StaticallyLaunchedTritonKernel: - if device_type == "cuda": - return StaticallyLaunchedCudaKernel(kernel) - else: - raise NotImplementedError(f"Device type {device_type} not supported") diff --git a/torch/_inductor/runtime/triton_heuristics.py b/torch/_inductor/runtime/triton_heuristics.py index 838fab19b46e..61c42cd2dc3a 100644 --- a/torch/_inductor/runtime/triton_heuristics.py +++ b/torch/_inductor/runtime/triton_heuristics.py @@ -65,10 +65,7 @@ from .runtime_utils import ( triton_hash_to_path_key, validate_triton_config, ) -from .static_triton_launcher import ( - statically_launched_kernel_by_device, - StaticallyLaunchedCudaKernel, -) +from .static_cuda_launcher import StaticallyLaunchedCudaKernel from .triton_compat import ( ASTSource, autograd_profiler, @@ -1730,9 +1727,7 @@ class StaticTritonCompileResult(CompileResult[StaticallyLaunchedCudaKernel]): kernel._cubin_path = cubin_location try: - static_kernel = statically_launched_kernel_by_device( - kernel, triton_meta.get("device_type") - ) + static_kernel = StaticallyLaunchedCudaKernel(kernel) except NotImplementedError as e: raise CannotStaticallyLaunchKernel(f"NotImplemented: {str(e)}") from e @@ -1770,7 +1765,7 @@ class StaticTritonCompileResult(CompileResult[StaticallyLaunchedCudaKernel]): def make_launcher(self) -> LauncherType: # If at least one static make_launcher call occurs, # we're sure static cuda launcher was used for this compile - set_feature_use("static_triton_launcher", True) + set_feature_use("static_cuda_launcher", True) # Load the binary on the parent if not self.kernel.cubin_path: self.reload_cubin_path() diff --git a/torch/csrc/Module.cpp b/torch/csrc/Module.cpp index 6162b7bfd08c..00206bf827ee 100644 --- a/torch/csrc/Module.cpp +++ b/torch/csrc/Module.cpp @@ -117,7 +117,7 @@ #include #include #include -#include +#include #ifdef __HIP_PLATFORM_AMD__ #include #else diff --git a/torch/csrc/inductor/static_launcher/cuda.cpp b/torch/csrc/inductor/static_cuda_launcher.cpp similarity index 99% rename from torch/csrc/inductor/static_launcher/cuda.cpp rename to torch/csrc/inductor/static_cuda_launcher.cpp index 1b2b673e4f6f..af8f25e69d56 100644 --- a/torch/csrc/inductor/static_launcher/cuda.cpp +++ b/torch/csrc/inductor/static_cuda_launcher.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include diff --git a/torch/csrc/inductor/static_launcher/cuda.h b/torch/csrc/inductor/static_cuda_launcher.h similarity index 100% rename from torch/csrc/inductor/static_launcher/cuda.h rename to torch/csrc/inductor/static_cuda_launcher.h