Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
momo609 committed Jan 30, 2024
1 parent a42224c commit 8ce4df7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions mmcv/ops/csrc/common/pytorch_npu_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,8 @@ inline c10::Scalar ConvertTensorToScalar(const at::Tensor &tensor) {
inline at::Tensor CopyTensorHostToDevice(const at::Tensor &cpu_tensor) {
at::Tensor cpuPinMemTensor = cpu_tensor.pin_memory();
int deviceIndex = 0;
return cpuPinMemTensor.to(
c10::Device(DEVICE_TYPE, deviceIndex),
cpuPinMemTensor.scalar_type(), true, true);
return cpuPinMemTensor.to(c10::Device(DEVICE_TYPE, deviceIndex),
cpuPinMemTensor.scalar_type(), true, true);
}

inline at::Tensor CopyScalarToDevice(const c10::Scalar &cpu_scalar,
Expand Down Expand Up @@ -260,16 +259,18 @@ inline aclTensor *ConvertType(const at::Tensor &at_tensor) {
if (at_tensor.unsafeGetTensorImpl()->is_wrapped_number()) {
c10::Scalar expScalar = ConvertTensorToScalar(at_tensor);
at::Tensor aclInput = CopyScalarToDevice(expScalar, scalar_data_type);
return aclCreateTensor(
aclInput.sizes().data(), aclInput.sizes().size(), acl_data_type,
aclInput.strides().data(), aclInput.storage_offset(), format,
storageDims.data(), storageDims.size(), const_cast<void*>(aclInput.storage().data()));
return aclCreateTensor(aclInput.sizes().data(), aclInput.sizes().size(),
acl_data_type, aclInput.strides().data(),
aclInput.storage_offset(), format,
storageDims.data(), storageDims.size(),
const_cast<void *>(aclInput.storage().data()));
}

auto acl_tensor = aclCreateTensor(
at_tensor.sizes().data(), at_tensor.sizes().size(), acl_data_type,
at_tensor.strides().data(), at_tensor.storage_offset(), format,
storageDims.data(), storageDims.size(), const_cast<void*>(at_tensor.storage().data()));
storageDims.data(), storageDims.size(),
const_cast<void *>(at_tensor.storage().data()));
return acl_tensor;
}

Expand Down Expand Up @@ -554,7 +555,7 @@ typedef void (*ReleaseHugeMem)(void *, bool);
at::TensorOptions(torch_npu::utils::get_npu_device_type()); \
auto workspace_tensor = \
at::empty({workspace_size}, options.dtype(kByte)); \
workspace_addr = const_cast<void*>(workspace_tensor.storage().data()); \
workspace_addr = const_cast<void *>(workspace_tensor.storage().data()); \
} \
auto acl_call = [converted_params, workspace_addr, workspace_size, \
acl_stream, executor]() -> int { \
Expand Down
2 changes: 1 addition & 1 deletion mmcv/ops/csrc/pytorch/npu/chamfer_distance_npu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ void chamfer_distance_backward_impl(Tensor xyz1, Tensor xyz2, Tensor idx1, Tenso
Tensor grad_dist1, Tensor grad_dist2,
Tensor grad_xyz1, Tensor grad_xyz2);
REGISTER_NPU_IMPL(chamfer_distance_backward_impl,
chamfer_distance_backward_npu);
chamfer_distance_backward_npu);

0 comments on commit 8ce4df7

Please sign in to comment.