[Kernel] Implement CUDA kernel for ReLUSquaredActivation (relu^2) (#39058)

Signed-off-by: Tanish Malekar <tanishmalekar32@gmail.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Tanish Malekar
2026-07-12 19:18:03 -07:00
committed by GitHub
co-authored by Claude Sonnet 4.6
parent 4c81772e8b
commit e26264f3ef
7 changed files with 140 additions and 2 deletions
+8 -2
View File
@@ -613,13 +613,19 @@ class ReLUSquaredActivation(CustomOp):
# --8<-- [end:relu2]
def __init__(self):
super().__init__()
if current_platform.is_cuda_alike():
self.op = torch.ops._C.relu_squared
def forward_native(self, x: torch.Tensor) -> torch.Tensor:
"""PyTorch-native implementation equivalent to forward()."""
return torch.square(F.relu(x))
def forward_cuda(self, x: torch.Tensor) -> torch.Tensor:
# TODO : implement cuda kernels
return self.forward_native(x)
out = torch.empty_like(x)
self.op(out, x)
return out
# --8<-- [start:xielu]