Permalink
Browse files

Complete change to the Makefiles and the compilation-to-C pipeline

  • Loading branch information...
pavpanchekha committed Oct 9, 2014
1 parent b2ce2b8 commit 20f6a54b3187b677f5bc0e482d4f5e6b4597772d
Showing with 1,003 additions and 148 deletions.
  1. +2 −1 .gitignore
  2. +94 −9 Makefile
  3. +0 −37 compile/Makefile
  4. +2 −6 compile/all.sh
  5. +28 −0 compile/casio-runtime.csv
  6. +35 −36 compile/compile.rkt
  7. +629 −0 compile/graph.py
  8. +28 −0 compile/mpfr-bits.csv
  9. +28 −0 compile/tc.id.csv
  10. +28 −0 compile/tc.if.csv
  11. +28 −0 compile/tc.names.csv
  12. +28 −0 compile/tc.od.csv
  13. +28 −0 compile/tc.of.csv
  14. +45 −59 compile/test.c
View
@@ -10,5 +10,6 @@ logs
/bench/harley/data/cooc.csv
compile/*.o
compile/*.bin
compile/tc*
compile/tc*.c
compile/tc*.out
pldi15/data/*.csv
View
103 Makefile
@@ -1,8 +1,8 @@
PREFIX=tc
BENCHDIR=bench/hamming/
# Running Casio
FLAGS=-p
BENCHDIR=bench/hamming/
.PHONY: all report publish c link clean loc
.PHONY: all report publish compile link clean loc all-fig all-convergence rebib
all:
$(MAKE) link
@@ -14,9 +14,6 @@ report:
publish:
bash reports/publish.sh
c: graphs/results.casio.dat
racket compile/compile.rkt -f compile/$(PREFIX)~a.c graphs/results.casio.dat
link:
raco link casio
raco link reports
@@ -26,16 +23,104 @@ link:
cost:
$(CC) -O0 cost.c -lm -o cost
loc:
find reports/ casio/ -type f -exec cat {} \; | wc -l
clean:
rm -f cost
rm -rf graphs/
rm compile/results.casio.dat
rm compile/$(PREFIX)*.c
rm compile/$(PREFIX)*.out
loc:
find reports/ casio/ -type f -exec cat {} \; | wc -l
rm compile/$(PREFIX)*.out
doc/tr-14wi.pdf: doc/tr-14wi.tex
cd doc/ && pdflatex -file-line-error -halt-on-error tr-14wi.tex
rm doc/tr-14wi.aux doc/tr-14wi.log
# Evaluating Casio's results
PREFIX=tc
DATAFILES=$(patsubst %,compile/$(PREFIX).%.csv,names if id of od)
CFILES=$(wildcard compile/$(PREFIX)*.c)
.SECONDARY: $(DATAFILES)
compile: graphs/results.casio.dat
racket compile/compile.rkt -d compile -f $(PREFIX)~a.c graphs/results.casio.dat graphs/results.casio.dat
# Flags for building and running C files
GCC_FLAGS=-std=c11
FAST_FLAGS=$(GCC_FLAGS) -march=native -mtune=native -mfpmath=both -O4 -flto
SLOW_FLAGS=$(GCC_FLAGS) -Wall -Wextra -Wpedantic -O0 -g
# How many samples to use for evaluation
EVALUATION_POINTS=100000
compile/%.o: %.c Makefile
gcc $(FAST_FLAGS) -c $< -o $@
compile/%.slow.o: %.c Makefile
gcc $(SLOW_FLAGS) -c $< -o $@
# Running evaluation binaries
compile/%.bin: test.c %.o
gcc $(FAST_FLAGS) $^ -o $@ -lm -lgmp -lmpfr -DNARGS=$(shell grep f_if $*.c | tr '()_ ,' '\n' | tail -n+2 | grep float -c)
compile/%.slow.bin: test.c %.slow.o
gcc $(SLOW_FLAGS) $^ -o $@ -lm -lgmp -lmpfr -DNARGS=$(shell grep f_if $*.c | tr '()_ ,' '\n' | tail -n+2 | grep float -c)
compile/%.out: %.bin
./$< $(EVALUATION_POINTS) > $@
$(DATAFILES): $(CFILES:.c=.out)
compile/all.sh compile/$(PREFIX)
# Generating convergence binaries
compile/%.cv_if.bin: convergence.c %.o
gcc $(FLAGS) $(FAST_FLAGS) $^ -o $@ -lm -lgmp -lmpfr -DNARGS=$(shell grep f_if $*.c | tr '()_ ,' '\n' | tail -n+2 | grep float -c)
compile/%.cv_if.csv: %.cv_if.bin
./$< > $@
compile/%.cv_if.png: %.cv_if.csv
gnuplot -e 'set datafile separator ","; set logscale; set term png; set output "'$@'"; plot "'$<'" using 1:4 title "Standard Error v. Points Sampled" with linespoints'
all-convergence: $(CFILES:.c=.cv_if.png)
# Generating the PLDI'15 paper
PLDI15TEX=$(wildcard pldi15/*.tex)
PLDI15BIB=pldi15/references.bib
PLDI15TIKZFIGS=mpfr-bits casio-runtime rect-f rect-d overhead-d
PLDI15FIGS=$(patsubst %,pldi15/fig/eval-%.tex,$(PLDI15TIKZFIGS)) pldi15/fig/eval-err.pdf pldi15/fig/eval-regimes-e2e.pdf
pldi15/paper.pdf: $(PLDI15TEX) $(PLDI15BIB) $(PLDI15FIGS)
cd pldi15 && pdflatex paper
cd pldi15 && bibtex paper
cd pldi15 && pdflatex paper
cd pldi15 && pdflatex paper
rebib:
@ cd pldi15 && pdflatex paper > /dev/null
@ cd pldi15 && bibtex paper > /dev/null
@ grep "didn't find a database entry for" pldi15/paper.blg | cut -d\ -f8 | tr -d \" | findcite >> $(PLDI15BIB)
# Generating graphs
pldi15/fig/eval-mpfr-bits.tex: compile/mpfr-bits.csv compile/graph.py
python compile/graph.py bits -d compile > $@
pldi15/fig/eval-casio-runtime.tex: compile/casio-runtime.csv compile/graph.py
python compile/graph.py time -d compile > $@
pldi15/fig/eval-rect-f.tex: compile/tc.if.csv compile/tc.of.csv compile/tc.id.csv compile/tc.od.csv compile/graph.py
python compile/graph.py rect-f -d compile > $@
pldi15/fig/eval-rect-d.tex: compile/tc.id.csv compile/tc.od.csv compile/graph.py
python compile/graph.py rect-d -d compile > $@
pldi15/fig/eval-overhead-d.tex: compile/tc.id.csv compile/tc.od.csv compile/graph.py
python compile/graph.py overhead-d -d compile > $@
View

This file was deleted.

Oops, something went wrong.
View
@@ -3,11 +3,7 @@
line () { tail $1 -n+$2 | head -n1; }
for i in $1*.out; do line $i 1 | cut -c 4-; done > $1.names.csv
for i in $1*.out; do line $i 3; done > $1.im.csv
for i in $1*.out; do line $i 4; done > $1.if.csv
for i in $1*.out; do line $i 5; done > $1.id.csv
for i in $1*.out; do line $i 6; done > $1.il.csv
for i in $1*.out; do line $i 7; done > $1.om.csv
for i in $1*.out; do line $i 8; done > $1.of.csv
for i in $1*.out; do line $i 9; done > $1.od.csv
for i in $1*.out; do line $i 10; done > $1.ol.csv
for i in $1*.out; do line $i 6; done > $1.of.csv
for i in $1*.out; do line $i 7; done > $1.od.csv
View
@@ -0,0 +1,28 @@
12.117870849609375
35.44230908203125
27.686952880859376
9.574218017578126
17.333179931640625
38.35959814453125
33.65588012695312
5.317513916015625
68.92357690429688
133.04277783203125
31.928704833984376
38.78518798828125
12.823776123046875
31.5298369140625
9.95505908203125
7.447171142578125
18.49539306640625
21.40588818359375
12.44997900390625
32.6267080078125
10.773785888671876
20.2168701171875
26.29110205078125
38.6904140625
14.206782958984375
13.7648359375
11.62531103515625
22.184846923828125
View
@@ -56,7 +56,7 @@
(define (if? l)
(and (list? l) (eq? (car l) 'if)))
(define (compile->c prog [type "double"] [fname "f"])
(define (program->c prog [type "double"] [fname "f"])
(define vars (program-variables prog))
(define body (compile (program-body prog)))
@@ -76,7 +76,7 @@
(write-string
(printf "double ~a(~a) {\n" fname
(string-join (for/list ([var vars]) (format "float ~a" (fix-name var))) ", "))
(string-join (for/list ([var vars]) (format "~a ~a" type (fix-name var))) ", "))
(for/list ([assignment (cadr body)])
(if (comparison? (cadr assignment))
@@ -126,7 +126,7 @@
[pi "mpfr_const_pi(~a, MPFR_RNDN)"]
[e "ERROR(\"E unsupported\")"])
(define (compile->mpfr prog [bits 128] [fname "f"])
(define (program->mpfr prog [bits 128] [fname "f"])
(define vars (program-variables prog))
(define body (compile (program-body prog)))
@@ -140,7 +140,7 @@
(let ([register (gensym "r")])
(format "mpfr_init_set_str(~a, \"~a\", 10, MPFR_RNDN)" out expr))]
[(member expr (program-variables prog))
(format "mpfr_set_flt(~a, ~a, MPFR_RNDN)" out (fix-name expr))]
(format "mpfr_set_d(~a, ~a, MPFR_RNDN)" out (fix-name expr))]
[(member expr constants)
(apply-converter (car (hash-ref constants->mpfr expr)) (list out))]
[(symbol? expr)
@@ -157,7 +157,7 @@
(printf "}\n\n")
(printf "double ~a(~a) {\n" fname
(string-join (for/list ([var vars]) (format "float ~a" (fix-name var))) ", "))
(string-join (for/list ([var vars]) (format "double ~a" (fix-name var))) ", "))
(for ([assignment (cadr body)])
(printf " ~a;\n" (app->mpfr (car assignment) (cadr assignment))))
@@ -166,64 +166,63 @@
(printf " return mpfr_get_d(~a, MPFR_RNDN);\n" (caddr body))
(printf "}\n\n")))
(define (compile->all name iprog oprog bits)
(define (compile-all name iprog fprog dprog bits)
(printf "#include <tgmath.h>\n")
(printf "#include <gmp.h>\n")
(printf "#include <mpfr.h>\n")
(printf "#include <stdio.h>\n")
(printf "#include <stdbool.h>\n\n")
(printf "char *name = \"~a\";\n\n" name)
(display (compile->c iprog "float" "f_if"))
(display (compile->c iprog "double" "f_id"))
(display (compile->c iprog "long double" "f_il"))
(printf "long double fmod2(long double n, long double d) {\n")
(printf " double r = fmodl(n, d);\n")
(printf " return r < 0 ? r + d : r;\n")
(printf "}\n\n")
(display (program->c iprog "float" "f_if"))
(display (program->c iprog "double" "f_id"))
(newline)
(display (compile->c oprog "float" "f_of"))
(display (compile->c oprog "double" "f_od"))
(display (compile->c oprog "long double" "f_ol"))
(display (program->c fprog "float" "f_of"))
(display (program->c dprog "double" "f_od"))
(printf "void mpfr_fmod2(mpfr_t r, mpfr_t n, mpfr_t d) {\n")
(printf " mpfr_fmod(r, n, d, MPFR_RNDN);\n")
(printf " if (mpfr_cmp_ui(r, 0) < 0) mpfr_add(r, r, d, MPFR_RNDN);\n")
(printf "}\n\n")
(newline)
(display (compile->mpfr iprog bits "f_im"))
(display (compile->mpfr oprog bits "f_om")))
(define (compile->c-files results-file [output-file "tc~a.c"])
(for ([id (in-naturals)] [line (read-datafile results-file)])
(match line
[`(,name ,input ,output ,target ,bits ,time)
(display (program->mpfr iprog bits "f_im"))
(display (program->mpfr fprog bits "f_fm"))
(display (program->mpfr dprog bits "f_dm")))
(define (compile-c-files float-results-file double-results-file [output-file "tc~a.c"])
(for ([id (in-naturals)] [fline (read-datafile float-results-file)] [dline (read-datafile double-results-file)])
(match (cons fline dline)
[`((,name ,input ,foutput ,target ,fbits ,ftime) .
(,name ,input ,doutput ,target ,dbits ,dtime))
(debug #:from 'compile-datafile "Compiling" name "to" (format output-file id))
(write-file (format output-file id) (compile->all name input output bits))])))
(write-file (format output-file id) (compile-all name input foutput doutput dbits))])))
(define (compile->mpfr-bits results-file)
(write-file "mpfr-bits.csv"
(for ([line (read-datafile results-file)])
(define (compile-mpfr-bits float-results-file double-results-file dir)
(write-file (build-path dir "mpfr-bits.csv")
(for ([line (read-datafile double-results-file)])
(match line
[`(,name ,input ,output ,target ,bits ,time)
(printf "~a\n" bits)]))))
(define (compile->casio-runtime results-file)
(write-file "casio-runtime.csv"
(for ([line (read-datafile results-file)])
(define (compile-casio-runtime float-results-file double-results-file dir)
(write-file (build-path dir "casio-runtime.csv")
(for ([line (read-datafile double-results-file)])
(match line
[`(,name ,input ,output ,target ,bits ,time)
(printf "~a\n" (/ time 1000))]))))
(define (compile-datafiles results-file [output-file "tc~a.c"])
(compile->c-files results-file output-file)
(compile->mpfr-bits results-file)
(compile->casio-runtime results-file))
(define (compile-datafiles float-results-file double-results-file [dir "."] [output-file "tc~a.c"])
(compile-c-files float-results-file double-results-file (string-append dir "/" output-file))
(compile-mpfr-bits float-results-file double-results-file dir)
(compile-casio-runtime float-results-file double-results-file dir))
(define *format* "tc~a.c")
(define *dir* ".")
(command-line
#:program "compile"
#:once-each
[("-d") dir "Directory into which to place compiled files"
(set! *dir* dir)]
[("-f") fmt "Format of output file names; use a single ~a for an index"
(set! *format* fmt)]
#:args (results-file)
(compile-datafiles results-file *format*))
#:args (float-results-file double-results-file)
(compile-datafiles float-results-file double-results-file *dir* *format*))
Oops, something went wrong.

0 comments on commit 20f6a54

Please sign in to comment.