Skip to content

Commit

Permalink
Merge pull request #2107 from su2code/codipack_tape_options
Browse files Browse the repository at this point in the history
Clarify and extend AD tape choices
  • Loading branch information
jblueh authored Aug 16, 2023
2 parents 931f367 + fb02214 commit da0c951
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 19 deletions.
24 changes: 17 additions & 7 deletions Common/include/code_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,30 @@ FORCEINLINE Out su2staticcast_p(In ptr) {
#if defined(HAVE_OMP)
using su2double = codi::RealReverseIndexOpenMPGen<double, double>;
#else
#if defined(CODI_INDEX_TAPE)
#if defined(CODI_JACOBIAN_LINEAR_TAPE)
using su2double = codi::RealReverse;
#elif defined(CODI_JACOBIAN_REUSE_TAPE)
using su2double = codi::RealReverseIndexGen<double, double, codi::ReuseIndexManager<int> >;
#elif defined(CODI_JACOBIAN_MULTIUSE_TAPE)
using su2double = codi::RealReverseIndex;
// #elif defined(CODI_PRIMAL_TAPE)
// using su2double = codi::RealReversePrimal;
// #elif defined(CODI_PRIMAL_INDEX_TAPE)
// using su2double = codi::RealReversePrimalIndex;
#elif defined(CODI_PRIMAL_LINEAR_TAPE)
using su2double = codi::RealReversePrimal;
#elif defined(CODI_PRIMAL_REUSE_TAPE)
using su2double = codi::RealReversePrimalIndexGen<double, double, codi::ReuseIndexManager<int> >;
#elif defined(CODI_PRIMAL_MULTIUSE_TAPE)
using su2double = codi::RealReversePrimalIndex;
#else
using su2double = codi::RealReverse;
#error "Please define a CoDiPack tape."
#endif
#endif

#if defined(HAVE_OMP) || defined(CODI_JACOBIAN_REUSE_TAPE) || defined(CODI_JACOBIAN_MULTIUSE_TAPE) || \
defined(CODI_PRIMAL_REUSE_TAPE) || defined(CODI_PRIMAL_MULTIUSE_TAPE)
#define CODI_INDEX_REUSE
#endif
#elif defined(CODI_FORWARD_TYPE) // forward mode AD
#include "codi.hpp"
using su2double = codi::RealForward;

#else // primal / direct / no AD
using su2double = double;
#endif
Expand Down
4 changes: 2 additions & 2 deletions SU2_CFD/src/drivers/CDiscAdjMultizoneDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,9 +786,9 @@ void CDiscAdjMultizoneDriver::SetAdjObjFunction() {

void CDiscAdjMultizoneDriver::ComputeAdjoints(unsigned short iZone, bool eval_transfer) {

#if defined(CODI_INDEX_TAPE) || defined(HAVE_OPDI)
#if defined(CODI_INDEX_REUSE)
if (nZone > 1 && rank == MASTER_NODE) {
std::cout << "WARNING: Index AD types do not support multiple zones." << std::endl;
std::cout << "WARNING: AD types that reuse indices do not support multiple zones." << std::endl;
}
#endif

Expand Down
26 changes: 19 additions & 7 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,25 @@ if get_option('enable-autodiff') or get_option('enable-directdiff')
codi_for_args = ['-DCODI_FORWARD_TYPE']
endif

if get_option('enable-autodiff')
if get_option('codi-tape') == 'JacobianIndex'
codi_rev_args += '-DCODI_INDEX_TAPE'
#elif get_option('codi-tape') == 'PrimalLinear'
# codi_rev_args += '-DCODI_PRIMAL_TAPE'
#elif get_option('codi-tape') == 'PrimalIndex'
# codi_rev_args += '-DCODI_PRIMAL_INDEX_TAPE'
if get_option('enable-autodiff') and not omp
if get_option('codi-tape') == 'JacobianLinear'
codi_rev_args += '-DCODI_JACOBIAN_LINEAR_TAPE'
elif get_option('codi-tape') == 'JacobianReuse'
codi_rev_args += '-DCODI_JACOBIAN_REUSE_TAPE'
elif get_option('codi-tape') == 'JacobianMultiUse'
codi_rev_args += '-DCODI_JACOBIAN_MULTIUSE_TAPE'
elif get_option('codi-tape') == 'PrimalLinear'
codi_rev_args += '-DCODI_PRIMAL_LINEAR_TAPE'
elif get_option('codi-tape') == 'PrimalReuse'
codi_rev_args += '-DCODI_PRIMAL_REUSE_TAPE'
elif get_option('codi-tape') == 'PrimalMultiUse'
codi_rev_args += '-DCODI_PRIMAL_MULTIUSE_TAPE'
else
message('Invalid CoDiPack tape choice @1@'.format(get_option('codi-tape')))
endif

if get_option('codi-tape') != 'JacobianLinear'
warning('The tape choice @1@ is not tested regularly in SU2'.format(get_option('codi-tape')))
endif
endif

Expand Down
2 changes: 1 addition & 1 deletion meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ option('enable-mpp', type : 'boolean', value : false, description: 'enable Muta
option('enable-coolprop', type : 'boolean', value : false, description: 'enable CoolProp support')
option('enable-mlpcpp', type : 'boolean', value : false, description: 'enable MLPCpp support')
option('opdi-backend', type : 'combo', choices : ['auto', 'macro', 'ompt'], value : 'auto', description: 'OpDiLib backend choice')
option('codi-tape', type : 'combo', choices : ['JacobianLinear', 'JacobianIndex'], value : 'JacobianLinear', description: 'CoDiPack tape choice')
option('codi-tape', type : 'combo', choices : ['JacobianLinear', 'JacobianReuse', 'JacobianMultiUse', 'PrimalLinear', 'PrimalReuse', 'PrimalMultiUse'], value : 'JacobianLinear', description: 'CoDiPack tape choice')
option('opdi-shared-read-opt', type : 'boolean', value : true, description : 'OpDiLib shared reading optimization')
option('librom_root', type : 'string', value : '', description: 'libROM base directory')
option('enable-librom', type : 'boolean', value : false, description: 'enable LLNL libROM support')
Expand Down
2 changes: 1 addition & 1 deletion meson_scripts/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def init_submodules(

# This information of the modules is used if projects was not cloned using git
# The sha tag must be maintained manually to point to the correct commit
sha_version_codi = "17232fed05245dbb8f04a31e274a02d53458c75c"
sha_version_codi = "c30f195eb9d772cadc75e9dbf4c88cb351ee34bb"
github_repo_codi = "https://github.com/scicompkl/CoDiPack"
sha_version_medi = "aafc2d1966ba1233640af737e71c77c1a86183fd"
github_repo_medi = "https://github.com/SciCompKL/MeDiPack"
Expand Down

0 comments on commit da0c951

Please sign in to comment.