Skip to content
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

Try to improve literal types #998

Merged
merged 27 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2b2af14
Try to improve literal types
vaithak Jul 22, 2024
61982a1
Try to improve literal types
vaithak Jul 22, 2024
4432e1f
Merge remote-tracking branch 'refs/remotes/vaithak/cuda-bug' into cud…
kchristin22 Aug 3, 2024
4b57f76
Get enum's underlying value type
kchristin22 Aug 3, 2024
1f4e2a3
Try to improve literal types
vaithak Jul 22, 2024
97acf5f
Get enum's underlying value type
kchristin22 Aug 3, 2024
aee91cd
Zero initialization based on type
kchristin22 Aug 8, 2024
6130c91
Fix pointer zero initialization
kchristin22 Aug 13, 2024
98352a8
Merge with master
kchristin22 Aug 13, 2024
1de6bbe
Merge remote-tracking branch 'vaithak/cuda-bug' into cuda-bug
kchristin22 Aug 13, 2024
17012c0
Fix format
kchristin22 Aug 13, 2024
9feae1b
Fix compatibility of zero initialization of unsigned ints in tests
kchristin22 Aug 13, 2024
03fbcec
Fix clang-tidy suggestions
kchristin22 Aug 13, 2024
1a1e25b
Remove unnecessary leftover casting for zero initilization
kchristin22 Aug 21, 2024
2dc1126
Merge branch 'master' into cuda-bug
kchristin22 Aug 21, 2024
ac042f9
Fix STL test
kchristin22 Aug 21, 2024
69075f1
Synthesize booleans separately from integers and cast type to int whe…
kchristin22 Aug 26, 2024
3a593d0
Create the boolean literal with the new keyword for compatibility rea…
kchristin22 Aug 26, 2024
d3740e4
Remove fail case of type for zero initialization
kchristin22 Aug 26, 2024
2e6b9d0
Add complex type test
kchristin22 Aug 26, 2024
2a8655e
Revert "Add complex type test"
kchristin22 Aug 26, 2024
df2617d
Remove check for nonRealType before calling synthesizeLiteral
kchristin22 Sep 2, 2024
6816d9a
Initialize pointers as nullptr and add a default int case for literal…
kchristin22 Sep 2, 2024
f7b3caa
Merge branch 'master' into cuda-bug
kchristin22 Sep 2, 2024
c74882d
Fix clang format
kchristin22 Sep 2, 2024
fd45301
Init chars as ints to remove suffix
kchristin22 Sep 3, 2024
0413ab7
Use AnyCharacterType check instead of plain CharType
kchristin22 Sep 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/Differentiator/BaseForwardModeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1008,8 +1008,11 @@ StmtDiff BaseForwardModeVisitor::VisitDeclRefExpr(const DeclRefExpr* DRE) {
// If DRE is of type pointer, then the derivative is a null pointer.
if (clonedDRE->getType()->isPointerType())
return StmtDiff(clonedDRE, nullptr);
QualType literalTy = utils::GetValueType(clonedDRE->getType());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should extend visitorbase::getZeroInit as discussed here #989 (comment)

cc: @gojakuch

if (!literalTy->isRealType())
Copy link
Owner

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 check here?

literalTy = m_Context.IntTy;
return StmtDiff(clonedDRE, ConstantFolder::synthesizeLiteral(
m_Context.IntTy, m_Context, /*val=*/0));
literalTy, m_Context, /*val=*/0));
}

StmtDiff BaseForwardModeVisitor::VisitIntegerLiteral(const IntegerLiteral* IL) {
Expand Down Expand Up @@ -1316,8 +1319,12 @@ StmtDiff BaseForwardModeVisitor::VisitUnaryOperator(const UnaryOperator* UnOp) {
} else if (opKind == UnaryOperatorKind::UO_Deref) {
if (Expr* dx = diff.getExpr_dx())
return StmtDiff(op, BuildOp(opKind, dx));
return StmtDiff(op, ConstantFolder::synthesizeLiteral(
m_Context.IntTy, m_Context, /*val=*/0));
QualType literalTy =
utils::GetValueType(UnOp->getSubExpr()->getType()->getPointeeType());
if (!literalTy->isRealType())
literalTy = m_Context.IntTy;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should not need this. This gets handled in ConstantFolder::synthesizeLiteral anyways.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, it was a leftover from Vaibhav's PR. I will remove these lines.

return StmtDiff(
op, ConstantFolder::synthesizeLiteral(literalTy, m_Context, /*val=*/0));
} else if (opKind == UnaryOperatorKind::UO_AddrOf) {
return StmtDiff(op, BuildOp(opKind, diff.getExpr_dx()));
} else if (opKind == UnaryOperatorKind::UO_LNot) {
Expand Down
2 changes: 1 addition & 1 deletion test/FirstDerivative/CallArguments.C
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ float f_call_inline_fxn(float *params, float const *obs, float const *xlArr) {

// CHECK: float f_call_inline_fxn_darg0_0(float *params, const float *obs, const float *xlArr) {
// CHECK-NEXT: clad::ValueAndPushforward<unsigned int, unsigned int> _t0 = getBin_pushforward(0., 1., params[0], 1, 0., 0., 1.F, 0);
// CHECK-NEXT: const float _d_t116 = 0;
// CHECK-NEXT: const float _d_t116 = 0.F;
// CHECK-NEXT: const float t116 = *(xlArr + _t0.value);
// CHECK-NEXT: return _d_t116 * params[0] + t116 * 1.F;
// CHECK-NEXT: }
Expand Down
2 changes: 1 addition & 1 deletion test/ForwardMode/Functors.C
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ int main() {
// CHECK-NEXT: double _d_i = 1;
// CHECK-NEXT: double _d_jj = 0;
// CHECK-NEXT: double _t0 = x * i;
// CHECK-NEXT: return (0 * i + x * _d_i) * jj + _t0 * _d_jj;
// CHECK-NEXT: return (0. * i + x * _d_i) * jj + _t0 * _d_jj;
// CHECK-NEXT: }

auto lambdaNNS = outer::inner::lambdaNNS;
Expand Down
4 changes: 2 additions & 2 deletions test/ForwardMode/Pointer.C
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ double fn9(double* params, const double *constants) {
}

// CHECK: double fn9_darg0_0(double *params, const double *constants) {
// CHECK-NEXT: double _d_c0 = 0;
// CHECK-NEXT: double _d_c0 = 0.;
// CHECK-NEXT: double c0 = *constants;
// CHECK-NEXT: return 1. * c0 + params[0] * _d_c0;
// CHECK-NEXT: }
Expand All @@ -209,7 +209,7 @@ double fn10(double *params, const double *constants) {
}

// CHECK: double fn10_darg0_0(double *params, const double *constants) {
// CHECK-NEXT: double _d_c0 = 0;
// CHECK-NEXT: double _d_c0 = 0.;
// CHECK-NEXT: double c0 = *(constants + 0);
// CHECK-NEXT: return 1. * c0 + params[0] * _d_c0;
// CHECK-NEXT: }
Expand Down
Loading