Skip to content

Conversation

@MiloszSkobejko
Copy link

Changes were cherry-picked from the following commit: c6fe12b

This changes add SPIR-V translator support for the SPIR-V extension documented here: KhronosGroup/SPIRV-Registry#193. This extension adds one decoration to represent maximum error for FP operations and adds the related Capability. SPIRV Headers support for representing this in SPIR-V: KhronosGroup/SPIRV-Headers#363

intel/llvm#8134 added a new call-site attribute associated with FP builtin intrinsics. This attribute is named 'fpbuiltin-max-error'. Following example shows how this extension is supported in the translator. The input LLVM IR uses new LLVM builtin calls to represent FP operations. An attribute named 'fpbuiltin-max-error' is used to represent the max-error allowed in the FP operation. Example
Input LLVM:
%t6 = call float @llvm.fpbuiltin.sin.f32(float %f1) #2 attributes #2 = { "fpbuiltin-max-error"="2.5" }

This is translated into a SPIR-V instruction (for add/sub/mul/div/rem) and OpenCl extended instruction for other instructions. A decoration to represent the max-error is attached to the SPIR-V instruction.

SPIR-V code:
4 Decorate 97 FPMaxErrorDecorationINTEL 1075838976 6 ExtInst 2 97 1 sin 88

No new support is added to support translating this SPIR_V back to LLVM. Existing support is used. The decoration is translated back into named metadata associated with the LLVM instruction. This can be readily consumed by backends.

Based on input from @andykaylor, we emit attributes when the FP operation is translated back to a call to a builtin function and emit metadata otherwise.

Translated LLVM code for basic math functions (add/sub/mul/div/rem): %t6 = fmul float %f1, %f2, !fpbuiltin-max-error !7 !7 = !{!"2.500000"}

Translated LLVM code for other math functions:
%t6 = call spir_func float @_Z3sinf(float %f1) #3
attributes #3 = { "fpbuiltin-max-error"="4.000000" }

@CLAassistant
Copy link

CLAassistant commented Mar 5, 2024

CLA assistant check
All committers have signed the CLA.

@MiloszSkobejko MiloszSkobejko marked this pull request as ready for review March 5, 2024 11:06
@MrSidims
Copy link
Contributor

restarting CI with new HEAD

@MrSidims MrSidims closed this Mar 18, 2024
@MrSidims MrSidims reopened this Mar 18, 2024
@MrSidims
Copy link
Contributor

restarting CI with new HEAD again

@MrSidims MrSidims closed this Mar 18, 2024
@MrSidims MrSidims reopened this Mar 18, 2024
add(CapabilityFPGAArgumentInterfacesINTEL, "FPGAArgumentInterfacesINTEL");
add(CapabilityFPGALatencyControlINTEL, "FPGALatencyControlINTEL");
add(CapabilityFPMaxErrorINTEL, "FPMaxErrorINTEL");
add(CapabilityRegisterLimitsINTEL, "RegisterLimitsINTEL");
Copy link
Contributor

Choose a reason for hiding this comment

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

RegisterLimitsINTEL should not be a part of this PR

@MiloszSkobejko MiloszSkobejko force-pushed the fpbuiltin-max-error-backport-llvm-17 branch from 4fe79d9 to 5190137 Compare March 19, 2024 13:27
@MiloszSkobejko MiloszSkobejko marked this pull request as draft March 19, 2024 13:29
@MiloszSkobejko MiloszSkobejko force-pushed the fpbuiltin-max-error-backport-llvm-17 branch from 5190137 to 4fe79d9 Compare March 19, 2024 13:40
Changes were cherry-picked from the following commit:
KhronosGroup@c6fe12b

Also cherry picked fixes from:
KhronosGroup#2208
KhronosGroup#2192

This changes add SPIR-V translator support for the SPIR-V extension documented here: KhronosGroup/SPIRV-Registry#193.
This extension adds one decoration to represent maximum error for FP operations and adds the related Capability.
SPIRV Headers support for representing this in SPIR-V: KhronosGroup/SPIRV-Headers#363

intel/llvm#8134 added a new call-site attribute associated with FP builtin intrinsics. This attribute is named 'fpbuiltin-max-error'.
Following example shows how this extension is supported in the translator. The input LLVM IR uses new LLVM builtin calls to represent FP operations. An attribute named 'fpbuiltin-max-error' is used to represent the max-error allowed in the FP operation.
Example
Input LLVM:
%t6 = call float @llvm.fpbuiltin.sin.f32(float %f1) KhronosGroup#2
attributes KhronosGroup#2 = { "fpbuiltin-max-error"="2.5" }

This is translated into a SPIR-V instruction (for add/sub/mul/div/rem) and OpenCl extended instruction for other instructions. A decoration to represent the max-error is attached to the SPIR-V instruction.

SPIR-V code:
4 Decorate 97 FPMaxErrorDecorationINTEL 1075838976
6 ExtInst 2 97 1 sin 88

No new support is added to support translating this SPIR_V back to LLVM. Existing support is used. The decoration is translated back into named metadata associated with the LLVM instruction. This can be readily consumed by backends.

Based on input from @andykaylor, we emit attributes when the FP operation is translated back to a call to a builtin function and emit metadata otherwise.

Translated LLVM code for basic math functions (add/sub/mul/div/rem):
%t6 = fmul float %f1, %f2, !fpbuiltin-max-error !7
!7 = !{!"2.500000"}

Translated LLVM code for other math functions:
%t6 = call spir_func float @_Z3sinf(float %f1) KhronosGroup#3
attributes KhronosGroup#3 = { "fpbuiltin-max-error"="4.000000" }
@MiloszSkobejko MiloszSkobejko force-pushed the fpbuiltin-max-error-backport-llvm-17 branch from 4fe79d9 to 4750a04 Compare March 19, 2024 16:38
@MiloszSkobejko MiloszSkobejko marked this pull request as ready for review March 20, 2024 10:46
@@ -0,0 +1,17 @@
; REQUIRES: pass-plugin
Copy link
Contributor

Choose a reason for hiding this comment

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

I missed that for the previously merged PR, my bad. But it's a part of a separate commit. Please preserve the same git history as on main, aka do not merge several patches into a single commit and please preserve the original commit messages and names

@MrSidims MrSidims merged commit 89ab5df into KhronosGroup:llvm_release_170 Mar 21, 2024
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