Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Op bitwise full type support #1404

Merged
merged 18 commits into from
May 16, 2023
Merged

Conversation

FisherWY
Copy link
Contributor

@FisherWY FisherWY commented May 9, 2023

  1. bitwise系列算子支持类型与paddle对齐
  2. 使用新单测体系增加bitwise系列算子单测
  3. 增强GetExternFuncName,增加可选参数,现有cinn的gpu函数原型注册中,存在以下两种命名方式:cinn_cuda_op_typecinn_nvgpu_op_type,由于nvgpu占大多数,因此默认使用nvgpu作为target名称
  4. 对于目前cinn的cpu函数原型,其命名只有算子名称,无法对多数据类型的支持进行区分(如:bitwise的cpu算子就只支持int32类型)
  5. 为增强通用型,在此提出一个规范,函数原型的命名如下格式:cinn_target_op_type,解释如下:
    • cinn_:CINN下的函数原型
    • target_:支持的平台,CPU为host,GPU为nvgpu
    • op_:算子名称
    • type:算子数据类型(bool、uint8、int32、fp64等)
  6. 增加全局变量CurrentTarget,能够通过该变量获取当前编译、生成代码的目标平台,用户也能够通过python接口设置target,而不再依赖于编译选项

@paddle-bot
Copy link

paddle-bot bot commented May 9, 2023

Thanks for your contribution!

@FisherWY
Copy link
Contributor Author

FisherWY commented May 9, 2023

描述

增加的单测

序号 算子 单测文件
16 bitwise_and test_bitwise_op.py
17 bitwise_or test_bitwise_op.py
18 bitwise_xor test_bitwise_op.py
107 bitwise_not test_bitwise_op.py

算子类型

  • ElementWise:输入张量索引和输出张量索引之间存在一对一的对应关系
  • Broadcast:输入张量索引和输出张量索引之间存在一对多的对应关系
  • Injective:单射算子,可以将一个输出 axis 映射到一个输入 axis
  • Reduction:输入张量索引和输出张量索引之间存在多对一的对应关系
  • OutFusible:复杂算子,仍然可以将一对一的算子融合到其输出中。
  • kNonFusible:无法融合的算子

OpMapper

  • 该算子是否 OpMapper? 如果是,请贴出在 Paddle 中对应的 OpMaker 代码路径。(给出 Github 链接更好)

Test Cases Checklist

张量维度

  • 1D 张量
  • 2D 张量
  • 3D 张量
  • 4D 张量

special shape

挑选 2D/3D/4D 张量中的一个,测试下面的特殊情况。

  • 其中一个维度为 1
  • 其中一个维度小于 1024
  • 其中一个维度大于 1024
  • 向量的所有维度都是 1

张量数据类型

  • bool
  • uint8
  • int8
  • int16
  • int32
  • int64
  • float16
  • float32
  • float64

广播

  • 这个算子是否支持广播?
  • 广播的测试样例

算子属性

算子属性的测试用例。

  • 属性:无
  • 使用 OpTestHelper 测试上述属性的笛卡尔积组合

@zzk0
Copy link
Contributor

zzk0 commented May 10, 2023

  1. 为增强通用型,在此提出一个规范,函数原型的命名如下格式:cinn_target_op_type,解释如下:
    cinn_:CINN下的函数原型
    target_:支持的平台,CPU为host,GPU为nvgpu
    op:算子名称
    type:算子数据类型

算子数据类型这一条需要细化。比如:

  • int32 类型,结尾应该 int32,而非 int
  • float32 类型,结尾应该 fp32,而非 float32

thisjiang
thisjiang previously approved these changes May 10, 2023
Copy link
Collaborator

@thisjiang thisjiang left a comment

Choose a reason for hiding this comment

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

LGTM

cinn/runtime/flags.h Outdated Show resolved Hide resolved
cinn/runtime/flags.h Outdated Show resolved Hide resolved
python/tests/test_pe_elementwise.py Show resolved Hide resolved
Copy link
Collaborator

@thisjiang thisjiang left a comment

Choose a reason for hiding this comment

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

LGTM

@thisjiang thisjiang merged commit d1f91d6 into PaddlePaddle:develop May 16, 2023
jiahy0825 pushed a commit to jiahy0825/CINN that referenced this pull request May 25, 2023
* Register bitwise_and_int64 extern call

* Bitwise_and support type bool, uint8, int8 and int16

* ir operator& support more dtype on nvgpu

* Bitwise op support dtypes are aligned with paddle

* Add bitwise op tests

* Fix float16 error

* Add broadcast test cases for bitwise

* Reformat code

* Fix ci error on x86

* Add global variable CurrentTarget

Enable users to choose target to run instead of relying on complile
options

* Use CurrentTarget instead of DefaultTarget

* Add compile with cuda check in set_current_target

* Add test case for inf and nan values

* Unify IsCompiledWithCUDA and IsCompiledWithCUDNN
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants