Skip to content

Commit

Permalink
Support Pytorch 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ClowDragon authored and fuwenguang committed Mar 22, 2024
1 parent 1f0d2e5 commit 93025c4
Show file tree
Hide file tree
Showing 26 changed files with 195 additions and 191 deletions.
4 changes: 0 additions & 4 deletions mmcv/ops/csrc/common/pytorch_mlu_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
#define PYTORCH_MLU_HELPER_HPP_

#ifdef MMCV_WITH_MLU
#ifdef MMCV_WITH_TORCH19
#include "aten.h"
#else
#include "utils/cnlog.h"
#include "utils/assert_tensor.h"
#include "framework/core/device.h"
Expand All @@ -25,7 +22,6 @@
#include "aten/utils/types.h"
#include "utils/cndumper.h"
#include "c10/core/ScalarTypeToTypeMeta.h"
#endif // MMCV_WITH_TORCH19

#define NFU_ALIGN_SIZE 128

Expand Down
6 changes: 3 additions & 3 deletions mmcv/ops/csrc/pytorch/mlu/ball_query_mlu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ void ball_query_forward_mlu(int b, int n, int m, float min_radius,
auto new_xyz_impl = torch_mlu::getMluTensorImpl(new_xyz_contiguous);
auto xyz_impl = torch_mlu::getMluTensorImpl(xyz_contiguous);
auto idx_impl = torch_mlu::getMluTensorImpl(idx_contiguous);
auto new_xyz_ptr = new_xyz_impl->cnnlMalloc();
auto xyz_ptr = xyz_impl->cnnlMalloc();
auto idx_ptr = idx_impl->cnnlMalloc();
auto new_xyz_ptr = torch_mlu::mlu_data_ptr(new_xyz_impl);
auto xyz_ptr = torch_mlu::mlu_data_ptr(xyz_impl);
auto idx_ptr = torch_mlu::mlu_data_ptr(idx_impl);

auto handle = mluOpGetCurrentHandle();
TORCH_MLUOP_CHECK(mluOpBallQuery(
Expand Down
6 changes: 3 additions & 3 deletions mmcv/ops/csrc/pytorch/mlu/box_iou_rotated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ void BoxIouRotatedMLUKernelLauncher(const Tensor boxes1, const Tensor boxes2,
auto boxes2_impl = torch_mlu::getMluTensorImpl(boxes2_contiguous);
auto ious_impl = torch_mlu::getMluTensorImpl(ious_contiguous);

auto boxes1_ptr = boxes1_impl->cnnlMalloc();
auto boxes2_ptr = boxes2_impl->cnnlMalloc();
auto ious_ptr = ious_impl->cnnlMalloc();
auto boxes1_ptr = torch_mlu::mlu_data_ptr(boxes1_impl);
auto boxes2_ptr = torch_mlu::mlu_data_ptr(boxes2_impl);
auto ious_ptr = torch_mlu::mlu_data_ptr(ious_impl);

CNLOG(INFO) << "Call mluOpBoxIouRotated().";
TORCH_MLUOP_CHECK(mluOpBoxIouRotated(
Expand Down
16 changes: 8 additions & 8 deletions mmcv/ops/csrc/pytorch/mlu/carafe_mlu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ void CARAFEForwardMLUKernelLauncher(const Tensor input, const Tensor mask,

// get ptr of tensors
auto input_impl = torch_mlu::getMluTensorImpl(rinput_);
auto input_ptr = input_impl->cnnlMalloc();
auto input_ptr = torch_mlu::mlu_data_ptr(input_impl);
auto mask_impl = torch_mlu::getMluTensorImpl(rmask_);
auto mask_ptr = mask_impl->cnnlMalloc();
auto mask_ptr = torch_mlu::mlu_data_ptr(mask_impl);
auto output_impl = torch_mlu::getMluTensorImpl(routput_);
auto output_ptr = output_impl->cnnlMalloc();
auto output_ptr = torch_mlu::mlu_data_ptr(output_impl);

// set op descriptor
auto handle = mluOpGetCurrentHandle();
Expand Down Expand Up @@ -146,15 +146,15 @@ void CARAFEBackwardMLUKernelLauncher(

// get ptr of tensors
auto input_impl = torch_mlu::getMluTensorImpl(rinput_);
auto input_ptr = input_impl->cnnlMalloc();
auto input_ptr = torch_mlu::mlu_data_ptr(input_impl);
auto mask_impl = torch_mlu::getMluTensorImpl(rmask_);
auto mask_ptr = mask_impl->cnnlMalloc();
auto mask_ptr = torch_mlu::mlu_data_ptr(mask_impl);
auto grad_output_impl = torch_mlu::getMluTensorImpl(rgrad_output_);
auto grad_output_ptr = grad_output_impl->cnnlMalloc();
auto grad_output_ptr = torch_mlu::mlu_data_ptr(grad_output_impl);
auto grad_input_impl = torch_mlu::getMluTensorImpl(rgrad_input_);
auto grad_input_ptr = grad_input_impl->cnnlMalloc();
auto grad_input_ptr = torch_mlu::mlu_data_ptr(grad_input_impl);
auto grad_mask_impl = torch_mlu::getMluTensorImpl(rgrad_mask_);
auto grad_mask_ptr = grad_mask_impl->cnnlMalloc();
auto grad_mask_ptr = torch_mlu::mlu_data_ptr(grad_mask_impl);

// set op descriptor
auto handle = mluOpGetCurrentHandle();
Expand Down
34 changes: 17 additions & 17 deletions mmcv/ops/csrc/pytorch/mlu/deform_conv_mlu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ void deform_conv_forward_mlu(Tensor input, Tensor weight, Tensor offset,

//get ptr of tensors
auto input_impl = torch_mlu::getMluTensorImpl(input_contiguous);
auto input_ptr = input_impl->cnnlMalloc();
auto input_ptr = torch_mlu::mlu_data_ptr(input_impl);
auto weight_impl = torch_mlu::getMluTensorImpl(weight_contiguous);
auto weight_ptr = weight_impl->cnnlMalloc();
auto weight_ptr = torch_mlu::mlu_data_ptr(weight_impl);
auto offset_impl = torch_mlu::getMluTensorImpl(offset_contiguous);
auto offset_ptr = offset_impl->cnnlMalloc();
auto offset_ptr = torch_mlu::mlu_data_ptr(offset_impl);
auto output_impl = torch_mlu::getMluTensorImpl(output_contiguous);
auto output_ptr = output_impl->cnnlMalloc();
auto output_ptr = torch_mlu::mlu_data_ptr(output_impl);

// allocate workspace
size_t workspace_size = 0;
Expand All @@ -67,7 +67,7 @@ void deform_conv_forward_mlu(Tensor input, Tensor weight, Tensor offset,
weight_desc.desc(), NULL, output_desc.desc(), &workspace_size));
auto workspace = at::empty(workspace_size, input.options().dtype(at::ScalarType::Char));
auto workspace_impl = torch_mlu::getMluTensorImpl(workspace);
auto workspace_ptr = workspace_impl->cnnlMalloc();
auto workspace_ptr = torch_mlu::mlu_data_ptr(workspace_impl);

TORCH_MLUOP_CHECK(mluOpDCNForward(handle, dcn_desc.desc(), input_desc.desc(),
input_ptr, offset_desc.desc(), offset_ptr, NULL, NULL,
Expand Down Expand Up @@ -119,12 +119,12 @@ void deform_conv_backward_input_mlu(Tensor input, Tensor offset, Tensor gradOutp
dcn_desc.set(input.dim(), padding, stride, dilation,
deformable_group, group, im2col_step, MLUOP_DTYPE_FLOAT);
// set ptrs
auto grad_ptr = grad_impl->cnnlMalloc();
auto input_ptr = input_impl->cnnlMalloc();
auto offset_ptr = offset_impl->cnnlMalloc();
auto weight_ptr = weight_impl->cnnlMalloc();
auto grad_input_ptr = grad_input_impl->cnnlMalloc();
auto grad_offset_ptr = grad_offset_impl->cnnlMalloc();
auto grad_ptr = torch_mlu::mlu_data_ptr(grad_impl);
auto input_ptr = torch_mlu::mlu_data_ptr(input_impl);
auto offset_ptr = torch_mlu::mlu_data_ptr(offset_impl);
auto weight_ptr = torch_mlu::mlu_data_ptr(weight_impl);
auto grad_input_ptr = torch_mlu::mlu_data_ptr(grad_input_impl);
auto grad_offset_ptr = torch_mlu::mlu_data_ptr(grad_offset_impl);
// allocate workspace
size_t data_workspace_size = 0;
TORCH_MLUOP_CHECK(mluOpGetDCNBakcwardDataWorkspaceSize(
Expand All @@ -145,7 +145,7 @@ void deform_conv_backward_input_mlu(Tensor input, Tensor offset, Tensor gradOutp
data_workspace = at::empty(data_workspace_size,
input.options().dtype(at::ScalarType::Char));
auto data_workspace_impl = torch_mlu::getMluTensorImpl(data_workspace);
data_workspace_ptr = data_workspace_impl->mlu_data_ptr();
data_workspace_ptr = torch_mlu::mlu_data_ptr(data_workspace_impl);
TORCH_MLUOP_CHECK(mluOpDCNBackwardData(
/* handle */ handle,
/* dcn_desc */ dcn_desc.desc(),
Expand Down Expand Up @@ -203,10 +203,10 @@ void deform_conv_backward_parameters_mlu(Tensor input, Tensor offset, Tensor gra
dcn_desc.set(input.dim(), padding, stride, dilation,
deformable_group, group, im2col_step, MLUOP_DTYPE_FLOAT);
// set ptrs
auto grad_ptr = grad_impl->cnnlMalloc();
auto input_ptr = input_impl->cnnlMalloc();
auto offset_ptr = offset_impl->cnnlMalloc();
auto grad_weight_ptr = grad_weight_impl->cnnlMalloc();
auto grad_ptr = torch_mlu::mlu_data_ptr(grad_impl);
auto input_ptr = torch_mlu::mlu_data_ptr(input_impl);
auto offset_ptr = torch_mlu::mlu_data_ptr(offset_impl);
auto grad_weight_ptr = torch_mlu::mlu_data_ptr(grad_weight_impl);

// allocate workspace
size_t weight_workspace_size = 0;
Expand All @@ -226,7 +226,7 @@ void deform_conv_backward_parameters_mlu(Tensor input, Tensor offset, Tensor gra
weight_workspace = at::empty(weight_workspace_size,
input.options().dtype(at::ScalarType::Char));
auto weight_workspace_impl = torch_mlu::getMluTensorImpl(weight_workspace);
weight_workspace_ptr = weight_workspace_impl->mlu_data_ptr();
weight_workspace_ptr = torch_mlu::mlu_data_ptr(weight_workspace_impl);
TORCH_MLUOP_CHECK(mluOpDCNBackwardWeight(
/* handle */ handle,
/* dcn_desc */ dcn_desc.desc(),
Expand Down
20 changes: 10 additions & 10 deletions mmcv/ops/csrc/pytorch/mlu/deform_roi_pool_mlu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ void DeformRoIPoolForwardMLUKernelLauncher(Tensor input, Tensor rois,
offset_desc.set(offset_contiguous);
offset_real_desc = offset_desc.desc();
auto offset_impl = torch_mlu::getMluTensorImpl(offset_contiguous);
offset_ptr = offset_impl->cnnlMalloc();
offset_ptr = torch_mlu::mlu_data_ptr(offset_impl);
}

// get ptr of tensors
auto input_impl = torch_mlu::getMluTensorImpl(input_);
auto input_ptr = input_impl->cnnlMalloc();
auto input_ptr = torch_mlu::mlu_data_ptr(input_impl);
auto rois_impl = torch_mlu::getMluTensorImpl(rois_contiguous);
auto rois_ptr = rois_impl->cnnlMalloc();
auto rois_ptr = torch_mlu::mlu_data_ptr(rois_impl);
auto output_impl = torch_mlu::getMluTensorImpl(output_contiguous);
auto output_ptr = output_impl->cnnlMalloc();
auto output_ptr = torch_mlu::mlu_data_ptr(output_impl);

// get compute handle
auto handle = mluOpGetCurrentHandle();
Expand Down Expand Up @@ -76,13 +76,13 @@ void DeformRoIPoolBackwardMLUKernelLauncher(

// get ptr of tensors
auto grad_output_impl = torch_mlu::getMluTensorImpl(grad_output_);
auto grad_output_ptr = grad_output_impl->cnnlMalloc();
auto grad_output_ptr = torch_mlu::mlu_data_ptr(grad_output_impl);
auto input_impl = torch_mlu::getMluTensorImpl(input_);
auto input_ptr = input_impl->cnnlMalloc();
auto input_ptr = torch_mlu::mlu_data_ptr(input_impl);
auto rois_impl = torch_mlu::getMluTensorImpl(rois_contiguous);
auto rois_ptr = rois_impl->cnnlMalloc();
auto rois_ptr = torch_mlu::mlu_data_ptr(rois_impl);
auto grad_input_impl = torch_mlu::getMluTensorImpl(grad_input_);
auto grad_input_ptr = grad_input_impl->cnnlMalloc();
auto grad_input_ptr = torch_mlu::mlu_data_ptr(grad_input_impl);

MluOpTensorDescriptor grad_output_desc, input_desc, rois_desc, offset_desc,
grad_input_desc, grad_offset_desc;
Expand All @@ -98,7 +98,7 @@ void DeformRoIPoolBackwardMLUKernelLauncher(
offset_desc.set(offset_contiguous);
offset_real_desc = offset_desc.desc();
auto offset_impl = torch_mlu::getMluTensorImpl(offset_contiguous);
offset_ptr = offset_impl->cnnlMalloc();
offset_ptr = torch_mlu::mlu_data_ptr(offset_impl);
}
mluOpTensorDescriptor_t grad_offset_real_desc = NULL;
void *grad_offset_ptr = NULL;
Expand All @@ -108,7 +108,7 @@ void DeformRoIPoolBackwardMLUKernelLauncher(
grad_offset_desc.set(grad_offset_contiguous);
grad_offset_real_desc = grad_offset_desc.desc();
auto grad_offset_impl = torch_mlu::getMluTensorImpl(grad_offset_contiguous);
grad_offset_ptr = grad_offset_impl->cnnlMalloc();
grad_offset_ptr = torch_mlu::mlu_data_ptr(grad_offset_impl);
}

// get compute handle
Expand Down
16 changes: 8 additions & 8 deletions mmcv/ops/csrc/pytorch/mlu/focal_loss_sigmoid_mlu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ void sigmoid_focal_loss_forward_mlu(Tensor input, Tensor target, Tensor weight,

// get ptr of tensors
auto input_impl = torch_mlu::getMluTensorImpl(input_contiguous);
auto input_ptr = input_impl->cnnlMalloc();
auto input_ptr = torch_mlu::mlu_data_ptr(input_impl);
auto target_impl = torch_mlu::getMluTensorImpl(target_contiguous);
auto target_ptr = target_impl->cnnlMalloc();
auto target_ptr = torch_mlu::mlu_data_ptr(target_impl);
auto weight_impl = torch_mlu::getMluTensorImpl(weight_contiguous);
auto weight_ptr = weight_impl->cnnlMalloc();
auto weight_ptr = torch_mlu::mlu_data_ptr(weight_impl);
auto output_impl = torch_mlu::getMluTensorImpl(output_contiguous);
auto output_ptr = output_impl->cnnlMalloc();
auto output_ptr = torch_mlu::mlu_data_ptr(output_impl);

// set prefer computation performance and redcuntion approach
mluOpComputationPreference_t prefer = MLUOP_COMPUTATION_FAST;
Expand Down Expand Up @@ -142,13 +142,13 @@ void sigmoid_focal_loss_backward_mlu(Tensor input, Tensor target, Tensor weight,

// get ptr of tensors
auto input_impl = torch_mlu::getMluTensorImpl(input_contiguous);
auto input_ptr = input_impl->cnnlMalloc();
auto input_ptr = torch_mlu::mlu_data_ptr(input_impl);
auto target_impl = torch_mlu::getMluTensorImpl(target_contiguous);
auto target_ptr = target_impl->cnnlMalloc();
auto target_ptr = torch_mlu::mlu_data_ptr(target_impl);
auto weight_impl = torch_mlu::getMluTensorImpl(weight_contiguous);
auto weight_ptr = weight_impl->cnnlMalloc();
auto weight_ptr = torch_mlu::mlu_data_ptr(weight_impl);
auto output_impl = torch_mlu::getMluTensorImpl(output_contiguous);
auto output_ptr = output_impl->cnnlMalloc();
auto output_ptr = torch_mlu::mlu_data_ptr(output_impl);

// set prefer computation performance and redcuntion approach
// backward only support MLUOP_COMPUTATION_HIGH_PRECISION
Expand Down
8 changes: 4 additions & 4 deletions mmcv/ops/csrc/pytorch/mlu/iou3d_mlu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ void IoU3DNMS3DMLUKernelLauncher(Tensor boxes, Tensor &keep, Tensor &keep_num,

// get compute queue
auto boxes_impl = torch_mlu::getMluTensorImpl(boxes_);
auto boxes_ptr = boxes_impl->cnnlMalloc();
auto boxes_ptr = torch_mlu::mlu_data_ptr(boxes_impl);
auto workspace_impl = torch_mlu::getMluTensorImpl(workspace);
auto workspace_ptr = workspace_impl->cnnlMalloc();
auto workspace_ptr = torch_mlu::mlu_data_ptr(workspace_impl);
auto output_impl = torch_mlu::getMluTensorImpl(keep);
auto output_ptr = output_impl->cnnlMalloc();
auto output_ptr = torch_mlu::mlu_data_ptr(output_impl);
auto output_size_impl = torch_mlu::getMluTensorImpl(keep_num);
auto output_size_ptr = output_size_impl->cnnlMalloc();
auto output_size_ptr = torch_mlu::mlu_data_ptr(output_size_impl);

// nms desc
mluOpNmsDescriptor_t nms_desc;
Expand Down
20 changes: 10 additions & 10 deletions mmcv/ops/csrc/pytorch/mlu/masked_conv2d_mlu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ void MaskedIm2colForwardMLUKernelLauncher(const Tensor im,

// get ptr of tensors
auto im_impl = torch_mlu::getMluTensorImpl(im_contiguous);
auto im_ptr = im_impl->cnnlMalloc();
auto im_ptr = torch_mlu::mlu_data_ptr(im_impl);
auto mask_h_idx_impl = torch_mlu::getMluTensorImpl(mask_h_idx_cast);
auto mask_h_idx_ptr = mask_h_idx_impl->cnnlMalloc();
auto mask_h_idx_ptr = torch_mlu::mlu_data_ptr(mask_h_idx_impl);
auto mask_w_idx_impl = torch_mlu::getMluTensorImpl(mask_w_idx_cast);
auto mask_w_idx_ptr = mask_w_idx_impl->cnnlMalloc();
auto mask_w_idx_ptr = torch_mlu::mlu_data_ptr(mask_w_idx_impl);
auto col_impl = torch_mlu::getMluTensorImpl(col);
auto col_ptr = col_impl->cnnlMalloc();
auto col_ptr = torch_mlu::mlu_data_ptr(col_impl);

// set descriptors
MluOpTensorDescriptor im_desc, col_desc, mask_h_idx_desc, mask_w_idx_desc;
Expand All @@ -93,7 +93,7 @@ void MaskedIm2colForwardMLUKernelLauncher(const Tensor im,

auto workspace = at::empty(workspace_size, im.options().dtype(at::kByte));
auto workspace_impl = torch_mlu::getMluTensorImpl(workspace);
auto workspace_ptr = workspace_impl->cnnlMalloc();
auto workspace_ptr = torch_mlu::mlu_data_ptr(workspace_impl);

// launch kernel
TORCH_MLUOP_CHECK(mluOpMaskedIm2colForward(
Expand Down Expand Up @@ -154,13 +154,13 @@ void MaskedCol2imForwardMLUKernelLauncher(const Tensor col,

// get ptr of tensors
auto im_impl = torch_mlu::getMluTensorImpl(im_contiguous);
auto im_ptr = im_impl->cnnlMalloc();
auto im_ptr = torch_mlu::mlu_data_ptr(im_impl);
auto mask_h_idx_impl = torch_mlu::getMluTensorImpl(mask_h_idx_cast);
auto mask_h_idx_ptr = mask_h_idx_impl->cnnlMalloc();
auto mask_h_idx_ptr = torch_mlu::mlu_data_ptr(mask_h_idx_impl);
auto mask_w_idx_impl = torch_mlu::getMluTensorImpl(mask_w_idx_cast);
auto mask_w_idx_ptr = mask_w_idx_impl->cnnlMalloc();
auto mask_w_idx_ptr = torch_mlu::mlu_data_ptr(mask_w_idx_impl);
auto col_impl = torch_mlu::getMluTensorImpl(col_contiguous);
auto col_ptr = col_impl->cnnlMalloc();
auto col_ptr = torch_mlu::mlu_data_ptr(col_impl);

// set descriptors
MluOpTensorDescriptor im_desc, col_desc, mask_h_idx_desc, mask_w_idx_desc;
Expand All @@ -180,7 +180,7 @@ void MaskedCol2imForwardMLUKernelLauncher(const Tensor col,

auto workspace = at::empty(workspace_size, im.options().dtype(at::kByte));
auto workspace_impl = torch_mlu::getMluTensorImpl(workspace);
auto workspace_ptr = workspace_impl->cnnlMalloc();
auto workspace_ptr = torch_mlu::mlu_data_ptr(workspace_impl);

// launch kernel
TORCH_MLUOP_CHECK(mluOpMaskedCol2imForward(
Expand Down
12 changes: 7 additions & 5 deletions mmcv/ops/csrc/pytorch/mlu/mlu_common_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
#pragma once
#include <ATen/ATen.h>
#include <c10/core/ScalarType.h>

#ifdef MMCV_WITH_TORCH19
#include "aten.h"
#else
#include "utils/cnlog.h"
#include "utils/assert_tensor.h"
#include "framework/core/device.h"
Expand All @@ -29,6 +25,12 @@ namespace torch_mlu::cnnl::ops {
using torch_mlu::cnnl_contiguous;
using torch_mlu::get_channels_last_memory_format;
}
#ifdef MMCV_WITH_TORCH_OLD
namespace torch_mlu {
inline void* mlu_data_ptr(c10::TensorImpl* impl) {
return impl->mlu_data_ptr();
}
} // namespace torch_mlu
#endif

#include "mlu_op.h"
Expand All @@ -46,7 +48,7 @@ using torch_mlu::get_channels_last_memory_format;
MluOpTensorDescriptor NAME##_desc; \
NAME##_desc.set(NAME##_contigous); \
auto NAME##_impl = torch_mlu::getMluTensorImpl(NAME##_contigous); \
auto NAME##_ptr = NAME##_impl->cnnlMalloc();
auto NAME##_ptr = torch_mlu::mlu_data_ptr(NAME##_impl);

#ifndef TORCH_MLUOP_CHECK
#define TORCH_MLUOP_CHECK(EXPR) \
Expand Down
Loading

0 comments on commit 93025c4

Please sign in to comment.