[LITE][CORE][NPU][XPU] Recording the data type when mutable_data() is called #2735
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.
背景问题:
目前,在NPU/XPU子图算子桥接器的实现过程中,我们利用算子Kernel的param的类型来推断输入Tensor的数据类型,以便使用NPU/XPU提供的Graph API创建NPU/XPU的IR/Layer(华为的HiAI和XPU的XTCL接口在创建Tensor IR/Layer的时候需要设置DataType)。但对于reshape类似的算子,其注册的Kernel如下所示,输入X的数据类型为PRECISION(kAny),因此,无法推断输入Tensor的数据类型。
REGISTER_LITE_KERNEL(reshape,
kHost,
kAny,
kAny,
paddle::lite::kernels::host::ReshapeCompute,
def)
.BindInput("X",
{LiteType::GetTensorTy(
TARGET(kHost), PRECISION(kAny), DATALAYOUT(kAny), -1)})
.BindInput("ShapeTensor",
{LiteType::GetTensorTy(
TARGET(kHost), PRECISION(kAny), DATALAYOUT(kAny), -1)})
.BindInput("Shape",
{LiteType::GetTensorTy(
TARGET(kHost), PRECISION(kAny), DATALAYOUT(kAny), -1)})
.BindOutput("Out",
{LiteType::GetTensorTy(
TARGET(kHost), PRECISION(kAny), DATALAYOUT(kAny), -1)})
.Finalize();
解决办法:
在Tensor的mutable_data被调用时保存其数据类型,在NPU/XPU的算子桥接器中通过scope访问该Tensor获得相应的数据类型。
对其它模块的影响:
无