deform_conv2d.cpp 2.59 KB
Newer Older
1
#include "deform_conv2d.h"
2

3
4
#include <ATen/core/dispatch/Dispatcher.h>
#include <torch/library.h>
5
#include <torch/types.h>
6

7
8
namespace vision {
namespace ops {
9
10

at::Tensor deform_conv2d(
11
12
13
    const at::Tensor& input,
    const at::Tensor& weight,
    const at::Tensor& offset,
14
    const at::Tensor& mask,
15
    const at::Tensor& bias,
16
17
18
19
20
21
22
    int64_t stride_h,
    int64_t stride_w,
    int64_t pad_h,
    int64_t pad_w,
    int64_t dilation_h,
    int64_t dilation_w,
    int64_t groups,
23
24
    int64_t offset_groups,
    bool use_mask) {
Kai Zhang's avatar
Kai Zhang committed
25
  C10_LOG_API_USAGE_ONCE("torchvision.csrc.ops.deform_conv2d.deform_conv2d");
26
27
28
29
30
31
32
  static auto op = c10::Dispatcher::singleton()
                       .findSchemaOrThrow("torchvision::deform_conv2d", "")
                       .typed<decltype(deform_conv2d)>();
  return op.call(
      input,
      weight,
      offset,
33
      mask,
34
35
36
37
38
39
40
      bias,
      stride_h,
      stride_w,
      pad_h,
      pad_w,
      dilation_h,
      dilation_w,
41
      groups,
42
43
      offset_groups,
      use_mask);
44
45
}

46
47
namespace detail {

48
std::tuple<at::Tensor, at::Tensor, at::Tensor, at::Tensor, at::Tensor>
49
50
51
52
53
_deform_conv2d_backward(
    const at::Tensor& grad,
    const at::Tensor& input,
    const at::Tensor& weight,
    const at::Tensor& offset,
54
    const at::Tensor& mask,
55
    const at::Tensor& bias,
56
57
58
59
60
61
62
    int64_t stride_h,
    int64_t stride_w,
    int64_t pad_h,
    int64_t pad_w,
    int64_t dilation_h,
    int64_t dilation_w,
    int64_t groups,
63
64
    int64_t offset_groups,
    bool use_mask) {
65
66
67
68
69
70
71
72
73
  static auto op =
      c10::Dispatcher::singleton()
          .findSchemaOrThrow("torchvision::_deform_conv2d_backward", "")
          .typed<decltype(_deform_conv2d_backward)>();
  return op.call(
      grad,
      input,
      weight,
      offset,
74
      mask,
75
76
77
78
79
80
81
      bias,
      stride_h,
      stride_w,
      pad_h,
      pad_w,
      dilation_h,
      dilation_w,
82
      groups,
83
84
      offset_groups,
      use_mask);
85
86
}

87
88
} // namespace detail

89
TORCH_LIBRARY_FRAGMENT(torchvision, m) {
90
91
92
93
  m.def(TORCH_SELECTIVE_SCHEMA(
      "torchvision::deform_conv2d(Tensor input, Tensor weight, Tensor offset, Tensor mask, Tensor bias, int stride_h, int stride_w, int pad_h, int pad_w, int dilation_h, int dilation_w, int groups, int offset_groups, bool use_mask) -> Tensor"));
  m.def(TORCH_SELECTIVE_SCHEMA(
      "torchvision::_deform_conv2d_backward(Tensor grad, Tensor input, Tensor weight, Tensor offset, Tensor mask, Tensor bias, int stride_h, int stride_w, int pad_h, int pad_w, int dilation_h, int dilation_w, int groups, int offset_groups, bool use_mask) -> (Tensor, Tensor, Tensor, Tensor, Tensor)"));
94
95
}

96
97
} // namespace ops
} // namespace vision