Skip to content

Commit 1eaeda5

Browse files
authored
Merge pull request #117 from herbie-fp/codex/store-max-precision-on-rival-machine
Cache rival machine max precision
2 parents 57ca115 + ea55a8c commit 1eaeda5

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ jobs:
1717
run: raco pkg install --name rival --no-cache --auto
1818
- name: "Install raco fmt"
1919
run: raco pkg install --auto fmt
20+
- name: "Run tests"
21+
run: raco test .
2022
- name: "Reformat all of the source code"
2123
run: raco fmt -i **/*.rkt
2224
- name: "Make sure files are correctly formatted with raco fmt"
2325
run: git diff --exit-code
24-
- run: raco test .

eval/adjust.rkt

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,15 @@
188188
[else (path-reduction vrepeats vregs varc instr i #:reexec-val #f)]))
189189

190190
; Step 2. Precision tuning
191-
(precision-tuning ivec vregs vprecs-new varc vstart-precs vrepeats vhint constants-lookup)
191+
(precision-tuning (rival-machine-max-precision machine)
192+
ivec
193+
vregs
194+
vprecs-new
195+
varc
196+
vstart-precs
197+
vrepeats
198+
vhint
199+
constants-lookup)
192200

193201
; Step 3. Repeating precisions check + Assigning if a operation should be computed again at all
194202
; vrepeats[i] = #t if the node has the same precision as an iteration before and children have #t flag as well
@@ -227,7 +235,15 @@
227235
; clean progress of the current tuning pass and start over
228236
(vector-fill! vprecs-new 0)
229237
(vector-fill! vrepeats #f)
230-
(precision-tuning ivec vregs vprecs-new varc vstart-precs vrepeats vhint constants-lookup)
238+
(precision-tuning (rival-machine-max-precision machine)
239+
ivec
240+
vregs
241+
vprecs-new
242+
varc
243+
vstart-precs
244+
vrepeats
245+
vhint
246+
constants-lookup)
231247
(repeats)) ; do repeats again
232248

233249
; Step 5. Copying new precisions into vprecs
@@ -245,7 +261,15 @@
245261
; Roughly speaking, the upper precision bound is calculated as:
246262
; vprecs-max[i] = (+ max-prec vstart-precs[i]), where min-prec < (+ max-prec vstart-precs[i]) < max-prec
247263
; max-prec = (car (get-bounds parent))
248-
(define (precision-tuning ivec vregs vprecs-max varc vstart-precs vrepeats vhint constants)
264+
(define (precision-tuning machine-max-precision
265+
ivec
266+
vregs
267+
vprecs-max
268+
varc
269+
vstart-precs
270+
vrepeats
271+
vhint
272+
constants)
249273
(define vprecs-min (make-vector (vector-length ivec) 0))
250274
(for ([instr (in-vector ivec (- (vector-length ivec) 1) -1 -1)]
251275
[repeat? (in-vector vrepeats (- (vector-length vrepeats) 1) -1 -1)]
@@ -258,22 +282,23 @@
258282
(define tail-registers (drop-self-pointer (cdr instr) n))
259283
(define srcs (append (map (lambda (x) (vector-ref vregs x)) tail-registers) constant))
260284

261-
(define max-prec (vector-ref vprecs-max (- n varc))) ; upper precision bound given from parent
285+
(define parent-max-prec
286+
(vector-ref vprecs-max (- n varc))) ; upper precision bound given from parent
262287
(define min-prec (vector-ref vprecs-min (- n varc))) ; lower precision bound given from parent
263288

264289
; Final precision assignment based on the upper bound
265290
(define final-precision
266-
(min (max (+ max-prec (vector-ref vstart-precs (- n varc))) (*rival-min-precision*))
267-
(*rival-max-precision*)))
291+
(min (max (+ parent-max-prec (vector-ref vstart-precs (- n varc))) (*rival-min-precision*))
292+
machine-max-precision))
268293
(vector-set! vprecs-max (- n varc) final-precision)
269294

270295
; Early stopping
271296
(match (*lower-bound-early-stopping*)
272297
[#t
273-
(when (>= min-prec (*rival-max-precision*))
298+
(when (>= min-prec machine-max-precision)
274299
(*sampling-iteration* (*rival-max-iterations*)))]
275300
[#f
276-
(when (equal? final-precision (*rival-max-precision*))
301+
(when (equal? final-precision machine-max-precision)
277302
(*sampling-iteration* (*rival-max-iterations*)))])
278303

279304
; Precision propogation for each tail instruction
@@ -286,7 +311,7 @@
286311
; Upper precision bound propogation
287312
(vector-set! vprecs-max
288313
(- x varc)
289-
(max (vector-ref vprecs-max (- x varc)) (+ max-prec up-bound)))
314+
(max (vector-ref vprecs-max (- x varc)) (+ parent-max-prec up-bound)))
290315

291316
; Lower precision bound propogation
292317
(vector-set! vprecs-min

eval/compile.rkt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@
325325
(make-vector (vector-length roots))
326326
default-hint
327327
constants-lookup
328+
(*rival-max-precision*)
328329
0
329330
0
330331
0

eval/machine.rkt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
output-distance
3535
default-hint
3636
constant-lookup
37+
max-precision
3738
[iteration #:mutable]
3839
[bumps #:mutable]
3940
[profile-ptr #:mutable]

0 commit comments

Comments
 (0)