-
Notifications
You must be signed in to change notification settings - Fork 16.3k
[SPIRV] Do not use OpTypeRuntimeArray in Kernel env. #149522
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
2933fcf
68b8e0c
e8953dd
b01c325
1d0f71c
ac4b60f
b1e37f7
c724cab
51beec0
0f4ee2b
7b3246a
744d36b
f7fec8b
69bba1a
a774605
292b18c
b9ce33c
ef4b988
f3124c7
6ed99c5
285be5b
247f938
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 |
|---|---|---|
|
|
@@ -744,8 +744,14 @@ void SPIRV::RequirementHandler::checkSatisfiable( | |
| IsSatisfiable = false; | ||
| } | ||
|
|
||
| AvoidCapabilitiesSet AvoidCaps; | ||
| if (!ST.isShader()) | ||
| AvoidCaps.S.insert(SPIRV::Capability::Shader); | ||
| else | ||
| AvoidCaps.S.insert(SPIRV::Capability::Kernel); | ||
|
|
||
| for (auto Cap : MinimalCaps) { | ||
| if (AvailableCaps.contains(Cap)) | ||
| if (AvailableCaps.contains(Cap) && !AvoidCaps.S.contains(Cap)) | ||
|
Comment on lines
+747
to
+754
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. This doesn't seem useful. I recompiled your patch with only the
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. I don't mind this change. It will help us identify errors of this type earlier. I'm guessing that if you do this change, and not the OpRuntimeArray change, the test case would give an error that the shader capability is not supported. This will be generally useful. We run into error like this with shader that accidentally adding the kernel capability.
Contributor
Author
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. It's not useful because after the patch, there is no conflict anymore, but having it would have helped us caught the error much more easily. Aside from that, it's just honoring
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.
We should already have this error surfacing: after all we have a list of available capabilities by environment. |
||
| continue; | ||
| LLVM_DEBUG(dbgs() << "Capability not supported: " | ||
| << getSymbolicOperandMnemonic( | ||
|
|
@@ -1865,6 +1871,10 @@ void addInstrRequirements(const MachineInstr &MI, | |
| Reqs.addCapability(SPIRV::Capability::TernaryBitwiseFunctionINTEL); | ||
| break; | ||
| } | ||
| case SPIRV::OpCopyMemorySized: { | ||
| Reqs.addCapability(SPIRV::Capability::Addresses); | ||
| // TODO: Add UntypedPointersKHR when implemented. | ||
| } | ||
|
|
||
| default: | ||
| break; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| ; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s | ||
| ; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64v1.2-unknown-unknown %s -o - -filetype=obj | spirv-val --target-env opencl2.2 %} | ||
|
|
||
| ; CHECK: OpCapability Kernel | ||
| ; CHECK-NOT: OpCapability Shader | ||
| ; CHECK-DAG: %[[#float16:]] = OpTypeFloat 16 | ||
| ; CHECK-DAG: %[[#SyclHalfTy:]] = OpTypeStruct %[[#float16]] | ||
| ; CHECK-DAG: %[[#i16:]] = OpTypeInt 16 | ||
| ; CHECK-DAG: %[[#i32:]] = OpTypeInt 32 | ||
| ; CHECK-DAG: %[[#i64:]] = OpTypeInt 64 | ||
| ; CHECK-DAG: %[[#ConstNull:]] = OpConstantNull %[[#i64]] | ||
| ; CHECK-DAG: %[[#ConstOne:]] = OpConstant %[[#i64]] 1 | ||
| ; CHECK-DAG: %[[#ConstFive:]] = OpConstant %[[#i16]] 5 | ||
| ; CHECK-DAG: %[[#SyclHalfTyPtr:]] = OpTypePointer Function %[[#SyclHalfTy]] | ||
| ; CHECK-DAG: %[[#i32Ptr:]] = OpTypePointer Function %[[#i32]] | ||
| ; CHECK-DAG: %[[#StorePtrTy:]] = OpTypePointer Function %[[#i16]] | ||
|
|
||
| %"class.sycl::_V1::detail::half_impl::half" = type { half } | ||
|
|
||
| ; Function Attrs: mustprogress norecurse nounwind | ||
| define spir_kernel void @foo(ptr %p){ | ||
| ; CHECK: OpFunction | ||
| ; CHECK: %[[#Ptr:]] = OpFunctionParameter | ||
| ; CHECK: OpLabel | ||
| ; CHECK: %[[#BitcastOp:]] = OpInBoundsPtrAccessChain %[[#SyclHalfTyPtr]] %[[#Ptr]] %[[#ConstNull]] %[[#ConstNull]] | ||
| ; CHECK: %[[#StorePtr:]] = OpBitcast %[[#StorePtrTy]] %[[#BitcastOp]] | ||
| ; CHECK: OpStore %[[#StorePtr]] %[[#ConstFive]] | ||
| ; CHECK: OpReturn | ||
| entry: | ||
| %0 = getelementptr inbounds [0 x [32 x %"class.sycl::_V1::detail::half_impl::half"]], ptr %p, i64 0, i64 0, i64 0 | ||
| store i16 5, ptr %0 | ||
| ret void | ||
| } | ||
|
|
||
| ; Function Attrs: mustprogress norecurse nounwind | ||
| define spir_kernel void @foo2(ptr %p){ | ||
| ; CHECK: OpFunction | ||
| ; CHECK: %[[#Ptr:]] = OpFunctionParameter | ||
| ; CHECK: OpLabel | ||
| ; CHECK: %[[#BitcastOp:]] = OpInBoundsPtrAccessChain %[[#SyclHalfTyPtr]] %[[#Ptr]] %[[#ConstOne]] %[[#ConstOne]] | ||
| ; CHECK: %[[#StorePtr:]] = OpBitcast %[[#StorePtrTy]] %[[#BitcastOp]] | ||
| ; CHECK: OpStore %[[#StorePtr]] %[[#ConstFive]] | ||
| ; CHECK: OpReturn | ||
| entry: | ||
| %0 = getelementptr inbounds [0 x [32 x %"class.sycl::_V1::detail::half_impl::half"]], ptr %p, i64 0, i64 1, i64 1 | ||
| store i16 5, ptr %0 | ||
| ret void | ||
| } | ||
|
|
||
| ; Function Attrs: mustprogress norecurse nounwind | ||
| define spir_kernel void @foo3(ptr %p){ | ||
| ; CHECK: OpFunction | ||
| ; CHECK: %[[#Ptr:]] = OpFunctionParameter | ||
| ; CHECK: OpLabel | ||
| ; CHECK: %[[#BitcastOp:]] = OpInBoundsPtrAccessChain %[[#i32Ptr]] %[[#Ptr]] %[[#ConstNull]] %[[#ConstNull]] | ||
| ; CHECK: %[[#StorePtr:]] = OpBitcast %[[#StorePtrTy]] %[[#BitcastOp]] | ||
| ; CHECK: OpStore %[[#StorePtr]] %[[#ConstFive]] | ||
| ; CHECK: OpReturn | ||
| entry: | ||
| %0 = getelementptr inbounds [0 x [32 x i32]], ptr %p, i64 0, i64 0, i64 0 | ||
| store i16 5, ptr %0 | ||
| ret void | ||
| } | ||
|
|
||
| ; Function Attrs: mustprogress norecurse nounwind | ||
| define spir_kernel void @foo4(ptr %p){ | ||
| ; CHECK: OpFunction | ||
| ; CHECK: %[[#Ptr:]] = OpFunctionParameter | ||
| ; CHECK: OpLabel | ||
| ; CHECK: %[[#BitcastOp:]] = OpInBoundsPtrAccessChain %[[#i32Ptr]] %[[#Ptr]] %[[#ConstOne]] %[[#ConstOne]] | ||
| ; CHECK: %[[#StorePtr:]] = OpBitcast %[[#StorePtrTy]] %[[#BitcastOp]] | ||
| ; CHECK: OpStore %[[#StorePtr]] %[[#ConstFive]] | ||
| ; CHECK: OpReturn | ||
| entry: | ||
| %0 = getelementptr inbounds [0 x [32 x i32]], ptr %p, i64 0, i64 1, i64 1 | ||
| store i16 5, ptr %0 | ||
| ret void | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| ; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-NO-EXTENSION | ||
| ; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %} | ||
| ; | ||
| ; CHECK-NO-EXTENSION-NOT: Capability BitInstructions | ||
| ; CHECK-NO-EXTENSION-NOT: Extension "SPV_KHR_bit_instructions" | ||
| ; CHECK-NO-EXTENSION: Capability Shader | ||
Keenuts marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| define internal spir_func void @testBitReverse_SPIRVFriendly() #3 { | ||
| entry: | ||
| %call = call <4 x i64> @llvm.bitreverse.v4i64(<4 x i64> <i64 1, i64 2, i64 3, i64 4>) | ||
| ret void | ||
| } | ||
|
|
||
| declare <4 x i64> @llvm.bitreverse.v4i64(<4 x i64>) | ||
|
|
||
| attributes #3 = { nounwind "hlsl.shader"="compute" } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| ; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv-unknown-vulkan-compute %s -o - | FileCheck %s --check-prefix=CHECK-NO-EXTENSION | ||
| ; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan-compute %s -o - -filetype=obj | spirv-val --target-env vulkan1.3 %} | ||
|
|
||
|
|
||
| ; CHECK-NO-EXTENSION: OpCapability Shader | ||
| ; CHECK-NO-EXTENSION-NOT: OpCabilitity BitInstructions | ||
| ; CHECK-NO-EXTENSION-NOT: OpExtension "SPV_KHR_bit_instructions" | ||
| ; CHECK-NO-EXTENSION: %[[#int:]] = OpTypeInt 32 | ||
| ; CHECK-NO-EXTENSION: OpBitReverse %[[#int]] | ||
|
|
||
| define hidden spir_func void @testBitRev(i32 %a, i32 %b, i32 %c, ptr %res) local_unnamed_addr { | ||
| entry: | ||
| %call = tail call i32 @llvm.bitreverse.i32(i32 %b) | ||
| store i32 %call, ptr %res, align 4 | ||
| ret void | ||
| } | ||
|
|
||
| define void @main() #1 { | ||
| ret void | ||
| } | ||
|
|
||
| declare i32 @llvm.bitreverse.i32(i32) | ||
| attributes #1 = { "hlsl.numthreads"="8,1,1" "hlsl.shader"="compute" } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,21 +18,18 @@ | |
| ; CL: %[[#FooVar:]] = OpVariable | ||
| ; CL-NEXT: %[[#Casted1:]] = OpBitcast %[[#PtrChar]] %[[#FooVar]] | ||
| ; CL-NEXT: OpLifetimeStart %[[#Casted1]], 72 | ||
| ; CL-NEXT: OpCopyMemorySized | ||
| ; CL-NEXT: OpBitcast | ||
| ; CL-NEXT: OpInBoundsPtrAccessChain | ||
| ; CL-NEXT: %[[#Casted2:]] = OpBitcast %[[#PtrChar]] %[[#FooVar]] | ||
| ; CL-NEXT: OpLifetimeStop %[[#Casted2]], 72 | ||
|
|
||
| ; VK: OpFunction | ||
| ; VK: %[[#FooVar:]] = OpVariable | ||
| ; VK-NEXT: OpCopyMemorySized | ||
| ; VK-NEXT: OpInBoundsAccessChain | ||
| ; VK-NEXT: OpReturn | ||
| define spir_func void @foo(ptr noundef byval(%tprange) align 8 %_arg_UserRange) { | ||
| %RoundedRangeKernel = alloca %tprange, align 8 | ||
| call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %RoundedRangeKernel) | ||
| call void @llvm.memcpy.p0.p0.i64(ptr align 8 %RoundedRangeKernel, ptr align 8 %_arg_UserRange, i64 16, i1 false) | ||
| %KernelFunc = getelementptr inbounds i8, ptr %RoundedRangeKernel, i64 8 | ||
| call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %RoundedRangeKernel) | ||
| ret void | ||
|
|
@@ -41,20 +38,17 @@ define spir_func void @foo(ptr noundef byval(%tprange) align 8 %_arg_UserRange) | |
| ; CL: OpFunction | ||
| ; CL: %[[#BarVar:]] = OpVariable | ||
| ; CL-NEXT: OpLifetimeStart %[[#BarVar]], 0 | ||
| ; CL-NEXT: OpCopyMemorySized | ||
| ; CL-NEXT: OpBitcast | ||
| ; CL-NEXT: OpInBoundsPtrAccessChain | ||
| ; CL-NEXT: OpLifetimeStop %[[#BarVar]], 0 | ||
|
|
||
| ; VK: OpFunction | ||
| ; VK: %[[#BarVar:]] = OpVariable | ||
| ; VK-NEXT: OpCopyMemorySized | ||
| ; VK-NEXT: OpInBoundsAccessChain | ||
| ; VK-NEXT: OpReturn | ||
| define spir_func void @bar(ptr noundef byval(%tprange) align 8 %_arg_UserRange) { | ||
| %RoundedRangeKernel = alloca %tprange, align 8 | ||
| call void @llvm.lifetime.start.p0(i64 -1, ptr nonnull %RoundedRangeKernel) | ||
| call void @llvm.memcpy.p0.p0.i64(ptr align 8 %RoundedRangeKernel, ptr align 8 %_arg_UserRange, i64 16, i1 false) | ||
| %KernelFunc = getelementptr inbounds i8, ptr %RoundedRangeKernel, i64 8 | ||
| call void @llvm.lifetime.end.p0(i64 -1, ptr nonnull %RoundedRangeKernel) | ||
| ret void | ||
|
|
@@ -63,20 +57,17 @@ define spir_func void @bar(ptr noundef byval(%tprange) align 8 %_arg_UserRange) | |
| ; CL: OpFunction | ||
| ; CL: %[[#TestVar:]] = OpVariable | ||
| ; CL-NEXT: OpLifetimeStart %[[#TestVar]], 1 | ||
| ; CL-NEXT: OpCopyMemorySized | ||
| ; CL-NEXT: OpInBoundsPtrAccessChain | ||
| ; CL-NEXT: OpLifetimeStop %[[#TestVar]], 1 | ||
|
|
||
| ; VK: OpFunction | ||
| ; VK: %[[#Test:]] = OpVariable | ||
| ; VK-NEXT: OpCopyMemorySized | ||
| ; VK-NEXT: OpInBoundsAccessChain | ||
| ; VK-NEXT: OpReturn | ||
| define spir_func void @test(ptr noundef align 8 %_arg) { | ||
| %var = alloca i8, align 8 | ||
| call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %var) | ||
| call void @llvm.memcpy.p0.p0.i64(ptr align 8 %var, ptr align 8 %_arg, i64 1, i1 false) | ||
| %KernelFunc = getelementptr inbounds i8, ptr %var, i64 0 | ||
| %KernelFunc = getelementptr inbounds i8, ptr %var, i64 1 | ||
|
Contributor
Author
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. I had to change index from 0 to 1, because otherwise |
||
| call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %var) | ||
| ret void | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,12 @@ | ||
| ; RUN: llc -O0 -mtriple=spirv32-unknown-unknown %s -o - | FileCheck %s --check-prefix=SPV | ||
| ; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv32v1.2-unknown-unknown %s -o - -filetype=obj | spirv-val --target-env opencl2.2 %} | ||
|
|
||
| ; SPV: OpMemoryModel Physical32 Simple | ||
| ; SPV: OpMemoryModel Physical32 OpenCL | ||
| define dso_local dllexport void @k_no_fc(i32 %ibuf, i32 %obuf) local_unnamed_addr { | ||
| entry: | ||
| ret void | ||
| } | ||
|
|
||
| !spirv.MemoryModel = !{!0} | ||
|
|
||
| !0 = !{i32 1, i32 0} | ||
| !0 = !{i32 1, i32 2} |
Uh oh!
There was an error while loading. Please reload this page.