Kernels
relu / torch-ext /torch_binding.cpp
superexpai's picture
Optimized relu: cpu/cuda/xpu, 1.2-1.85x faster on RTX 4090, benchmarked vs upstream and torch.relu
e873e70 verified
Raw
History Blame Contribute Delete
524 Bytes
#include <torch/library.h>
#include "registration.h"
#include "torch_binding.h"
TORCH_LIBRARY_EXPAND(TORCH_EXTENSION_NAME, ops) {
ops.def("relu(Tensor! out, Tensor input) -> ()");
#if defined(CPU_KERNEL)
ops.impl("relu", torch::kCPU, &relu);
#elif defined(CUDA_KERNEL) || defined(ROCM_KERNEL)
ops.impl("relu", torch::kCUDA, &relu);
#elif defined(METAL_KERNEL)
ops.impl("relu", torch::kMPS, relu);
#elif defined(XPU_KERNEL)
ops.impl("relu", torch::kXPU, &relu);
#endif
}
REGISTER_EXTENSION(TORCH_EXTENSION_NAME)