Skip to content

Commit 942450c

Browse files
committed
Cache rival machine max precision
1 parent 57ca115 commit 942450c

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

eval/adjust.rkt

Lines changed: 33 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,22 @@
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 (vector-ref vprecs-max (- n varc))) ; upper precision bound given from parent
262286
(define min-prec (vector-ref vprecs-min (- n varc))) ; lower precision bound given from parent
263287

264288
; Final precision assignment based on the upper bound
265289
(define final-precision
266-
(min (max (+ max-prec (vector-ref vstart-precs (- n varc))) (*rival-min-precision*))
267-
(*rival-max-precision*)))
290+
(min (max (+ parent-max-prec (vector-ref vstart-precs (- n varc))) (*rival-min-precision*))
291+
machine-max-precision))
268292
(vector-set! vprecs-max (- n varc) final-precision)
269293

270294
; Early stopping
271295
(match (*lower-bound-early-stopping*)
272296
[#t
273-
(when (>= min-prec (*rival-max-precision*))
297+
(when (>= min-prec machine-max-precision)
274298
(*sampling-iteration* (*rival-max-iterations*)))]
275299
[#f
276-
(when (equal? final-precision (*rival-max-precision*))
300+
(when (equal? final-precision machine-max-precision)
277301
(*sampling-iteration* (*rival-max-iterations*)))])
278302

279303
; Precision propogation for each tail instruction
@@ -286,7 +310,7 @@
286310
; Upper precision bound propogation
287311
(vector-set! vprecs-max
288312
(- x varc)
289-
(max (vector-ref vprecs-max (- x varc)) (+ max-prec up-bound)))
313+
(max (vector-ref vprecs-max (- x varc)) (+ parent-max-prec up-bound)))
290314

291315
; Lower precision bound propogation
292316
(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)