Skip to content

Commit 755df3b

Browse files
committed
Add arg to include zero-kernel in rocprof bench script
1 parent 01741ab commit 755df3b

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

‎op_tests/topk_decode_rocprof_driver.py‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@
3939
# .co is specialized for K=2048 and takes no k argument.
4040
FIXED_K = {"aiter_asm": 2048}
4141

42+
# Per-call workspace-zeroing kernel each impl launches before its compute kernel
43+
# (only when a multi-block tier runs). Used by --include-zero to fold the memset
44+
# into the reported time. flydsl zeroes via torch's zero_() (FillFunctor); aiter
45+
# zeroes via hipMemset (rocclr fillBufferAligned). Matched by time-window, not
46+
# count, so one-time setup fills (e.g. seqLens allocation) don't mis-pair.
47+
KERNEL_ZERO_MATCH = {
48+
"flydsl": re.compile(r"FillFunctor"),
49+
"flydsl_tiered": re.compile(r"FillFunctor"),
50+
"aiter_hip": re.compile(r"fillBufferAligned"),
51+
}
52+
4253
KERNEL_ENV = {
4354
"flydsl_tiered": {
4455
"FLYDSL_TOPK_TIERED": "1",
@@ -61,6 +72,7 @@ def run_cell(
6172
pmc_kernel_regex: str | None,
6273
stat: str = "median",
6374
boost_ms: float = 0.0,
75+
include_zero: bool = False,
6476
) -> tuple[float, float, int, str]:
6577
width_tag = "" if max_width is None else f"_W{max_width}"
6678
tag = f"{kernel}_k{k}_rows{num_rows}_L{L}{width_tag}"
@@ -133,10 +145,40 @@ def run_cell(
133145
per_call = [sum(durs_ns[i : i + kpc]) for i in range(0, len(durs_ns), kpc)]
134146
if not per_call:
135147
return float("nan"), float("nan"), kpc, "no measured launches"
148+
149+
zero_note = ""
150+
if include_zero and KERNEL_ZERO_MATCH.get(kernel) is not None:
151+
zpat = KERNEL_ZERO_MATCH[kernel]
152+
fills = sorted(
153+
(int(r["Start_Timestamp"]), int(r["End_Timestamp"]) - int(r["Start_Timestamp"]))
154+
for r in rows
155+
if zpat.search(r["Kernel_Name"])
156+
)
157+
# Attribute a fill to a call if it runs between the prior call's compute
158+
# and this call's compute (i.e. this call's workspace zero). Lower bound is
159+
# inclusive: some impls (aiter's hipMemset) pipeline the fill to start
160+
# exactly at the prior compute's end timestamp. Warmup region excluded so
161+
# one-time setup fills (seqLens, etc.) never get counted.
162+
prev_end = (
163+
int(matched[warmup * kpc - 1]["End_Timestamp"]) if warmup * kpc > 0 else 0
164+
)
165+
n_zero = 0
166+
for ci in range(len(per_call)):
167+
cs = int(measured[ci * kpc]["Start_Timestamp"])
168+
ce = int(measured[ci * kpc + kpc - 1]["End_Timestamp"])
169+
zsum = sum(d for (st, d) in fills if prev_end <= st < cs)
170+
if zsum:
171+
n_zero += 1
172+
per_call[ci] += zsum
173+
prev_end = ce
174+
zero_note = f"+zero({n_zero}/{len(per_call)})"
175+
136176
# ``min`` is robust to noisy co-tenant GPU contention (sharing CUs only ever
137177
# inflates a kernel's measured duration), while ``median`` is the default.
138178
reduce_fn = min if stat == "min" else statistics.median
139179
note = "" if kpc == 1 else f"{kpc} kernels/call summed"
180+
if zero_note:
181+
note = f"{note}; {zero_note}".strip("; ")
140182
if pmc:
141183
pmc_csvs = glob.glob(str(out_file) + "*counter_collection.csv")
142184
if not pmc_csvs:
@@ -213,6 +255,12 @@ def main() -> None:
213255
default=250.0,
214256
help="Run the GPU with a dummy matmul for this many ms to stabilize clocks.",
215257
)
258+
ap.add_argument(
259+
"--include-zero",
260+
action="store_true",
261+
help="Fold the per-call workspace-zeroing kernel (memset/fill) into the "
262+
"reported time (kernel + zero). Default is kernel-only.",
263+
)
216264
ap.add_argument(
217265
"--stat",
218266
choices=["median", "min"],
@@ -269,6 +317,7 @@ def main() -> None:
269317
args.pmc_kernel_regex,
270318
args.stat,
271319
args.boost_ms,
320+
args.include_zero,
272321
)
273322
results[(kernel, k, L)] = res
274323
print(

0 commit comments

Comments
 (0)