-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1760a6
commit 07538a2
Showing
47 changed files
with
1,595 additions
and
861 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Copyright (c) Facebook, Inc. and its affiliates. | ||
# | ||
# This source code is licensed under the MIT license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
from pathlib import Path | ||
from typing import Callable, List | ||
|
||
from compiler_gym.service.proto import Benchmark as BenchmarkProto | ||
from compiler_gym.service.proto import File | ||
from compiler_gym.validation_result import ValidationResult | ||
|
||
|
||
class Benchmark(object): | ||
|
||
__slots__ = ["_uri", "_program_data", "_validation_callbacks"] | ||
|
||
def __init__(self, uri: str, program_data: BenchmarkProto): | ||
self._uri = uri | ||
self._program_data = program_data | ||
self._validation_callbacks = [] | ||
|
||
@property | ||
def uri(self) -> str: | ||
return self._uri | ||
|
||
def program_data(self) -> BenchmarkProto: # The data that the service needs | ||
return self._program_data | ||
|
||
def is_validatable(self) -> bool: | ||
return self._validation_callbacks != [] | ||
|
||
def validate(self) -> ValidationResult: | ||
raise NotImplementedError | ||
|
||
def validation_callbacks( | ||
self, | ||
) -> List[Callable[["CompilerEnv"], ValidationResult]]: # noqa: F821 | ||
"""Run any ad-hoc validation, e.g. difftest, valgrind, etc""" | ||
return self._validation_callbacks | ||
|
||
def add_validation_callback( | ||
self, | ||
validation_callback: Callable[["CompilerEnv"], ValidationResult], # noqa: F821 | ||
): | ||
self._validation_callbacks.append(validation_callback) | ||
|
||
def __repr__(self) -> str: | ||
return str(self.uri) | ||
|
||
@classmethod | ||
def from_file(cls, uri: str, path: Path): | ||
return cls( | ||
uri=uri, | ||
program_data=BenchmarkProto( | ||
uri=uri, program=File(uri=f"file:///{Path(path).absolute()}") | ||
), | ||
) | ||
|
||
@classmethod | ||
def from_file_data(cls, uri: str, data: bytes): | ||
return cls( | ||
uri=uri, program_data=BenchmarkProto(uri=uri, program=File(contents=data)) | ||
) |
Oops, something went wrong.