Recompute the values of CUDA built-in index functions - #1430
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
9263133 to
540098a
Compare
|
clang-tidy review says "All clean, LGTM! 👍" |
| isCUDABuiltInIndex(E); | ||
| } | ||
|
|
||
| bool ReverseModeVisitor::isCUDABuiltInIndex(const Expr* E) { |
There was a problem hiding this comment.
Instead of checking if this is a CUDA Builtin, since effectively these are const variables, can we extend this functionality for all const expressions?
There was a problem hiding this comment.
Yes, you are right. I took this approach because extracting CallExpr from lets say threadIdx.x is rather ugly, so I guess it deserves to be in a separate function.
There was a problem hiding this comment.
Yes, I agree with this being a separate function, but instead of checking the names we can check if it's a const type. In the CUDA case, you can make it to check directly the second subE (OpaqueValueExpr) whether it's a const type. I guess this could work and you wouldn't have to dive that deep as in the case of the CallExpr. But it would be nice if we had a more generic function that checks if the expression is of const type, and one if case there would include this PseudoObjectExpr check-path.
There was a problem hiding this comment.
Addressed. I think we would need to look into a solution for a more generic case, which is out of the scope of this PR.
There was a problem hiding this comment.
Maybe something like this?
if (const auto *pseudoE = llvm::dyn_cast<PseudoObjectExpr>(B)) {
if (const auto *opaqueE =
llvm::dyn_cast<OpaqueValueExpr>(pseudoE->getSemanticExpr(0))) {
const Expr *innerE = opaqueE->getSourceExpr()->IgnoreImplicit();
QualType innerT = innerE->getType();
if (innerT.isConstQualified())
return true;
}
}
There was a problem hiding this comment.
Looks so much better! Thanks:)
There was a problem hiding this comment.
This can be a file static function.
|
clang-tidy review says "All clean, LGTM! 👍" |
|
clang-tidy review says "All clean, LGTM! 👍" |
|
clang-tidy review says "All clean, LGTM! 👍" |
|
clang-tidy review says "All clean, LGTM! 👍" |
|
clang-tidy review says "All clean, LGTM! 👍" |
Before this PR, we used to save the values like
threadIdx.x, see exapmle.Here we create
_t0to store theblockDim.x, but clearly the function doesn't have any side effects, hence should be recomputed.