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

Remove clad::array_ref from the reverse, hessian, jacobian and error estimation modes #758

Merged
merged 6 commits into from
Mar 21, 2024

Conversation

PetroZarytskyi
Copy link
Collaborator

@PetroZarytskyi PetroZarytskyi commented Feb 13, 2024

This PR removes clad::array_ref from the derivative code in all reverse modes. This is done to simplify the interface and make the code more efficient. This should also make it easier to add support for C and improve pointer support. All new pointer interfaces will remain compatible with old array_ref interfaces. In the error estimation mode, arrayRef.size() was replaced with arrayRef_size to track the biggest index of arrayRef used in the gradient.

Partially fixes #726, #274.

@vgvassilev
Copy link
Owner

That may also fix #762.

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/ErrorEstimator.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ErrorEstimator.cpp Outdated Show resolved Hide resolved
lib/Differentiator/HessianModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/MultiplexExternalRMVSource.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

@parth-07 parth-07 left a comment

Choose a reason for hiding this comment

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

This looks really good. Very impressive work, especially the work involving making the correct call to gradient overload using template metaprogramming.

It's good to see this feature close to complete. Removing the dependency of clad::array_ref for representing derivatives will simplify lots of things.

This is only an initial review. I will need some more time for the complete review.

lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Outdated Show resolved Hide resolved
lib/Differentiator/ReverseModeVisitor.cpp Show resolved Hide resolved
@PetroZarytskyi PetroZarytskyi force-pushed the remove-array-ref branch 2 times, most recently from db91298 to 4cef797 Compare February 26, 2024 20:03
Copy link

codecov bot commented Feb 26, 2024

Codecov Report

Attention: Patch coverage is 98.43750% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 94.81%. Comparing base (8682322) to head (d6dbaa4).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #758      +/-   ##
==========================================
- Coverage   94.95%   94.81%   -0.14%     
==========================================
  Files          49       49              
  Lines        7467     7490      +23     
==========================================
+ Hits         7090     7102      +12     
- Misses        377      388      +11     
Files Coverage Δ
include/clad/Differentiator/Differentiator.h 100.00% <ø> (ø)
include/clad/Differentiator/ErrorEstimator.h 100.00% <ø> (ø)
...e/clad/Differentiator/MultiplexExternalRMVSource.h 100.00% <ø> (ø)
lib/Differentiator/ErrorEstimator.cpp 99.14% <100.00%> (+0.11%) ⬆️
lib/Differentiator/HessianModeVisitor.cpp 99.46% <100.00%> (-0.01%) ⬇️
lib/Differentiator/MultiplexExternalRMVSource.cpp 90.81% <100.00%> (+0.29%) ⬆️
lib/Differentiator/ReverseModeForwPassVisitor.cpp 100.00% <100.00%> (ø)
lib/Differentiator/ReverseModeVisitor.cpp 97.20% <100.00%> (-0.10%) ⬇️
include/clad/Differentiator/ExternalRMVSource.h 25.00% <0.00%> (-0.65%) ⬇️

... and 1 file with indirect coverage changes

Files Coverage Δ
include/clad/Differentiator/Differentiator.h 100.00% <ø> (ø)
include/clad/Differentiator/ErrorEstimator.h 100.00% <ø> (ø)
...e/clad/Differentiator/MultiplexExternalRMVSource.h 100.00% <ø> (ø)
lib/Differentiator/ErrorEstimator.cpp 99.14% <100.00%> (+0.11%) ⬆️
lib/Differentiator/HessianModeVisitor.cpp 99.46% <100.00%> (-0.01%) ⬇️
lib/Differentiator/MultiplexExternalRMVSource.cpp 90.81% <100.00%> (+0.29%) ⬆️
lib/Differentiator/ReverseModeForwPassVisitor.cpp 100.00% <100.00%> (ø)
lib/Differentiator/ReverseModeVisitor.cpp 97.20% <100.00%> (-0.10%) ⬇️
include/clad/Differentiator/ExternalRMVSource.h 25.00% <0.00%> (-0.65%) ⬇️

... and 1 file with indirect coverage changes

@PetroZarytskyi PetroZarytskyi force-pushed the remove-array-ref branch 2 times, most recently from ee75866 to edb09b0 Compare February 27, 2024 20:19
@vgvassilev
Copy link
Owner

@PetroZarytskyi, can you rebase this PR?

@PetroZarytskyi PetroZarytskyi force-pushed the remove-array-ref branch 6 times, most recently from f61d650 to 6242f82 Compare March 19, 2024 18:53
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

include/clad/Differentiator/FunctionTraits.h Outdated Show resolved Hide resolved
@PetroZarytskyi PetroZarytskyi force-pushed the remove-array-ref branch 2 times, most recently from 21c688f to 4915afb Compare March 19, 2024 22:30
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

@@ -42,6 +42,12 @@ void MultiplexExternalRMVSource::ActAfterParsingDiffArgs(
}
}

void MultiplexExternalRMVSource::ActAfterProcessingArraySubscriptExpr(
const clang::Expr* revArrSub) {
for (auto source : m_Sources)
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: 'auto source' can be declared as 'auto *source' [llvm-qualified-auto]

Suggested change
for (auto source : m_Sources)
for (auto *source : m_Sources)

@PetroZarytskyi PetroZarytskyi marked this pull request as ready for review March 19, 2024 22:58
Copy link
Owner

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

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

That's a massive step forward, thank you, @PetroZarytskyi. The patch looks mostly good to me. I'd wait for @parth-07 to review it and then we can move forward.

};
template <std::size_t N, typename... Args>
constexpr auto TakeNFirstArgs(list<Args...>)
-> decltype(TakeNFirstArgs<Args...>(MakeIndexSequence<N>{}));
Copy link
Owner

Choose a reason for hiding this comment

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

Is that c++11 compliant?

@@ -0,0 +1,33 @@
// RUN: %cladnumdiffclang %s -I%S/../../include -oInterfaceCompatibility.out 2>&1 | FileCheck %s
Copy link
Owner

Choose a reason for hiding this comment

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

Nice!

Copy link
Collaborator

@parth-07 parth-07 left a comment

Choose a reason for hiding this comment

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

Looks great to me. It's great to see this finally landing. Thank you!

A small side note: The function traits have become really complicated now. You are perhaps one of the very few people who understands that code completely now. I remember the time when the function traits used were incredibly basic and were just used for handling minor things. The function traits have grown so much now.

@vgvassilev
Copy link
Owner

Looks great to me. It's great to see this finally landing. Thank you!

A small side note: The function traits have become really complicated now. You are perhaps one of the very few people who understands that code completely now. I remember the time when the function traits used were incredibly basic and were just used for handling minor things. The function traits have grown so much now.

@PetroZarytskyi, can you open an issue for this part of the comment? I believe it was expanded due to array_ref and friends.

@vgvassilev vgvassilev merged commit 5cb3c18 into vgvassilev:master Mar 21, 2024
87 of 88 checks passed
@PetroZarytskyi PetroZarytskyi deleted the remove-array-ref branch March 28, 2024 12:16
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.

Reduce the use of clad::array and clad::array_ref for representing derivatives of C-arrays and pointers
3 participants