Skip to content

Commit 7337190

Browse files
committed
Delete *sampling-iteration*, fixing #133
Thank you, amp code!
1 parent ec901a6 commit 7337190

File tree

6 files changed

+177
-143
lines changed

6 files changed

+177
-143
lines changed

AGENTS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@
1010
task to format your code correctly.
1111
- When editing an interval arithmetic function, always run the tests.
1212
Run tests with `racket -y test.rkt add` (for the right function).
13+
- When editing the eval stuff, always run the tests. Run them with
14+
`racket -y time.rkt --id N ../../infra/points.json`. The number `N`
15+
is a benchmark ID; some common choices are 12 and 57, but there are
16+
a bit over 500 in total and sometimes you're asked to focus on a
17+
particular one. Smaller numbers are faster to run.

eval/adjust.rkt

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
[out-dr? (in-vector slackvec)]
167167
#:when (>= root-reg varc)
168168
#:when out-dr?)
169-
(vector-set! vprecs-new (- root-reg varc) (get-slack)))
169+
(vector-set! vprecs-new (- root-reg varc) (get-slack current-iter)))
170170

171171
; Step 1b. Checking if a operation should be computed again at all
172172
; This step traverses instructions top-down and check whether a reevaluation is needed
@@ -188,15 +188,17 @@
188188
[else (path-reduction vrepeats vregs varc instr i #:reexec-val #f)]))
189189

190190
; Step 2. Precision tuning
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)
191+
(define hit-max?
192+
(precision-tuning (rival-machine-max-precision machine)
193+
ivec
194+
vregs
195+
vprecs-new
196+
varc
197+
vstart-precs
198+
vrepeats
199+
vhint
200+
constants-lookup
201+
current-iter))
200202

201203
; Step 3. Repeating precisions check + Assigning if a operation should be computed again at all
202204
; vrepeats[i] = #t if the node has the same precision as an iteration before and children have #t flag as well
@@ -235,19 +237,23 @@
235237
; clean progress of the current tuning pass and start over
236238
(vector-fill! vprecs-new 0)
237239
(vector-fill! vrepeats #f)
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)
240+
(define hit-max2?
241+
(precision-tuning (rival-machine-max-precision machine)
242+
ivec
243+
vregs
244+
vprecs-new
245+
varc
246+
vstart-precs
247+
vrepeats
248+
vhint
249+
constants-lookup
250+
current-iter))
251+
(set! hit-max? (or hit-max? hit-max2?))
247252
(repeats)) ; do repeats again
248253

249254
; Step 5. Copying new precisions into vprecs
250-
(vector-copy! vprecs 0 vprecs-new))
255+
(vector-copy! vprecs 0 vprecs-new)
256+
hit-max?)
251257

252258
; Usually, add-bang instructions have a pointer to itself that is needed to be dropped
253259
(define (drop-self-pointer tail-regs n)
@@ -269,8 +275,10 @@
269275
vstart-precs
270276
vrepeats
271277
vhint
272-
constants)
278+
constants
279+
iter)
273280
(define vprecs-min (make-vector (vector-length ivec) 0))
281+
(define hit-max? #f)
274282
(for ([instr (in-vector ivec (- (vector-length ivec) 1) -1 -1)]
275283
[repeat? (in-vector vrepeats (- (vector-length vrepeats) 1) -1 -1)]
276284
[n (in-range (- (vector-length vregs) 1) -1 -1)]
@@ -296,13 +304,14 @@
296304
(match (*lower-bound-early-stopping*)
297305
[#t
298306
(when (>= min-prec machine-max-precision)
299-
(*sampling-iteration* (*rival-max-iterations*)))]
307+
(set! hit-max? #t))]
300308
[#f
301309
(when (equal? final-precision machine-max-precision)
302-
(*sampling-iteration* (*rival-max-iterations*)))])
310+
(set! hit-max? #t))])
303311

304312
; Precision propogation for each tail instruction
305-
(define ampl-bounds (get-bounds op output srcs)) ; amplification bounds for children instructions
313+
(define ampl-bounds
314+
(get-bounds op output srcs iter)) ; amplification bounds for children instructions
306315
(for ([x (in-list tail-registers)]
307316
[bound (in-list ampl-bounds)]
308317
#:when (>= x varc)) ; when tail register is not a variable
@@ -316,4 +325,5 @@
316325
; Lower precision bound propogation
317326
(vector-set! vprecs-min
318327
(- x varc)
319-
(max (vector-ref vprecs-min (- x varc)) (+ min-prec (max 0 lo-bound)))))))
328+
(max (vector-ref vprecs-min (- x varc)) (+ min-prec (max 0 lo-bound))))))
329+
hit-max?)

eval/machine.rkt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*rival-max-iterations*
99
*rival-profile-executions*
1010
*ampl-tuning-bits*
11-
*sampling-iteration*
1211
*lower-bound-early-stopping*
1312
*base-tuning-precision*
1413
*bumps-activated*)
@@ -46,5 +45,4 @@
4645
profile-iteration))
4746

4847
(define *ampl-tuning-bits* (make-parameter 2))
49-
(define *sampling-iteration* (make-parameter 0))
5048
(define *base-tuning-precision* (make-parameter 5))

eval/main.rkt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,12 @@
3434
*rival-profile-executions*)
3535

3636
(define (rival-machine-full machine vhint)
37-
(set-rival-machine-iteration! machine (*sampling-iteration*))
38-
(rival-machine-adjust machine vhint)
39-
(cond
40-
[(>= (*sampling-iteration*) (*rival-max-iterations*)) (values #f #f #f #t #f)]
41-
[else
42-
(rival-machine-run machine vhint)
43-
(rival-machine-return machine)]))
37+
(define early-stop? (rival-machine-adjust machine vhint))
38+
(if early-stop?
39+
(values #f #f #f #t #f)
40+
(begin
41+
(rival-machine-run machine vhint)
42+
(rival-machine-return machine))))
4443

4544
(struct exn:rival exn:fail ())
4645
(struct exn:rival:invalid exn:rival (pt))
@@ -82,9 +81,9 @@
8281
; Load arguments
8382
(rival-machine-load machine (vector-map ival-real pt))
8483
(let loop ([iter 0])
84+
(set-rival-machine-iteration! machine iter)
8585
(define-values (good? done? bad? stuck? fvec)
86-
(parameterize ([*sampling-iteration* iter]
87-
[*rival-max-precision* (rival-machine-max-precision machine)])
86+
(parameterize ([*rival-max-precision* (rival-machine-max-precision machine)])
8887
(rival-machine-full machine (or hint (rival-machine-default-hint machine)))))
8988
(cond
9089
[bad? (raise (exn:rival:invalid "Invalid input" (current-continuation-marks) pt))]
@@ -98,9 +97,9 @@
9897
(define (rival-analyze-with-hints machine rect [hint #f])
9998
; Load arguments
10099
(rival-machine-load machine rect)
100+
(set-rival-machine-iteration! machine 0)
101101
(define-values (good? done? bad? stuck? fvec)
102-
(parameterize ([*sampling-iteration* 0])
103-
(rival-machine-full machine (or hint (rival-machine-default-hint machine)))))
102+
(rival-machine-full machine (or hint (rival-machine-default-hint machine))))
104103
(define-values (hint* hint*-converged?)
105104
(make-hint machine (or hint (rival-machine-default-hint machine))))
106105
(list (ival (or bad? stuck?) (not good?)) hint* hint*-converged?))

eval/run.rkt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,15 @@
118118
(define iter (rival-machine-iteration machine))
119119
(let ([start-time (current-inexact-milliseconds)]
120120
[start-memory (current-memory-use 'cumulative)])
121-
(unless (zero? iter)
122-
(backward-pass machine vhint))
121+
(define early-stop?
122+
(if (zero? iter)
123+
#f
124+
(backward-pass machine vhint)))
123125
(rival-machine-record machine
124126
'adjust
125127
-1
126128
(* iter 1000)
127129
(- (current-inexact-milliseconds) start-time)
128130
(- (current-memory-use 'cumulative) start-memory)
129-
iter)))
131+
iter)
132+
early-stop?))

0 commit comments

Comments
 (0)