forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConvolutionMM2d.cu
73 lines (65 loc) · 1.83 KB
/
ConvolutionMM2d.cu
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
#include <ATen/ATen.h>
#include <ATen/LegacyTHFunctionsCUDA.h>
namespace at {
namespace native {
std::tuple<Tensor&, Tensor&, Tensor&> slow_conv2d_backward_out_cuda(const Tensor& grad_output,
const Tensor& self,
const Tensor& weight,
IntArrayRef kernel_size,
IntArrayRef stride,
IntArrayRef padding,
const Tensor& finput,
const Tensor& fgrad_input,
Tensor& grad_input,
Tensor& grad_weight,
Tensor& grad_bias) {
if (grad_weight.defined()) {
grad_weight.resize_(weight.sizes());
grad_weight.zero_();
}
if (grad_bias.defined()) {
grad_bias.resize_({ weight.size(0) });
grad_bias.zero_();
}
return legacy::cuda::_thnn_conv2d_backward_out(grad_input, grad_weight, grad_bias,
grad_output, self, weight,
kernel_size, stride, padding,
finput, fgrad_input);
}
std::tuple<Tensor, Tensor, Tensor> slow_conv2d_backward_cuda(
const Tensor& grad_output,
const Tensor& self,
const Tensor& weight,
IntArrayRef kernel_size,
IntArrayRef stride,
IntArrayRef padding,
const Tensor& finput,
const Tensor& fgrad_input,
std::array<bool, 3> output_mask) {
Tensor grad_input;
Tensor grad_weight;
Tensor grad_bias;
if (output_mask[0]) {
grad_input = at::empty({0}, grad_output.options());
}
if (output_mask[1]) {
grad_weight = at::empty({0}, grad_output.options());
}
if (output_mask[2]) {
grad_bias = at::empty({0}, grad_output.options());
}
return native::slow_conv2d_backward_out_cuda(
grad_output,
self,
weight,
kernel_size,
stride,
padding,
finput,
fgrad_input,
grad_input,
grad_weight,
grad_bias);
}
} // namespace native
} // namespace at