Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions examples/hpctoolkit_service/agent_py/datasets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from compiler_gym.datasets import Benchmark
from compiler_gym.datasets.uri import BenchmarkUri
from compiler_gym.service.proto import Benchmark as BenchmarkProto, BenchmarkDynamicConfig
from compiler_gym.service.proto import File
from typing import Union


def benchmark_from_file_contents(uri: Union[str, BenchmarkUri], data: bytes,
dynamic_config: BenchmarkDynamicConfig):
"""Construct a benchmark from raw data.

:param uri: The URI of the benchmark.

:param data: An array of bytes that will be passed to the compiler
service.

:param dynamic_config: BenchmarkDynamicConfig that specifies build, pre_run, run,
post_run commands.
"""
return Benchmark(proto=BenchmarkProto(uri=str(uri), program=File(contents=data),
dynamic_config=dynamic_config))
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
sys.path.insert(0, Path(__file__).parent.parent.parent.resolve())
import utils

from . import benchmark_from_file_contents
from compiler_gym.service.proto import BenchmarkDynamicConfig, Command


# BENCHMARKS_PATH: Path = runfiles_path("examples/hpctoolkit_service/benchmarks")
BENCHMARKS_PATH: Path = Path(
Expand Down Expand Up @@ -39,6 +42,25 @@ def __init__(self, *args, **kwargs):
"benchmark://hpctoolkit-cpu-v0/nanosleep",
self.preprocess(BENCHMARKS_PATH / "nanosleep.c"),
),
"benchmark://hpctoolkit-cpu-v0/simple_pow": benchmark_from_file_contents(
"benchmark://hpctoolkit-cpu-v0/simple_pow",
self.preprocess(BENCHMARKS_PATH / "simple_pow.c"),
BenchmarkDynamicConfig(
build_cmd=Command(
# $CC is replaced with clang command,
# $IN is replaced with benchmark path
# Following are linking flags (only one in this case).
argument=["$CC", "$IN", "-lm"],
timeout_seconds=60,
outfile=["a.out"],
),
run_cmd=Command(
argument=["./a.out"],
timeout_seconds=300,
infile=["a.out"],
)
)
),
}

@staticmethod
Expand Down
21 changes: 21 additions & 0 deletions examples/hpctoolkit_service/benchmarks/cpu-benchmarks/simple_pow.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// #include <stdbool.h>
#include <time.h>
#include <math.h>
#include <stdio.h>

#define ITER 10

__attribute__((noinline))
double test_bench_func() {
double sum = 0.0;
for (int ic = 1; ic <= ITER; ic++) {
sum += pow(ic, 3);
}
return sum;
}

__attribute__((optnone)) int main(int argc, char* argv[]) {
double ret = test_bench_func();
printf("*** The bench result is: %f\n", ret);
return 0;
}
1 change: 1 addition & 0 deletions examples/hpctoolkit_service/demo_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def main():

benchmark_to_process = [
# from benchmarks directory
"benchmark://hpctoolkit-cpu-v0/simple_pow",
# "benchmark://hpctoolkit-cpu-v0/offsets1",
"benchmark://hpctoolkit-cpu-v0/conv2d",
# "benchmark://hpctoolkit-cpu-v0/nanosleep",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self, working_directory: Path, benchmark: Benchmark, timeout_sec: f
self.bc_path,
"-o",
self.exe_path,
"-lm",
# "-lm",
], # "-nostartfiles"
"save": [self.llvm_dis, "-o", self.llvm_new_path, self.bc_path],
}
Expand Down