thesis version

This commit is contained in:
2021-05-10 18:11:23 +02:00
commit 8d0b353391
152 changed files with 28007 additions and 0 deletions

8
ctbenchmarks/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
build/
debug/
clang/
release/
data/
datam/
srcs/
plots/

168
ctbenchmarks/gen_ct Executable file
View File

@ -0,0 +1,168 @@
#!/bin/bash
rand() {
echo $((RANDOM%($2-$1)+$1))
}
index_expr_rand() {
echo "pfor::ctv<$(rand 0 100)>*i+pfor::ctv<$(rand 0 100)>"
}
index_expr_fixed() {
echo "pfor::ctv<3>*i+pfor::ctv<2>"
}
header() {
cat<<EOF
#include <pfor/pfor.h>
#include <cstdio>
std::size_t pfor::ParallelForParameters::nThreads = 16;
constexpr unsigned n = BUFSIZ;
int main() {
pfor::Index i;
EOF
}
footer() {
cat<<EOF
}
EOF
}
variable() {
i=$1
echo -e "\tint v${i}_[n];\tauto v${i} = pfor::Operand<int*, class TID${i}>{v${i}_};"
}
independent_with() {
index_expr_str=$1; shift
index_expr() {
eval ${index_expr_str}
}
for i in $@; do
echo -ne ",\n\t\tv${i}[$(index_expr)] = v1[$(index_expr)]"
done
}
dependent_with() {
index_expr_str=$1; shift
index_expr() {
eval ${index_expr_str}
}
ii=$1; shift
for i in $@; do
echo -ne ",\n\t\tv${i}[$(index_expr)] = v${ii}[$(index_expr)]"
ii=$i
done
}
####
fixed_count=100
fixed_var_count() {
mode=$1; shift
opening=$1; shift
index_expr_str=$1; shift
header
for i in $(seq ${fixed_count}); do
variable "${i}"
done
echo -ne "\t${opening}"
eval "${mode} '${index_expr_str}' $*"
echo -e "\n\t);"
footer
}
fixed_instr_count() {
mode=$1; shift
opening=$1; shift
index_expr_str=$1; shift
var_count=$1
[ "${mode}" = 'dependent_with' ] && vars='1 ' || vars=
ntimes=$(((fixed_count+(var_count-1)-1)/(var_count-1) - 1))
vars_last="${vars}$(seq -s' ' 2 $((fixed_count-ntimes*(var_count-1) + 1)))"
vars="${vars}$(seq -s' ' 2 ${var_count})"
header
for i in $(seq ${var_count}); do
variable "${i}"
done
echo -ne "\t${opening}"
for i in $(seq ${ntimes}); do
eval "${mode} '${index_expr_str}' ${vars}"
done
eval "${mode} '${index_expr_str}' ${vars_last}"
echo -e "\n\t);"
footer
}
fixed_instr_var_count() {
mode=$1; shift
opening=$1; shift
index_expr_str=$1; shift
loop_count=$1
[ "${mode}" = 'dependent_with' ] && first_=1 || first_=2
[ "${mode}" = 'dependent_with' ] && offset=0 || offset=-1
instr_count=$((fixed_count/loop_count))
remainder=$((fixed_count - instr_count*loop_count))
header
for i in $(seq ${fixed_count}); do
variable "${i}"
done
first=${first_}
for i in $(seq $((loop_count))); do
n=$((instr_count + ! ! remainder))
last=$((first + n + offset))
if [ ${last} -gt ${fixed_count} ]; then
first=${first_}
last=$((first + n + offset))
fi
echo -ne "\t${opening}"
eval "${mode} '${index_expr_str}' $(seq -s' ' ${first} ${last})"
echo -e "\n\t);"
first=$((last+1))
remainder=$((remainder > 0 ? remainder-1 : 0))
done
footer
}
####
outdir=srcs
opening='pfor::parallelFor<pfor::ForLoopThread>(pfor::RangeCT<0,2>{n}'
for count in $(echo 5 $(seq 10 10 100)); do
fixed_var_count>"${outdir}/main_fixedv_indep_randi_${count}.cpp" independent_with "${opening}" 'index_expr_rand' $(seq 2 ${count})
fixed_var_count>"${outdir}/main_fixedv_dep_randi_${count}.cpp" dependent_with "${opening}" 'index_expr_rand' $(seq ${count})
fixed_var_count>"${outdir}/main_fixedv_indep_fixedi_${count}.cpp" independent_with "${opening}" 'index_expr_fixed' $(seq 2 ${count})
fixed_var_count>"${outdir}/main_fixedv_dep_fixedi_${count}.cpp" dependent_with "${opening}" 'index_expr_fixed' $(seq ${count})
# fixed_instr_count>"${outdir}/main_fixedi_indep_randi_${count}.cpp" independent_with "${opening}" 'index_expr_rand' "${count}"
# fixed_instr_count>"${outdir}/main_fixedi_dep_randi_${count}.cpp" dependent_with "${opening}" 'index_expr_rand' "${count}"
# fixed_instr_count>"${outdir}/main_fixedi_indep_fixedi_${count}.cpp" independent_with "${opening}" 'index_expr_fixed' "${count}"
# fixed_instr_count>"${outdir}/main_fixedi_dep_fixedi_${count}.cpp" dependent_with "${opening}" 'index_expr_fixed' "${count}"
fixed_instr_var_count>"${outdir}/main_fixediv_indep_randi_${count}.cpp" independent_with "${opening}" 'index_expr_rand' "${count}"
fixed_instr_var_count>"${outdir}/main_fixediv_dep_randi_${count}.cpp" dependent_with "${opening}" 'index_expr_rand' "${count}"
fixed_instr_var_count>"${outdir}/main_fixediv_indep_fixedi_${count}.cpp" independent_with "${opening}" 'index_expr_fixed' "${count}"
fixed_instr_var_count>"${outdir}/main_fixediv_dep_fixedi_${count}.cpp" dependent_with "${opening}" 'index_expr_fixed' "${count}"
done

121
ctbenchmarks/plot Executable file
View File

@ -0,0 +1,121 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os, sys
sys.path.append(os.path.abspath(os.path.dirname(os.path.abspath(__file__))+"/../scripts"))
import fileinput
import numpy as np
import matplotlib as mpl
show = len(sys.argv) > 1 and sys.argv[1] == 'show'
if not show:
mpl.use('pgf')
import matplotlib.pyplot as plt
import matplotlib.lines as lines
from common import set_size, config_plt, get_colors, fix_log_rects
config_plt()
def toFloat(s):
return float(s.split(' ')[1].replace(',', '.'))
def loadData(fn):
content = []
with open(fn) as f:
content = f.readlines()
values = {}
for line in content:
n, real, user, sys, _ = [x for x in line.split(':')]
time = toFloat(user) + toFloat(sys)
if not n in values:
values[n] = []
values[n].append(time);
if "5" in values:
values.pop("5")
return values
def figCT(title, xlabel, xticks, output, datasrcs, legendOutside=False, error=False, log=False):
fig = plt.figure()
plt.title(title)
plt.xlabel(xlabel)
plt.ylabel(u"temps (s)")
plt.xticks(xticks)
if log:
plt.yscale('log')
nd = len(datasrcs)
width = 1.5
pos = .5-.5*nd
for f, label in datasrcs:
values = loadData(f)
barcolor, errcolor = get_colors(['dep/fixed', 'indep/fixed', 'dep/rand', 'indep/rand'], label)
for k, a in values.items():
x = int(k)
m = np.mean(a)
s = 2.5758 * np.std(a) / np.sqrt(len(a))
x = x + pos*width
bar = plt.bar(x, m, width=width, color=barcolor, label=label)
if log:
fix_log_rects(bar, 1e-4)
if error:
plt.errorbar(x, m, s, elinewidth=.8, capsize=1, ecolor=errcolor)
label=''
pos = pos + 1
bbox=(1, 1)
if not legendOutside:
bbox=(.38, 1)
plt.legend(bbox_to_anchor=bbox)
fig.set_size_inches(set_size(455.24408, .8))
if not show:
plt.savefig(output, format='pdf', bbox_inches='tight')
return plt
# script
plts = []
plt = figCT(u"", u"nombre de boucles", [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],
"plots/fixediv.pdf", [
['data/ct_fixediv_dep_fixedi', 'dep/fixed'],
['data/ct_fixediv_indep_fixedi', 'indep/fixed'],
['data/ct_fixediv_dep_randi', 'dep/rand'],
['data/ct_fixediv_indep_randi', 'indep/rand'],
],
legendOutside=True,
error=True
)
plts.append(plt)
plt = figCT(u"", u"nombre d'instructions", [10, 20, 30, 40, 50, 60, 70, 80, 90, 100],
"plots/fixedv.pdf", [
['data/ct_fixedv_dep_fixedi', 'dep/fixed'],
['data/ct_fixedv_indep_fixedi', 'indep/fixed'],
['data/ct_fixedv_dep_randi', 'dep/rand'],
['data/ct_fixedv_indep_randi', 'indep/rand'],
],
error=True,
log=True
)
plts.append(plt)
if show:
for plt in plts:
plt.show()

15
ctbenchmarks/run_ct Executable file
View File

@ -0,0 +1,15 @@
#!/bin/bash
repetitions=$1; shift
cxx=g++
for mode in $*; do
:>"data/ct_${mode}"
for f in $(ls srcs|grep -E "^main_${mode}_[0-9]+.cpp"); do
n=$(echo ${f}|cut -d'_' -f5|cut -d'.' -f1)
for i in $(seq ${repetitions}); do
echo>>"data/ct_${mode}" "${n}:$( (time -p ${cxx} -O2 -pthread -I../src -o build/null "srcs/${f}") 2>&1|tr '\n' ':')"
done
done
done