BugFix with ParseInputDataType from LodTensorArray #32918
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR types
Bug fixes
PR changes
Others
Describe
1. PR内容
修复LoDTensorArray作为Op的输入时,在GetExepectedKernelType函数中ParseInputDataType的极其隐藏bug。
2. BUG原因
报错信息:
问题代码:
https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/fluid/framework/operator.cc#L1541-L1572
3. 解决方案
将t_arr改为引用,因为此处每次返回指向的Tensor都是内在的Tensor地址。
PR之前:
修复之后:
I0514 08:16:24.946592 17077 device_context.cc:94] DeviceContextPool Get: CUDAPlace(0) I0514 08:16:24.946602 17077 device_context.cc:94] DeviceContextPool Get: CUDAPlace(0)0x7fc3ef8c8700 # 以下4次的 t 的指针都是一致的,后两行为出了if block后,t->Holder()也是一致的 I0514 08:16:24.946631 17077 operator.cc:1556] tensor array[0] ptr: 0x7fc3a4013df8 holder: 0x7fc3a400de40 , 0x7fc3ef8c8600 I0514 08:16:24.946635 17077 operator.cc:1557] tensor array[0] ptr: 0x7fc3a4013df8 holder: 0x7fc3a400de40 , 0x7fc3ef8c8600 I0514 08:16:24.946640 17077 operator.cc:1561] tmp dtype int tensor ptr: 0x7fc3a4013df8 holder: 0x7fc3a400de40 , 0x7fc3ef8c8600 I0514 08:16:24.946645 17077 operator.cc:1569] tmp dtype int tensor ptr: 0x7fc3a4013df8 holder: 0x7fc3a400de40 , 0x7fc3ef8c8600
4. 之前为啥没有触发
undefined behavior
,如果block外的访问的内存还未被释放或未被重新重新分配和修改,可能误打误撞返回有效值。