Skip to content

Commit

Permalink
Add software filter rule
Browse files Browse the repository at this point in the history
  • Loading branch information
YuriiPerets committed Sep 4, 2024
1 parent 0ff5ba8 commit a76f22f
Show file tree
Hide file tree
Showing 4 changed files with 239 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/bashi/filter_software_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
"""

from typing import Optional, IO
import packaging.version as pkv
from typeguard import typechecked
from bashi.types import ParameterValueTuple
from bashi.globals import DEVICE_COMPILER, HOST_COMPILER, GCC, UBUNTU
from bashi.utils import reason


@typechecked
Expand Down Expand Up @@ -40,4 +43,23 @@ def software_dependency_filter(
Returns:
bool: True, if parameter-value-tuple is valid.
"""

if UBUNTU in row and row[UBUNTU].version >= pkv.parse("20.04"):
if DEVICE_COMPILER in row and row[DEVICE_COMPILER].name == GCC:
if row[DEVICE_COMPILER].version <= pkv.parse("6"):
reason(
output,
f"Device compiler GCC {row[DEVICE_COMPILER].version}"
f" is not available in Ubuntu {row[UBUNTU].version}",
)
return False
if HOST_COMPILER in row and row[HOST_COMPILER].name == GCC:
if row[HOST_COMPILER].version <= pkv.parse("6"):
reason(
output,
f"Host compiler GCC {row[HOST_COMPILER].version}"
f" is not available in Ubuntu {row[UBUNTU].version}",
)
return False

return True
27 changes: 26 additions & 1 deletion src/bashi/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def get_expected_bashi_parameter_value_pairs(
_remove_unsupported_clang_sdk_versions_for_clang_cuda(
param_val_pair_list, removed_param_val_pair_list
)

_remove_unsupported_gcc_versions_for_ubuntu2004(
param_val_pair_list, removed_param_val_pair_list
)
return (param_val_pair_list, removed_param_val_pair_list)


Expand Down Expand Up @@ -747,3 +749,26 @@ def filter_func(param_val_pair: ParameterValuePair) -> bool:
return True

bi_filter(parameter_value_pairs, removed_parameter_value_pairs, filter_func)


def _remove_unsupported_gcc_versions_for_ubuntu2004(
parameter_value_pairs: List[ParameterValuePair],
removed_parameter_value_pairs: List[ParameterValuePair],
):
"""Remove pairs where GCC version 6 and older is used with Ubuntu 20.04 or newer.
Args:
parameter_value_pairs (List[ParameterValuePair]): List of parameter-value pairs.
"""
for compiler_type in (HOST_COMPILER, DEVICE_COMPILER):
for gcc_version in range(1, 7):
remove_parameter_value_pairs(
parameter_value_pairs,
removed_parameter_value_pairs,
parameter1=compiler_type,
value_name1=GCC,
value_version1=gcc_version,
parameter2=UBUNTU,
value_name2=UBUNTU,
value_version2="<20.04",
)
137 changes: 137 additions & 0 deletions tests/test_filter_software_dependency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# pylint: disable=missing-docstring
import unittest
import io

from collections import OrderedDict as OD
from utils_test import parse_param_val as ppv
from bashi.globals import * # pylint: disable=wildcard-import,unused-wildcard-import
from bashi.filter_software_dependency import software_dependency_filter_typechecked


class TestOldGCCVersionInUbuntu2004(unittest.TestCase):
def test_valid_gcc_is_in_ubuntu_2004_d1(self):
for gcc_version in [7, 13, 99]:
self.assertTrue(
software_dependency_filter_typechecked(
OD({HOST_COMPILER: ppv((GCC, gcc_version)), UBUNTU: ppv((UBUNTU, "22.04"))}),
)
)

self.assertTrue(
software_dependency_filter_typechecked(
OD(
{
HOST_COMPILER: ppv((GCC, gcc_version)),
DEVICE_COMPILER: ppv((GCC, gcc_version)),
UBUNTU: ppv((UBUNTU, "22.04")),
}
),
)
)
for gcc_version in [7, 13, 99]:
self.assertTrue(
software_dependency_filter_typechecked(
OD({HOST_COMPILER: ppv((GCC, gcc_version)), UBUNTU: ppv((UBUNTU, "20.04"))}),
)
)

self.assertTrue(
software_dependency_filter_typechecked(
OD(
{
HOST_COMPILER: ppv((GCC, gcc_version)),
DEVICE_COMPILER: ppv((GCC, gcc_version)),
UBUNTU: ppv((UBUNTU, "20.04")),
}
),
)
)
for gcc_version in [1, 3, 6, 7, 13, 99]:
self.assertTrue(
software_dependency_filter_typechecked(
OD({HOST_COMPILER: ppv((GCC, gcc_version)), UBUNTU: ppv((UBUNTU, "18.04"))}),
)
)
for gcc_version in [1, 3, 6, 7, 13, 99]:
self.assertTrue(
software_dependency_filter_typechecked(
OD({DEVICE_COMPILER: ppv((GCC, gcc_version)), UBUNTU: ppv((UBUNTU, "18.04"))}),
)
)
for gcc_version in [1, 3, 6, 7, 13, 99]:
self.assertTrue(
software_dependency_filter_typechecked(
OD(
{
DEVICE_COMPILER: ppv((GCC, gcc_version)),
UBUNTU: ppv((UBUNTU, "18.04")),
}
),
)
)
for gcc_version in [1, 3, 6, 7, 13, 99]:
self.assertTrue(
software_dependency_filter_typechecked(
OD(
{
HOST_COMPILER: ppv((GCC, gcc_version)),
UBUNTU: ppv((UBUNTU, "18.04")),
}
),
)
)

def test_not_valid_gcc_is_in_ubuntu_2004_d1(self):
for gcc_version in [6, 3, 1]:
reason_msg = io.StringIO()
self.assertFalse(
software_dependency_filter_typechecked(
OD({HOST_COMPILER: ppv((GCC, gcc_version)), UBUNTU: ppv((UBUNTU, "20.04"))}),
reason_msg,
),
f"Host compiler GCC {gcc_version} + Ubuntu 20.4",
)
self.assertEqual(
reason_msg.getvalue(),
f"Host compiler GCC {gcc_version} is not available in Ubuntu 20.4",
)
for gcc_version in [6, 3, 1]:
reason_msg = io.StringIO()
self.assertFalse(
software_dependency_filter_typechecked(
OD({HOST_COMPILER: ppv((GCC, gcc_version)), UBUNTU: ppv((UBUNTU, "22.04"))}),
reason_msg,
),
f"Host compiler GCC {gcc_version} + Ubuntu 22.4",
)
self.assertEqual(
reason_msg.getvalue(),
f"Host compiler GCC {gcc_version} is not available in Ubuntu 22.4",
)

for gcc_version in [6, 3, 1]:
reason_msg = io.StringIO()
self.assertFalse(
software_dependency_filter_typechecked(
OD({DEVICE_COMPILER: ppv((GCC, gcc_version)), UBUNTU: ppv((UBUNTU, "20.04"))}),
reason_msg,
),
f"Device compiler GCC {gcc_version} + Ubuntu 20.4",
)
self.assertEqual(
reason_msg.getvalue(),
f"Device compiler GCC {gcc_version} is not available in Ubuntu 20.4",
)
for gcc_version in [6, 3, 1]:
reason_msg = io.StringIO()
self.assertFalse(
software_dependency_filter_typechecked(
OD({DEVICE_COMPILER: ppv((GCC, gcc_version)), UBUNTU: ppv((UBUNTU, "22.04"))}),
reason_msg,
),
f"Device compiler GCC {gcc_version} + Ubuntu 22.4",
)
self.assertEqual(
reason_msg.getvalue(),
f"Device compiler GCC {gcc_version} is not available in Ubuntu 22.4",
)
54 changes: 54 additions & 0 deletions tests/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
_remove_device_compiler_gcc_clang_enabled_cuda_backend,
_remove_specific_cuda_clang_combinations,
_remove_unsupported_clang_sdk_versions_for_clang_cuda,
_remove_unsupported_gcc_versions_for_ubuntu2004,
)
from bashi.versions import NvccHostSupport, NVCC_GCC_MAX_VERSION

Expand Down Expand Up @@ -2248,3 +2249,56 @@ def test_remove_unsupported_clang_sdk_versions_for_clang_cuda(self):
expected_results,
self,
)

def test_remove_unsupported_gcc_versions_for_ubuntu2004_and_later(self):
test_param_value_pairs: List[ParameterValuePair] = parse_expected_val_pairs(
[
OD({DEVICE_COMPILER: (GCC, 6), UBUNTU: (UBUNTU, "20.04")}),
OD({HOST_COMPILER: (GCC, 6), UBUNTU: (UBUNTU, "20.04")}),
OD({DEVICE_COMPILER: (GCC, 6), UBUNTU: (UBUNTU, "22.04")}),
OD({HOST_COMPILER: (GCC, 6), UBUNTU: (UBUNTU, "22.04")}),
OD({HOST_COMPILER: (GCC, 3), UBUNTU: (UBUNTU, "22.04")}),
OD({HOST_COMPILER: (GCC, 12), UBUNTU: (UBUNTU, "22.04")}),
OD({HOST_COMPILER: (GCC, 7), UBUNTU: (UBUNTU, "20.04")}),
OD({HOST_COMPILER: (GCC, 3), UBUNTU: (UBUNTU, "20.04")}),
OD({HOST_COMPILER: (GCC, 13), UBUNTU: (UBUNTU, "20.04")}),
OD({HOST_COMPILER: (GCC, 99), UBUNTU: (UBUNTU, "20.04")}),
OD({DEVICE_COMPILER: (GCC, 6), UBUNTU: (UBUNTU, "18.04")}),
OD({DEVICE_COMPILER: (GCC, 6), UBUNTU: (UBUNTU, "18.04")}),
OD({HOST_COMPILER: (GCC, 6), UBUNTU: (UBUNTU, "18.04")}),
OD({HOST_COMPILER: (GCC, 7), UBUNTU: (UBUNTU, "18.04")}),
OD({HOST_COMPILER: (GCC, 3), UBUNTU: (UBUNTU, "18.04")}),
OD({HOST_COMPILER: (GCC, 6), DEVICE_COMPILER: (GCC, 6)}),
OD({HOST_COMPILER: (GCC, 10), DEVICE_COMPILER: (NVCC, 11.2)}),
OD({HOST_COMPILER: (GCC, 6), DEVICE_COMPILER: (NVCC, 11.2)}),
OD({HOST_COMPILER: (GCC, 3), DEVICE_COMPILER: (NVCC, 12.2)}),
]
)
expected_results = parse_expected_val_pairs(
[
OD({HOST_COMPILER: (GCC, 7), UBUNTU: (UBUNTU, "20.04")}),
OD({HOST_COMPILER: (GCC, 12), UBUNTU: (UBUNTU, "22.04")}),
OD({HOST_COMPILER: (GCC, 13), UBUNTU: (UBUNTU, "20.04")}),
OD({HOST_COMPILER: (GCC, 99), UBUNTU: (UBUNTU, "20.04")}),
OD({DEVICE_COMPILER: (GCC, 6), UBUNTU: (UBUNTU, "18.04")}),
OD({HOST_COMPILER: (GCC, 6), UBUNTU: (UBUNTU, "18.04")}),
OD({DEVICE_COMPILER: (GCC, 6), UBUNTU: (UBUNTU, "18.04")}),
OD({HOST_COMPILER: (GCC, 7), UBUNTU: (UBUNTU, "18.04")}),
OD({HOST_COMPILER: (GCC, 3), UBUNTU: (UBUNTU, "18.04")}),
OD({HOST_COMPILER: (GCC, 6), DEVICE_COMPILER: (GCC, 6)}),
OD({HOST_COMPILER: (GCC, 10), DEVICE_COMPILER: (NVCC, 11.2)}),
OD({HOST_COMPILER: (GCC, 6), DEVICE_COMPILER: (NVCC, 11.2)}),
OD({HOST_COMPILER: (GCC, 3), DEVICE_COMPILER: (NVCC, 12.2)}),
]
)
default_remove_test(
_remove_unsupported_gcc_versions_for_ubuntu2004,
test_param_value_pairs,
expected_results,
self,
)
self.assertEqual(
test_param_value_pairs,
expected_results,
create_diff_parameter_value_pairs(test_param_value_pairs, expected_results),
)

0 comments on commit a76f22f

Please sign in to comment.