Build uploaded using `kernels`.
Browse files
build/torch-ext/relu/__init__.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Optional
|
| 2 |
+
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
from ._ops import ops
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def relu(x: torch.Tensor, out: Optional[torch.Tensor] = None) -> torch.Tensor:
|
| 9 |
+
if out is None:
|
| 10 |
+
out = torch.empty_like(x)
|
| 11 |
+
ops.relu(out, x)
|
| 12 |
+
return out
|
build/torch-ext/torch_binding.cpp
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <torch/library.h>
|
| 2 |
+
|
| 3 |
+
#include "registration.h"
|
| 4 |
+
#include "torch_binding.h"
|
| 5 |
+
|
| 6 |
+
TORCH_LIBRARY_EXPAND(TORCH_EXTENSION_NAME, ops) {
|
| 7 |
+
ops.def("relu(Tensor! out, Tensor input) -> ()");
|
| 8 |
+
#if defined(CUDA_KERNEL) || defined(ROCM_KERNEL)
|
| 9 |
+
ops.impl("relu", torch::kCUDA, &relu);
|
| 10 |
+
#elif defined(METAL_KERNEL)
|
| 11 |
+
ops.impl("relu", torch::kMPS, relu);
|
| 12 |
+
#elif defined(XPU_KERNEL)
|
| 13 |
+
ops.impl("relu", torch::kXPU, &relu);
|
| 14 |
+
#endif
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
REGISTER_EXTENSION(TORCH_EXTENSION_NAME)
|
build/torch-ext/torch_binding.h
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#pragma once
|
| 2 |
+
|
| 3 |
+
#include <torch/torch.h>
|
| 4 |
+
|
| 5 |
+
void relu(torch::Tensor &out, torch::Tensor const &input);
|