-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[SPIRV] Add support for bfloat16 atomics via the SPV_INTEL_16bit_atomics extension
#166257
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
Changes from all commits
dfe6d00
184482c
114eaaa
3a48494
cd27043
fc4c730
a4a8ee1
b4e93f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| ; RUN: not llc -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_KHR_bfloat16 %s -o %t.spvt 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR1 | ||
| ; RUN: not llc -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_EXT_shader_atomic_float_add,+SPV_KHR_bfloat16 %s -o %t.spvt 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR2 | ||
|
|
||
| ; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_EXT_shader_atomic_float_add,+SPV_INTEL_16bit_atomics,+SPV_KHR_bfloat16,+SPV_INTEL_bfloat16_arithmetic %s -o - | FileCheck %s | ||
|
|
||
| ; CHECK-ERROR1: LLVM ERROR: The atomic float instruction requires the following SPIR-V extension: SPV_EXT_shader_atomic_float_add | ||
| ; CHECK-ERROR2: LLVM ERROR: The atomic bfloat16 instruction requires the following SPIR-V extension: SPV_INTEL_16bit_atomics | ||
|
Comment on lines
+6
to
+7
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's not available it should go through the AtomicExpand legalization
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this pass enabled by default for all the pipelines? |
||
|
|
||
| ; CHECK: Capability BFloat16TypeKHR | ||
| ; CHECK: Capability AtomicBFloat16AddINTEL | ||
| ; CHECK: Extension "SPV_KHR_bfloat16" | ||
| ; CHECK: Extension "SPV_EXT_shader_atomic_float_add" | ||
| ; CHECK: Extension "SPV_INTEL_16bit_atomics" | ||
| ; CHECK-DAG: %[[TyBF16:[0-9]+]] = OpTypeFloat 16 0 | ||
| ; CHECK-DAG: %[[TyBF16Ptr:[0-9]+]] = OpTypePointer {{[a-zA-Z]+}} %[[TyBF16]] | ||
| ; CHECK-DAG: %[[TyInt32:[0-9]+]] = OpTypeInt 32 0 | ||
| ; CHECK-DAG: %[[ConstBF16:[0-9]+]] = OpConstant %[[TyBF16]] 16936{{$}} | ||
| ; CHECK-DAG: %[[Const0:[0-9]+]] = OpConstantNull %[[TyBF16]] | ||
| ; CHECK-DAG: %[[BF16Ptr:[0-9]+]] = OpVariable %[[TyBF16Ptr]] CrossWorkgroup %[[Const0]] | ||
| ; CHECK-DAG: %[[ScopeAllSvmDevices:[0-9]+]] = OpConstantNull %[[TyInt32]] | ||
| ; CHECK-DAG: %[[MemSeqCst:[0-9]+]] = OpConstant %[[TyInt32]] 16{{$}} | ||
| ; CHECK: OpAtomicFAddEXT %[[TyBF16]] %[[BF16Ptr]] %[[ScopeAllSvmDevices]] %[[MemSeqCst]] %[[ConstBF16]] | ||
| ; CHECK: %[[NegatedConstBF16:[0-9]+]] = OpFNegate %[[TyBF16]] %[[ConstBF16]] | ||
| ; CHECK: OpAtomicFAddEXT %[[TyBF16]] %[[BF16Ptr]] %[[ScopeAllSvmDevices]] %[[MemSeqCst]] %[[NegatedConstBF16]] | ||
|
|
||
|
|
||
| @f = common dso_local local_unnamed_addr addrspace(1) global bfloat 0.000000e+00, align 8 | ||
|
|
||
| define dso_local spir_func void @test1() local_unnamed_addr { | ||
| entry: | ||
| %addval = atomicrmw fadd ptr addrspace(1) @f, bfloat 42.000000e+00 seq_cst | ||
| %subval = atomicrmw fsub ptr addrspace(1) @f, bfloat 42.000000e+00 seq_cst | ||
| ret void | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| ; RUN: not llc -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_EXT_shader_atomic_float_min_max,+SPV_KHR_bfloat16 %s -o %t.spvt 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR | ||
| ; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_EXT_shader_atomic_float_min_max,+SPV_INTEL_16bit_atomics,+SPV_KHR_bfloat16 %s -o - | FileCheck %s | ||
|
|
||
| ; CHECK-ERROR: LLVM ERROR: The atomic bfloat16 instruction requires the following SPIR-V extension: SPV_INTEL_16bit_atomics | ||
|
|
||
| ; CHECK: Capability AtomicBFloat16MinMaxINTEL | ||
| ; CHECK: Extension "SPV_KHR_bfloat16" | ||
| ; CHECK: Extension "SPV_EXT_shader_atomic_float_min_max" | ||
| ; CHECK: Extension "SPV_INTEL_16bit_atomics" | ||
| ; CHECK-DAG: %[[TyBF16:[0-9]+]] = OpTypeFloat 16 0 | ||
| ; CHECK-DAG: %[[TyBF16Ptr:[0-9]+]] = OpTypePointer {{[a-zA-Z]+}} %[[TyBF16]] | ||
| ; CHECK-DAG: %[[TyInt32:[0-9]+]] = OpTypeInt 32 0 | ||
| ; CHECK-DAG: %[[ConstBF16:[0-9]+]] = OpConstant %[[TyBF16]] 16936{{$}} | ||
| ; CHECK-DAG: %[[Const0:[0-9]+]] = OpConstantNull %[[TyBF16]] | ||
| ; CHECK-DAG: %[[BF16Ptr:[0-9]+]] = OpVariable %[[TyBF16Ptr]] CrossWorkgroup %[[Const0]] | ||
| ; CHECK-DAG: %[[ScopeAllSvmDevices:[0-9]+]] = OpConstantNull %[[TyInt32]] | ||
| ; CHECK-DAG: %[[MemSeqCst:[0-9]+]] = OpConstant %[[TyInt32]] 16{{$}} | ||
| ; CHECK: OpAtomicFMinEXT %[[TyBF16]] %[[BF16Ptr]] %[[ScopeAllSvmDevices]] %[[MemSeqCst]] %[[ConstBF16]] | ||
| ; CHECK: OpAtomicFMaxEXT %[[TyBF16]] %[[BF16Ptr]] %[[ScopeAllSvmDevices]] %[[MemSeqCst]] %[[ConstBF16]] | ||
|
|
||
| @f = common dso_local local_unnamed_addr addrspace(1) global bfloat 0.000000e+00, align 8 | ||
|
|
||
| define spir_func void @test1() { | ||
| entry: | ||
| %minval = atomicrmw fmin ptr addrspace(1) @f, bfloat 42.0e+00 seq_cst | ||
| %maxval = atomicrmw fmax ptr addrspace(1) @f, bfloat 42.0e+00 seq_cst | ||
| ret void | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pass should probably not be using fatal errors for anything
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC there is a later mechanism which checks which extension is allowed for the current target and raises an "SPIR-V module cannot be satisfied" error if an extension/capability is showing but is not allowed.