forked from zzd1992/Image-Local-Attention
-
Notifications
You must be signed in to change notification settings - Fork 0
/
localAttention.cpp
73 lines (63 loc) · 1.83 KB
/
localAttention.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// Created by zhang on 20-1-14.
//
#include "localAttention.h"
torch::Tensor similar_forward(
const torch::Tensor &x_ori,
const torch::Tensor &x_loc,
const int kH,
const int kW) {
return similar_cuda_forward(
x_ori, x_loc,
kH, kW);
}
torch::Tensor similar_backward(
const torch::Tensor &x,
const torch::Tensor &grad_out,
const int kH,
const int kW,
const bool is_ori) {
return similar_cuda_backward(
x, grad_out,
kH, kW,
is_ori);
}
torch::Tensor weighting_forward(
const torch::Tensor &x_ori,
const torch::Tensor &x_weight,
const int kH,
const int kW) {
return weighting_cuda_forward(
x_ori, x_weight,
kH, kW);
}
torch::Tensor weighting_backward_ori(
const torch::Tensor &x_weight,
const torch::Tensor &grad_out,
const int kH,
const int kW) {
return weighting_cuda_backward_ori(
x_weight, grad_out,
kH, kW);
}
torch::Tensor weighting_backward_weight(
const torch::Tensor &x_ori,
const torch::Tensor &grad_out,
const int kH,
const int kW) {
return weighting_cuda_backward_weight(
x_ori, grad_out,
kH, kW);
}
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
m.def("similar_forward", &similar_forward,
"similar_forward (CUDA)");
m.def("similar_backward", &similar_backward,
"similar_backward (CUDA)");
m.def("weighting_forward", &weighting_forward,
"weighting_forward (CUDA)");
m.def("weighting_backward_ori", &weighting_backward_ori,
"weighting_backward_ori (CUDA)");
m.def("weighting_backward_weight", &weighting_backward_weight,
"weighting_backward_weight (CUDA)");
}