Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] support dipu_mock_cuda=False in dipu for mmcv ext ops with cpu fallback #2839

Merged
merged 5 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion mmcv/ops/csrc/pytorch/bbox_overlaps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ void bbox_overlaps_diopi(const Tensor bboxes1, const Tensor bboxes2,
diopiContextHandle_t ch = &ctx;
auto bboxes2_p = toDiopiTensorHandle(bboxes2);
auto ious_p = toDiopiTensorHandle(ious);
if (reinterpret_cast<void *>(diopiBboxOverlapsMmcv) != nullptr) {
bool is_mock_cuda = bboxes1.device().type() == c10::DeviceType::PrivateUse1;
if (is_mock_cuda &&
reinterpret_cast<void *>(diopiBboxOverlapsMmcv) != nullptr) {
auto ret = diopiBboxOverlapsMmcv(ch, ious_p, bboxes1_p, bboxes2_p, mode,
offset, aligned);
if (ret == diopiSuccess) return;
Expand Down
3 changes: 2 additions & 1 deletion mmcv/ops/csrc/pytorch/nms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ Tensor nms_diopi(Tensor boxes, Tensor scores, float iou_threshold, int offset) {
auto outp = toDiopiTensorHandle(out);
diopiTensorHandle_t* outhandle = &outp;
auto scores_p = toDiopiTensorHandle(scores);
if (reinterpret_cast<void*>(diopiNmsMmcv) != nullptr) {
bool is_mock_cuda = boxes.device().type() == c10::DeviceType::PrivateUse1;
if (is_mock_cuda && reinterpret_cast<void*>(diopiNmsMmcv) != nullptr) {
auto ret =
diopiNmsMmcv(ch, outhandle, boxes_p, scores_p, iou_threshold, offset);
if (ret == diopiSuccess) {
Expand Down
8 changes: 6 additions & 2 deletions mmcv/ops/csrc/pytorch/roi_align.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ void roi_align_forward_diopi(Tensor input, Tensor rois, Tensor output,
auto out_p = toDiopiTensorHandle(output);
auto argmax_y_p = toDiopiTensorHandle(argmax_y);
auto argmax_x_p = toDiopiTensorHandle(argmax_x);
if (reinterpret_cast<void*>(diopiRoiAlignMmcv) != nullptr) {
bool is_mock_cuda = input.device().type() == c10::DeviceType::PrivateUse1;
if (is_mock_cuda && reinterpret_cast<void*>(diopiRoiAlignMmcv) != nullptr) {
auto ret = diopiRoiAlignMmcv(
ch, out_p, argmax_y_p, argmax_x_p, input_p, rois_p, aligned_height,
aligned_width, sampling_ratio, pool_mode, spatial_scale, aligned);
Expand Down Expand Up @@ -91,7 +92,10 @@ void roi_align_backward_diopi(Tensor grad_output, Tensor rois, Tensor argmax_y,
auto grad_input_ = toDiopiTensorHandle(grad_input);
diopiContext ctx(dipu::getCurrentDIPUStream().rawstream());
diopiContextHandle_t ch = &ctx;
if (reinterpret_cast<void*>(diopiRoiAlignBackwardMmcv) != nullptr) {
bool is_mock_cuda =
grad_output.device().type() == c10::DeviceType::PrivateUse1;
if (is_mock_cuda &&
reinterpret_cast<void*>(diopiRoiAlignBackwardMmcv) != nullptr) {
auto ret = diopiRoiAlignBackwardMmcv(ch, grad_input_, grad_output_, rois_,
argmax_y_, argmax_x_, aligned_height,
aligned_width, sampling_ratio,
Expand Down