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

Initialize derivative pointers that are allocated through malloc or realloc #1124

Merged
merged 5 commits into from
Oct 27, 2024

Conversation

kchristin22
Copy link
Collaborator

This PR identifies calls to malloc or realloc and for the derivative pointers it:

  • replaces malloc with calloc
  • adds a calloc call after realloc

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

Copy link

codecov bot commented Oct 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.39%. Comparing base (d82f7fd) to head (96ede8f).
Report is 1 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1124      +/-   ##
==========================================
+ Coverage   94.37%   94.39%   +0.02%     
==========================================
  Files          50       50              
  Lines        8366     8713     +347     
==========================================
+ Hits         7895     8225     +330     
- Misses        471      488      +17     
Files with missing lines Coverage Δ
include/clad/Differentiator/ReverseModeVisitor.h 97.32% <ø> (+0.09%) ⬆️
lib/Differentiator/ReverseModeVisitor.cpp 95.58% <100.00%> (+0.07%) ⬆️
lib/Differentiator/VisitorBase.cpp 97.27% <100.00%> (+0.12%) ⬆️

... and 30 files with indirect coverage changes

Files with missing lines Coverage Δ
include/clad/Differentiator/ReverseModeVisitor.h 97.32% <ø> (+0.09%) ⬆️
lib/Differentiator/ReverseModeVisitor.cpp 95.58% <100.00%> (+0.07%) ⬆️
lib/Differentiator/VisitorBase.cpp 97.27% <100.00%> (+0.12%) ⬆️

... and 30 files with indirect coverage changes

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

lib/Differentiator/ReverseModeVisitor.cpp Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
@@ -2842,6 +2877,19 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context,
ComputeEffectiveDOperands(Ldiff, Rdiff, derivedL, derivedR);
addToCurrentBlock(BuildOp(opCode, derivedL, derivedR),
direction::forward);
if (opCode == BO_Assign && derivedR)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this required? I thought this PR is only modifying the differentiation of malloc calls.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I took it one step further and covered realloc as well where there's not a decl stmt, but this may be required for malloc functions also. For example:

double *ptr = nullptr;
ptr = (double *)malloc(10 * sizeof(double));

lib/Differentiator/VisitorBase.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
test/Gradient/Pointers.C Outdated Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@@ -1788,6 +1790,25 @@ Expr* getArraySizeExpr(const ArrayType* AT, ASTContext& context,
return StmtDiff();
}

// If all arguments are constant literals, then this does not contribute to
// the gradient.
// FIXME: revert this when this is integrated in the activity analysis pass.
Copy link
Owner

Choose a reason for hiding this comment

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

@ovdiiuv, can you comment here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought about that recently. I don't think it has to be reverted, rather modified to track arguments that are elements of constant sets for example. This would resolve #682.

Copy link
Owner

Choose a reason for hiding this comment

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

But that should be part of the analysis not here, right? That is, it needs to be implemented on your end.

Copy link
Collaborator

Choose a reason for hiding this comment

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

No, I think it's the right place.

Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@vgvassilev vgvassilev merged commit 72f0edd into vgvassilev:master Oct 27, 2024
90 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants