-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcatconv2d_cuda.cpp
59 lines (47 loc) · 1.49 KB
/
catconv2d_cuda.cpp
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <torch/extension.h>
#include <vector>
// CUDA forward declarations
std::vector<torch::Tensor> catconv2d_cuda_forward(
std::vector<torch::Tensor> input_list,
torch::Tensor weights,
torch::Tensor bias,
bool relu);
std::vector<torch::Tensor> catconv2d_cuda_backward(
torch::Tensor grad_output,
torch::Tensor X,
torch::Tensor weights,
torch::Tensor bias);
// C++ interface
// NOTE: AT_ASSERT has become AT_CHECK on master after 0.4.
#define CHECK_CUDA(x) AT_ASSERTM(x.type().is_cuda(), #x " must be a CUDA tensor")
#define CHECK_CONTIGUOUS(x) AT_ASSERTM(x.is_contiguous(), #x " must be contiguous")
#define CHECK_INPUT(x) CHECK_CUDA(x); CHECK_CONTIGUOUS(x)
std::vector<torch::Tensor> catconv2d_forward(
std::vector<torch::Tensor> input_list,
torch::Tensor weights,
torch::Tensor bias,
bool relu) {
CHECK_INPUT(input_list[0]);
CHECK_INPUT(weights);
CHECK_INPUT(bias);
return catconv2d_cuda_forward(input_list, weights, bias, relu);
}
std::vector<torch::Tensor> catconv2d_backward(
torch::Tensor grad_output,
torch::Tensor X,
torch::Tensor weights,
torch::Tensor bias) {
CHECK_INPUT(grad_output);
CHECK_INPUT(X);
CHECK_INPUT(weights);
CHECK_INPUT(bias);
return catconv2d_cuda_backward(
grad_output,
X,
weights,
bias);
}
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
m.def("forward", &catconv2d_forward, "CatConv2d forward (CUDA)");
m.def("backward", &catconv2d_backward, "CatConv2d backward (CUDA)");
}