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

add helper functions to verify generated combination-lists #6

Merged
Merged
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
33 changes: 33 additions & 0 deletions bashi/globals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""This module contains constants used in the bashi library."""

# index positions of the parameter-value
NAME: int = 0
VERSION: int = 1

# parameter key names, whit special meaning
HOST_COMPILER: str = "host_compiler"
DEVICE_COMPILER: str = "device_compiler"

# name of the used compilers
GCC: str = "gcc"
CLANG: str = "clang"
NVCC: str = "nvcc"
CLANG_CUDA: str = "clang-cuda"
HIPCC: str = "hipcc"
ICPX: str = "icpx"

# alpaka backend names
ALPAKA_ACC_CPU_B_SEQ_T_SEQ_ENABLE: str = "alpaka_ACC_CPU_B_SEQ_T_SEQ_ENABLE"
ALPAKA_ACC_CPU_B_SEQ_T_THREADS_ENABLE: str = "alpaka_ACC_CPU_B_SEQ_T_THREADS_ENABLE"
ALPAKA_ACC_CPU_B_TBB_T_SEQ_ENABLE: str = "alpaka_ACC_CPU_B_TBB_T_SEQ_ENABLE"
ALPAKA_ACC_CPU_B_OMP2_T_SEQ_ENABLE: str = "alpaka_ACC_CPU_B_OMP2_T_SEQ_ENABLE"
ALPAKA_ACC_CPU_B_SEQ_T_OMP2_ENABLE: str = "alpaka_ACC_CPU_B_SEQ_T_OMP2_ENABLE"
ALPAKA_ACC_GPU_CUDA_ENABLE: str = "alpaka_ACC_GPU_CUDA_ENABLE"
ALPAKA_ACC_GPU_HIP_ENABLE: str = "alpaka_ACC_GPU_HIP_ENABLE"
ALPAKA_ACC_SYCL_ENABLE: str = "alpaka_ACC_SYCL_ENABLE"

# software dependencies and compiler configurations
UBUNTU: str = "ubuntu"
CMAKE: str = "cmake"
BOOST: str = "boost"
CXX_STANDARD: str = "cxx_standard"
113 changes: 108 additions & 5 deletions bashi/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
"""Different helper functions for bashi"""

from typing import Dict, Tuple, List
from typing import Dict, List, IO
from collections import OrderedDict
import dataclasses
from packaging.version import Version
from bashi.types import FilterFunction, ParameterValueTuple
import sys
from typeguard import typechecked
from bashi.types import (
Parameter,
ParameterValue,
ParameterValueTuple,
ParameterValuePair,
ParameterValueMatrix,
CombinationList,
FilterFunction,
)


@dataclasses.dataclass
Expand Down Expand Up @@ -47,10 +56,10 @@ def filter_function(row: OrderedDict[str, Tuple[str, Version]]):
function used by allpairspy, see class doc string.
"""

param_map: Dict[int, str]
param_map: Dict[int, Parameter]
filter_func: FilterFunction

def __call__(self, row: List[Tuple[str, Version]]) -> bool:
def __call__(self, row: List[ParameterValue]) -> bool:
"""The expected interface of allpairspy filter rule.
Transform the type of row from List[Tuple[str, Version]] to
[OrderedDict[str, Tuple[str, Version]]].
Expand All @@ -65,3 +74,97 @@ def __call__(self, row: List[Tuple[str, Version]]) -> bool:
for index, param_name in enumerate(row):
ordered_row[self.param_map[index]] = param_name
return self.filter_func(ordered_row)


@typechecked
def get_expected_parameter_value_pairs(
parameter_matrix: ParameterValueMatrix,
) -> List[ParameterValuePair]:
"""Takes parameter-value-matrix an creates a list of all expected parameter-values-pairs.
The pair-wise generator guaranties, that each pair of two parameter-values exist in at least one
combination if no filter rules exist. Therefore the generated the generated list can be used
to verify the output of the pair-wise generator.

Args:
parameter_matrix (ParameterValueMatrix): matrix of parameter values

Returns:
List[ParameterValuePair]: list of all possible parameter-value-pairs
"""
expected_pairs: List[ParameterValuePair] = []

number_of_keys: int = len(parameter_matrix.keys())
param_map: Dict[int, str] = {}
for index, param in enumerate(parameter_matrix.keys()):
param_map[index] = param

for v1_index in range(number_of_keys):
for v2_index in range(v1_index + 1, number_of_keys):
_loop_over_parameter_values(
parameter_matrix,
expected_pairs,
param_map[v1_index],
param_map[v2_index],
)

return expected_pairs


@typechecked
def _loop_over_parameter_values(
parameters: ParameterValueMatrix,
expected_pairs: List[ParameterValuePair],
v1_parameter: Parameter,
v2_parameter: Parameter,
):
"""Creates all parameter-value-pairs for two give parameters.

Args:
parameters (ParameterValueMatrix): The complete parameter-value-matrix
expected_pairs (List[ParameterValuePair]): Add the generated parameter-values-pairs to the
list.
v1_parameter (Parameter): the first parameter
v2_parameter (Parameter): the second parameter
"""
for v1_name, v1_version in parameters[v1_parameter]:
for v2_name, v2_version in parameters[v2_parameter]:
param_val_pair: ParameterValuePair = OrderedDict()
param_val_pair[v1_parameter] = (v1_name, v1_version)
param_val_pair[v2_parameter] = (v2_name, v2_version)
expected_pairs.append(param_val_pair)


def check_parameter_value_pair_in_combination_list(
combination_list: CombinationList,
parameter_value_pairs: List[ParameterValuePair],
output: IO[str] = sys.stdout,
) -> bool:
"""Check if all given parameter-values-pairs exist at least in on combination.

Args:
combination_list (CombinationList): list of given combination
parameter_value_pairs (List[ParameterValuePair]): list of parameter-value-pair to be search
for
output (IO[str], optional): Writes missing parameter-values-pairs to it. Defaults to
sys.stdout.

Returns:
bool: returns True, if all given parameter-values-pairs was found in the combination-list
"""
missing_expected_param = False

for ex_param_val_pair in parameter_value_pairs:
param1, param_val1 = list(ex_param_val_pair.items())[0]
param2, param_val2 = list(ex_param_val_pair.items())[1]
found = False
for comb in combination_list:
# comb contains all parameters, therefore a check is not required
if comb[param1] == param_val1 and comb[param2] == param_val2:
found = True
break

if not found:
print(f"{ex_param_val_pair} is missing in combination list", file=output)
missing_expected_param = True

return not missing_expected_param
Loading
Loading