tin_shift.cpp 1.46 KB
Newer Older
Jintao Lin's avatar
Jintao Lin committed
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
#include "pytorch_cpp_helper.hpp"

#ifdef MMCV_WITH_CUDA
void TINShiftForwardCUDAKernelLauncher(Tensor input, Tensor shift,
                                       Tensor output);

void TINShiftBackwardCUDAKernelLauncher(Tensor grad_output, Tensor shift,
                                        Tensor grad_input);

void tin_shift_forward_cuda(Tensor input, Tensor shift, Tensor output) {
  TINShiftForwardCUDAKernelLauncher(input, shift, output);
}

void tin_shift_backward_cuda(Tensor grad_output, Tensor shift,
                             Tensor grad_input) {
  TINShiftBackwardCUDAKernelLauncher(grad_output, shift, grad_input);
}

#endif

void tin_shift_forward(Tensor input, Tensor shift, Tensor output) {
  if (input.device().is_cuda()) {
#ifdef MMCV_WITH_CUDA
    CHECK_CUDA_INPUT(input);
    CHECK_CUDA_INPUT(shift);
    CHECK_CUDA_INPUT(output);

    tin_shift_forward_cuda(input, shift, output);
#else
    AT_ERROR("TINShift is not compiled with GPU support");
#endif
  } else {
    AT_ERROR("TINShift is not implemented on CPU");
  }
}

void tin_shift_backward(Tensor grad_output, Tensor shift, Tensor grad_input) {
  if (grad_output.device().is_cuda()) {
#ifdef MMCV_WITH_CUDA
    CHECK_CUDA_INPUT(grad_output);
    CHECK_CUDA_INPUT(shift);
    CHECK_CUDA_INPUT(grad_input);

    tin_shift_backward_cuda(grad_output, shift, grad_input);
#else
    AT_ERROR("TINShift is not compiled with GPU support");
#endif
  } else {
    AT_ERROR("TINShift is not implemented on CPU");
  }
}