-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcust_act_cuda.cpp
More file actions
33 lines (22 loc) · 954 Bytes
/
cust_act_cuda.cpp
File metadata and controls
33 lines (22 loc) · 954 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <torch/extension.h>
#include <vector>
// CUDA forward declarations
torch::Tensor cust_act_cuda_forward(torch::Tensor input);
torch::Tensor cust_act_cuda_backward(torch::Tensor input, torch::Tensor grad_out);
// C++ interface
#define CHECK_CUDA(x) TORCH_CHECK(x.type().is_cuda(), #x " must be a CUDA tensor")
#define CHECK_CONTIGUOUS(x) TORCH_CHECK(x.is_contiguous(), #x " must be contiguous")
#define CHECK_INPUT(x) CHECK_CUDA(x); CHECK_CONTIGUOUS(x)
torch::Tensor cust_act_forward(torch::Tensor input) {
CHECK_INPUT(input);
return cust_act_cuda_forward(input);
}
torch::Tensor cust_act_backward(torch::Tensor input, torch::Tensor grad_out) {
CHECK_INPUT(input);
CHECK_INPUT(grad_out);
return cust_act_cuda_backward(input, grad_out);
}
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
m.def("forward", &cust_act_forward, "Custom activation forward (CUDA)");
m.def("backward", &cust_act_backward, "Custom activation (CUDA)");
}