Skip to content

Commit 2706e11

Browse files
committed
[mlir][spirv] Add SPV_KHR_float_controls2 extension functionalities
1 parent 2c20bc5 commit 2706e11

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

mlir/include/mlir/Dialect/SPIRV/IR/SPIRVBase.td

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ def SPV_KHR_subgroup_rotate : I32EnumAttrCase<"SPV_KHR_subgroup
344344
def SPV_KHR_non_semantic_info : I32EnumAttrCase<"SPV_KHR_non_semantic_info", 29>;
345345
def SPV_KHR_terminate_invocation : I32EnumAttrCase<"SPV_KHR_terminate_invocation", 30>;
346346
def SPV_KHR_cooperative_matrix : I32EnumAttrCase<"SPV_KHR_cooperative_matrix", 31>;
347+
def SPV_KHR_float_controls2 : I32EnumAttrCase<"SPV_KHR_float_controls2", 32>;
347348

348349
def SPV_EXT_demote_to_helper_invocation : I32EnumAttrCase<"SPV_EXT_demote_to_helper_invocation", 1000>;
349350
def SPV_EXT_descriptor_indexing : I32EnumAttrCase<"SPV_EXT_descriptor_indexing", 1001>;
@@ -469,7 +470,8 @@ def SPIRV_ExtensionAttr :
469470
SPV_NV_shader_image_footprint, SPV_NV_shader_sm_builtins,
470471
SPV_NV_shader_subgroup_partitioned, SPV_NV_shading_rate,
471472
SPV_NV_stereo_view_rendering, SPV_NV_viewport_array2, SPV_NV_bindless_texture,
472-
SPV_NV_ray_tracing_motion_blur, SPV_NVX_multiview_per_view_attributes
473+
SPV_NV_ray_tracing_motion_blur, SPV_NVX_multiview_per_view_attributes,
474+
SPV_KHR_float_controls2
473475
]>;
474476

475477
//===----------------------------------------------------------------------===//
@@ -850,6 +852,11 @@ def SPIRV_C_BitInstructions : I32EnumAttrCase<"BitIn
850852
Extension<[SPV_KHR_bit_instructions]>
851853
];
852854
}
855+
def SPIRV_C_FloatControls2 : I32EnumAttrCase<"FloatControls2", 6029> {
856+
list<Availability> availability = [
857+
Extension<[SPV_KHR_float_controls2]>
858+
];
859+
}
853860
def SPIRV_C_AtomicFloat32AddEXT : I32EnumAttrCase<"AtomicFloat32AddEXT", 6033> {
854861
list<Availability> availability = [
855862
Extension<[SPV_EXT_shader_atomic_float_add]>
@@ -1461,8 +1468,8 @@ def SPIRV_CapabilityAttr :
14611468
SPIRV_C_USMStorageClassesINTEL, SPIRV_C_IOPipesINTEL, SPIRV_C_BlockingPipesINTEL,
14621469
SPIRV_C_FPGARegINTEL, SPIRV_C_DotProductInputAll,
14631470
SPIRV_C_DotProductInput4x8BitPacked, SPIRV_C_DotProduct, SPIRV_C_RayCullMaskKHR,
1464-
SPIRV_C_CooperativeMatrixKHR,
1465-
SPIRV_C_BitInstructions, SPIRV_C_AtomicFloat32AddEXT, SPIRV_C_AtomicFloat64AddEXT,
1471+
SPIRV_C_CooperativeMatrixKHR, SPIRV_C_BitInstructions, SPIRV_C_FloatControls2,
1472+
SPIRV_C_AtomicFloat32AddEXT, SPIRV_C_AtomicFloat64AddEXT,
14661473
SPIRV_C_LongConstantCompositeINTEL, SPIRV_C_OptNoneINTEL,
14671474
SPIRV_C_AtomicFloat16AddEXT, SPIRV_C_DebugInfoModuleINTEL, SPIRV_C_SplitBarrierINTEL,
14681475
SPIRV_C_GroupUniformArithmeticKHR, SPIRV_C_Shader, SPIRV_C_Vector16,
@@ -2255,7 +2262,8 @@ def SPIRV_D_FuncParamAttr : I32EnumAttrCase<"FuncParamAttr"
22552262
def SPIRV_D_FPRoundingMode : I32EnumAttrCase<"FPRoundingMode", 39>;
22562263
def SPIRV_D_FPFastMathMode : I32EnumAttrCase<"FPFastMathMode", 40> {
22572264
list<Availability> availability = [
2258-
Capability<[SPIRV_C_Kernel]>
2265+
MinVersion<SPIRV_V_1_0>,
2266+
Capability<[SPIRV_C_FloatControls2, SPIRV_C_Kernel]>
22592267
];
22602268
}
22612269
def SPIRV_D_LinkageAttributes : I32EnumAttrCase<"LinkageAttributes", 41> {
@@ -3086,6 +3094,11 @@ def SPIRV_EM_SchedulerTargetFmaxMhzINTEL : I32EnumAttrCase<"SchedulerTarget
30863094
Capability<[SPIRV_C_FPGAKernelAttributesINTEL]>
30873095
];
30883096
}
3097+
def SPIRV_EM_FPFastMathDefault : I32EnumAttrCase<"FPFastMathDefault", 6028> {
3098+
list<Availability> availability = [
3099+
Capability<[SPIRV_C_FloatControls2]>
3100+
];
3101+
}
30893102
def SPIRV_EM_StreamingInterfaceINTEL : I32EnumAttrCase<"StreamingInterfaceINTEL", 6154> {
30903103
list<Availability> availability = [
30913104
Capability<[SPIRV_C_FPGAKernelAttributesINTEL]>
@@ -4781,22 +4794,27 @@ def SPIRV_FPFMM_NotInf : I32BitEnumAttrCaseBit<"NotInf", 1>;
47814794
def SPIRV_FPFMM_NSZ : I32BitEnumAttrCaseBit<"NSZ", 2>;
47824795
def SPIRV_FPFMM_AllowRecip : I32BitEnumAttrCaseBit<"AllowRecip", 3>;
47834796
def SPIRV_FPFMM_Fast : I32BitEnumAttrCaseBit<"Fast", 4>;
4784-
def SPIRV_FPFMM_AllowContractFastINTEL : I32BitEnumAttrCaseBit<"AllowContractFastINTEL", 16> {
4797+
def SPIRV_FPFMM_AllowContract : I32BitEnumAttrCaseBit<"AllowContract", 16> {
4798+
list<Availability> availability = [
4799+
Capability<[SPIRV_C_FPFastMathModeINTEL, SPIRV_C_FloatControls2]>
4800+
];
4801+
}
4802+
def SPIRV_FPFMM_AllowReassoc : I32BitEnumAttrCaseBit<"AllowReassoc", 17> {
47854803
list<Availability> availability = [
4786-
Capability<[SPIRV_C_FPFastMathModeINTEL]>
4804+
Capability<[SPIRV_C_FPFastMathModeINTEL, SPIRV_C_FloatControls2]>
47874805
];
47884806
}
4789-
def SPIRV_FPFMM_AllowReassocINTEL : I32BitEnumAttrCaseBit<"AllowReassocINTEL", 17> {
4807+
def SPIRV_FPFMM_AllowTransform : I32BitEnumAttrCaseBit<"AllowTransform", 18> {
47904808
list<Availability> availability = [
4791-
Capability<[SPIRV_C_FPFastMathModeINTEL]>
4809+
Capability<[SPIRV_C_FloatControls2]>
47924810
];
47934811
}
47944812

47954813
def SPIRV_FPFastMathModeAttr :
47964814
SPIRV_BitEnumAttr<"FPFastMathMode", "Indicates a floating-point fast math flag", "fastmath_mode", [
47974815
SPIRV_FPFMM_None, SPIRV_FPFMM_NotNaN, SPIRV_FPFMM_NotInf, SPIRV_FPFMM_NSZ,
4798-
SPIRV_FPFMM_AllowRecip, SPIRV_FPFMM_Fast, SPIRV_FPFMM_AllowContractFastINTEL,
4799-
SPIRV_FPFMM_AllowReassocINTEL
4816+
SPIRV_FPFMM_AllowRecip, SPIRV_FPFMM_Fast, SPIRV_FPFMM_AllowContract,
4817+
SPIRV_FPFMM_AllowReassoc, SPIRV_FPFMM_AllowTransform
48004818
]>;
48014819

48024820
#endif // MLIR_DIALECT_SPIRV_IR_BASE

mlir/test/Target/SPIRV/decorations.mlir

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ spirv.func @fadd_decorations(%arg: f32) -> f32 "None" {
9090

9191
// -----
9292

93+
spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Kernel], []> {
94+
spirv.func @fadd_floatcontrols2(%arg: f32) -> f32 "None" {
95+
// CHECK: spirv.FAdd %{{.*}}, %{{.*}} {fp_fast_math_mode = #spirv.fastmath_mode<AllowContract|AllowReassoc|AllowTransform>}
96+
%0 = spirv.FAdd %arg, %arg {fp_fast_math_mode = #spirv.fastmath_mode<AllowContract|AllowReassoc|AllowTransform>} : f32
97+
spirv.ReturnValue %0 : f32
98+
}
99+
}
100+
101+
// -----
102+
93103
spirv.module Logical GLSL450 requires #spirv.vce<v1.0, [Kernel], []> {
94104
spirv.func @fmul_decorations(%arg: f32) -> f32 "None" {
95105
// CHECK: spirv.FMul %{{.*}}, %{{.*}} {no_contraction}

0 commit comments

Comments
 (0)