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

[WIP] Tag / debug tape recordings #2343

Open
wants to merge 25 commits into
base: develop
Choose a base branch
from

Conversation

oleburghardt
Copy link
Contributor

Proposed Changes

Add feature to record a tape for debug purposes (as a tool for AD / discrete adjoint / .. developers), using CoDiPack's codi::RealReverseTag.

Related Work

Supposed to help finding remaining errors in #2317.

PR Checklist

Put an X by all that apply. You can fill this out after submitting the PR. If you have any questions, don't hesitate to ask! We want to help. These are a guide for you to know what the reviewers will be looking for in your contribution.

  • I am submitting my contribution to the develop branch.
  • My contribution generates no new compiler warnings (try with --warnlevel=3 when using meson).
  • My contribution is commented and consistent with SU2 style (https://su2code.github.io/docs_v7/Style-Guide/).
  • I used the pre-commit hook to prevent dirty commits and used pre-commit run --all to format old commits.
  • I have added a test case that demonstrates my contribution, if necessary.
  • I have updated appropriate documentation (Tutorials, Docs Page, config_template.cpp), if necessary.

@@ -744,7 +744,7 @@
if (kind_recording == RECORDING::SOLUTION_VARIABLES) {
cout << " Objective function : " << ObjFunc;
if (driver_config->GetWrt_AD_Statistics()){
cout << " (" << ObjFunc_Index << ")\n";
// cout << " (" << ObjFunc_Index << ")\n";

Check notice

Code scanning / CodeQL

Commented-out code

This comment appears to contain commented-out code.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will be resolved inside CoDiPack :)

Copy link
Member

@pcarruscag pcarruscag left a comment

Choose a reason for hiding this comment

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

Looks good, can you document how it would be used?

@oleburghardt
Copy link
Contributor Author

Looks good, can you document how it would be used?

Sure. Added an option so that you can compile the AD build using the tag type (-Dcodi-tape=Tag) for now. You will have to check out the current develop branch of CoDiPack.
I'm thinking about writing a "SetRecording_Debug" next. Together with config file options and so on... documentation will follow.

static constexpr bool StoreAsRef = true;

private:
alignas(Size * sizeof(Scalar)) Scalar x_[N];
alignas(Size * 32) Scalar x_[N];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would you be okay with replacing 32 by a function to find the next power of 2? (Requirement of alignas.) Or could this be done any better?

Copy link
Member

Choose a reason for hiding this comment

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

For what type is the result not a power of 2?
If we use a fixed number instead of sizeof, arrays of this type may take more space than necessary.

Copy link
Contributor Author

@oleburghardt oleburghardt Aug 26, 2024

Choose a reason for hiding this comment

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

The reverse tag type is 24 I think. If sizeof(Scalar) is already a power of 2 that function should of course not change it :)

Copy link
Member

Choose a reason for hiding this comment

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

I see, so the tag doesn't have a float/double part? Then it should be ok to round Size * sizeof(Scalar) to the next power of 2.
Or maybe using Size * alignof(Scalar), that may be more generic and achieve the desired result.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well it does contain at least a double for the primal value (show must go on). I'll check or ask what the remaining bytes are for besides two ints for index and tag. But sizeof(RealReverseTag) = 24.

@oleburghardt
Copy link
Contributor Author

oleburghardt commented Sep 24, 2024

These are WIP commits just in order to make the debug mode already available to e.g. @joshkellyjak :-)

@@ -515,9 +536,9 @@
FORCEINLINE void SetPreaccIn(const T& data, const int size) {
if (PreaccActive) {
for (int i = 0; i < size; i++) {
if (IsIdentifierActive(data[i])) {
// if (IsIdentifierActive(data[i])) {

Check notice

Code scanning / CodeQL

Commented-out code

This comment appears to contain commented-out code.
PreaccHelper.addInput(data[i]);
}
// }

Check notice

Code scanning / CodeQL

Commented-out code

This comment appears to contain commented-out code.
@@ -527,9 +548,9 @@
if (!PreaccActive) return;
for (int i = 0; i < size_x; i++) {
for (int j = 0; j < size_y; j++) {
if (IsIdentifierActive(data[i][j])) {
// if (IsIdentifierActive(data[i][j])) {

Check notice

Code scanning / CodeQL

Commented-out code

This comment appears to contain commented-out code.
PreaccHelper.addInput(data[i][j]);
}
// }

Check notice

Code scanning / CodeQL

Commented-out code

This comment appears to contain commented-out code.
SetPreaccOut(moreData...);
}

template <class T>
FORCEINLINE void SetPreaccOut(T&& data, const int size) {
if (PreaccActive) {
for (int i = 0; i < size; i++) {
if (IsIdentifierActive(data[i])) {
// if (IsIdentifierActive(data[i])) {

Check notice

Code scanning / CodeQL

Commented-out code

This comment appears to contain commented-out code.
PreaccHelper.addOutput(data[i]);
}
// }

Check notice

Code scanning / CodeQL

Commented-out code

This comment appears to contain commented-out code.
@@ -567,9 +589,9 @@
if (!PreaccActive) return;
for (int i = 0; i < size_x; i++) {
for (int j = 0; j < size_y; j++) {
if (IsIdentifierActive(data[i][j])) {
// if (IsIdentifierActive(data[i][j])) {

Check notice

Code scanning / CodeQL

Commented-out code

This comment appears to contain commented-out code.
PreaccHelper.addOutput(data[i][j]);
}
// }

Check notice

Code scanning / CodeQL

Commented-out code

This comment appears to contain commented-out code.
This reverts commit 683de77.

Working on the wrong branch.
commit e40f943
Author: Josh Kelly <[email protected]>
Date:   Fri Sep 27 15:42:16 2024 +0200

    Revert "Merge remote-tracking branch 'origin/feature_tag_debug_tape' into feature_mz_adjoint_for_turbo"

    This reverts commit 89c95ba, reversing
    changes made to c002911.

commit 08b7979
Merge: e1a04fa 887e9e6
Author: Josh Kelly <[email protected]>
Date:   Thu Sep 26 18:15:08 2024 +0200

    Merge branch 'feature_mz_adjoint_for_turbo' of https://github.com/su2code/SU2 into feature_mz_adjoint_for_turbo

commit 887e9e6
Author: Josh Kelly <[email protected]>
Date:   Thu Sep 26 18:14:08 2024 +0200

    Resolving tag errors

commit e1a04fa
Merge: 89c95ba 5a9773c
Author: Josh Kelly <[email protected]>
Date:   Thu Sep 26 18:02:36 2024 +0200

    Merge branch 'feature_mz_adjoint_for_turbo' of https://github.com/su2code/SU2 into feature_mz_adjoint_for_turbo

commit 89c95ba
Merge: c002911 13ca3f5
Author: Josh Kelly <[email protected]>
Date:   Thu Sep 26 18:01:02 2024 +0200

    Merge remote-tracking branch 'origin/feature_tag_debug_tape' into feature_mz_adjoint_for_turbo

commit 5a9773c
Author: Josh Kelly <[email protected]>
Date:   Wed Sep 4 10:19:16 2024 +0200

    formatting

commit c002911
Author: Josh Kelly <[email protected]>
Date:   Tue Sep 3 15:26:40 2024 +0200

    Revert "Merge remote-tracking branch 'upstream/feature_tag_debug_tape' into feature_mz_adjoint_for_turbo"

    This reverts commit 9f1b07c, reversing
    changes made to 4327942.

commit 54515e9
Merge: 9f1b07c da21602
Author: Josh Kelly <[email protected]>
Date:   Tue Sep 3 15:24:43 2024 +0200

    Merge branch 'feature_mz_adjoint_for_turbo' of https://github.com/su2code/SU2 into feature_mz_adjoint_for_turbo

commit da21602
Merge: 905f1e6 ae68274
Author: Josh Kelly <[email protected]>
Date:   Fri Aug 30 11:29:35 2024 +0200

    Merge branch 'feature_mz_adjoint_for_turbo' of https://github.com/su2code/SU2 into feature_mz_adjoint_for_turbo

commit 905f1e6
Author: Josh Kelly <[email protected]>
Date:   Fri Aug 30 11:29:30 2024 +0200

    Resource releasing

commit ae68274
Merge: 4327942 66ed495
Author: Josh Kelly <[email protected]>
Date:   Fri Aug 30 11:26:33 2024 +0200

    Merge branch 'develop' into feature_mz_adjoint_for_turbo
This reverts commit 019c87f.
@oleburghardt
Copy link
Contributor Author

I'm sorry for the single fix commit, this PR wasn't meant to include all the fixes alongside the debug mode implementation (it was just meant as an example). We can continue to add them here but I'm afraid this PR becomes less readable then.

@joshkellyjak
Copy link
Contributor

I'm sorry for the single fix commit, this PR wasn't meant to include all the fixes alongside the debug mode implementation (it was just meant as an example). We can continue to add them here but I'm afraid this PR becomes less readable then.

I think I have already made this pretty unreadable, everything from my fork keeps pushing here.

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.

3 participants