Skip to content

Commit

Permalink
Merge pull request #351 from CFD-GO/hotfix/adjoint
Browse files Browse the repository at this point in the history
Correcting bug for adjoint compilation in makefile
  • Loading branch information
llaniewski authored May 13, 2021
2 parents aa97a05 + cbad57a commit 9e1ceb1
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/ADTools.cu
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
CudaSharedMemory int pushcontrol[MAX_THREADS];

#define pushcontrol1b(x__) pushcontrol1b_(x__)
#define pushControl1b(x__) pushcontrol1b_(x__)
#define pushcontrol2b(x__) pushcontrol2b_(x__)
#define pushControl2b(x__) pushcontrol2b_(x__)
#define pushcontrol3b(x__) pushcontrol3b_(x__)
#define pushControl3b(x__) pushcontrol3b_(x__)
#define popcontrol1b(x__) popcontrol1b_(x__)
#define popControl1b(x__) popcontrol1b_(x__)
#define popcontrol2b(x__) popcontrol2b_(x__)
#define popControl2b(x__) popcontrol2b_(x__)
#define popcontrol3b(x__) popcontrol3b_(x__)
#define popControl3b(x__) popcontrol3b_(x__)


inline CudaDeviceFunction void pushcontrol1b_(int i) {
Expand Down
4 changes: 4 additions & 0 deletions src/ADpost.sed.Rt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ s/0xFFDF<?%s formatC(v$index, width = 2, format = "d", flag = "0") ?>/<?%s v$nam
s/0xFFCCFFCC/NodeType/g
s/\bfloat\b/real_t/g
s/\bdouble\b/real_t/g
/#include[ ]*<[ ]*adBuffer.h[ ]*>/d
<?R for (g in rows(Globals)) if (! g$adjoint) { ?>
s/<?%s g$name ?>[ ]*[+][=]([^;]*);/AddTo<?%s g$name ?>(\1);/g<?R
} ?>
6 changes: 6 additions & 0 deletions src/ADpre_b.h.Rt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@
#define objectiveb 1.0
<?R for (v in Globals$name) { ?>
#define <?%s v ?>b <?%s v ?>InObj <?R } ?>


#pragma GCC diagnostic warning "-Wpragmas"
#pragma GCC diagnostic ignored "-Wdangling-else"
#pragma GCC diagnostic ignored "-Wparentheses"
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
2 changes: 1 addition & 1 deletion src/makefile.main.Rt
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ for (d in destinations) {
add = paste("$(addprefix ",dest,"/,$(ADDITIONALS))",sep="")
src_all = paste(src_all,add)
rtopt = NULL
if (adjoint) rtopt = c(rtopt, "MODEL=TRUE")
if (adjoint) rtopt = c(rtopt, "ADJOINT=1")
rtopt = c(rtopt, paste0("MODEL=\\\"",m,"\\\""))
if (length(opts) > 0) {
opts = ifelse(opts==0,"FALSE","TRUE")
Expand Down
16 changes: 9 additions & 7 deletions tools/ADmod.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ begins = which(diff(a)==1)+1

f = file(opt$out)
open(f,"wt")
pushi = grep("pushreal",lines)
looki = grep("lookreal",lines)
popi = grep("popreal",lines)
pushi = grep("push[rR]eal",lines)
looki = grep("look[rR]eal",lines)
popi = grep("pop[rR]eal",lines)

begins = c(begins,length(lines))
alli = sort(c(pushi,popi,begins,looki))
Expand All @@ -63,7 +63,7 @@ for (i in alli) {
decl = 0;
} else {
l = lines[i]
l1 = sub("[ pushpopreallook]*","",l);
l1 = sub("[ pushpopRreallook]*","",l);
l1 = sub("[_]?\\(.*$","",l1);
tp = switch(l1,
"4"=list(type="float",array=FALSE),
Expand Down Expand Up @@ -92,21 +92,23 @@ for (i in alli) {
cat("var: ",var," ----- fixed\n");
buf = c(buf, paste("//",l));
} else {
if (grepl("pushreal", l)) {
if (grepl("push", l)) {
idx = idx + 1
name = paste(tmpname, idx, sep="_")
if (idx > decl) {
vars = c(vars, paste(tp," ",name,ar_dec,"; // ADmod.R: ",l,sep=""));
decl = idx;
}
buf = c(buf, paste(name,ar_idx," = ", var,ar_idx, "; // ADmod.R: ",l,sep=""));
} else if (grepl("lookreal", l)) {
} else if (grepl("look", l)) {
name = paste(tmpname, idx, sep="_")
buf = c(buf, paste(var,ar_idx, " = ", name,ar_idx,"; // ADmod.R: ",l,sep=""));
} else {
} else if (grepl("pop", l)) {
name = paste(tmpname, idx, sep="_")
buf = c(buf, paste(var,ar_idx, " = ", name,ar_idx,"; // ADmod.R: ",l,sep=""));
idx = idx - 1;
} else {
stop("Unknown type of push/pop: ",l);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions tools/makeAD
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@ echo tapenade -html -msglevel 12 -b Dynamics_tmp.c -root $MAIN_FUN -o DynamicsS
$TAPENADE -msglevel 12 -b Dynamics_tmp.c -root $MAIN_FUN -o DynamicsS -vars "$VARIABLES $SETTINGS" -outvars "$VARIABLES $SETTINGS"
echo "#define CONST_SETTINGS" > ADpre_.h
cat ADpre.h >> ADpre_.h
echo tapenade -html -msglevel 12 -b Dynamics_tmp.c -root $MAIN_FUN -o DynamicsS -vars "$VARIABLES $SETTINGS" -outvars "$VARIABLES $SETTINGS"
echo tapenade -html -msglevel 12 -b Dynamics_tmp.c -root $MAIN_FUN -o DynamicsS -vars "$VARIABLES" -outvars "$VARIABLES"
$TAPENADE -msglevel 12 -b Dynamics_tmp.c -root $MAIN_FUN -o Dynamics -vars "$VARIABLES" -outvars "$VARIABLES"
for f in Dynamics_b.c DynamicsS_b.c
do
test -f $f || { echo "Tapenade failed"; exit -1; }
cp $f ${f}_tapenade_raw
$path_to_script/ADmod.R -f $f -o ${f}_ -x "$FIX"
mv ${f}_ $f
while read -r line; do
if test ! -z "$line"
then
sed "$line" $f > ${f}_
sed -E "$line" $f > ${f}_
mv ${f}_ $f
fi
done <ADpost.sed
Expand Down

0 comments on commit 9e1ceb1

Please sign in to comment.