From 2732011ddc4624471685f2e91324eeed54b6dfad Mon Sep 17 00:00:00 2001 From: Pavel Panchekha Date: Thu, 29 Aug 2024 16:27:27 -0600 Subject: [PATCH 1/3] Basically, don't record rule applications, which seem expensive --- src/core/egg-herbie.rkt | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/core/egg-herbie.rkt b/src/core/egg-herbie.rkt index 420664758..a0fe060af 100644 --- a/src/core/egg-herbie.rkt +++ b/src/core/egg-herbie.rkt @@ -205,6 +205,8 @@ (define (egraph-eclasses egraph-data) (egraph_get_eclasses (egraph-data-egraph-pointer egraph-data))) +(define empty-u32vec (make-u32vector 0)) + ;; Extracts the nodes of an e-class as a vector ;; where each enode is either a symbol, number, or list (define (egraph-get-eclass egraph-data id) @@ -215,7 +217,7 @@ (for ([enode (in-vector eclass)] [i (in-naturals)]) (when (and (symbol? enode) (not (hash-has-key? egg->herbie enode))) - (vector-set! eclass i (cons enode (make-u32vector 0))))) + (vector-set! eclass i (cons enode empty-u32vec)))) eclass) (define (egraph-find egraph-data id) @@ -1165,27 +1167,13 @@ (define-values (egg-graph* iteration-data) (egraph-run-rules egg-graph egg-rules params)) ; get cost statistics - (for/fold ([time 0]) - ([iter (in-list iteration-data)] - [i (in-naturals)]) + (for ([iter (in-list iteration-data)] [i (in-naturals)]) (define cnt (iteration-data-num-nodes iter)) (define cost (apply + (map (λ (id) (egraph-get-cost egg-graph* id i)) root-ids))) - (define new-time (+ time (iteration-data-time iter))) - (timeline-push! 'egraph i cnt cost new-time) - new-time) - - ;; get rule statistics - (for ([(egg-rule ffi-rule) (in-dict egg-rules)]) - (define count (egraph-get-times-applied egg-graph* ffi-rule)) - (define canon-name (hash-ref (*canon-names*) (rule-name egg-rule))) - (hash-update! rule-apps canon-name (curry + count) count)) + (timeline-push! 'egraph i cnt cost (iteration-data-time iter))) egg-graph*)) - ; report rule statistics - (for ([(name count) (in-hash rule-apps)]) - (when (> count 0) - (timeline-push! 'rules (~a name) count))) ; root eclasses may have changed (define root-ids* (map (lambda (id) (egraph-find egg-graph* id)) root-ids)) ; return what we need From 1756e4cd7148ab4984ad5e328755cfd592d8f994 Mon Sep 17 00:00:00 2001 From: Pavel Panchekha Date: Thu, 29 Aug 2024 16:30:05 -0600 Subject: [PATCH 2/3] Minor --- src/core/egg-herbie.rkt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/core/egg-herbie.rkt b/src/core/egg-herbie.rkt index a0fe060af..5bcc81e0f 100644 --- a/src/core/egg-herbie.rkt +++ b/src/core/egg-herbie.rkt @@ -1158,10 +1158,8 @@ (define root-ids (egraph-add-exprs egg-graph exprs ctx)) ; run the schedule - (define rule-apps (make-hash)) (define egg-graph* - (for/fold ([egg-graph egg-graph]) ([instr (in-list schedule)]) - (match-define (cons rules params) instr) + (for/fold ([egg-graph egg-graph]) ([(rules params) (in-dict schedule)]) ; run rules in the egraph (define egg-rules (expand-rules rules)) (define-values (egg-graph* iteration-data) (egraph-run-rules egg-graph egg-rules params)) From 0b259f2336b74a62e1c71f927001fc53d598f90c Mon Sep 17 00:00:00 2001 From: Pavel Panchekha Date: Thu, 29 Aug 2024 16:32:03 -0600 Subject: [PATCH 3/3] fmt --- src/core/egg-herbie.rkt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/egg-herbie.rkt b/src/core/egg-herbie.rkt index 5bcc81e0f..0204415b3 100644 --- a/src/core/egg-herbie.rkt +++ b/src/core/egg-herbie.rkt @@ -1165,7 +1165,8 @@ (define-values (egg-graph* iteration-data) (egraph-run-rules egg-graph egg-rules params)) ; get cost statistics - (for ([iter (in-list iteration-data)] [i (in-naturals)]) + (for ([iter (in-list iteration-data)] + [i (in-naturals)]) (define cnt (iteration-data-num-nodes iter)) (define cost (apply + (map (λ (id) (egraph-get-cost egg-graph* id i)) root-ids))) (timeline-push! 'egraph i cnt cost (iteration-data-time iter)))