-
Notifications
You must be signed in to change notification settings - Fork 315
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
Added support to generate OpenMP parallel construct clauses, at this time for num_threads and proc_bind #2944
Changes from all commits
d5e20e3
31c3ab2
2399a98
94ba7a9
e737bac
75821e4
88fba85
1e885ae
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 |
---|---|---|
|
@@ -742,6 +742,10 @@ static LogicalResult interpretOperation(Operation *op, OpBuilder &builder, | |
<< parallelOp << "\n"); | ||
// ToFix handle multiple parallel loop | ||
ValueRange loopRefs = parallelOp.getLoops(); | ||
Value numThreads = parallelOp.getNumThreads(); | ||
StringAttr procBind = parallelOp.getProcBindAttr(); | ||
bool needParallelClause = | ||
numThreads || (procBind && procBind.getValue().size() > 0); | ||
|
||
// Obtain the the reference the loop that needs to be parallelized | ||
for (Value loopRef : loopRefs) { | ||
|
@@ -778,6 +782,23 @@ static LogicalResult interpretOperation(Operation *op, OpBuilder &builder, | |
parallelLoop.getRegion().takeBody(loopToParallel.getRegion()); | ||
Operation *yieldOp = ¶llelLoop.getBody()->back(); | ||
yieldOp->setOperands(reducedValues); | ||
if (needParallelClause) { | ||
// Use clause only for the first one (expected the outermost one). | ||
// Ideally, we would generate here a single, multi-dimensional | ||
// AffineParallelOp, and we would not need to reset the flag. | ||
needParallelClause = false; | ||
// Currently approach: insert after yield and then move before it. | ||
PatternRewriter::InsertionGuard insertGuard(builder); | ||
builder.setInsertionPointAfter(yieldOp); | ||
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. Doesn't 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. For some reasons, if I don't have the "moveBefore", it get's me this error
Strangely, with the Since it works as is, I prefer to leave it that way. 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 conversion pass traverses the IR by ourselves. We manipulate graph directly. That might be the reason why it is fragile. 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. OK, then it's fine with the current way. |
||
// Get induction variable. | ||
ValueRange optionalLoopIndices = parallelLoop.getIVs(); | ||
assert(optionalLoopIndices.size() >= 1 && | ||
"expected at least one loop index"); | ||
Value parallelLoopIndex = optionalLoopIndices[0]; | ||
Operation *newOp = opBuilder.create<KrnlParallelClauseOp>( | ||
loc, parallelLoopIndex, numThreads, procBind); | ||
newOp->moveBefore(yieldOp); | ||
} | ||
// Replace the affine.forOp with affine.parallelOp in loopRefToTop | ||
loopRefToOp[loopRef] = parallelLoop; | ||
loopToParallel.erase(); | ||
|
@@ -975,6 +996,7 @@ void ConvertKrnlToAffinePass::runOnOperation() { | |
target.addIllegalOp<KrnlCopyToBufferOp>(); | ||
target.addIllegalOp<KrnlCopyFromBufferOp>(); | ||
target.addIllegalOp<KrnlPrefetchOp>(); | ||
target.addLegalOp<KrnlParallelClauseOp>(); | ||
target.addLegalOp<AffineYieldOp>(); | ||
target.addLegalOp<AffineLoadOp>(); | ||
target.addLegalOp<AffineStoreOp>(); | ||
|
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.
Is this condition used afterwards?
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, when we need the parallel clause, then only the first loop iteration in the
for(Value loopRef : loopRefs)
will execute the addition of theKrnlParallelClauseOp