Skip to content

Commit 5627e49

Browse files
authored
Merge pull request #2528 from MaxSagebaum/bugfix/reduce_tape_overhead
Reduce the tapeing overhead in CFVMFlowSolverBase.inl.
2 parents 24f1cb5 + f16dc8c commit 5627e49

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

Common/include/basic_types/ad_structure.hpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ inline void StartRecording() {}
5252
* \brief Pause the recording of the operations and involved variables.
5353
* If called, all operations occuring after the call will not be stored on the computational graph.
5454
*/
55-
inline void PauseRecording() {}
55+
inline bool PauseRecording() { return false; }
5656

5757
/*!
5858
* \brief Resume the recording of the operations and variables after the recording had been paused.
5959
*/
60-
inline void ResumeRecording() {}
60+
inline void ResumeRecording(bool wasActive) { (void)wasActive; }
6161

6262
/*!
6363
* \brief Stops the recording of the operations and variables.
@@ -413,9 +413,19 @@ FORCEINLINE void ResetInput(su2double& data) { data = data.getValue(); }
413413

414414
FORCEINLINE void StartRecording() { AD::getTape().setActive(); }
415415

416-
FORCEINLINE void PauseRecording() { AD::getTape().setPassive(); }
416+
FORCEINLINE bool PauseRecording() {
417+
if (AD::getTape().isActive()) {
418+
AD::getTape().setPassive();
419+
return true;
420+
}
421+
return false;
422+
}
417423

418-
FORCEINLINE void ResumeRecording() { AD::getTape().setActive(); }
424+
FORCEINLINE void ResumeRecording(bool wasActive) {
425+
if (wasActive) {
426+
AD::getTape().setActive();
427+
}
428+
}
419429

420430
FORCEINLINE void StopRecording() { AD::getTape().setPassive(); }
421431

SU2_CFD/include/solvers/CFVMFlowSolverBase.inl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -673,9 +673,11 @@ void CFVMFlowSolverBase<V, R>::ComputeVorticityAndStrainMag(const CConfig& confi
673673
AD::SetPreaccOut(StrainMag(iPoint));
674674
AD::EndPreacc();
675675

676-
/*--- Max is not differentiable, so we not register them for preacc. ---*/
677-
strainMax = SU2_TYPE::GetValue(max(strainMax, StrainMag(iPoint)));
678-
omegaMax = SU2_TYPE::GetValue(max(omegaMax, GeometryToolbox::Norm(3, Vorticity)));
676+
/*--- The derivative with respect to strainMax and omegaMax is not required. ---*/
677+
bool wa = AD::PauseRecording();
678+
strainMax = max(strainMax, StrainMag(iPoint));
679+
omegaMax = max(omegaMax, GeometryToolbox::Norm(3, Vorticity));
680+
AD::ResumeRecording(wa);
679681
}
680682
END_SU2_OMP_FOR
681683

0 commit comments

Comments
 (0)