Skip to content

Commit 506891a

Browse files
authored
Merge pull request #1308 from herbie-fp/load-one-platform
Load one platform at a time
2 parents 5b0e222 + bfb6534 commit 506891a

33 files changed

+295
-377
lines changed

.github/workflows/plugins.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@ jobs:
2424
- uses: actions/checkout@master
2525
- name: "Install dependencies"
2626
run: make install
27+
- name: "Install SoftPosit support"
28+
run: raco pkg install softposit-rkt
2729
- name: "Run posit benchmarks"
28-
run: racket infra/ci.rkt --platform softposit --precision posit16 --seed 0 infra/bench/posits.fpcore
30+
run: racket infra/ci.rkt --platform infra/softposit.rkt --precision posit16 --seed 0 infra/bench/posits.fpcore

.github/workflows/unit-test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ jobs:
2424
- uses: actions/checkout@master
2525
- name: "Install dependencies"
2626
run: make install
27+
# SoftPosit is required to test the softposit platform we use for testing
28+
- name: "Install SoftPosit support"
29+
run: raco pkg install softposit-rkt
2730

2831
- name: "Test raco fmt compliance"
2932
run: make fmt && git diff --exit-code

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ clean:
1515
raco pkg remove --force --no-docs egg-herbie-macosm1 && echo "Uninstalled old egg-herbie" || :
1616

1717
update:
18-
raco pkg install --skip-installed softposit-rkt
1918
raco pkg install --skip-installed --no-docs --auto --name herbie src/
2019
raco pkg update --auto rival
2120
raco pkg update --name herbie --deps search-auto src/
@@ -59,7 +58,7 @@ start-server:
5958
--log infra/server.log --quiet 2>&1
6059

6160
fmt:
62-
@raco fmt -i $(shell find egg-herbie/ src/ infra/ -name '*.rkt' -not -path 'src/platforms/*.rkt')
61+
@raco fmt -i $(shell find egg-herbie/ src/ infra/ -name '*.rkt' -not -path 'src/platforms/*.rkt' -not -path "infra/softposit.rkt")
6362

6463
herbie.zip herbie.zip.CHECKSUM:
6564
raco pkg create src/

infra/ci.rkt

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
(require "../src/utils/common.rkt"
44
"../src/core/points.rkt"
5-
"../src/syntax/load-plugin.rkt"
65
"../src/utils/alternative.rkt"
76
"../src/api/sandbox.rkt"
87
"../src/syntax/read.rkt"
@@ -27,12 +26,9 @@
2726
(cons var (representation-name repr)))]))
2827

2928
(define (run-tests . bench-dirs)
30-
(define default-precision
31-
(if (*precision*)
32-
(representation-name (*precision*))
33-
(*default-precision*)))
29+
(activate-platform! (*platform-name*))
3430
(define tests
35-
(parameterize ([*default-precision* default-precision])
31+
(parameterize ([*default-precision* (*precision*)])
3632
(append-map load-tests bench-dirs)))
3733
(define seed (pseudo-random-generator->vector (current-pseudo-random-generator)))
3834
(printf "Running Herbie on ~a tests, seed: ~a\n" (length tests) seed)
@@ -41,7 +37,7 @@
4137
(printf "~a/~a\t" (~a (+ 1 i) #:width 3 #:align 'right) (length tests))
4238
(define the-test*
4339
(if (*precision*)
44-
(override-test-precision the-test (*precision*))
40+
(override-test-precision the-test (get-representation (*precision*)))
4541
the-test))
4642
(define result (run-herbie 'improve the-test* #:seed seed))
4743
(match-define (job-result _ test status time timeline profile warnings backend) result)
@@ -93,30 +89,22 @@
9389

9490
(module+ main
9591
;; Load all the plugins
96-
(load-herbie-plugins)
97-
9892
(define seed (random 1 (expt 2 31)))
9993
(set-seed! seed)
10094

101-
(command-line #:program "ci.rkt"
102-
#:once-each
103-
[("--seed")
104-
rs
105-
"The random seed to use in point generation. If false (#f), a random seed is used'"
106-
(define given-seed (read (open-input-string rs)))
107-
(when given-seed
108-
(set-seed! given-seed))]
109-
[("--platform")
110-
platform
111-
"Which platform to use for tests"
112-
(activate-platform! (string->symbol platform))]
113-
[("--precision")
114-
prec
115-
"Which precision to use for tests"
116-
(*precision* (get-representation (string->symbol prec)))]
117-
[("--num-iters")
118-
num
119-
"The number of iterations to use for the main loop"
120-
(*num-iterations* (string->number num))]
121-
#:args bench-dir
122-
(exit (if (apply run-tests bench-dir) 0 1))))
95+
(command-line
96+
#:program "ci.rkt"
97+
#:once-each [("--seed")
98+
rs
99+
"The random seed to use in point generation. If false (#f), a random seed is used'"
100+
(define given-seed (read (open-input-string rs)))
101+
(when given-seed
102+
(set-seed! given-seed))]
103+
[("--platform") platform "Which platform to use for tests" (*platform-name* platform)]
104+
[("--precision") prec "Which precision to use for tests" (*precision* (string->symbol prec))]
105+
[("--num-iters")
106+
num
107+
"The number of iterations to use for the main loop"
108+
(*num-iterations* (string->number num))]
109+
#:args bench-dir
110+
(exit (if (apply run-tests bench-dir) 0 1))))

infra/merge.rkt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"../src/utils/profile.rkt"
66
"../src/api/datafile.rkt"
77
"../src/reports/timeline.rkt"
8-
"../src/syntax/load-plugin.rkt"
9-
"../src/reports/common.rkt")
8+
"../src/reports/common.rkt"
9+
"../src/syntax/platform.rkt")
1010

1111
(define (merge-timelines outdir . dirs)
1212
(define tls
@@ -36,7 +36,6 @@
3636
(curry write-json (profile->json joint-pf))))
3737

3838
(define (merge-reports outdir . dirs)
39-
(load-herbie-builtins)
4039
(define rss
4140
(filter (conjoin (negate eof-object?) identity)
4241
(for/list ([dir (in-list dirs)])
@@ -53,6 +52,7 @@
5352

5453
(module+ main
5554
(command-line #:args (outdir . dirs)
55+
(activate-platform! (*platform-name*))
5656
(apply merge-reports outdir dirs)
5757
(apply merge-timelines outdir dirs)
5858
(apply merge-profiles outdir dirs)

src/platforms/softposit.rkt renamed to infra/softposit.rkt

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
(require math/flonum
77
math/bigfloat
88
softposit-rkt
9-
"../utils/float.rkt" ; for shift/unshift
9+
"../src/utils/float.rkt" ; for shift/unshift
1010
rival
11-
"../syntax/platform.rkt")
11+
"../src/syntax/platform.rkt")
12+
(provide platform)
1213

1314
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; utils ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1415

@@ -86,7 +87,7 @@
8687

8788
(define cost 1)
8889

89-
(define softposit-platform
90+
(define platform
9091
(make-empty-platform 'softposit #:if-cost 1))
9192

9293
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; REPRESENTATIONS ;;;;;;;;;;;;;;;;;;;;;;;
@@ -180,21 +181,21 @@
180181
#:total-bits 64
181182
#:special-value? nan?))
182183

183-
(platform-register-representation! softposit-platform #:repr bool #:cost cost)
184-
(platform-register-representation! softposit-platform #:repr posit8 #:cost cost)
185-
(platform-register-representation! softposit-platform #:repr posit16 #:cost cost)
186-
(platform-register-representation! softposit-platform #:repr posit32 #:cost cost)
187-
(platform-register-representation! softposit-platform #:repr quire8 #:cost cost)
188-
(platform-register-representation! softposit-platform #:repr quire16 #:cost cost)
189-
(platform-register-representation! softposit-platform #:repr quire32 #:cost cost)
190-
(platform-register-representation! softposit-platform #:repr binary64 #:cost cost)
184+
(platform-register-representation! platform #:repr bool #:cost cost)
185+
(platform-register-representation! platform #:repr posit8 #:cost cost)
186+
(platform-register-representation! platform #:repr posit16 #:cost cost)
187+
(platform-register-representation! platform #:repr posit32 #:cost cost)
188+
(platform-register-representation! platform #:repr quire8 #:cost cost)
189+
(platform-register-representation! platform #:repr quire16 #:cost cost)
190+
(platform-register-representation! platform #:repr quire32 #:cost cost)
191+
(platform-register-representation! platform #:repr binary64 #:cost cost)
191192

192193
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; OPERATORS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
193194

194195
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; BOOLEAN IMPLS ;;;;;;;;;;;;;;;;;;;;;;;;;
195196

196197
(platform-register-implementations!
197-
softposit-platform
198+
platform
198199
([TRUE () bool (TRUE) (const true) (! TRUE) cost]
199200
[FALSE () bool (FALSE) (const false) (! FALSE) cost]
200201
[not ([x : bool]) bool (not x) not (not x) cost]
@@ -205,7 +206,7 @@
205206

206207
; ([name ([var : repr] ...) otype spec fl fpcore cost])
207208
(platform-register-implementations!
208-
softposit-platform
209+
platform
209210
(; Posit8
210211
[neg.p8 ([x : posit8]) posit8 (neg x) posit8-neg (! :precision posit8 (- x)) cost]
211212
[+.p8 ([x : posit8] [y : posit8]) posit8 (+ x y) posit8-add (! :precision posit8 (+ x y)) cost]
@@ -257,7 +258,7 @@
257258

258259
; ([name ([var : repr] ...) otype spec fl fpcore cost])
259260
(platform-register-implementations!
260-
softposit-platform
261+
platform
261262
(; Posit/float implementations
262263
[binary64->posit8 ([x : binary64]) posit8 x double->posit8 (! :precision posit8 (cast x)) cost]
263264
[binary64->posit16 ([x : binary64]) posit16 x double->posit16 (! :precision posit16 (cast x)) cost]
@@ -280,12 +281,12 @@
280281
[posit16->quire16 ([x : posit16]) quire16 x posit16->quire16 (! :precision quire16 (cast x)) cost]
281282
[posit32->quire32 ([x : posit32]) quire32 x posit32->quire32 (! :precision quire32 (cast x)) cost]))
282283

283-
(register-platform! softposit-platform)
284+
(register-platform! platform)
284285

285286
(module+ main
286-
(display-platform softposit-platform))
287+
(display-platform platform))
287288

288289
;; Do not run this file during testing
289290
(module test racket/base
290291
)
291-
292+

src/api/demo.rkt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"../syntax/types.rkt"
1919
"../syntax/read.rkt"
2020
"../syntax/sugar.rkt"
21+
"../syntax/platform.rkt"
2122
"../utils/common.rkt"
2223
"../utils/errors.rkt"
2324
"../utils/float.rkt"
@@ -520,6 +521,7 @@
520521
(*demo-output* output)
521522
(*demo-prefix* prefix)
522523
(*demo-log* log)
524+
(activate-platform! (*platform-name*))
523525
(server-start threads)
524526

525527
(serve/servlet dispatch

src/api/run.rkt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@
3838
(table-row-conversions row)))
3939

4040
(define (make-report bench-dirs #:dir dir #:threads threads)
41+
(activate-platform! (*platform-name*))
4142
(define tests (reverse (sort (append-map load-tests bench-dirs) test<?)))
4243
(run-tests tests #:dir dir #:threads threads))
4344

4445
(define (rerun-report json-file #:dir dir #:threads threads)
4546
(define data (call-with-input-file json-file read-datafile))
4647
(define tests (map extract-test (report-info-tests data)))
48+
(activate-platform! (*platform-name*))
4749
(*flags* (report-info-flags data))
4850
(set-seed! (report-info-seed data))
4951
(*num-points* (report-info-points data))

src/api/server.rkt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
(require openssl/sha1)
44
(require (only-in xml write-xexpr))
55

6-
(require "../syntax/load-plugin.rkt"
7-
"../syntax/read.rkt"
6+
(require "../syntax/read.rkt"
87
"../syntax/sugar.rkt"
98
"../syntax/syntax.rkt"
109
"../syntax/types.rkt"
10+
"../syntax/platform.rkt"
1111
"../utils/alternative.rkt"
1212
"../utils/common.rkt"
1313
"../utils/errors.rkt"
@@ -174,8 +174,7 @@
174174
*platform-name*
175175
*loose-plugins*
176176
*functions*)
177-
(parameterize ([current-error-port (open-output-nowhere)]) ; hide output
178-
(load-herbie-plugins))
177+
(activate-platform! (*platform-name*))
179178
; not sure if the above code is actaully needed.
180179
(define busy-workers (make-hash))
181180
(define waiting-workers (make-hash))
@@ -296,8 +295,7 @@
296295
*platform-name*
297296
*loose-plugins*
298297
*functions*)
299-
(parameterize ([current-error-port (open-output-nowhere)]) ; hide output
300-
(load-herbie-plugins))
298+
(activate-platform! (*platform-name*))
301299
(define worker-thread
302300
(thread (λ ()
303301
(let loop ()

src/api/shell.rkt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#lang racket
22

3-
(require "../syntax/read.rkt"
3+
(require "../syntax/platform.rkt"
4+
"../syntax/read.rkt"
45
"../utils/common.rkt"
56
"server.rkt")
67
(provide run-shell
@@ -40,6 +41,7 @@
4041

4142
(define (run-improve input output #:threads [threads #f])
4243
(define seed (get-seed))
44+
(activate-platform! (*platform-name*))
4345
(define tests (load-tests input))
4446
(server-start threads)
4547
(define ids
@@ -57,6 +59,7 @@
5759

5860
(define (run-shell)
5961
(define seed (get-seed))
62+
(activate-platform! (*platform-name*))
6063
(server-start #f)
6164
(eprintf "Find help on https://herbie.uwplse.org/, exit with ~a\n"
6265
(match (system-type 'os)

0 commit comments

Comments
 (0)