Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
romnn committed Feb 11, 2024
1 parent d916bdf commit 050bf95
Show file tree
Hide file tree
Showing 11 changed files with 412 additions and 134 deletions.
58 changes: 43 additions & 15 deletions gpucachesim/benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@

BENCH_TARGET_INDEX_COLS = ["target", "benchmark"]

PREVIEW_COLS = list(BENCH_TARGET_INDEX_COLS + ["input_id"] + INDEX_COLS + SIMULATE_INPUT_COLS)
PREVIEW_COLS = list(
BENCH_TARGET_INDEX_COLS + ["input_id"] + INDEX_COLS + SIMULATE_INPUT_COLS
)

RATE_COLUMNS = [
"l2_hit_rate",
Expand Down Expand Up @@ -235,7 +237,9 @@ def _map_dtype(dtype: str) -> str:
assert len(missing_dtypes) == 0, "missing dtypes for {}".format(missing_dtypes)


CATEGORICAL_COLS = set([col for col, dtype in SPECIAL_DTYPES.items() if dtype == "category"])
CATEGORICAL_COLS = set(
[col for col, dtype in SPECIAL_DTYPES.items() if dtype == "category"]
)


def benchmark_name_human_readable(name: str) -> str:
Expand Down Expand Up @@ -461,10 +465,18 @@ def construct_playground_simulate_target_config(self, node):
BenchmarkLoader.add_constructor("!Profile", construct_profile_target_config)
BenchmarkLoader.add_constructor("!Trace", construct_trace_target_config)
BenchmarkLoader.add_constructor("!Simulate", construct_simulate_target_config)
BenchmarkLoader.add_constructor("!ExecDrivenSimulate", construct_exec_driven_simulate_target_config)
BenchmarkLoader.add_constructor("!AccelsimSimulate", construct_accelsim_simulate_target_config)
BenchmarkLoader.add_constructor("!AccelsimTrace", construct_accelsim_trace_target_config)
BenchmarkLoader.add_constructor("!PlaygroundSimulate", construct_playground_simulate_target_config)
BenchmarkLoader.add_constructor(
"!ExecDrivenSimulate", construct_exec_driven_simulate_target_config
)
BenchmarkLoader.add_constructor(
"!AccelsimSimulate", construct_accelsim_simulate_target_config
)
BenchmarkLoader.add_constructor(
"!AccelsimTrace", construct_accelsim_trace_target_config
)
BenchmarkLoader.add_constructor(
"!PlaygroundSimulate", construct_playground_simulate_target_config
)


class Benchmarks:
Expand Down Expand Up @@ -508,18 +520,24 @@ def main():


@main.command()
@click.option("--path", default=DEFAULT_BENCH_FILE, help="Path to materialized benchmark config")
@click.option(
"--path", default=DEFAULT_BENCH_FILE, help="Path to materialized benchmark config"
)
def count_bench_configs(path):
print("loading", path)
b = Benchmarks(path)
benches = b.benchmarks[Target.Simulate.value]

total_bench_configs = sum([len(bench_configs) for bench_configs in benches.values()])
total_bench_configs = sum(
[len(bench_configs) for bench_configs in benches.values()]
)
print("total bench configs: {}".format(total_bench_configs))


@main.command()
@click.option("--path", default=DEFAULT_BENCH_FILE, help="Path to materialized benchmark config")
@click.option(
"--path", default=DEFAULT_BENCH_FILE, help="Path to materialized benchmark config"
)
@click.option("--baseline", type=bool, default=True, help="Baseline configurations")
def table(path, baseline):
print("loading", path)
Expand Down Expand Up @@ -550,13 +568,17 @@ def is_baseline(config):
return not baseline or all(
[
config["values"].get("memory_only") in [False, None],
config["values"].get("num_clusters") in [int(BASELINE["num_clusters"]), None],
config["values"].get("cores_per_cluster") in [int(BASELINE["cores_per_cluster"]), None],
config["values"].get("num_clusters")
in [int(BASELINE["num_clusters"]), None],
config["values"].get("cores_per_cluster")
in [int(BASELINE["cores_per_cluster"]), None],
config["values"].get("mode") in ["serial", None],
]
)

baseline_bench_configs = [config for config in bench_configs if is_baseline(config)]
baseline_bench_configs = [
config for config in bench_configs if is_baseline(config)
]

print(bench_name)

Expand Down Expand Up @@ -615,7 +637,9 @@ def is_baseline(config):


@main.command()
@click.option("--path", default=DEFAULT_BENCH_FILE, help="Path to materialized benchmark config")
@click.option(
"--path", default=DEFAULT_BENCH_FILE, help="Path to materialized benchmark config"
)
def list(path):
print("loading", path)
b = Benchmarks(path)
Expand All @@ -625,7 +649,9 @@ def list(path):


@main.command()
@click.option("--path", default=DEFAULT_BENCH_FILE, help="Path to materialized benchmark config")
@click.option(
"--path", default=DEFAULT_BENCH_FILE, help="Path to materialized benchmark config"
)
def fix(path):
print("loading", path)
b = Benchmarks(path)
Expand Down Expand Up @@ -695,7 +721,9 @@ def fix(path):
pass

try:
if (result_dir / "Simulate").is_dir() and (result_dir / "simulate").is_dir():
if (result_dir / "Simulate").is_dir() and (
result_dir / "simulate"
).is_dir():
# Simulate is newer
shutil.rmtree(result_dir / "simulate")
os.rename(result_dir / "Simulate", result_dir / "simulate")
Expand Down
13 changes: 9 additions & 4 deletions gpucachesim/microbench/pchase.py
Original file line number Diff line number Diff line change
Expand Up @@ -2322,14 +2322,19 @@ def find_cache_set_mapping(
print(combined.shape)

combined_binary = combined.copy()
combined_binary["offset"] = combined_binary["offset"].apply(lambda x: np.binary_repr(x, width=num_sets_log2))
combined_binary["set"] = combined_binary["set"].apply(lambda x: np.binary_repr(x, width=num_sets_log2))
combined_binary["offset"] = combined_binary["offset"].apply(
lambda x: np.binary_repr(x, width=num_sets_log2)
)
combined_binary["set"] = combined_binary["set"].apply(
lambda x: np.binary_repr(x, width=num_sets_log2)
)
highest_virt_addr = combined_binary["virt_addr"].max()
combined_binary["virt_addr"] = combined_binary["virt_addr"].apply(lambda x: np.binary_repr(x, width=int(np.ceil(np.log2(highest_virt_addr))) + 1))
combined_binary["virt_addr"] = combined_binary["virt_addr"].apply(
lambda x: np.binary_repr(x, width=int(np.ceil(np.log2(highest_virt_addr))) + 1)
)
print(combined_binary.head(n=10))
print(combined_binary.shape)


print(compute_set_probability(combined))

# return
Expand Down
4 changes: 3 additions & 1 deletion gpucachesim/plot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ def human_format_thousands(num, round_to=2, variable_precision=False):
["", "K", "M", "G", "T", "P"][magnitude],
)
return "{}{}".format(
round_to_precision_str(num, round_to=round_to, variable_precision=variable_precision),
round_to_precision_str(
num, round_to=round_to, variable_precision=variable_precision
),
["", "K", "M", "G", "T", "P"][magnitude],
)
4 changes: 3 additions & 1 deletion gpucachesim/plot/equations.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ def equations():
print(color("wrote {}".format(pdf_output_path), fg="cyan"))

png_output_path = (plot.EQUATIONS_DIR / "png" / name).with_suffix(".png")
utils.convert_to_png(input_path=pdf_output_path, output_path=png_output_path, density=600)
utils.convert_to_png(
input_path=pdf_output_path, output_path=png_output_path, density=600
)
print(color("wrote {}".format(png_output_path), fg="cyan"))

pass
Expand Down
74 changes: 57 additions & 17 deletions gpucachesim/stats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ def different_cols(df):
return [col for col in df.columns if len(df[col].value_counts()) > 1]



@main.command(name="speed-table")
@click.option("-p", "--path", help="Path to materialized benchmark config")
@click.option("-b", "--bench", "bench_name", help="Benchmark name")
Expand All @@ -224,9 +223,13 @@ def different_cols(df):
def run_speed_table(bench_name, path, nsight, verbose, include_mean_time, png):
profiler = "nsight" if nsight else "nvprof"
selected_df = load_stats(bench_name=bench_name, profiler=profiler, path=path)
gpucachesim.stats.speed_table.speed_table(selected_df, bench_name, include_mean_time=include_mean_time, verbose=verbose, png=png)


gpucachesim.stats.speed_table.speed_table(
selected_df,
bench_name,
include_mean_time=include_mean_time,
verbose=verbose,
png=png,
)


@main.command(name="result-table")
Expand All @@ -235,7 +238,11 @@ def run_speed_table(bench_name, path, nsight, verbose, include_mean_time, png):
@click.option("--bench", "bench_name", help="Benchmark name")
@click.option("--metric", "metric", type=str, help="metric")
@click.option(
"--combined-only", "combined_only", type=bool, is_flag=True, help="only output combined metrics"
"--combined-only",
"combined_only",
type=bool,
is_flag=True,
help="only output combined metrics",
)
@click.option("--nsight", "nsight", type=bool, is_flag=True, help="use nsight")
@click.option(
Expand All @@ -245,7 +252,15 @@ def run_speed_table(bench_name, path, nsight, verbose, include_mean_time, png):
def run_result_table(path, bench_name, metric, combined_only, nsight, verbose, png):
profiler = "nsight" if nsight else "nvprof"
selected_df = load_stats(bench_name=bench_name, profiler=profiler, path=path)
gpucachesim.stats.result_table.result_table(selected_df, bench_name=bench_name, metrics=[metric], combined_only=combined_only, verbose=verbose, png=png)
gpucachesim.stats.result_table.result_table(
selected_df,
bench_name=bench_name,
metrics=[metric],
combined_only=combined_only,
verbose=verbose,
png=png,
)


@main.command(name="all-result-table")
# @click.pass_context
Expand All @@ -263,20 +278,34 @@ def all_result_table(path, bench_name, metric, nsight, verbose, png):

all_benches = sorted(list(selected_df["benchmark"].unique()))
if metric is None:
metrics = ["dramreads", "dramwrites", "l2accesses", "l2dhitrate", "l1accesses", "l1dhitrate", "cycles"]
metrics = [
"dramreads",
"dramwrites",
"l2accesses",
"l2dhitrate",
"l1accesses",
"l1dhitrate",
"cycles",
]
else:
metrics = [metric]

options = dict(verbose=verbose, png=png)

for bench_name in all_benches:
gpucachesim.stats.result_table.result_table(selected_df.copy(), bench_name=bench_name, metrics=metrics, **options)
gpucachesim.stats.result_table.result_table(
selected_df.copy(), bench_name=bench_name, metrics=metrics, **options
)

for combined_only in [True, False]:
gpucachesim.stats.result_table.result_table(selected_df.copy(), bench_name=None, metrics=metrics, combined_only=combined_only, **options)

gpucachesim.stats.result_table.result_table(
selected_df.copy(),
bench_name=None,
metrics=metrics,
combined_only=combined_only,
**options,
)



@main.command(name="parallel-table")
# @click.pass_context
Expand Down Expand Up @@ -309,7 +338,13 @@ def run_parallel_table(bench_name, path, nsight, scale_clusters, large, verbose,
profiler = "nsight" if nsight else "nvprof"
selected_df = load_stats(bench_name=bench_name, profiler=profiler, path=path)
gpucachesim.stats.parallel_table.parallel_table(
selected_df, bench_name=bench_name, scale_clusters=scale_clusters, large=large, verbose=verbose, png=png)
selected_df,
bench_name=bench_name,
scale_clusters=scale_clusters,
large=large,
verbose=verbose,
png=png,
)


@main.command(name="all-parallel-table")
Expand All @@ -318,8 +353,7 @@ def run_parallel_table(bench_name, path, nsight, scale_clusters, large, verbose,
@click.option("--png", "png", type=bool, is_flag=True, help="convert to png")
def run_all_parallel_table(path, nsight, png):
profiler = "nsight" if nsight else "nvprof"
selected_df = load_stats(
bench_name=None, profiler=profiler, path=path)
selected_df = load_stats(bench_name=None, profiler=profiler, path=path)

bench_names = sorted(list(selected_df["benchmark"].unique()))
configs = list(itertools.product([True, False], [True, False]))
Expand All @@ -329,17 +363,23 @@ def run_all_parallel_table(path, nsight, png):
options = dict(batch=True, verbose=False, png=png)

done = 0
for (scale_clusters, large) in configs:
for scale_clusters, large in configs:
print("========= {:>4}/{:<4} =======".format(done, total))
gpucachesim.stats.parallel_table.parallel_table(
selected_df, bench_name=None, scale_clusters=scale_clusters, large=large, **options)
selected_df,
bench_name=None,
scale_clusters=scale_clusters,
large=large,
**options,
)

# for all benchmarks
for bench_name in bench_names:
mask = selected_df["benchmark"] == bench_name
bench_df = selected_df[mask].copy()
gpucachesim.stats.parallel_table.parallel_table(
bench_df, bench_name=bench_name,
bench_df,
bench_name=bench_name,
scale_clusters=scale_clusters,
**options,
)
Expand Down
Loading

0 comments on commit 050bf95

Please sign in to comment.