-
Notifications
You must be signed in to change notification settings - Fork 31
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
Add support for OpenCL SPIR-V #792
base: development
Are you sure you want to change the base?
Conversation
Oh, this is a big one, but I immediately have two questions: (1) What is the purpose of (2) Why does |
(1) Thanks for pointing this out! Yes (2) It was not relevant to the scoped pointers. We now have new cases where one test has multiple functions. |
I don't understand this point. C-code also has multiple functions, yet we do not need special transformers when inlining. |
Yes for pointers inside a function call, we sometimes need to translate them into thread-local/workgroup-local memory objects. Does C-code has similar cases? |
Ok, I guessed so. But then you are facing a different issue. I think there are two canonical solutions to this: |
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.
First part of the review, will continue tomorrow.
dartagnan/src/main/java/com/dat3m/dartagnan/encoding/ExpressionEncoder.java
Outdated
Show resolved
Hide resolved
...n/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsAnnotation.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
...nan/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsConstant.java
Outdated
Show resolved
Hide resolved
...an/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsExtension.java
Outdated
Show resolved
Hide resolved
...an/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsExtension.java
Outdated
Show resolved
Hide resolved
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 just saw Natalia stated her review too, so some comments might be repeated
dartagnan/src/main/java/com/dat3m/dartagnan/encoding/ExpressionEncoder.java
Outdated
Show resolved
Hide resolved
dartagnan/src/main/java/com/dat3m/dartagnan/expression/Expression.java
Outdated
Show resolved
Hide resolved
dartagnan/src/main/java/com/dat3m/dartagnan/expression/ExpressionVisitor.java
Outdated
Show resolved
Hide resolved
dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/VisitorLitmusC.java
Show resolved
Hide resolved
...an/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsComposite.java
Outdated
Show resolved
Hide resolved
...agnan/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsMemory.java
Outdated
Show resolved
Hide resolved
dartagnan/src/main/java/com/dat3m/dartagnan/program/event/EventFactory.java
Outdated
Show resolved
Hide resolved
dartagnan/src/main/java/com/dat3m/dartagnan/program/event/core/Local.java
Outdated
Show resolved
Hide resolved
public List<Event> visitSpirvLoad(SpirvLoad e) { | ||
String mo = moToOpenCLTag(Tag.Spirv.getMoTag(e.getTags())); | ||
Load load = newLoadWithMo(e.getResultRegister(), e.getAddress(), mo); | ||
load.setFunction(e.getFunction()); |
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.
why do spirv events need to propagate the function from the original event?
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 should definitely be avoided because it causes inconsistent state: the event thinks it belongs to a function, but it is not inserted into the function yet. Basically this function should never be called directly (maybe we can make it private, not sure though).
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.
For single event they are not useful, but for RMW events which are translated to C11 event sequences, functions are needed for creating dummy registers.
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.
VisitorSpirvVulkan
is translated to Vulkan event sequences and those also need to create dummy registers for RMW. Why is this not a problem in that case?
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.
@Override | ||
public List<Event> visitControlBarrier(ControlBarrier e) { | ||
Event entryFence = EventFactory.newControlBarrier(e.getName() + "_entry", e.getId()); | ||
entryFence.addTags(Tag.OpenCL.ENTRY_FENCE, Tag.C11.MO_RELEASE); |
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 we discussed about getting rid of this fence tags and treat barriers in OpenCL the same we do for the other languages (IIRC this was only needed for barrier divergence; we can figure out later how to handle that property)
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 agree with Hernan that we should treat control barriers in the same way for all models, unless there is a really good reason to do otherwise. But I suggest to merge this commit first and change barriers after that in a separate commit.
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.
If I am not wrong, the Tag.OpenCL.ENTRY_FENCE
tag is not used anymore, so we can simply remove it from the Tag
class and remove the axiom from the cat file (all this is dead code ATM)
.../src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsControlFlow.java
Outdated
Show resolved
Hide resolved
.../src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsControlFlow.java
Outdated
Show resolved
Hide resolved
.../src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsControlFlow.java
Outdated
Show resolved
Hide resolved
.../src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsControlFlow.java
Outdated
Show resolved
Hide resolved
55e9306
to
f813b99
Compare
adec207
to
cd3219c
Compare
dartagnan/src/main/java/com/dat3m/dartagnan/program/event/core/Local.java
Outdated
Show resolved
Hide resolved
dartagnan/src/main/java/com/dat3m/dartagnan/program/processing/Inlining.java
Outdated
Show resolved
Hide resolved
dartagnan/src/main/java/com/dat3m/dartagnan/program/Function.java
Outdated
Show resolved
Hide resolved
dartagnan/src/main/java/com/dat3m/dartagnan/program/event/common/RMWExtremum.java
Outdated
Show resolved
Hide resolved
dartagnan/src/main/java/com/dat3m/dartagnan/program/processing/Inlining.java
Outdated
Show resolved
Hide resolved
.../src/main/java/com/dat3m/dartagnan/program/analysis/alias/InclusionBasedPointerAnalysis.java
Outdated
Show resolved
Hide resolved
dartagnan/src/main/java/com/dat3m/dartagnan/program/Thread.java
Outdated
Show resolved
Hide resolved
5ddbf02
to
6b10bf4
Compare
...agnan/src/main/java/com/dat3m/dartagnan/program/event/arch/vulkan/VulkanRMWExtremumBase.java
Outdated
Show resolved
Hide resolved
...agnan/src/main/java/com/dat3m/dartagnan/program/event/arch/opencl/OpenCLRMWExtremumBase.java
Outdated
Show resolved
Hide resolved
dartagnan/src/main/java/com/dat3m/dartagnan/program/event/functions/FunctionCall.java
Outdated
Show resolved
Hide resolved
...n/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsAnnotation.java
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
.../src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsControlFlow.java
Outdated
Show resolved
Hide resolved
...an/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsComposite.java
Outdated
Show resolved
Hide resolved
We normalize such loops first:
|
...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
@tonghaining please rebase and fix the conflicts |
...rc/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/builders/ProgramBuilder.java
Outdated
Show resolved
Hide resolved
...rc/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/builders/ProgramBuilder.java
Outdated
Show resolved
Hide resolved
...rc/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/builders/ProgramBuilder.java
Show resolved
Hide resolved
...rc/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/builders/ProgramBuilder.java
Outdated
Show resolved
Hide resolved
...an/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsComposite.java
Outdated
Show resolved
Hide resolved
3163cb4
to
2c93434
Compare
...nan/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/helpers/HelperTags.java
Outdated
Show resolved
Hide resolved
...an/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/utils/ThreadCreator.java
Outdated
Show resolved
Hide resolved
...nan/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsFunction.java
Outdated
Show resolved
Hide resolved
dartagnan/src/main/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsType.java
Show resolved
Hide resolved
dartagnan/src/main/java/com/dat3m/dartagnan/program/event/EventFactory.java
Outdated
Show resolved
Hide resolved
...nan/src/main/java/com/dat3m/dartagnan/program/processing/compilation/VisitorSpirvOpenCL.java
Outdated
Show resolved
Hide resolved
...nan/src/main/java/com/dat3m/dartagnan/program/processing/compilation/VisitorSpirvOpenCL.java
Outdated
Show resolved
Hide resolved
...nan/src/main/java/com/dat3m/dartagnan/program/processing/compilation/VisitorSpirvOpenCL.java
Outdated
Show resolved
Hide resolved
...nan/src/main/java/com/dat3m/dartagnan/program/processing/compilation/VisitorSpirvOpenCL.java
Outdated
Show resolved
Hide resolved
...nan/src/main/java/com/dat3m/dartagnan/program/processing/compilation/VisitorSpirvOpenCL.java
Outdated
Show resolved
Hide resolved
...nan/src/main/java/com/dat3m/dartagnan/program/processing/compilation/VisitorSpirvOpenCL.java
Outdated
Show resolved
Hide resolved
dartagnan/src/main/java/com/dat3m/dartagnan/program/processing/ProcessingManager.java
Outdated
Show resolved
Hide resolved
6e0eb25
to
232d7d5
Compare
...nan/src/main/java/com/dat3m/dartagnan/program/processing/compilation/VisitorSpirvOpenCL.java
Show resolved
Hide resolved
dartagnan/src/main/java/com/dat3m/dartagnan/program/ThreadGrid.java
Outdated
Show resolved
Hide resolved
dartagnan/src/test/java/com/dat3m/dartagnan/spirv/benchmarks/ClangSpirvAssertionsTest.java
Outdated
Show resolved
Hide resolved
...src/test/java/com/dat3m/dartagnan/parsers/program/visitors/spirv/VisitorOpsFunctionTest.java
Outdated
Show resolved
Hide resolved
dartagnan/src/main/java/com/dat3m/dartagnan/program/processing/compilation/VisitorC11.java
Outdated
Show resolved
Hide resolved
dartagnan/src/main/java/com/dat3m/dartagnan/program/processing/compilation/VisitorC11.java
Outdated
Show resolved
Hide resolved
dartagnan/src/main/java/com/dat3m/dartagnan/program/ThreadGrid.java
Outdated
Show resolved
Hide resolved
dartagnan/src/main/java/com/dat3m/dartagnan/program/processing/ThreadCreation.java
Show resolved
Hide resolved
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.
First pass up to VisitorExtensionOpenClStd
if (!(element instanceof ConstructExpr)) { | ||
throw new ParsingException(String.format("Element is not a ConstructExpr at index: %d for: %s", index, id)); | ||
} |
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.
Isn't this the same check as line 29?
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.
Yes, line 29 removed.
@Override | ||
public List<Event> visitControlBarrier(ControlBarrier e) { | ||
Event entryFence = EventFactory.newControlBarrier(e.getName() + "_entry", e.getId()); | ||
entryFence.addTags(Tag.OpenCL.ENTRY_FENCE, Tag.C11.MO_RELEASE); |
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.
If I am not wrong, the Tag.OpenCL.ENTRY_FENCE
tag is not used anymore, so we can simply remove it from the Tag
class and remove the axiom from the cat file (all this is dead code ATM)
final Map<String, Function> forwardFunctions = new HashMap<>(); | ||
final Map<String, Set<FunctionCall>> forwardCalls = new HashMap<>(); |
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.
Why are those 2 not private?
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.
Updated to private.
if (type instanceof ArrayType aType) { | ||
Type elementType = HelperTypes.getMemberType(id, aType, List.of(0)); | ||
return 1 + getFirstElementDepth(id, elementType); | ||
} else if (type instanceof AggregateType agType) { | ||
Type elementType = HelperTypes.getMemberType(id, agType, List.of(0)); | ||
return 1 + getFirstElementDepth(id, elementType); | ||
} |
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.
Can we merge the two bodies or would the type checker complain about getMemberType
?
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.
Merged
return 0; | ||
} | ||
|
||
private void createExternalVariable(String id, Type type) { |
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 cannot really follow what is going on with createExternalVariable
, addExternalValue
, createPointedExternalValue
, addExternalParameterLocalEvent
and addParameterRegisters
. Why do we need all this?
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.
They are used to create external variables which entry function pointers may point to (which are not declared by OpVariable as our earlier tests).
I update their name as:
createExternalVariable
-> createParameterVariable
addExternalValue
-> addParameterVariable
createPointedExternalValue
-> createExternalVariable
addExternalParameterLocalEvent
-> addEntryParameterLocalEvent
Would it be better as this?
@@ -191,8 +210,9 @@ public String getPointerStorageClass(String id) { | |||
|
|||
public Register addRegister(String id, String typeId) { | |||
Type type = getType(typeId); | |||
if (type instanceof ScopedPointerType) { | |||
throw new ParsingException("Register cannot be a pointer"); | |||
// TODO: Remove this check when tuple registers are supported |
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.
Tuple registers are supported, it is just that we do not create single memory events for them.
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.
Comment updated
public void updateEntry(Event event){ | ||
if (entry == null) { | ||
append(event); | ||
} else { | ||
Event originalEntry = entry; | ||
entry = event; | ||
entry.setFunction(this); | ||
event.setSuccessor(originalEntry); | ||
originalEntry.setPredecessor(event); | ||
} | ||
} | ||
|
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 should probably be symmetric to updateExit()
as it is the case in #803
if (loopBegin.getPredecessor() == null) { | ||
Event newEntry = copies.get(0); | ||
loopBegin.getFunction().updateEntry(newEntry); | ||
newEntry.insertAfter(copies.subList(1, copies.size())); | ||
} else { |
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.
Why do we need this special handling?
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.
Due to the lack of insertBefore
I think. I think its best to merge #803 and use the new functions rather than working around the limitations.
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.
Yeah it causes issue when loop from the first event.
final Thread thread = createSPVThreadFromFunction(entryFunction, tid, grid, transformers); | ||
program.addThread(thread); | ||
} | ||
// Remove unused memory objects of the entry function |
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.
By "unused" you mean that a given object X
was repladed by e.g., WX
and from now one the program will use WX
?
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.
Given object X
in the entry function, it will be replaceds by X0
in thread0, X1
in thread1.., and the entry function objects will not be used anymore.
import com.dat3m.dartagnan.program.Function; | ||
import com.dat3m.dartagnan.program.Program; | ||
import com.dat3m.dartagnan.program.Register; | ||
import com.dat3m.dartagnan.program.processing.transofrmers.MemoryTransformer; |
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.
typo in transformer
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.
Thanks! updated
public List<Event> visitSpirvLoad(SpirvLoad e) { | ||
String mo = moToOpenCLTag(Tag.Spirv.getMoTag(e.getTags())); | ||
Load load = newLoadWithMo(e.getResultRegister(), e.getAddress(), mo); | ||
load.setFunction(e.getFunction()); |
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.
VisitorSpirvVulkan
is translated to Vulkan event sequences and those also need to create dummy registers for RMW. Why is this not a problem in that case?
Signed-off-by: Haining Tong <[email protected]>
No description provided.