已合并
bugfix: eliminate redundant operations in sort. #5130
yvjc创建于 6月8日
bugfix: eliminate redundant operations in sort. #5130
已合并
从已删除 :shangfa合入到Ascend/op-plugin26.1.0
共 1 个文件变更+0-15
| @@ -27,20 +27,11 @@ std::tuple<at::Tensor &, at::Tensor &> sort_output(const at::Tensor &self, bool | |||
| 27 | return std::tie(values, indices); | 27 | return std::tie(values, indices); |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | -std::vector<int64_t> compute_sort_strides(const at::Tensor& self) { | ||
| 31 | - return self.is_non_overlapping_and_dense() | ||
| 32 | - ? self.strides().vec() | ||
| 33 | - : at::infer_dense_strides(self.sizes(), self.strides()); | ||
| 34 | -} | ||
| 35 | - | ||
| 36 | std::tuple<at::Tensor, at::Tensor> sort(const at::Tensor &self, int64_t dim, bool descending) | 30 | std::tuple<at::Tensor, at::Tensor> sort(const at::Tensor &self, int64_t dim, bool descending) |
| 37 | { | 31 | { |
| 38 | DO_COMPATIBILITY(aclnnSort, acl_op::sort(self, dim, descending)); | 32 | DO_COMPATIBILITY(aclnnSort, acl_op::sort(self, dim, descending)); |
| 39 | - auto strides = compute_sort_strides(self); | ||
| 40 | at::Tensor values = npu_preparation::apply_tensor_without_format(self); | 33 | at::Tensor values = npu_preparation::apply_tensor_without_format(self); |
| 41 | at::Tensor indices = npu_preparation::apply_tensor_without_format(self.sizes(), self.options().dtype(at::kLong)); | 34 | at::Tensor indices = npu_preparation::apply_tensor_without_format(self.sizes(), self.options().dtype(at::kLong)); |
| 42 | - values = values.as_strided_(self.sizes(), strides); | ||
| 43 | - indices = indices.as_strided_(self.sizes(), strides); | ||
| 44 | bool stable = false; | 35 | bool stable = false; |
| 45 | 36 | ||
| 46 | return sort_output(self, stable, dim, descending, values, indices); | 37 | return sort_output(self, stable, dim, descending, values, indices); |
| @@ -49,11 +40,8 @@ std::tuple<at::Tensor, at::Tensor> sort(const at::Tensor &self, int64_t dim, boo | |||
| 49 | std::tuple<at::Tensor, at::Tensor> sort(const at::Tensor &self, at::Dimname dim, bool descending) | 40 | std::tuple<at::Tensor, at::Tensor> sort(const at::Tensor &self, at::Dimname dim, bool descending) |
| 50 | { | 41 | { |
| 51 | DO_COMPATIBILITY(aclnnSort, acl_op::sort(self, dim, descending)); | 42 | DO_COMPATIBILITY(aclnnSort, acl_op::sort(self, dim, descending)); |
| 52 | - auto strides = compute_sort_strides(self); | ||
| 53 | at::Tensor values = npu_preparation::apply_tensor_without_format(self); | 43 | at::Tensor values = npu_preparation::apply_tensor_without_format(self); |
| 54 | at::Tensor indices = npu_preparation::apply_tensor_without_format(self.sizes(), self.options().dtype(at::kLong)); | 44 | at::Tensor indices = npu_preparation::apply_tensor_without_format(self.sizes(), self.options().dtype(at::kLong)); |
| 55 | - values = values.as_strided_(self.sizes(), strides); | ||
| 56 | - indices = indices.as_strided_(self.sizes(), strides); | ||
| 57 | bool stable = false; | 45 | bool stable = false; |
| 58 | int64_t argDim = dimname_to_position(self, dim); | 46 | int64_t argDim = dimname_to_position(self, dim); |
| 59 | 47 | ||
| @@ -90,11 +78,8 @@ std::tuple<at::Tensor, at::Tensor> sort(const at::Tensor &self, | |||
| 90 | auto dtype = self.scalar_type(); | 78 | auto dtype = self.scalar_type(); |
| 91 | TORCH_CHECK(!(dtype == at::kDouble), | 79 | TORCH_CHECK(!(dtype == at::kDouble), |
| 92 | "Input data type should not be float64 " + OPS_ERROR(ErrCode::TYPE)); | 80 | "Input data type should not be float64 " + OPS_ERROR(ErrCode::TYPE)); |
| 93 | - auto strides = compute_sort_strides(self); | ||
| 94 | at::Tensor values = npu_preparation::apply_tensor_without_format(self); | 81 | at::Tensor values = npu_preparation::apply_tensor_without_format(self); |
| 95 | at::Tensor indices = npu_preparation::apply_tensor_without_format(self.sizes(), self.options().dtype(at::kLong)); | 82 | at::Tensor indices = npu_preparation::apply_tensor_without_format(self.sizes(), self.options().dtype(at::kLong)); |
| 96 | - values = values.as_strided_(self.sizes(), strides); | ||
| 97 | - indices = indices.as_strided_(self.sizes(), strides); | ||
| 98 | bool argStable = c10::value_or_else(stable, [] { return false; }); | 83 | bool argStable = c10::value_or_else(stable, [] { return false; }); |
| 99 | EXEC_NPU_CMD(aclnnSort, self, argStable, dim, descending, values, indices); | 84 | EXEC_NPU_CMD(aclnnSort, self, argStable, dim, descending, values, indices); |
| 100 | return std::tie(values, indices); | 85 | return std::tie(values, indices); |