Skip to content

Commit 1081908

Browse files
committed
Version bump, provide changes, doc changes
1 parent 6f38311 commit 1081908

File tree

7 files changed

+114
-68
lines changed

7 files changed

+114
-68
lines changed

eval/main.rkt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@
2424
*rival-use-shorthands*
2525
*rival-name-constants*
2626
rival-profile
27-
(struct-out execution)
27+
make-execution
28+
execution-name
29+
execution-number
30+
execution-precision
31+
execution-time
32+
execution-memory
33+
execution-iteration
2834
*rival-profile-executions*)
2935

3036
(define (rival-machine-full machine vhint)
@@ -42,6 +48,9 @@
4248

4349
(struct execution (name number precision time memory iteration) #:prefab)
4450

51+
(define (make-execution name number precision time memory iteration)
52+
(execution name number precision time memory iteration))
53+
4554
(define (rival-profile machine param)
4655
(match param
4756
['instructions (vector-length (rival-machine-instructions machine))]

info.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#lang info
22

33
(define collection "rival")
4-
(define version "2.2")
4+
(define version "2.3")
55
(define license 'MIT)
66

77
;; Packaging information

infra/run-baseline.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@
398398
[time (in-flvector profile-time 0 profile-ptr)]
399399
[memory (in-vector profile-memory 0 profile-ptr)]
400400
[iter (in-vector profile-iteration 0 profile-ptr)])
401-
(execution instruction number precision time memory iter))
401+
(make-execution instruction number precision time memory iter))
402402
(set-baseline-machine-profile-ptr! machine 0))]))
403403

404404
(define (baseline-machine-record machine name number precision time memory iter)

main.rkt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,13 @@
122122
*rival-profile-executions*
123123
*rival-use-shorthands*
124124
*rival-name-constants*
125-
(struct-out execution))
125+
make-execution
126+
execution-name
127+
execution-number
128+
execution-precision
129+
execution-time
130+
execution-memory
131+
execution-iteration)
126132

127133
(require "utils.rkt")
128134
(provide flonum-discretization

repl.rkt

Lines changed: 83 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
(define iter 0)
2929
(define last #f)
3030
(for/list ([exec (in-vector execs)])
31-
(match-define (execution name id precision time _ _) exec)
31+
(define id (execution-number exec))
3232
(when (and last (< id last))
3333
(set! iter (+ iter 1)))
3434
(set! last id)
@@ -40,13 +40,21 @@
4040
(display (~a (fn row col) #:width width #:align 'right)))
4141
(newline)))
4242

43-
(define-syntax-rule (list-find-match l pattern body ...)
44-
(let loop ([l l])
45-
(match l
46-
[(cons pattern rest)
47-
body ...]
48-
[(cons _ rest) (loop rest)]
49-
['() ""])))
43+
(define (lookup-execution execs
44+
#:iter [target-iter #f]
45+
#:id [target-id #f]
46+
#:name [target-name #f]
47+
#:default [default ""]
48+
#:value [value (lambda (_iter exec) exec)])
49+
(define entry
50+
(for/first ([exec (in-list execs)]
51+
#:when (and (or (not target-iter) (= (car exec) target-iter))
52+
(or (not target-id) (= (execution-number (cdr exec)) target-id))
53+
(or (not target-name) (= (execution-name (cdr exec)) target-name))))
54+
exec))
55+
(if entry
56+
(value (car entry) (cdr entry))
57+
default))
5058

5159
(struct repl ([precision #:mutable] context))
5260

@@ -88,58 +96,73 @@
8896
(printf "Executed ~a instructions for ~a iterations:\n\n" num-instructions num-iterations)
8997

9098
(define execs* (executions-iterations execs))
91-
(write-table #:rows (+ 5 num-instructions) ; 1 for the "adjust" row
92-
#:cols (+ 1 (* 2 num-iterations))
93-
#:width 6
94-
(lambda (row col)
95-
(match* (row col)
96-
[(0 0) ""]
97-
[(0 col)
98-
#:when (= (modulo col 2) 1)
99-
"Bits"]
100-
[(0 col)
101-
#:when (= (modulo col 2) 0)
102-
"Time"]
103-
[(1 _) "------"]
104-
[(2 0) 'adjust]
105-
[(2 col)
106-
#:when (and (= (modulo col 2) 0) (> col 2))
107-
(define iter (- (/ col 2) 1))
108-
(list-find-match execs*
109-
(cons (== iter) (execution 'adjust _ _ time _ _))
110-
(~r (* time 1000) #:precision '(= 1)))]
111-
[(2 col) ""]
112-
[((== (+ 3 num-instructions)) _) "------"]
113-
[((== (+ 4 num-instructions)) 0) "Total"]
114-
[((== (+ 4 num-instructions)) col)
115-
#:when (= (modulo col 2) 1)
116-
""]
117-
[((== (+ 4 num-instructions)) col)
118-
#:when (= (modulo col 2) 0)
119-
(define iter (/ (- col 2) 2))
120-
(define time
121-
(apply +
122-
(for/list ([exec (in-list execs*)]
123-
#:when (= (car exec) iter))
124-
(execution-time (cdr exec)))))
125-
(~r (* time 1000) #:precision '(= 1))]
126-
[(row 0)
127-
(define id (+ (- row 3) num-args))
128-
(list-find-match execs*
129-
(cons _ (execution name (== id) _ _ _ _))
130-
(normalize-function-name (~a name)))]
131-
[(row col)
132-
#:when (= (modulo col 2) 1) ; precision
133-
(define id (+ (- row 3) num-args))
134-
(define iter (/ (- col 1) 2))
135-
(list-find-match execs* (cons (== iter) (execution _ (== id) prec _ _ _)) prec)]
136-
[(row col)
137-
#:when (= (modulo col 2) 0) ; time
138-
(define id (+ (- row 3) num-args))
139-
(define iter (/ (- col 2) 2))
140-
(list-find-match execs*
141-
(cons (== iter) (execution _ (== id) _ time _ _))
142-
(~r (* time 1000) #:precision '(= 1)))]))))
99+
(write-table
100+
#:rows (+ 5 num-instructions) ; 1 for the "adjust" row
101+
#:cols (+ 1 (* 2 num-iterations))
102+
#:width 6
103+
(lambda (row col)
104+
(match* (row col)
105+
[(0 0) ""]
106+
[(0 col)
107+
#:when (= (modulo col 2) 1)
108+
"Bits"]
109+
[(0 col)
110+
#:when (= (modulo col 2) 0)
111+
"Time"]
112+
[(1 _) "------"]
113+
[(2 0) 'adjust]
114+
[(2 col)
115+
#:when (and (= (modulo col 2) 0) (> col 2))
116+
(define iter (- (/ col 2) 1))
117+
(lookup-execution execs*
118+
#:iter iter
119+
#:name 'adjust
120+
#:default ""
121+
#:value (lambda (_iter exec)
122+
(~r (* (execution-time exec) 1000) #:precision '(= 1))))]
123+
[(2 col) ""]
124+
[((== (+ 3 num-instructions)) _) "------"]
125+
[((== (+ 4 num-instructions)) 0) "Total"]
126+
[((== (+ 4 num-instructions)) col)
127+
#:when (= (modulo col 2) 1)
128+
""]
129+
[((== (+ 4 num-instructions)) col)
130+
#:when (= (modulo col 2) 0)
131+
(define iter (/ (- col 2) 2))
132+
(define time
133+
(apply +
134+
(for/list ([exec (in-list execs*)]
135+
#:when (= (car exec) iter))
136+
(execution-time (cdr exec)))))
137+
(~r (* time 1000) #:precision '(= 1))]
138+
[(row 0)
139+
(define id (+ (- row 3) num-args))
140+
(lookup-execution execs*
141+
#:id id
142+
#:default ""
143+
#:value (lambda (_iter exec)
144+
(normalize-function-name (~a (execution-name exec)))))]
145+
[(row col)
146+
#:when (= (modulo col 2) 1) ; precision
147+
(define id (+ (- row 3) num-args))
148+
(define iter (/ (- col 1) 2))
149+
(lookup-execution execs*
150+
#:iter iter
151+
#:id id
152+
#:default ""
153+
#:value (lambda (_iter exec) (execution-precision exec)))]
154+
[(row col)
155+
#:when (= (modulo col 2) 0) ; time
156+
(define id (+ (- row 3) num-args))
157+
(define iter (/ (- col 2) 2))
158+
(define value
159+
(lookup-execution execs*
160+
#:iter iter
161+
#:id id
162+
#:default ""
163+
#:value (lambda (_iter exec)
164+
(~r (* (execution-time exec) 1000) #:precision '(= 1)))))
165+
value]))))
143166

144167
(define (rival-repl p)
145168
(let/ec k

scribblings/profile.scrbl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ The currently-supported command symbols and their return values are:
2121
@item{@code{instructions} returns the number of register machine instructions in the compiled @racket[machine].}
2222
@item{@code{iterations} returns the number of re-evaluation iterations needed for the most recent call to @racket[rival-apply] with the compiled @racket[machine]. This should be a number from 0 to @racket[*rival-max-iterations*], inclusive.}
2323
@item{@code{bumps} returns the number of unexpected non-convergences detected during the most recent call to @racket[rival-apply] with the compiled @racket[machine]. These generally represent internal errors in Rival. While Rival will attempt to handle these "bumps" smoothly, they should still be reported to the developers as a bug.}
24-
@item{@code{executions} returns a list of @racket{execution} structs, one for every register machine instruction executed by Rival. These executions are stored in a fixed-size buffer (see @racket[*rival-profile-executions*]) which is retained across @racket[rival-apply] calls and can fill up. The buffer is emptied by calls to @racket[(rival-profile machine 'executions)], so make sure to call this function regularly. If the list of @racket{execution}s returned by @racket[rival-profile] is equal in length to @racket[*rival-profile-executions*], you likely filled the buffer and are missing some executions.}
24+
@item{@code{executions} returns a list of values from which you can obtain execution metadata using the accessor functions @racket[execution-name], @racket[execution-number], @racket[execution-precision], @racket[execution-time], @racket[execution-memory], and @racket[execution-iteration]. These executions are stored in a fixed-size buffer (see @racket[*rival-profile-executions*]) which is retained across @racket[rival-apply] calls and can fill up. The buffer is emptied by calls to @racket[(rival-profile machine 'executions)], so make sure to call this function regularly. If the list of @racket{execution}s returned by @racket[rival-profile] is equal in length to @racket[*rival-profile-executions*], you likely filled the buffer and are missing some executions.}
2525
]
2626

2727
}
@@ -30,7 +30,9 @@ The currently-supported command symbols and their return values are:
3030
([name symbol?]
3131
[number natural?]
3232
[precision natural?]
33-
[time flonum?])]{
33+
[time flonum?]
34+
[memory natural?]
35+
[iteration natural?])]{
3436
Each execution corresponds to a single Rival interval operator being executed.
3537
The @racket[name] names the operator,
3638
except the special symbol @racket['adjust],
@@ -39,7 +41,9 @@ The currently-supported command symbols and their return values are:
3941
this allows disambiguating if an expression contains, say, multiple
4042
addition operations.
4143
The @racket[precision] is the @racket[bf-precision] that the operator is executed at,
42-
and the @racket[time] is the time, in milliseconds, that that execution took.
44+
the @racket[time] is the time, in milliseconds, that the execution took,
45+
and the @racket[memory] is the number of bytes allocated during that execution.
46+
The @racket[iteration] records which sampling iteration triggered the execution.
4347
Note that, because Rival executes the register machine multiple times,
4448
the same operator (with the same @racket[name] and @racket[number])
4549
can appear multiple times for a single point.
@@ -49,6 +53,8 @@ The currently-supported command symbols and their return values are:
4953
the same number of times.
5054
}
5155

56+
Only the accessor functions (such as @racket[execution-name]) are exported. You can make an execution struct using @racket[make-execution].
57+
5258
@defparam[*rival-profile-executions* executions natural? #:value 1000]{
5359

5460
The executions are, for maximum performance, written into a single

time.rkt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@
151151
(define h (make-hash))
152152
(define max-prec 0)
153153
(for ([exec (in-vector rival-executions)])
154-
(match-define (execution name number precision time _ _) exec)
154+
(define name (execution-name exec))
155+
(define number (execution-number exec))
156+
(define precision (execution-precision exec))
155157
(unless (equal? name 'adjust)
156158
(define precision* (hash-ref h (list name number) (λ () 0)))
157159
(hash-set! h (list name number) (max precision precision*))

0 commit comments

Comments
 (0)