Merged
新增ViewCopy重载接口,支持传入inplaceFlag参数 #6164
ren-botaoAdd on Oct 8
新增ViewCopy重载接口,支持传入inplaceFlag参数 #6164
Merged
Total: 2 files changed+21-5
| @@ -67,6 +67,16 @@ const aclTensor* Contiguous(const aclTensor* x, aclOpExecutor* executor); | |||
| 67 | */ | 67 | */ |
| 68 | const aclTensor* ViewCopy(const aclTensor* x, const aclTensor* y, aclOpExecutor* executor); | 68 | const aclTensor* ViewCopy(const aclTensor* x, const aclTensor* y, aclOpExecutor* executor); |
| 69 | 69 | ||
| 70 | +/** | ||
| 71 | + * @brief 将连续tensor拷贝到非连续的tensor上 | ||
| 72 | + * @param x | ||
| 73 | + * @param y | ||
| 74 | + * @param executor | ||
| 75 | + * @param inplaceFlag | ||
| 76 | + * @return aclTensor 转换后的tensor | ||
| 77 | + */ | ||
| 78 | +const aclTensor* ViewCopy(const aclTensor* x, const aclTensor* y, aclOpExecutor* executor, bool inplaceFlag); | ||
| 79 | + | ||
| 70 | /** | 80 | /** |
| 71 | * @brief 对Tensor创建一个View,要求Tensor满足PickView的条件 | 81 | * @brief 对Tensor创建一个View,要求Tensor满足PickView的条件 |
| 72 | * @param x 输入Tensor,可以是一整块的非连续Tensor | 82 | * @param x 输入Tensor,可以是一整块的非连续Tensor |
| @@ -78,9 +88,8 @@ const aclTensor* PickViewAsContiguous(const aclTensor* x, aclOpExecutor* executo | |||
| 78 | const aclTensor* ReViewToOut(const aclTensor* x, const aclTensor* y, aclOpExecutor* executor); | 88 | const aclTensor* ReViewToOut(const aclTensor* x, const aclTensor* y, aclOpExecutor* executor); |
| 79 | 89 | ||
| 80 | // ============内部接口============= | 90 | // ============内部接口============= |
| 81 | -bool CanOptimizeContiguous( | 91 | +bool CanOptimizeContiguous(const op::Shape& viewShape, const op::Strides& strides, int64_t offset, int64_t storageSize, |
| 82 | - const op::Shape& viewShape, const op::Strides& strides, int64_t offset, int64_t storageSize, | 92 | + ContiguousParam& param); |
| 83 | - ContiguousParam& param); | ||
| 84 | 93 | ||
| 85 | bool CanOptimizeView(const op::Shape& viewShape, const op::Strides& strides, int64_t offset, ContiguousParam& param); | 94 | bool CanOptimizeView(const op::Shape& viewShape, const op::Strides& strides, int64_t offset, ContiguousParam& param); |
| 86 | // ============内部接口============= | 95 | // ============内部接口============= |
| @@ -664,6 +664,11 @@ inline bool CheckViewCopyParams(const aclTensor* x, const aclTensor* y) | |||
| 664 | } | 664 | } |
| 665 | 665 | ||
| 666 | const aclTensor* ViewCopy(const aclTensor* x, const aclTensor* y, aclOpExecutor* executor) | 666 | const aclTensor* ViewCopy(const aclTensor* x, const aclTensor* y, aclOpExecutor* executor) |
| 667 | +{ | ||
| 668 | + return ViewCopy(x, y, executor, false); | ||
| 669 | +} | ||
| 670 | + | ||
| 671 | +const aclTensor* ViewCopy(const aclTensor* x, const aclTensor* y, aclOpExecutor* executor, bool inplaceFlag) | ||
| 667 | { | 672 | { |
| 668 | L0_DFX(ViewCopy, x, y); | 673 | L0_DFX(ViewCopy, x, y); |
| 669 | OP_LOGD("ViewCopy data addr: %p", y->GetData()); | 674 | OP_LOGD("ViewCopy data addr: %p", y->GetData()); |
| @@ -677,8 +682,10 @@ const aclTensor* ViewCopy(const aclTensor* x, const aclTensor* y, aclOpExecutor* | |||
| 677 | if (!x->IsFromWorkspace()) { | 682 | if (!x->IsFromWorkspace()) { |
| 678 | // x and y point to the same tensor. | 683 | // x and y point to the same tensor. |
| 679 | if (x->GetData() == y->GetData()) { | 684 | if (x->GetData() == y->GetData()) { |
| 680 | - executor->AbandonCache(true); | 685 | + OP_LOGD("The input and output point to the same address, inplace flag: %d.", inplaceFlag); |
| 681 | - OP_LOGD("The input and output point to the same address."); | 686 | + if (!inplaceFlag) { |
| 687 | + executor->AbandonCache(true); | ||
| 688 | + } | ||
| 682 | return y; | 689 | return y; |
| 683 | } | 690 | } |
| 684 | auto yView = (x->GetStorageShape() == y->GetStorageShape()) ? y : | 691 | auto yView = (x->GetStorageShape() == y->GetStorageShape()) ? y : |