hey @glaringlee thanks a lot for your inputs. Yes, you are right. it’s the code from maskrcnn.
Here is what I tried:

I replaced the THCudaTensor stuff with at::Tensor…

The signature of the function BilinearSamplerBHWD_updateOutput looks like
int BilinearSamplerBHWD_updateOutput_cpu(const at::Tensor& inputImages, const at::Tensor& grids, at::Tensor& output)
{
      int batchsize = inputImages.size(0);
      int inputImages_height = inputImages.size(1);
      int inputImages_width = inputImages.size(2);
      int output_height = output.size(0);
      int output_width = output.size(2);
      int inputImages_channels = inputImages.size(3);

      int output_strideBatch = output.stride(0);
      int output_strideHeight = output.stride(1);
      int output_strideWidth = output.stride(2);

      int inputImages_strideBatch = inputImages.stride(0);
      int inputImages_strideHeight = inputImages.stride(1);
      int inputImages_strideWidth = inputImages.stride(2);

      int grids_strideBatch = grids.stride(0);
      int grids_strideHeight = grids.stride(1);
      int grids_strideWidth = grids.stride(2);

      real *inputImages_data, *output_data, *grids_data;
      // TODO: inputImages.scalar_type()
      inputImages_data = inputImages.data_ptr<float>();
      output_data = output.data_ptr<float>();
      grids_data = grids.data_ptr<float>();
      ....

After replacement, the code works, but  I guess I should use the template to re-write this function, as **TODO** line highlights, according to the type of inputs, the function can automatically cast the data type as it needs. I’ll re-write all functions with the template later.

Second try, as you suggested, I replaced them and complied the codes without errors. The signature of the function BilinearSamplerBHWD_updateOutput looks as follows:

int BilinearSamplerBHWD_updateOutput_cpu(THCudaTensor* inputImages, THCudaTensor* grids, THCudaTensor* output)

However, in this case, the complied functions in .so file are never called. The program seeds like freeze forever. The codes where the C++ function got called are defined as follows:
class RoICropFunction(Function):
    @staticmethod
    def forward(self, input1, input2):
        print("RoICropFunction forward")
        self.input1 = input1.clone()
        self.input2 = input2.clone()
        output = input2.new(input2.size()[0], input1.size()[1], input2.size()[1], input2.size()[2]).zero_()
        assert output.get_device() == input1.get_device(), "output and input1 must on the same device"
        assert output.get_device() == input2.get_device(), "output and input2 must on the same device"
        #  It freeze at this line
        _C.BilinearSamplerBHWD_updateOutput(input1, input2, output)

Any ideas to figure it out, what’s going on there? Thanks in advance! -Anakin