Skip to content

Commit 6dd293c

Browse files
committed
Adjust relative cost calculation
As GT improve our LB calculation, the relative cost of no GT should be relative to the with-GT lower bound. Otherwise, the "Block Cost - Relative" metric is including the LB improvement, which is misleading.
1 parent 81fe20a commit 6dd293c

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

util/gt_analysis/gt_cmp.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22

33
import argparse
4+
from typing import Tuple
45

56
import analyze
67
from analyze import Block, Logs, utils
@@ -67,6 +68,25 @@ def is_improved(before: Block, after: Block):
6768
return cost_for_blk(before) > cost_for_blk(after)
6869

6970

71+
def blk_relative_cost(nogt, gt) -> Tuple[int, int]:
72+
no_sum = yes_sum = 0
73+
for no, yes in zip(nogt, gt):
74+
no_cost = block_stats.block_cost(no)
75+
yes_cost = block_stats.block_cost(yes)
76+
no_lb = block_stats.block_cost_lower_bound(no)
77+
yes_lb = block_stats.block_cost_lower_bound(yes)
78+
assert no_lb <= yes_lb
79+
80+
# relative to the tightest LB we know
81+
no_rel = no_cost - yes_lb
82+
yes_rel = yes_cost - yes_lb
83+
84+
no_sum += no_rel
85+
yes_sum += yes_rel
86+
87+
return no_sum, yes_sum
88+
89+
7090
def compute_stats(nogt: Logs, gt: Logs, *, pass_num: int):
7191
TOTAL_BLOCKS = utils.count(nogt)
7292

@@ -83,6 +103,8 @@ def compute_stats(nogt: Logs, gt: Logs, *, pass_num: int):
83103

84104
nogt_opt, gt_opt = utils.zipped_keep_blocks_if(nogt, gt, pred=lambda b: 'DagSolvedOptimally' in b)
85105

106+
nogt_rel, gt_rel = blk_relative_cost(nogt, gt)
107+
86108
result = {
87109
'Total Blocks in Benchsuite': TOTAL_BLOCKS,
88110
'Num Blocks enumerated with & without GT': utils.count(nogt),
@@ -101,8 +123,8 @@ def compute_stats(nogt: Logs, gt: Logs, *, pass_num: int):
101123
'Enum Time (opt. blocks only) (No GT)': utils.sum_stat_for_all(enum_time_for_blk, nogt_opt),
102124
'Enum Time (opt. blocks only) (GT)': utils.sum_stat_for_all(enum_time_for_blk, gt_opt),
103125

104-
'Block Cost - Relative (No GT)': utils.sum_stat_for_all(block_stats.block_relative_cost, nogt),
105-
'Block Cost - Relative (GT)': utils.sum_stat_for_all(block_stats.block_relative_cost, gt),
126+
'Block Cost - Relative (No GT)': nogt_rel,
127+
'Block Cost - Relative (GT)': gt_rel,
106128
'Block Cost (No GT)': utils.sum_stat_for_all(block_stats.block_cost, nogt),
107129
'Block Cost (GT)': utils.sum_stat_for_all(block_stats.block_cost, gt),
108130

0 commit comments

Comments
 (0)