-
Notifications
You must be signed in to change notification settings - Fork 31
Add Support for OpenCL Alignment Decoration #813
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
base: development
Are you sure you want to change the base?
Add Support for OpenCL Alignment Decoration #813
Conversation
dartagnan/src/test/java/com/dat3m/dartagnan/spirv/opencl/gpuverify/SpirvRacesTest.java
Outdated
Show resolved
Hide resolved
3b130e3
to
760d56e
Compare
...nan/src/main/java/com/dat3m/dartagnan/program/processing/transformers/MemoryTransformer.java
Outdated
Show resolved
Hide resolved
...nan/src/main/java/com/dat3m/dartagnan/program/processing/transformers/MemoryTransformer.java
Outdated
Show resolved
Hide resolved
6f5d0de
to
64ee14a
Compare
dartagnan/src/test/java/com/dat3m/dartagnan/spirv/basic/SpirvAssertionsOpenCLTest.java
Outdated
Show resolved
Hide resolved
...c/test/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsAnnotationTest.java
Show resolved
Hide resolved
...nan/src/main/java/com/dat3m/dartagnan/program/processing/transformers/MemoryTransformer.java
Outdated
Show resolved
Hide resolved
dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/utils/ProgramBuilder.java
Outdated
Show resolved
Hide resolved
...n/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsConversion.java
Outdated
Show resolved
Hide resolved
alignmentList.add(offset); | ||
offset += alignmentNum; | ||
} | ||
type = types.getAggregateType(elementTypes, alignmentList); |
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 might be a problem if we have two variables that use the same type (type_id) but different alignments. Let's check tomorrow what would be a better way to deal with such cases.
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.
As we discussed since the alignment will not affect the element type, type checking (staticTypeOf) will not be an issue.
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.
I think there is still a problem, see the comment to the vector-alignment test.
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.
I added a new step to getOpVariableInitialValue()
to create initial value with valid-type.
...n/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsConversion.java
Outdated
Show resolved
Hide resolved
...n/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsConversion.java
Outdated
Show resolved
Hide resolved
...n/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsConversion.java
Outdated
Show resolved
Hide resolved
...n/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsConversion.java
Outdated
Show resolved
Hide resolved
0f0d092
to
e0370ea
Compare
...an/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsComposite.java
Outdated
Show resolved
Hide resolved
...c/test/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/mocks/MockProgramBuilder.java
Outdated
Show resolved
Hide resolved
@@ -0,0 +1,57 @@ | |||
; @Input: %output = {0, 0} |
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.
Hmm, this test doesn't test anything. If we remove the alignment, the test still passes. But if we try to add initial values for the variable with alignment (e.g. below), the test will crash with a parsing exception (an aggregate type created instead of an array type).
Also, we should test non-zero indexes and non-zero values, the element at 0 index is not affected by alignment.
%arr1 = OpConstantComposite %v3uint %uint_0 %uint_1 %uint_2
%arr2 = OpConstantComposite %v3uint %uint_3 %uint_4 %uint_5
%arr3 = OpConstantComposite %v3uint %uint_6 %uint_7 %uint_8
%arr4 = OpConstantComposite %v3uint %uint_9 %uint_10 %uint_11
%value1 = OpConstantComposite %_arr_v3uint_uint_2 %arr1 %arr2
%value2 = OpConstantComposite %_arr_v3uint_uint_2 %arr3 %arr4
%aligned_data = OpVariable %_ptr_Workgroup__arr_v3uint_uint_2 Workgroup %value1
%normal_data = OpVariable %_ptr_Workgroup__arr_v3uint_uint_2 Workgroup %value2
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.
Test updated, the initial array type will now be cast to aggregate type based on alignment decoration.
alignmentList.add(offset); | ||
offset += alignmentNum; | ||
} | ||
type = types.getAggregateType(elementTypes, alignmentList); |
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.
I think there is still a problem, see the comment to the vector-alignment test.
dartagnan/src/test/resources/spirv/basic/composite-insert.spv.dis
Outdated
Show resolved
Hide resolved
bd69c2b
to
7a96b98
Compare
3783aa8
to
1d8784c
Compare
396df68
to
3cb13a4
Compare
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.
I suggest to split this PR into two: the alignment and the new instructions. For the new instructions, there are few small comments, but overall it looks good. And having these instructions might be also useful for other tests.
For the alignment part, the conversion from array to struct doesn't look right to me. What we need is to support non-default alignments for types, i.e. it should be possible to specify a particular alignment when creating a type (i.e. alignment should be a property of a type). And later this new explicit alignment should be used to compute element size.
dartagnan/src/main/java/com/dat3m/dartagnan/expression/ExpressionFactory.java
Outdated
Show resolved
Hide resolved
...an/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsComposite.java
Outdated
Show resolved
Hide resolved
...an/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsComposite.java
Outdated
Show resolved
Hide resolved
...n/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsConversion.java
Outdated
Show resolved
Hide resolved
...n/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsConversion.java
Outdated
Show resolved
Hide resolved
...nan/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsConstant.java
Outdated
Show resolved
Hide resolved
Is this common in SPIRV? In C, for example, types have no alignment property. The alignment is part of the allocation site, and therefore the same type can be allocated with different alignments (IIRC, there is not even a default alignment at all). Also, struct types have explicit control over the layout and can therefore enforce alignment. |
Actually, t is possible to define a type like this in C
First, the LLVM parser can continue using default alignment, and other languages can have user-defined alignments when needed. Second, what could be a problem with non-default alignment, assuming it is a power of 2?
Struct is not enough. For the current use case, it might be sufficient to have alignment for pointers and arrays, but it will likely lead to a lot of fragile code like "if type instanceof ScopedPOinterType and pointer.getAlignment() != null". I would prefer to have a generic solution. |
Yes and no. You can write it on the C-level, but the alignment is not part of the type and instead specifies alignments on all allocation sites of that type. If you look into the LLVM IR, you won't see the alignment on the type at all.
There is no problem with non-default alignment. In fact, we can even do non-power-of-two alignment.
That being said, for struct types the alignment can yield different types if the alignment is too large and padding bits need to be inserted.
I'm wondering if SPIRV really does it differently and bakes it into the type or not. From the documentation I can see that SPIRV allows multiple identical types to be defined with possibly different decorations, but I didn't see any alignment decorations. EDIT: Checking the benchmarks of this PR, it seems SPIRV does not attach alignments to types either. The decorations are on allocation sites as far as I can tell.
Well, when you make alignment part of the type, you need to do alignment checks for each and every expression in the IR, or weaken the type checking to disregard alignments. Still, for most operations on types alignment doesn't make sense, e.g., every computation you perform on typed registers. Alignment is only meaningful on memory operations and that is why LLVM IR decides to annotate the memory operations rather than the types. |
for (int i = 0; i < arrayType.getNumElements(); i++) { | ||
List<Expression> index = List.of(expressions.makeValue(i, types.getArchType())); | ||
Expression address = expressions.makeGetElementPointer(arrayType.getElementType(), pointer, index); | ||
Expression element = expressions.makeExtract(value, i); | ||
Event store = EventFactory.newStore(address, element); | ||
events.add(store); | ||
} |
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 only works if element
has a basic type (e.g. int or bool). If it has an aggregate type, we should go deeper in the type hierarchy. I would start by throwing an exception in this case. The same is true for visitOpLoad
.
3cb13a4
to
5681cce
Compare
505faf3
to
5f09ecb
Compare
758ab09
to
098932c
Compare
...n/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsConversion.java
Outdated
Show resolved
Hide resolved
04efb1a
to
75c0df4
Compare
Signed-off-by: Haining Tong <[email protected]>
75c0df4
to
22eab93
Compare
No description provided.