Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LITE][CORE][NPU][XPU] Recording the data type when mutable_data() is called #2735

Merged

Conversation

hong19860320
Copy link
Collaborator

@hong19860320 hong19860320 commented Jan 8, 2020

背景问题:

目前,在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获得相应的数据类型。

对其它模块的影响:

…data() of the tensor, and supporting the type inference from the tensor for the op bridges

test=develop
… and fix the compiling errors of XPU op bridges

test=develop
@hong19860320 hong19860320 changed the title [CORE][NPU][XPU] Recording the data type when mutable_data() is called [LITE][CORE][NPU][XPU] Recording the data type when mutable_data() is called Jan 8, 2020
@Shixiaowei02 Shixiaowei02 requested review from NHZlX and jiweibo January 8, 2020 08:40
Copy link
Collaborator

@NHZlX NHZlX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hong19860320 hong19860320 merged commit 6e4acdc into PaddlePaddle:develop Jan 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants