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

[Hackathon NO.77] 为 Paddle-TRT 添加 bitwise 算子 #51971

Merged
merged 9 commits into from Mar 28, 2023
Merged

[Hackathon NO.77] 为 Paddle-TRT 添加 bitwise 算子 #51971

merged 9 commits into from Mar 28, 2023

Conversation

Young-Flash
Copy link
Contributor

@Young-Flash Young-Flash commented Mar 22, 2023

PR types

Others

PR changes

Others

Describe

TensorRT 中没有 bitwise 操作的算子,无法直接映射 bitwise_and,TensorRT 中与 bitwise_and 算子接近的是 ElementWiseAnd,但只支持 bool 类型

这个 PR 中用 TensorRT 已有算子组合出了 bitwise_not,思路如下:

  • 对于 bool 类型,使用 UnaryOperation::kNOT
  • 对于 int 类型,~n = -n - 1,使用 ElementWiseOperation::kPRODElementWiseOperation::kSUM 组合而成

image

@CLAassistant
Copy link

CLAassistant commented Mar 22, 2023

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Comment on lines +38 to +41
if (data_type == nvinfer1::DataType::kBOOL) {
layer = TRT_ENGINE_ADD_LAYER(
engine_, Unary, *input_tensor, nvinfer1::UnaryOperation::kNOT);
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

bool类型支持需要trt 8.4,可以在op_teller中判断过滤。 对应单测可能有细微调整。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改,有劳老师再 review 一下

Comment on lines 28 to 32
ver = paddle_infer.get_trt_compile_version()
trt_version = ver[0] * 1000 + ver[1] * 100 + ver[2] * 10
if trt_version < 8400:
if program_config.inputs['input_data'].dtype == bool:
return False
Copy link
Contributor

@zhangjun zhangjun Mar 23, 2023

Choose a reason for hiding this comment

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

参考其他单测,也可以放在generate_trt_nodes_num中,此处不做限制.

if ver[0] * 1000 + ver[1] * 100 + ver[0] * 10 >= 7130:

paddle/fluid/inference/tensorrt/op_teller.cc Outdated Show resolved Hide resolved
Comment on lines 107 to 109
def generate_trt_nodes_num(attrs, dynamic_shape):
if self.dims == 1 and not dynamic_shape:
return 0, 3
Copy link
Contributor

Choose a reason for hiding this comment

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

这里加和op_teller一样的trt 版本限制,否则单测会无法通过。
is_program_valid处可以去掉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改

paddle/fluid/inference/tensorrt/op_teller.cc Outdated Show resolved Hide resolved
zhangjun
zhangjun previously approved these changes Mar 24, 2023
Copy link
Contributor

@zhangjun zhangjun 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

@zhangjun zhangjun left a comment

Choose a reason for hiding this comment

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

LGTM

@luotao1 luotao1 merged commit 864b50c into PaddlePaddle:develop Mar 28, 2023
24 of 25 checks passed
@luotao1
Copy link
Contributor

luotao1 commented Mar 28, 2023

hi, @Young-Flash

  • 非常感谢你对飞桨框架的贡献,我们正在运营一个PFCC组织,会通过定期分享技术知识与发布开发者主导任务的形式持续为飞桨框架做贡献,详情可见 https://github.com/luotao1 主页说明。
  • 如果你对PFCC有兴趣,请发送邮件至 ext_paddle_oss@baidu.com,我们会邀请你加入~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants