Skip to content

Commit

Permalink
Add warmup runs and profile all iterations to benchmarks (#1402)
Browse files Browse the repository at this point in the history
Add support for initial warmup runs in benchmarks and allows profiling all iterations or just the last one.

This is technically a breaking change since `--profile` now profiles all iterations, and the new `--profile-last` option profiles only the last one as `--profile` used to behave.

Authors:
  - Peter Andreas Entschev (https://github.com/pentschev)

Approvers:
  - Mads R. B. Kristensen (https://github.com/madsbk)

URL: #1402
  • Loading branch information
pentschev authored Nov 5, 2024
1 parent fc80d43 commit 233376d
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 56 deletions.
21 changes: 15 additions & 6 deletions dask_cuda/benchmarks/common.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import contextlib
from argparse import Namespace
from functools import partial
from typing import Any, Callable, List, Mapping, NamedTuple, Optional, Tuple
Expand All @@ -7,7 +8,7 @@
import pandas as pd

import dask
from distributed import Client
from distributed import Client, performance_report

from dask_cuda.benchmarks.utils import (
address_to_index,
Expand Down Expand Up @@ -87,12 +88,20 @@ def run_benchmark(client: Client, args: Namespace, config: Config):
If ``args.profile`` is set, the final run is profiled.
"""

results = []
for _ in range(max(1, args.runs) - 1):
res = config.bench_once(client, args, write_profile=None)
results.append(res)
results.append(config.bench_once(client, args, write_profile=args.profile))
return results
for _ in range(max(0, args.warmup_runs)):
config.bench_once(client, args, write_profile=None)

ctx = contextlib.nullcontext()
if args.profile is not None:
ctx = performance_report(filename=args.profile)
with ctx:
for _ in range(max(1, args.runs) - 1):
res = config.bench_once(client, args, write_profile=None)
results.append(res)
results.append(config.bench_once(client, args, write_profile=args.profile_last))
return results


def gather_bench_results(client: Client, args: Namespace, config: Config):
Expand Down
13 changes: 3 additions & 10 deletions dask_cuda/benchmarks/local_cudf_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,9 @@ def bench_once(client, args, write_profile=None):
"False": False,
}.get(args.shuffle, args.shuffle)

if write_profile is None:
ctx = contextlib.nullcontext()
else:
ctx = performance_report(filename=args.profile)
ctx = contextlib.nullcontext()
if write_profile is not None:
ctx = performance_report(filename=write_profile)

with ctx:
t1 = clock()
Expand Down Expand Up @@ -260,12 +259,6 @@ def parse_args():
"type": str,
"help": "Do shuffle with GPU or CPU dataframes (default 'gpu')",
},
{
"name": "--runs",
"default": 3,
"type": int,
"help": "Number of runs",
},
]

return parse_benchmark_args(
Expand Down
8 changes: 1 addition & 7 deletions dask_cuda/benchmarks/local_cudf_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def bench_once(client, args, write_profile=None):
if args.backend == "explicit-comms":
ctx1 = dask.config.set(explicit_comms=True)
if write_profile is not None:
ctx2 = performance_report(filename=args.profile)
ctx2 = performance_report(filename=write_profile)

with ctx1:
with ctx2:
Expand Down Expand Up @@ -346,12 +346,6 @@ def parse_args():
"action": "store_true",
"help": "Don't shuffle the keys of the left (base) dataframe.",
},
{
"name": "--runs",
"default": 3,
"type": int,
"help": "Number of runs",
},
{
"name": [
"-s",
Expand Down
13 changes: 3 additions & 10 deletions dask_cuda/benchmarks/local_cudf_shuffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,9 @@ def create_data(
def bench_once(client, args, write_profile=None):
data_processed, df = create_data(client, args)

if write_profile is None:
ctx = contextlib.nullcontext()
else:
ctx = performance_report(filename=args.profile)
ctx = contextlib.nullcontext()
if write_profile is not None:
ctx = performance_report(filename=write_profile)

with ctx:
if args.backend in {"dask", "dask-noop"}:
Expand Down Expand Up @@ -228,12 +227,6 @@ def parse_args():
"type": str,
"help": "Do shuffle with GPU or CPU dataframes (default 'gpu')",
},
{
"name": "--runs",
"default": 3,
"type": int,
"help": "Number of runs",
},
{
"name": "--ignore-index",
"action": "store_true",
Expand Down
15 changes: 4 additions & 11 deletions dask_cuda/benchmarks/local_cupy.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,11 @@ def bench_once(client, args, write_profile=None):
chunksize = x.chunksize
data_processed = sum(arg.nbytes for arg in func_args)

# Execute the operations to benchmark
if args.profile is not None and write_profile is not None:
ctx = performance_report(filename=args.profile)
else:
ctx = contextlib.nullcontext()
ctx = contextlib.nullcontext()
if write_profile is not None:
ctx = performance_report(filename=write_profile)

# Execute the operations to benchmark
with ctx:
rng = start_range(message=args.operation, color="purple")
result = func(*func_args)
Expand Down Expand Up @@ -297,12 +296,6 @@ def parse_args():
"type": int,
"help": "Chunk size (default 2500).",
},
{
"name": "--runs",
"default": 3,
"type": int,
"help": "Number of runs (default 3).",
},
{
"name": [
"-b",
Expand Down
15 changes: 4 additions & 11 deletions dask_cuda/benchmarks/local_cupy_map_overlap.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ def bench_once(client, args, write_profile=None):

data_processed = x.nbytes

# Execute the operations to benchmark
if args.profile is not None and write_profile is not None:
ctx = performance_report(filename=args.profile)
else:
ctx = contextlib.nullcontext()
ctx = contextlib.nullcontext()
if write_profile is not None:
ctx = performance_report(filename=write_profile)

# Execute the operations to benchmark
with ctx:
result = x.map_overlap(mean_filter, args.kernel_size, shape=ks)
if args.backend == "dask-noop":
Expand Down Expand Up @@ -168,12 +167,6 @@ def parse_args():
"type": int,
"help": "Kernel size, 2*k+1, in each dimension (default 1)",
},
{
"name": "--runs",
"default": 3,
"type": int,
"help": "Number of runs",
},
{
"name": [
"-b",
Expand Down
23 changes: 22 additions & 1 deletion dask_cuda/benchmarks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,16 @@ def parse_benchmark_args(
metavar="PATH",
default=None,
type=str,
help="Write dask profile report (E.g. dask-report.html)",
help="Write dask profile report (E.g. dask-report.html) on all "
"iterations (excluding warmup).",
)
parser.add_argument(
"--profile-last",
metavar="PATH",
default=None,
type=str,
help="Write dask profile report (E.g. dask-report.html) on last "
"iteration only.",
)
# See save_benchmark_data for more information
parser.add_argument(
Expand All @@ -344,6 +353,18 @@ def parse_benchmark_args(
type=parse_bytes,
help="Bandwidth statistics: ignore messages smaller than this (default '1 MB')",
)
parser.add_argument(
"--runs",
default=3,
type=int,
help="Number of runs",
)
parser.add_argument(
"--warmup-runs",
default=1,
type=int,
help="Number of warmup runs",
)

for args in args_list:
name = args.pop("name")
Expand Down

0 comments on commit 233376d

Please sign in to comment.