aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/perf_monitoring/gemm/run_gemm.sh
blob: d3a9fadc91689d1467c5cca4eda229f4e8085466 (plain)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/bash

# Examples of environment variables to be set:
#   PREFIX="haswell-fma-"
#   CXX_FLAGS="-mfma"

# Options:
#   -up : enforce the recomputation of existing data, and keep best results as a merging strategy


if echo "$*" | grep '\-up' > /dev/null; then
  update=true
else
  update=false
fi

if [ $update == true ]; then
 echo "(Re-)Compute all changesets and keep bests"
else
 echo "Skip previously computed changesets"
fi

if [ ! -d "eigen_src" ]; then
  hg clone https://bitbucket.org/eigen/eigen eigen_src
fi

if [ ! -z '$CXX' ]; then
  CXX=g++
fi

function make_backup
{
  if [ -f "$1.out" ]; then
    mv "$1.out" "$1.backup"
  fi
}

function merge
{
  count1=`echo $1 |  wc -w`
  count2=`echo $2 |  wc -w`
  
  if [ $count1 == $count2 ]; then
    a=( $1 ); b=( $2 )
    res=""
    for (( i=0 ; i<$count1 ; i++ )); do
      ai=${a[$i]}; bi=${b[$i]}
      tmp=`echo "if ($ai > $bi) $ai else $bi " | bc -l`
      res="$res $tmp"
    done
    echo $res

  else
    echo $1
  fi
}

function test_current 
{
  rev=$1
  scalar=$2
  name=$3
  
  prev=`grep $rev "$name.backup" | cut -c 14-`
  res=$prev
  count_rev=`echo $prev |  wc -w`
  count_ref=`cat "settings.txt" |  wc -l`
  if [ $update == true ] || [ $count_rev != $count_ref ]; then
    if $CXX -O2 -DNDEBUG -march=native $CXX_FLAGS -I eigen_src gemm.cpp -DSCALAR=$scalar -o $name; then
      curr=`./$name`
      echo merge $prev
      echo with  $curr
      res=`merge "$curr" "$prev"`
      echo $res
      echo "$rev $res" >> $name.out
    else
      echo "Compilation failed, skip rev $rev"
    fi
  else
    echo "Skip existing results for $rev / $name"
    echo "$rev $res" >> $name.out
  fi
}

make_backup $PREFIX"sgemm"
make_backup $PREFIX"dgemm"
make_backup $PREFIX"cgemm"

cut -f1 -d"#" < changesets.txt | while read rev
do
  if [ ! -z '$rev' ]; then
    echo "Testing rev $rev"
    cd eigen_src
    hg up -C $rev
    actual_rev=`hg identify | cut -f1 -d' '`
    cd ..
    
    test_current $actual_rev float                  $PREFIX"sgemm"
    test_current $actual_rev double                 $PREFIX"dgemm"
    test_current $actual_rev "std::complex<double>" $PREFIX"cgemm"
  fi
  
done

echo "Float:"
cat $PREFIX"sgemm.out"
echo ""

echo "Double:"
cat $PREFIX"dgemm.out"
echo ""

echo "Complex:"
cat $PREFIX"cgemm.out"
echo ""

./make_plot.sh $PREFIX"sgemm"
./make_plot.sh $PREFIX"dgemm"
./make_plot.sh $PREFIX"cgemm"