deform_conv2d.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include "deform_conv2d.h"
  2. #include <ATen/core/dispatch/Dispatcher.h>
  3. #include <torch/library.h>
  4. #include <torch/types.h>
  5. namespace vision {
  6. namespace ops {
  7. at::Tensor deform_conv2d(
  8. const at::Tensor& input,
  9. const at::Tensor& weight,
  10. const at::Tensor& offset,
  11. const at::Tensor& mask,
  12. const at::Tensor& bias,
  13. int64_t stride_h,
  14. int64_t stride_w,
  15. int64_t pad_h,
  16. int64_t pad_w,
  17. int64_t dilation_h,
  18. int64_t dilation_w,
  19. int64_t groups,
  20. int64_t offset_groups,
  21. bool use_mask) {
  22. C10_LOG_API_USAGE_ONCE("torchvision.csrc.ops.deform_conv2d.deform_conv2d");
  23. static auto op = c10::Dispatcher::singleton()
  24. .findSchemaOrThrow("torchvision::deform_conv2d", "")
  25. .typed<decltype(deform_conv2d)>();
  26. return op.call(
  27. input,
  28. weight,
  29. offset,
  30. mask,
  31. bias,
  32. stride_h,
  33. stride_w,
  34. pad_h,
  35. pad_w,
  36. dilation_h,
  37. dilation_w,
  38. groups,
  39. offset_groups,
  40. use_mask);
  41. }
  42. namespace detail {
  43. std::tuple<at::Tensor, at::Tensor, at::Tensor, at::Tensor, at::Tensor>
  44. _deform_conv2d_backward(
  45. const at::Tensor& grad,
  46. const at::Tensor& input,
  47. const at::Tensor& weight,
  48. const at::Tensor& offset,
  49. const at::Tensor& mask,
  50. const at::Tensor& bias,
  51. int64_t stride_h,
  52. int64_t stride_w,
  53. int64_t pad_h,
  54. int64_t pad_w,
  55. int64_t dilation_h,
  56. int64_t dilation_w,
  57. int64_t groups,
  58. int64_t offset_groups,
  59. bool use_mask) {
  60. static auto op =
  61. c10::Dispatcher::singleton()
  62. .findSchemaOrThrow("torchvision::_deform_conv2d_backward", "")
  63. .typed<decltype(_deform_conv2d_backward)>();
  64. return op.call(
  65. grad,
  66. input,
  67. weight,
  68. offset,
  69. mask,
  70. bias,
  71. stride_h,
  72. stride_w,
  73. pad_h,
  74. pad_w,
  75. dilation_h,
  76. dilation_w,
  77. groups,
  78. offset_groups,
  79. use_mask);
  80. }
  81. } // namespace detail
  82. TORCH_LIBRARY_FRAGMENT(torchvision, m) {
  83. m.def(TORCH_SELECTIVE_SCHEMA(
  84. "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"));
  85. m.def(TORCH_SELECTIVE_SCHEMA(
  86. "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)"));
  87. }
  88. } // namespace ops
  89. } // namespace vision