Skip to content

Conversation

0x45f
Copy link
Contributor

@0x45f 0x45f commented Dec 1, 2023

PR types

Others

PR changes

Others

Description

本PR的工作:

  • 在pd_api.cc内根据Value类型是DenseType还是SelectedRowsType选择不同的Op,以shape为例:
- op : shape
  args : (Tensor input)
  output : Tensor(out)
  infer_meta :
    func : ShapeInferMeta
  kernel :
    func : shape {dense -> dense},
           shape_sr {selected_rows -> dense}
  data_transform:
    skip_transform : input

在动态图下,shape会根据输入类型的不同,会分发到两个kernel上去。在PIR下需要分发到两个op上去,pir下生成了如下的代码,代码形式上和动态图保持了一致:

pir::OpResult shape(const pir::Value& input) {
  if (input.type().isa<paddle::dialect::DenseTensorType>()) {
    paddle::dialect::ShapeOp shape_op =
        ApiBuilder::Instance().GetBuilder()->Build<paddle::dialect::ShapeOp>(
            input);
    return shape_op.result(0);
  }
  if (input.type().isa<paddle::dialect::SelectedRowsType>()) {
    paddle::dialect::ShapeSrOp shape_sr_op =
        ApiBuilder::Instance().GetBuilder()->Build<paddle::dialect::ShapeSrOp>(
            input);
    return shape_sr_op.result(0);
  }
  PADDLE_THROW(phi::errors::Unimplemented(
      "The kernel of (shape) for input OpResult is unimplemented, please check "
      "the type of input OpResult."));
}
  • 在生成pd_api.cc时尝试调用clang-format,在开发环境下会正常将代码format

Pcard-67164

@0x45f 0x45f changed the title [PIR]Choose op in PIR apis [PIR]Choose op by value type in PIR apis Dec 1, 2023
Copy link
Contributor

@2742195759 2742195759 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@Aurelius84 Aurelius84 left a comment

Choose a reason for hiding this comment

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

LGTM

@0x45f 0x45f merged commit a1f3dd6 into PaddlePaddle:develop Dec 5, 2023
@0x45f 0x45f deleted the choose-op-in-pir-api branch December 5, 2023 06:56
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.

3 participants