-
Notifications
You must be signed in to change notification settings - Fork 248
Fix SPV_INTEL_runtime_aligned implementation part 1 #1796
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 3 commits
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 |
|---|---|---|
|
|
@@ -200,19 +200,19 @@ static void addRuntimeAlignedMetadata( | |
| LLVMContext *Context, SPIRVFunction *BF, llvm::Function *Fn, | ||
| std::function<Metadata *(SPIRVFunctionParameter *)> ForeachFnArg) { | ||
| std::vector<Metadata *> ValueVec; | ||
| bool DecorationFound = false; | ||
| bool RuntimeAlignedFound = false; | ||
| BF->foreachArgument([&](SPIRVFunctionParameter *Arg) { | ||
| if (Arg->getType()->isTypePointer() && | ||
| if (Arg->hasAttr(FunctionParameterAttributeRuntimeAlignedINTEL) || | ||
| Arg->hasDecorate(internal::DecorationRuntimeAlignedINTEL)) { | ||
| DecorationFound = true; | ||
| RuntimeAlignedFound = true; | ||
| ValueVec.push_back(ForeachFnArg(Arg)); | ||
|
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. ForeachFnArg seems unnecessary here. We can just create a ConstantInt with 1 and push it here.
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. It actually does exactly what you're mentioned, see https://github.com/KhronosGroup/SPIRV-LLVM-Translator/pull/1796/files#diff-7990d99acb2f8325d245dfecdab758eae5aebae2b54c04fd8e906212eb80ae10R4472-R4473 |
||
| } else { | ||
| llvm::Metadata *DefaultNode = ConstantAsMetadata::get( | ||
|
||
| ConstantInt::get(Type::getInt1Ty(*Context), 0)); | ||
| ValueVec.push_back(DefaultNode); | ||
| } | ||
| }); | ||
| if (DecorationFound) | ||
| if (RuntimeAlignedFound) | ||
| Fn->setMetadata("kernel_arg_runtime_aligned", | ||
| MDNode::get(*Context, ValueVec)); | ||
| } | ||
|
|
@@ -2983,6 +2983,10 @@ void SPIRVToLLVM::transFunctionAttrs(SPIRVFunction *BF, Function *F) { | |
| setName(&(*I), BA); | ||
| AttributeMask IllegalAttrs = AttributeFuncs::typeIncompatible(I->getType()); | ||
| BA->foreachAttr([&](SPIRVFuncParamAttrKind Kind) { | ||
| // Skip this function parameter attribute as it will translated among | ||
|
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. Just to clarify, why wasn't it skipped before?
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. Because it wasn't a function parameter attribute (since it was implemented incorrectly) |
||
| // OpenCL metadata | ||
| if (Kind == FunctionParameterAttributeRuntimeAlignedINTEL) | ||
| return; | ||
| Attribute::AttrKind LLVMKind = SPIRSPIRVFuncParamAttrMap::rmap(Kind); | ||
| if (IllegalAttrs.contains(LLVMKind)) | ||
| return; | ||
|
|
@@ -4465,13 +4469,8 @@ bool SPIRVToLLVM::transOCLMetadata(SPIRVFunction *BF) { | |
| }); | ||
| // Generate metadata for kernel_arg_runtime_aligned | ||
| addRuntimeAlignedMetadata(Context, BF, F, [=](SPIRVFunctionParameter *Arg) { | ||
| auto Literals = | ||
| Arg->getDecorationLiterals(internal::DecorationRuntimeAlignedINTEL); | ||
| assert(Literals.size() == 1 && | ||
| "RuntimeAlignedINTEL decoration shall have 1 ID literal"); | ||
|
|
||
| return ConstantAsMetadata::get( | ||
| ConstantInt::get(Type::getInt1Ty(*Context), Literals[0])); | ||
| ConstantInt::get(Type::getInt1Ty(*Context), 1)); | ||
| }); | ||
| // Generate metadata for spirv.ParameterDecorations | ||
| addKernelArgumentMetadata(Context, SPIRV_MD_PARAMETER_DECORATIONS, BF, F, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -171,6 +171,7 @@ inline bool isValid(spv::FunctionParameterAttribute V) { | |
| case FunctionParameterAttributeNoCapture: | ||
| case FunctionParameterAttributeNoWrite: | ||
| case FunctionParameterAttributeNoReadWrite: | ||
| case FunctionParameterAttributeRuntimeAlignedINTEL: | ||
|
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 suppose this change will be useful when SPIRVWriter.cpp is updated. |
||
| return true; | ||
| default: | ||
| return false; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| ; RUN: llvm-spirv -spirv-text -r %s -o %t.bc | ||
|
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. Not a blocker for this PR. Going forward, it will be great if we can introduce such .spt tests by generating them using the spirv-dis tool which generates a more readable file. Thanks |
||
| ; RUN: llvm-dis < %t.bc | FileCheck %s --check-prefix=CHECK-LLVM | ||
|
|
||
| ; CHECK-LLVM: define spir_kernel void @test{{.*}} !kernel_arg_runtime_aligned ![[RTALIGN_MD:[0-9]+]] {{.*}} | ||
| ; CHECK-LLVM: ![[RTALIGN_MD]] = !{i1 true, i1 false, i1 true, i1 false, i1 false} | ||
|
|
||
| 119734787 65536 393230 22 0 | ||
| 2 Capability Addresses | ||
| 2 Capability Linkage | ||
| 2 Capability Kernel | ||
| 2 Capability Int8 | ||
| 2 Capability RuntimeAlignedAttributeINTEL | ||
| 8 Extension "SPV_INTEL_runtime_aligned" | ||
| 5 ExtInstImport 1 "OpenCL.std" | ||
| 3 MemoryModel 2 2 | ||
| 5 EntryPoint 6 14 "test" | ||
| 3 Source 0 0 | ||
| 4 Name 7 "test" | ||
| 3 Name 8 "a" | ||
| 3 Name 9 "b" | ||
| 3 Name 10 "c" | ||
| 3 Name 11 "d" | ||
| 3 Name 12 "e" | ||
| 4 Name 13 "entry" | ||
| 3 Name 15 "a" | ||
| 3 Name 16 "b" | ||
| 3 Name 17 "c" | ||
| 3 Name 18 "d" | ||
| 3 Name 19 "e" | ||
|
|
||
| 6 Decorate 7 LinkageAttributes "test" Export | ||
| 4 Decorate 8 FuncParamAttr 5940 | ||
| 4 Decorate 10 FuncParamAttr 5940 | ||
| 4 Decorate 15 FuncParamAttr 5940 | ||
| 4 Decorate 17 FuncParamAttr 5940 | ||
| 4 TypeInt 3 8 0 | ||
| 4 TypeInt 5 32 0 | ||
| 2 TypeVoid 2 | ||
| 4 TypePointer 4 5 3 | ||
| 8 TypeFunction 6 2 4 4 4 5 5 | ||
|
|
||
|
|
||
|
|
||
| 5 Function 2 7 0 6 | ||
| 3 FunctionParameter 4 8 | ||
| 3 FunctionParameter 4 9 | ||
| 3 FunctionParameter 4 10 | ||
| 3 FunctionParameter 5 11 | ||
| 3 FunctionParameter 5 12 | ||
|
|
||
| 2 Label 13 | ||
| 1 Return | ||
|
|
||
| 1 FunctionEnd | ||
|
|
||
| 5 Function 2 14 0 6 | ||
| 3 FunctionParameter 4 15 | ||
| 3 FunctionParameter 4 16 | ||
| 3 FunctionParameter 4 17 | ||
| 3 FunctionParameter 5 18 | ||
| 3 FunctionParameter 5 19 | ||
|
|
||
| 2 Label 20 | ||
| 9 FunctionCall 2 21 7 15 16 17 18 19 | ||
| 1 Return | ||
|
|
||
| 1 FunctionEnd | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
we finally will remove this line
"Arg->hasDecorate(internal::DecorationRuntimeAlignedINTEL)"
right?
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.
Right, I believe that is the intention - but only after consumers are ready to work with the correct implementation.