-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgen_tapemodel.sh
86 lines (68 loc) · 2.39 KB
/
gen_tapemodel.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
OUTDIR="./tapeout"
mkdir -p "$OUTDIR"
rm "$OUTDIR/*"
rm ./tapeout/*
infile="$1"
# Remove the extension (file.f90 => file)
infile="${infile%.*}"
name=$(basename ${infile})
modflag="YAEOSD"
ADFirstAidKitDIR=../src/adiff/autodiff_api/tapenade #ADFirstAidKit
# Forward
tapenade -tangent -head "ar(arval)/(n, v, t)" \
-ext ${ADFirstAidKitDIR}/PUSHPOPGeneralLib \
-tgtmodulename "$modflag" \
-noisize\
"${infile}".f90 \
-O tapeout
# Double forward
tapenade -tangent -head "ar_d(arval_d)/(v, t)" \
-ext ${ADFirstAidKitDIR}/PUSHPOPGeneralLib \
-tgtmodulename "$modflag" \
-noisize \
"tapeout/${name}_d.f90" \
-O tapeout
# Triple forward
tapenade -tangent -head "ar_d_d(arval_d_d)/(v, t)" \
-ext ${ADFirstAidKitDIR}/PUSHPOPGeneralLib \
-tgtmodulename "$modflag" \
-noisize \
"tapeout/${name}_d_d.f90" \
-O tapeout
# Forward-Backward
tapenade -reverse -head "ar_d/(n, nd, v, vd, t, td)" \
-noisize \
-ext ${ADFirstAidKitDIR}/PUSHPOPGeneralLib \
-adjmodulename "$modflag" \
"tapeout/${name}_d_d_d.f90" \
-O tapeout
# Single backward
tapenade -reverse -head "ar(arval)/(n, v, t)" \
-noisize \
-ext ${ADFirstAidKitDIR}/PUSHPOPGeneralLib \
-adjmodulename "$modflag" \
"tapeout/${name}_d_d_d_b.f90" \
-O tapeout
# Remove the intermediate files
rm tapeout/*msg
rm tapeout/${name}_d.f90
rm tapeout/${name}_d_d.f90
rm tapeout/${name}_d_d_d.f90
rm tapeout/${name}_d_d_d_b.f90
mv tapeout/${name}_d_d_d_b_b.f90 tapeout/${name}_diff.f90
# Remove the flags
sed -i "s/$modflag//g" tapeout/${name}_diff.f90
# Change the way reals are defined
sed -i 's/REAL\*8/REAL(pr)/' tapeout/${name}_diff.f90
sed -i 's/_8/_pr/' tapeout/${name}_diff.f90
# Remove the implicit R constant that tapenade can not find
sed -i "s/REAL :: r//g" tapeout/${name}_diff.f90
# make the types into classes for polymorphism
sed -i 's/TYPE(\(.*\)),/class(\1),/' tapeout/${name}_diff.f90
# remove all the external definition of functions. we use interfaces now
sed -i '/EXTERNAL.*/d' tapeout/${name}_diff.f90
# Options to format document
# fprettify -i 3 --case 1 1 1 1
# findent < tapeout/${name}_diff.f90 > tapeout/${name}_diff.f90
# lfortran fmt -i tapeout/${infile}_diff.f90
# =============================================================================