Skip to content

Commit 4370b94

Browse files
committed
Display accelerator counts
1 parent 0b6451f commit 4370b94

File tree

5 files changed

+86
-66
lines changed

5 files changed

+86
-66
lines changed

growlibm/count_accelerators.sh

Lines changed: 0 additions & 35 deletions
This file was deleted.

growlibm/extend-platform.rkt

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,13 @@
5353

5454
(define sorted-pairs (sort scored-pairs > #:key fourth))
5555

56-
(define fpcore (with-input-from-string (first (first sorted-pairs)) read))
57-
(define link (second (first sorted-pairs)))
56+
(when (null? sorted-pairs)
57+
(displayln "No accelerators discovered in this iteration.")
58+
(exit 0))
59+
60+
(define chosen-pair (first sorted-pairs))
61+
(define fpcore (with-input-from-string (first chosen-pair) read))
62+
(define link (second chosen-pair))
5863
(define ctx (context (free-variables fpcore)
5964
(get-representation 'binary64)
6065
(make-list (length (free-variables fpcore))
@@ -86,9 +91,24 @@
8691
(displayln operator-strf32))
8792
#:exists 'append)
8893

89-
(with-output-to-file "reports/report_info.txt"
90-
(lambda ()
91-
(displayln (format "~a, ~a" link spec)))
92-
#:exists 'append)
94+
(define accelerators-path "reports/accelerators.json")
95+
96+
(define new-entry (hash 'name link 'spec (format "~a" spec)))
97+
98+
(define updated-accelerators
99+
(let ([previous
100+
(if (file-exists? accelerators-path)
101+
(let ([data (call-with-input-file accelerators-path read-json)])
102+
(cond
103+
[(vector? data) (vector->list data)]
104+
[(list? data) data]
105+
[else '()]))
106+
'())])
107+
(append previous (list new-entry))))
108+
109+
(call-with-output-file accelerators-path
110+
(lambda (out)
111+
(write-json updated-accelerators out))
112+
#:exists 'truncate)
93113

94114
(displayln (format "adding accelerator ~a, with spec: ~a" link spec))

growlibm/generate-candidates.rkt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,23 +130,13 @@
130130
(define renamed-subexprs (map rename-vars filtered-again))
131131
(define pairs (hash->list (count-frequencies renamed-subexprs)))
132132

133-
(with-output-to-file (string-append report-dir "/report_info.txt")
134-
(lambda ()
135-
(printf "og length, ~a\n"(length pairs)))
136-
#:exists 'replace)
137-
138133
(define deduplicated-pairs (hash->list (deduplicate pairs)))
139134

140-
(with-output-to-file (string-append report-dir "/report_info.txt")
141-
(lambda ()
142-
(printf "deduped length, ~a\n"(length deduplicated-pairs)))
143-
#:exists 'append)
144-
145135
(define sorted-pairs (sort deduplicated-pairs (lambda (p1 p2) (> (cdr p1) (cdr p2)))))
146136
(define first-2000 (take sorted-pairs (min (length sorted-pairs) 2000)))
147137

148-
(define filtered (filter (lambda (p) (< 0.1 (get-error (car p)))) first-2000))
149-
;;; (define filtered first-1000)
138+
;;; (define filtered (filter (lambda (p) (< 0.1 (get-error (car p)))) first-2000))
139+
(define filtered first-2000)
150140
(define first-500 (take filtered (min (length filtered) 500)))
151141
(define fpcores-out (map to-fpcore-str first-500))
152142
(define counts-out (map to-count-print first-500))

growlibm/generate-html.py

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import json
2+
import html
23

34
START_REPORT_PATH = 'reports/start/results.json'
45
END_REPORT_PATH = 'reports/end/results.json'
56
START_FOLDER = 'start'
67
END_FOLDER = 'end'
78
OUTPUT_FILE = 'reports/index.html'
89
NUM_ITERATIONS = 10
10+
ACCELERATORS_PATH = 'reports/accelerators.json'
911

1012
def calculate_end_accuracy(data):
1113
total_end = 0
@@ -17,17 +19,55 @@ def calculate_end_accuracy(data):
1719
return 0.0
1820
return 100 - (100 * (total_end / max_accuracy))
1921

22+
def load_report(path):
23+
with open(path, 'r') as f:
24+
return json.load(f)
25+
2026
def get_accuracy_str(path):
21-
try:
22-
with open(path, 'r') as f:
23-
data = json.load(f)
24-
percent = calculate_end_accuracy(data)
25-
return f"{percent:.1f}%"
26-
except (FileNotFoundError, json.JSONDecodeError):
27-
return "N/A"
27+
report = load_report(path)
28+
percent = calculate_end_accuracy(report)
29+
return f"{percent:.1f}%"
30+
31+
def load_accelerators(path):
32+
with open(path, 'r') as f:
33+
data = json.load(f)
34+
if isinstance(data, dict):
35+
return [data]
36+
if isinstance(data, (list, tuple, set)):
37+
return list(data)
38+
return []
39+
40+
41+
def format_accelerator_rows(accelerators, counts):
42+
if not accelerators:
43+
return '<tr><td colspan="3">No accelerators recorded.</td></tr>'
44+
rows = []
45+
for acc in accelerators:
46+
name = html.escape(str(acc.get("name", "")))
47+
spec = html.escape(str(acc.get("spec", "")))
48+
count = counts.get(acc.get("name"), 0)
49+
rows.append(f'<tr><td>{name}</td><td><code>{spec}</code></td><td>{count}</td></tr>')
50+
return "".join(rows)
51+
52+
end_report = load_report(END_REPORT_PATH)
2853

2954
start_accuracy_str = get_accuracy_str(START_REPORT_PATH)
3055
end_accuracy_str = get_accuracy_str(END_REPORT_PATH)
56+
accelerators = load_accelerators(ACCELERATORS_PATH)
57+
58+
def read_text(path):
59+
with open(path, 'r') as f:
60+
return f.read()
61+
62+
report_paths = [END_REPORT_PATH] + [f"reports/iter{i}/results.json" for i in range(NUM_ITERATIONS)]
63+
report_texts = [read_text(p) for p in report_paths]
64+
counts = {
65+
acc_name: sum(text.count(acc_name) for text in report_texts)
66+
for acc_name in [str(acc.get("name", "")) for acc in accelerators]
67+
if acc_name
68+
}
69+
70+
accelerator_rows = format_accelerator_rows(accelerators, counts)
3171

3272
table_rows = "".join([
3373
f'<tr><td><a href="iter{i}/">iter{i}</a></td><td>{get_accuracy_str(f"reports/iter{i}/results.json")}</td></tr>'
@@ -45,12 +85,21 @@ def get_accuracy_str(path):
4585
<h1>GrowLibm Report</h1>
4686
<p><a href="grow_platform.txt">Grow Platform</a></p>
4787
<p><a href="candidates.txt">Candidates</a></p>
48-
<p><a href="report_info.txt">More Info</a></p>
4988
5089
<h2>Overall Summary</h2>
5190
<p><strong>Start:</strong> {start_accuracy_str} - <a href="{START_FOLDER}/">Folder</a></p>
5291
<p><strong>End:</strong> {end_accuracy_str} - <a href="{END_FOLDER}/">Folder</a></p>
5392
93+
<h2>Accelerators</h2>
94+
<table border="1" style="border-collapse:collapse; width:100%; max-width:900px;">
95+
<tr>
96+
<th>Name</th>
97+
<th>Spec</th>
98+
<th>Uses</th>
99+
</tr>
100+
{accelerator_rows}
101+
</table>
102+
54103
<h2>Grow Platform Iterations</h2>
55104
<table border="1" style="border-collapse:collapse; width:300px;">
56105
<tr>
@@ -65,4 +114,3 @@ def get_accuracy_str(path):
65114

66115
with open(OUTPUT_FILE, 'w') as f:
67116
f.write(html_content)
68-

infra/nightly.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export PATH="$PATH:$HOME/.cargo/bin/"
88

99
# Seed is fixed for the whole day; this way two branches run the same seed
1010
SEED=$(date "+%Y%j")
11-
BENCHDIR="bench/tmerc4.fpcore"
11+
BENCHDIR="bench/pbrt"
1212
REPORTDIR="reports"
1313
NUMITERS=10
1414

@@ -54,8 +54,5 @@ racket -y "src/main.rkt" report \
5454
# print the new platform
5555
cat "src/platforms/grow.rkt" > "$REPORTDIR/grow_platform.txt"
5656

57-
chmod +x growlibm/count_accelerators.sh
58-
growlibm/count_accelerators.sh "$REPORTDIR/report_info.txt" "$REPORTDIR/end/results.json"
59-
6057
# generate the html report page
6158
python3 growlibm/generate-html.py

0 commit comments

Comments
 (0)