evox.triton_kernels.kernels.fused_add¶
Example fused element-wise addition kernel.
This module demonstrates the full Triton kernel integration pattern:
Define the
@triton.jitkernel function.Define a launcher function that sets up the grid and calls the kernel.
Define a PyTorch fallback that runs on all devices (CPU, MPS, etc.).
Define a fake (abstract evaluation) function for
torch.compiletracing.Register everything via :func:
~evox.triton_kernels.register_triton_op.
At call time, PyTorch’s dispatcher routes CUDA tensors to the Triton kernel and all other tensors to the PyTorch fallback automatically.
To extend coverage to additional backends such as Ascend NPU, register the
device type with :func:~evox.triton_kernels.register_triton_device_type
(e.g. register_triton_device_type("npu")) and pass an explicit
triton_device_types=["cuda", "npu"] to
- func:
~evox.triton_kernels.register_triton_op.
Module Contents¶
Functions¶
Launch the Triton addition kernel. |
|
Fake (abstract evaluation) function for torch.compile tracing. |
|
Element-wise addition of two tensors with the same shape. |
API¶
- evox.triton_kernels.kernels.fused_add._triton_fused_add(x: torch.Tensor, y: torch.Tensor) torch.Tensor[source]¶
Launch the Triton addition kernel.
- evox.triton_kernels.kernels.fused_add._fused_add_fake(x: torch.Tensor, y: torch.Tensor) torch.Tensor[source]¶
Fake (abstract evaluation) function for torch.compile tracing.
- evox.triton_kernels.kernels.fused_add.fused_add(x: torch.Tensor, y: torch.Tensor) torch.Tensor¶
Element-wise addition of two tensors with the same shape.
Uses a fused Triton kernel on CUDA devices and falls back to PyTorch’s native
+operator on all other devices (CPU, MPS, etc.).- Parameters:
x – First input tensor.
y – Second input tensor, must have the same shape as
x.
- Returns:
Element-wise sum
x + y.