-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[flang][mlir] Add support for implicit linearization in omp.simd #150386
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: main
Are you sure you want to change the base?
Changes from 1 commit
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 |
---|---|---|
|
@@ -146,6 +146,27 @@ class LinearClauseProcessor { | |
llvm::BasicBlock *linearLastIterExitBB; | ||
|
||
public: | ||
// Allocate space for linear variabes | ||
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. Merge conflict? The only difference between this an the following function seems to be 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 is actually But now that I detail this, I realise that maybe in the second case, I could invoke ModuleTranslation to lookup the |
||
LogicalResult createLinearVar(llvm::IRBuilderBase &builder, | ||
LLVM::ModuleTranslation &moduleTranslation, | ||
llvm::Value *linearVar, Operation &op) { | ||
if (llvm::AllocaInst *linearVarAlloca = | ||
dyn_cast<llvm::AllocaInst>(linearVar)) { | ||
linearPreconditionVars.push_back(builder.CreateAlloca( | ||
linearVarAlloca->getAllocatedType(), nullptr, ".linear_var")); | ||
llvm::Value *linearLoopBodyTemp = builder.CreateAlloca( | ||
linearVarAlloca->getAllocatedType(), nullptr, ".linear_result"); | ||
linearOrigVal.push_back(linearVar); | ||
linearLoopBodyTemps.push_back(linearLoopBodyTemp); | ||
linearOrigVars.push_back(linearVarAlloca); | ||
return success(); | ||
} | ||
|
||
else | ||
return op.emitError() << "not yet implemented: linear clause support" | ||
<< " for non alloca linear variables"; | ||
} | ||
|
||
// Allocate space for linear variabes | ||
LogicalResult createLinearVar(llvm::IRBuilderBase &builder, | ||
LLVM::ModuleTranslation &moduleTranslation, | ||
|
@@ -265,7 +286,8 @@ class LinearClauseProcessor { | |
users.push_back(user); | ||
for (auto *user : users) { | ||
if (auto *userInst = dyn_cast<llvm::Instruction>(user)) { | ||
if (userInst->getParent()->getName().str() == BBName) | ||
if (userInst->getParent()->getName().str().find(BBName) != | ||
std::string::npos) | ||
user->replaceUsesOfWith(linearOrigVal[varIndex], | ||
linearLoopBodyTemps[varIndex]); | ||
} | ||
|
@@ -2849,17 +2871,6 @@ convertOmpSimd(Operation &opInst, llvm::IRBuilderBase &builder, | |
llvm::OpenMPIRBuilder::InsertPointTy allocaIP = | ||
findAllocaInsertPoint(builder, moduleTranslation); | ||
|
||
// Create linear variables and initialize linear step | ||
LinearClauseProcessor linearClauseProcessor; | ||
|
||
for (mlir::Value linearVar : simdOp.getLinearVars()) { | ||
if (failed(linearClauseProcessor.createLinearVar(builder, moduleTranslation, | ||
linearVar, opInst))) | ||
return failure(); | ||
} | ||
for (mlir::Value linearStep : simdOp.getLinearStepVars()) | ||
linearClauseProcessor.initLinearStep(moduleTranslation, linearStep); | ||
|
||
llvm::Expected<llvm::BasicBlock *> afterAllocas = allocatePrivateVars( | ||
builder, moduleTranslation, privateVarsInfo, allocaIP); | ||
if (handleError(afterAllocas, opInst).failed()) | ||
|
@@ -2876,6 +2887,31 @@ convertOmpSimd(Operation &opInst, llvm::IRBuilderBase &builder, | |
.failed()) | ||
return failure(); | ||
|
||
LinearClauseProcessor linearClauseProcessor; | ||
|
||
// Create linear variables and initialize linear step | ||
for (mlir::Value linearVar : simdOp.getLinearVars()) { | ||
bool isImplicit = false; | ||
for (auto [mlirPrivVar, llvmPrivateVar] : | ||
llvm::zip_equal(privateVarsInfo.mlirVars, privateVarsInfo.llvmVars)) { | ||
if (linearVar == mlirPrivVar) { | ||
isImplicit = true; | ||
if (failed(linearClauseProcessor.createLinearVar( | ||
builder, moduleTranslation, llvmPrivateVar, opInst))) | ||
return failure(); | ||
break; | ||
} | ||
} | ||
if (!isImplicit) { | ||
if (failed(linearClauseProcessor.createLinearVar( | ||
builder, moduleTranslation, linearVar, opInst))) | ||
return failure(); | ||
} | ||
} | ||
|
||
for (mlir::Value linearStep : simdOp.getLinearStepVars()) | ||
linearClauseProcessor.initLinearStep(moduleTranslation, linearStep); | ||
|
||
// No call to copyFirstPrivateVars because FIRSTPRIVATE is not allowed for | ||
// SIMD. | ||
|
||
|
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.
Are we iterating over the symbols for the loop nest iteration variables here?
If so, should we iterate over
iv
instead? Also, make sure we use the properloopSteps[...]
(we always use the step from the first loop in the nest below)?