-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[MLIR][OpenMP] Fix the assertion failure for VariableCaptureKind::ByCopy #72424
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
Conversation
@llvm/pr-subscribers-mlir-llvm @llvm/pr-subscribers-mlir Author: Akash Banerjee (TIFitis) ChangesFull diff: https://github.com/llvm/llvm-project/pull/72424.diff 1 Files Affected:
diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index ae13a745196c42d..c1bc9d42bed75e6 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -2202,16 +2202,11 @@ createDeviceArgumentAccessor(MapInfoData &mapData, llvm::Argument &arg,
ompBuilder.M.getDataLayout().getProgramAddressSpace();
// Create the alloca for the argument the current point.
- llvm::Value *v =
- builder.CreateAlloca(arg.getType()->isPointerTy()
- ? arg.getType()
- : llvm::Type::getInt64Ty(builder.getContext()),
- ompBuilder.M.getDataLayout().getAllocaAddrSpace());
+ llvm::Value *v = builder.CreateAlloca(arg.getType(), allocaAS);
- if (allocaAS != defaultAS && arg.getType()->isPointerTy()) {
+ if (allocaAS != defaultAS && arg.getType()->isPointerTy())
v = builder.CreatePointerBitCastOrAddrSpaceCast(
v, arg.getType()->getPointerTo(defaultAS));
- }
builder.CreateStore(&arg, v);
@@ -2219,15 +2214,7 @@ createDeviceArgumentAccessor(MapInfoData &mapData, llvm::Argument &arg,
switch (capture) {
case mlir::omp::VariableCaptureKind::ByCopy: {
- // RHS of || aims to ignore conversions like int -> uint, but further
- // extension of this path must be implemented for the moment it'll fall
- // through to the assert.
- if (inputType->isPointerTy() || v->getType() == inputType->getPointerTo()) {
- retVal = v;
- return builder.saveIP();
- }
-
- assert(false && "Currently unsupported OMPTargetVarCaptureByCopy Type");
+ retVal = v;
break;
}
case mlir::omp::VariableCaptureKind::ByRef: {
|
This seems to be only one part of the problem when mapping the captured index variables unfortunately. Take the following example that I believe will crash during verification with these changes:
The verifier will complain due to the for loop in this case (if I haven't butchered this example at least), because of incompatible PHI node branches (as the index is now a pointer with this patch, but it successfully gets passed the previous hurdle). So, there's two possible fixes that I've found to this:
Or the second simpler fix, where we change the following line inside of the argAccessorCB lambda from:
And simply return the argument without any extra instructions for accessing for now, we might end up with some weird write back behavior of the index to the host, at the end of the loop despite it being a scalar, although, I'm not entirely sure without some testing. But it can be ironed out if we maintain the usage of non-pointer types long term, and for the moment we tend to pick these cases up as implicit captures that I don't think users directly access. I do also think the runtime has issues passing types that are bigger than i64's from my very basic understanding of some comments I've read, so we might need to be careful about that occurring but it seems quite unlikely (it could also be fixed and the comment I read is just out of date). If you do opt for two, you can keep the useful simplification of the createDeviceArgumentAccessor function you have in the PR currently and perhaps also remove the other isPointerTy() checks for the time being as it'd now only handle pointers! The isPointerTy checks are there for the cases where a variable is ByCopy+i64 type which Clang seems to do in very special cases (and stores types other than i64 in it I think), but it does need fleshed out a fair bit more for this case I think, if it's something we want to carry over. I'd also remove the inputType variable if it's no longer used! However, these are just two suggestions to the secondary issue I found, you don't need to go with either, there might be better solutions! |
Please add a test and a suitable description. |
#72444 should fix scenarios. |
I've updated the description. We already have tests for them in The lowering tests don't show these errors because with the |
I plan on merging this patch tomorrow along with #72444. Please let me know if you have any concerns, or if you'd like some more time. |
This patch removes some of the code instrumentation that was put in place to support non reference values for map operands.
#72444 removes such values from being mapped and thus, we no longer require to handle them.
Depends on #72444.