• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3# ./run.sh gemm
4# ./run.sh lazy_gemm
5
6# Examples of environment variables to be set:
7#   PREFIX="haswell-fma-"
8#   CXX_FLAGS="-mfma"
9
10# Options:
11#   -up : enforce the recomputation of existing data, and keep best results as a merging strategy
12#   -s  : recompute selected changesets only and keep bests
13
14bench=$1
15
16if echo "$*" | grep '\-up' > /dev/null; then
17  update=true
18else
19  update=false
20fi
21
22if echo "$*" | grep '\-s' > /dev/null; then
23  selected=true
24else
25  selected=false
26fi
27
28global_args="$*"
29
30if [ $selected == true ]; then
31 echo "Recompute selected changesets only and keep bests"
32elif [ $update == true ]; then
33 echo "(Re-)Compute all changesets and keep bests"
34else
35 echo "Skip previously computed changesets"
36fi
37
38
39
40if [ ! -d "eigen_src" ]; then
41  hg clone https://bitbucket.org/eigen/eigen eigen_src
42else
43  cd eigen_src
44  hg pull -u
45  cd ..
46fi
47
48if [ ! -z '$CXX' ]; then
49  CXX=g++
50fi
51
52function make_backup
53{
54  if [ -f "$1.out" ]; then
55    mv "$1.out" "$1.backup"
56  fi
57}
58
59function merge
60{
61  count1=`echo $1 |  wc -w`
62  count2=`echo $2 |  wc -w`
63
64  if [ $count1 == $count2 ]; then
65    a=( $1 ); b=( $2 )
66    res=""
67    for (( i=0 ; i<$count1 ; i++ )); do
68      ai=${a[$i]}; bi=${b[$i]}
69      tmp=`echo "if ($ai > $bi) $ai else $bi " | bc -l`
70      res="$res $tmp"
71    done
72    echo $res
73
74  else
75    echo $1
76  fi
77}
78
79function test_current
80{
81  rev=$1
82  scalar=$2
83  name=$3
84
85  prev=""
86  if [ -e "$name.backup" ]; then
87    prev=`grep $rev "$name.backup" | cut -c 14-`
88  fi
89  res=$prev
90  count_rev=`echo $prev |  wc -w`
91  count_ref=`cat $bench"_settings.txt" |  wc -l`
92  if echo "$global_args" | grep "$rev" > /dev/null; then
93    rev_found=true
94  else
95    rev_found=false
96  fi
97#  echo $update et $selected et $rev_found because $rev et "$global_args"
98#  echo $count_rev et $count_ref
99  if [ $update == true ] || [ $count_rev != $count_ref ] || ([ $selected == true ] &&  [ $rev_found == true ]); then
100    if $CXX -O2 -DNDEBUG -march=native $CXX_FLAGS -I eigen_src $bench.cpp -DSCALAR=$scalar -o $name; then
101      curr=`./$name`
102      if [ $count_rev == $count_ref ]; then
103        echo "merge previous $prev"
104        echo "with new       $curr"
105      else
106        echo "got            $curr"
107      fi
108      res=`merge "$curr" "$prev"`
109#       echo $res
110      echo "$rev $res" >> $name.out
111    else
112      echo "Compilation failed, skip rev $rev"
113    fi
114  else
115    echo "Skip existing results for $rev / $name"
116    echo "$rev $res" >> $name.out
117  fi
118}
119
120make_backup $PREFIX"s"$bench
121make_backup $PREFIX"d"$bench
122make_backup $PREFIX"c"$bench
123
124cut -f1 -d"#" < changesets.txt | grep -E '[[:alnum:]]' | while read rev
125do
126  if [ ! -z '$rev' ]; then
127    echo "Testing rev $rev"
128    cd eigen_src
129    hg up -C $rev > /dev/null
130    actual_rev=`hg identify | cut -f1 -d' '`
131    cd ..
132
133    test_current $actual_rev float                  $PREFIX"s"$bench
134    test_current $actual_rev double                 $PREFIX"d"$bench
135    test_current $actual_rev "std::complex<double>" $PREFIX"c"$bench
136  fi
137
138done
139
140echo "Float:"
141cat $PREFIX"s""$bench.out"
142echo " "
143
144echo "Double:"
145cat $PREFIX"d""$bench.out"
146echo ""
147
148echo "Complex:"
149cat $PREFIX"c""$bench.out"
150echo ""
151
152./make_plot.sh $PREFIX"s"$bench $bench
153./make_plot.sh $PREFIX"d"$bench $bench
154./make_plot.sh $PREFIX"c"$bench $bench
155
156
157