Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow use of benchmark scheduler within benchmarking pipeline #273

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
316f631
[𝘀𝗽𝗿] changes to main this commit is based on
boomanaiden154 Dec 30, 2024
5205f7d
[𝘀𝗽𝗿] initial version
boomanaiden154 Dec 30, 2024
8249295
[𝘀𝗽𝗿] changes introduced through rebase
boomanaiden154 Dec 30, 2024
0dd9d18
rebase
boomanaiden154 Dec 30, 2024
d5026cc
[𝘀𝗽𝗿] changes introduced through rebase
boomanaiden154 Dec 31, 2024
35a15fd
rebase
boomanaiden154 Dec 31, 2024
495f5de
[𝘀𝗽𝗿] changes introduced through rebase
boomanaiden154 Dec 31, 2024
a8d5ec0
rebase
boomanaiden154 Dec 31, 2024
edb54ff
[𝘀𝗽𝗿] changes introduced through rebase
boomanaiden154 Dec 31, 2024
4c1b6cf
rebase
boomanaiden154 Dec 31, 2024
e875be9
[𝘀𝗽𝗿] changes introduced through rebase
boomanaiden154 Dec 31, 2024
373e41d
rebase
boomanaiden154 Dec 31, 2024
0397f17
[𝘀𝗽𝗿] changes introduced through rebase
boomanaiden154 Dec 31, 2024
013d8c9
rebase
boomanaiden154 Dec 31, 2024
cd44e16
[𝘀𝗽𝗿] changes introduced through rebase
boomanaiden154 Dec 31, 2024
2cdbcde
rebase
boomanaiden154 Dec 31, 2024
9260245
address feedback
boomanaiden154 Dec 31, 2024
2b15dbb
[𝘀𝗽𝗿] changes introduced through rebase
boomanaiden154 Jan 16, 2025
cb4bf04
rebase
boomanaiden154 Jan 16, 2025
b6d2c30
[𝘀𝗽𝗿] changes introduced through rebase
boomanaiden154 Jan 16, 2025
47f27e0
rebase
boomanaiden154 Jan 16, 2025
7ed5d71
[𝘀𝗽𝗿] changes introduced through rebase
boomanaiden154 Jan 16, 2025
2fef2e6
rebase
boomanaiden154 Jan 16, 2025
4b23864
[𝘀𝗽𝗿] changes introduced through rebase
boomanaiden154 Jan 17, 2025
e2d2398
rebase
boomanaiden154 Jan 17, 2025
ee345eb
[𝘀𝗽𝗿] changes introduced through rebase
boomanaiden154 Jan 17, 2025
2395268
rebase
boomanaiden154 Jan 17, 2025
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
3 changes: 3 additions & 0 deletions gematria/datasets/pipelines/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ gematria_py_binary(
name = "benchmark_bbs_lib",
srcs = ["benchmark_bbs_lib.py"],
deps = [
":benchmark_cpu_scheduler",
"//gematria/datasets/python:exegesis_benchmark",
"//gematria/proto:execution_annotation_py_pb2",
],
Expand All @@ -63,6 +64,7 @@ gematria_py_binary(
srcs = ["benchmark_bbs.py"],
deps = [
":benchmark_bbs_lib",
":benchmark_cpu_scheduler",
],
)

Expand All @@ -77,6 +79,7 @@ gematria_py_test(
],
deps = [
":benchmark_bbs_lib",
":benchmark_cpu_scheduler",
"//gematria/io/python:tfrecord",
"//gematria/proto:execution_annotation_py_pb2",
],
Expand Down
11 changes: 10 additions & 1 deletion gematria/datasets/pipelines/benchmark_bbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from apache_beam.options import pipeline_options

from gematria.datasets.pipelines import benchmark_bbs_lib
from gematria.datasets.pipelines import benchmark_cpu_scheduler

_INPUT_FILE_PATTERN = flags.DEFINE_string(
'input_file_pattern',
Expand All @@ -30,6 +31,12 @@
_OUTPUT_FILE_PATTERN = flags.DEFINE_string(
'output_file_pattern', None, 'The output file path/pattern.', required=True
)
_BENCHMARK_SCHEDULER = flags.DEFINE_enum_class(
'benchmark_scheduler',
benchmark_cpu_scheduler.BenchmarkSchedulerImplementations.NO_SCHEDULING,
benchmark_cpu_scheduler.BenchmarkSchedulerImplementations,
'The scheduler to use for choosing a core for running benchmarks.',
)


def main(argv) -> None:
Expand All @@ -39,7 +46,9 @@ def main(argv) -> None:
beam_options = pipeline_options.PipelineOptions()

pipeline_constructor = benchmark_bbs_lib.benchmark_bbs(
_INPUT_FILE_PATTERN.value, _OUTPUT_FILE_PATTERN.value
_INPUT_FILE_PATTERN.value,
_OUTPUT_FILE_PATTERN.value,
_BENCHMARK_SCHEDULER.value,
)

with beam.Pipeline(options=beam_options) as pipeline:
Expand Down
29 changes: 24 additions & 5 deletions gematria/datasets/pipelines/benchmark_bbs_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,37 @@

from gematria.proto import execution_annotation_pb2
from gematria.datasets.python import exegesis_benchmark
from gematria.datasets.pipelines import benchmark_cpu_scheduler

_BEAM_METRIC_NAMESPACE_NAME = 'benchmark_bbs'


class BenchmarkBasicBlock(beam.DoFn):
"""A Beam function that benchmarks basic blocks."""

def setup(self):
self._exegesis_benchmark = exegesis_benchmark.ExegesisBenchmark.create()
def __init__(
self,
benchmark_scheduler_type: benchmark_cpu_scheduler.BenchmarkSchedulerImplementations,
):
self._benchmark_scheduler_type = benchmark_scheduler_type
self._benchmark_success_blocks = metrics.Metrics.counter(
_BEAM_METRIC_NAMESPACE_NAME, 'benchmark_bbs_success'
)
self._benchmark_failed_blocks = metrics.Metrics.counter(
_BEAM_METRIC_NAMESPACE_NAME, 'benchmark_blocks_failed'
)

def setup(self):
self._exegesis_benchmark = exegesis_benchmark.ExegesisBenchmark.create()
self._benchmark_scheduler = (
benchmark_cpu_scheduler.construct_benchmark_scheduler(
self._benchmark_scheduler_type
)
)
self._benchmarking_core = (
self._benchmark_scheduler.setup_and_get_benchmark_core()
)

def process(
self,
block_with_annotations: execution_annotation_pb2.BlockWithExecutionAnnotations,
Expand All @@ -44,8 +59,10 @@ def process(
benchmark_code = self._exegesis_benchmark.process_annotated_block(
block_with_annotations
)

self._benchmark_scheduler.verify()
benchmark_value = self._exegesis_benchmark.benchmark_basic_block(
benchmark_code
benchmark_code, self._benchmarking_core
)
self._benchmark_success_blocks.inc()
yield (block_with_annotations.block_hex, benchmark_value)
Expand All @@ -65,7 +82,9 @@ def process(


def benchmark_bbs(
input_file_pattern: str, output_file_pattern: str
input_file_pattern: str,
output_file_pattern: str,
benchmark_scheduler_type: benchmark_cpu_scheduler.BenchmarkSchedulerImplementations,
) -> Callable[[beam.Pipeline], None]:
"""Creates a pipeline to benchmark BBs."""

Expand All @@ -78,7 +97,7 @@ def pipeline(root: beam.Pipeline) -> None:
)
annotated_bbs_shuffled = annotated_bbs | 'Shuffle' >> beam.Reshuffle()
benchmarked_blocks = annotated_bbs_shuffled | 'Benchmarking' >> beam.ParDo(
BenchmarkBasicBlock()
BenchmarkBasicBlock(benchmark_scheduler_type)
)
formatted_output = benchmarked_blocks | 'Formatting' >> beam.ParDo(
FormatBBsForOutput()
Expand Down
9 changes: 7 additions & 2 deletions gematria/datasets/pipelines/benchmark_bbs_lib_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from gematria.datasets.pipelines import benchmark_bbs_lib
from gematria.proto import execution_annotation_pb2
from gematria.io.python import tfrecord
from gematria.datasets.pipelines import benchmark_cpu_scheduler

BLOCK_FOR_TESTING = execution_annotation_pb2.BlockWithExecutionAnnotations(
execution_annotations=execution_annotation_pb2.ExecutionAnnotations(
Expand All @@ -45,7 +46,9 @@
class BenchmarkBBsTests(absltest.TestCase):

def test_benchmark_basic_block(self):
benchmark_transform = benchmark_bbs_lib.BenchmarkBasicBlock()
benchmark_transform = benchmark_bbs_lib.BenchmarkBasicBlock(
benchmark_cpu_scheduler.BenchmarkSchedulerImplementations.NO_SCHEDULING
)
benchmark_transform.setup()

block_outputs = list(benchmark_transform.process(BLOCK_FOR_TESTING))
Expand Down Expand Up @@ -74,7 +77,9 @@ def test_benchmark_bbs(self):
output_file_pattern = os.path.join(output_folder, 'bhive-output')

pipeline_constructor = benchmark_bbs_lib.benchmark_bbs(
test_tfrecord.full_path, output_file_pattern
test_tfrecord.full_path,
output_file_pattern,
benchmark_cpu_scheduler.BenchmarkSchedulerImplementations.NO_SCHEDULING,
)

with test_pipeline.TestPipeline() as pipeline_under_test:
Expand Down
18 changes: 18 additions & 0 deletions gematria/datasets/pipelines/benchmark_cpu_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import abc
from collections.abc import Collection
import enum
import os
import re
from typing_extensions import override
Expand Down Expand Up @@ -148,3 +149,20 @@ def verify(self):
cpu_mask = list(os.sched_getaffinity(0))
if self._cpu_mask != cpu_mask:
raise ValueError('Expected the CPU mask to not change.')


class BenchmarkSchedulerImplementations(enum.Enum):
NO_SCHEDULING = 1
DEFAULT = 2


def construct_benchmark_scheduler(
scheduler_type: BenchmarkSchedulerImplementations,
) -> BenchmarkScheduler:
match scheduler_type:
case BenchmarkSchedulerImplementations.NO_SCHEDULING:
return NoSchedulingBenchmarkScheduler()
case BenchmarkSchedulerImplementations.DEFAULT:
return DefaultBenchmarkScheduler()
case _:
raise ValueError('Unexpected Benchmark Scheduler Type.')
Loading