Skip to content

Commit

Permalink
Merge pull request #17 from SimeonEhrig/RuleClangCudaMinVersion
Browse files Browse the repository at this point in the history
add rule which disallow clang-cuda 13 and older
  • Loading branch information
SimeonEhrig authored Feb 15, 2024
2 parents 209a5df + 5d025ad commit 3c778af
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 24 deletions.
13 changes: 13 additions & 0 deletions bashi/filter_compiler_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,17 @@ def compiler_version_filter(
return False
break

# Rule: v5
# clang-cuda 13 and older is not supported
# this rule will be never used, because of an implementation detail of the covertable library
# it is not possible to add the clang-cuda versions and filter it out afterwards
# this rule is only used by bashi-verify
if (
DEVICE_COMPILER in row
and row[DEVICE_COMPILER].name == CLANG_CUDA
and row[DEVICE_COMPILER].version < pkv.parse("14")
):
reason(output, "all clang versions older than 14 are disabled as CUDA Compiler")
return False

return True
39 changes: 37 additions & 2 deletions bashi/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from typing import Dict, List
from collections import OrderedDict
import copy
import packaging.version as pkv

from covertable import make # type: ignore

Expand All @@ -13,6 +15,7 @@
Combination,
CombinationList,
)
from bashi.globals import * # pylint: disable=wildcard-import,unused-wildcard-import
from bashi.filter_chain import get_default_filter_chain


Expand All @@ -31,12 +34,44 @@ def generate_combination_list(
Returns:
CombinationList: combination-list
"""
# use local version to do not modify parameter_value_matrix
local_param_val_mat = copy.deepcopy(parameter_value_matrix)

filter_chain = get_default_filter_chain(custom_filter)

def host_compiler_filter(param_val: ParameterValue) -> bool:
# Rule: n1
# remove nvcc as host compiler
if param_val.name == NVCC:
return False
# Rule: v5
# remove clang-cuda older than 14
if param_val.name == CLANG_CUDA and param_val.version < pkv.parse("14"):
return False

return True

def device_compiler_filter(param_val: ParameterValue) -> bool:
# Rule: v5
# remove clang-cuda older than 14
if param_val.name == CLANG_CUDA and param_val.version < pkv.parse("14"):
return False

return True

pre_filters = {HOST_COMPILER: host_compiler_filter, DEVICE_COMPILER: device_compiler_filter}

# some filter rules requires that specific parameter-values are already removed from the
# parameter-value-matrix
# otherwise the covertable library throws an error
for param, filter_func in pre_filters.items():
if param in local_param_val_mat:
local_param_val_mat[param] = list(filter(filter_func, local_param_val_mat[param]))

comb_list: CombinationList = []

all_pairs: List[Dict[Parameter, ParameterValue]] = make(
factors=parameter_value_matrix,
factors=local_param_val_mat,
length=2,
pre_filter=filter_chain,
) # type: ignore
Expand All @@ -46,7 +81,7 @@ def generate_combination_list(
tmp_comb: Combination = OrderedDict({})
# covertable does not keep the ordering of the parameters
# therefore we sort it
for param in parameter_value_matrix.keys():
for param in local_param_val_mat.keys():
tmp_comb[param] = all_pair[param]
comb_list.append(tmp_comb)

Expand Down
42 changes: 35 additions & 7 deletions bashi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dataclasses
import sys
import copy
from collections import OrderedDict
from typing import IO, Dict, List, Optional, Union

Expand Down Expand Up @@ -316,7 +317,9 @@ def reason(output: Optional[IO[str]], msg: str):
)


# TODO(SimeonEhrig) modularize the function
# pylint: disable=too-many-branches
# pylint: disable=too-many-locals
@typechecked
def get_expected_bashi_parameter_value_pairs(
parameter_matrix: ParameterValueMatrix,
Expand All @@ -331,9 +334,34 @@ def get_expected_bashi_parameter_value_pairs(
Returns:
List[ParameterValuePair]: list of all parameter-value-pairs supported by bashi
"""
param_val_pair_list = get_expected_parameter_value_pairs(parameter_matrix)
local_parameter_matrix = copy.deepcopy(parameter_matrix)

extend_versions = VERSIONS.copy()
def remove_host_compiler_nvcc(param_val: ParameterValue) -> bool:
if param_val.name == NVCC:
return False
return True

# remove nvcc as host compiler
local_parameter_matrix[HOST_COMPILER] = list(
filter(remove_host_compiler_nvcc, local_parameter_matrix[HOST_COMPILER])
)

# remove clang-cuda 13 and older
def remove_unsupported_clang_cuda_version(param_val: ParameterValue) -> bool:
if param_val.name == CLANG_CUDA and param_val.version < packaging.version.parse("14"):
return False
return True

local_parameter_matrix[HOST_COMPILER] = list(
filter(remove_unsupported_clang_cuda_version, local_parameter_matrix[HOST_COMPILER])
)
local_parameter_matrix[DEVICE_COMPILER] = list(
filter(remove_unsupported_clang_cuda_version, local_parameter_matrix[DEVICE_COMPILER])
)

param_val_pair_list = get_expected_parameter_value_pairs(local_parameter_matrix)

extend_versions = copy.deepcopy(VERSIONS)
extend_versions[CLANG_CUDA] = extend_versions[CLANG]

# remove all combinations where nvcc is device compiler and the host compiler is not gcc or
Expand Down Expand Up @@ -390,15 +418,15 @@ def get_expected_bashi_parameter_value_pairs(
gcc_versions = [packaging.version.parse(str(v)) for v in VERSIONS[GCC]]
gcc_versions.sort()
for nvcc_version in nvcc_versions:
for max_nvcc_clang_version in NVCC_GCC_MAX_VERSION:
if nvcc_version >= max_nvcc_clang_version.nvcc:
for clang_version in gcc_versions:
if clang_version > max_nvcc_clang_version.host:
for max_nvcc_gcc_version in NVCC_GCC_MAX_VERSION:
if nvcc_version >= max_nvcc_gcc_version.nvcc:
for gcc_version in gcc_versions:
if gcc_version > max_nvcc_gcc_version.host:
remove_parameter_value_pair(
to_remove=create_parameter_value_pair(
HOST_COMPILER,
GCC,
clang_version,
gcc_version,
DEVICE_COMPILER,
NVCC,
nvcc_version,
Expand Down
11 changes: 4 additions & 7 deletions bashi/versions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Provides all supported software versions"""

import copy
from typing import Dict, List, Union
from collections import OrderedDict
from typeguard import typechecked
Expand Down Expand Up @@ -111,6 +112,7 @@ def __str__(self) -> str:
NVCC_CLANG_MAX_VERSION.sort(reverse=True)


# pylint: disable=too-many-branches
def get_parameter_value_matrix() -> ParameterValueMatrix:
"""Generates a parameter-value-matrix from all supported compilers, softwares and compilation
configuration.
Expand All @@ -120,17 +122,12 @@ def get_parameter_value_matrix() -> ParameterValueMatrix:
"""
param_val_matrix: ParameterValueMatrix = OrderedDict()

extended_version = VERSIONS.copy()
extended_version = copy.deepcopy(VERSIONS)
extended_version[CLANG_CUDA] = extended_version[CLANG]

for compiler_type in [HOST_COMPILER, DEVICE_COMPILER]:
param_val_matrix[compiler_type] = []
for sw_name, sw_versions in extended_version.items():
# do not add NVCC as HOST_COMPILER
# filtering out all NVCC as HOST_COMPILER later does not work with the covertable
# library
if compiler_type == HOST_COMPILER and sw_name == NVCC:
continue
if sw_name in COMPILERS:
for sw_version in sw_versions:
param_val_matrix[compiler_type].append(
Expand Down Expand Up @@ -178,7 +175,7 @@ def is_supported_version(name: ValueName, version: ValueVersion) -> bool:
if name not in known_names:
raise ValueError(f"Unknown software name: {name}")

local_versions = VERSIONS.copy()
local_versions = copy.deepcopy(VERSIONS)

local_versions[CLANG_CUDA] = local_versions[CLANG]
local_versions[ALPAKA_ACC_GPU_CUDA_ENABLE] = [OFF]
Expand Down
78 changes: 78 additions & 0 deletions tests/test_clang_cuda_filter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# 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_compiler_version import compiler_version_filter_typechecked


class TestClangCudaOldVersions(unittest.TestCase):
def test_valid_clang_cuda_versions_rule_v5(self):
for clang_cuda_version in [14, 16, 18, 78]:
self.assertTrue(
compiler_version_filter_typechecked(
OD(
{
HOST_COMPILER: ppv((CLANG_CUDA, clang_cuda_version)),
DEVICE_COMPILER: ppv((CLANG_CUDA, clang_cuda_version)),
}
)
)
)

def test_valid_clang_cuda_versions_multi_row_rule_v5(self):
for clang_cuda_version in [14, 16, 18, 78]:
self.assertTrue(
compiler_version_filter_typechecked(
OD(
{
HOST_COMPILER: ppv((CLANG_CUDA, clang_cuda_version)),
ALPAKA_ACC_GPU_CUDA_ENABLE: ppv((ALPAKA_ACC_GPU_CUDA_ENABLE, 11.2)),
DEVICE_COMPILER: ppv((CLANG_CUDA, clang_cuda_version)),
CMAKE: ppv((CMAKE, 3.22)),
}
),
)
)

def test_invalid_clang_cuda_versions_rule_v5(self):
for clang_cuda_version in [13, 7, 1]:
reason_msg = io.StringIO()
self.assertFalse(
compiler_version_filter_typechecked(
OD(
{
HOST_COMPILER: ppv((CLANG_CUDA, clang_cuda_version)),
DEVICE_COMPILER: ppv((CLANG_CUDA, clang_cuda_version)),
}
),
reason_msg,
)
)
self.assertEqual(
reason_msg.getvalue(),
"all clang versions older than 14 are disabled as CUDA Compiler",
)

def test_invalid_clang_cuda_versions_multi_row_rule_v5(self):
for clang_cuda_version in [13, 7, 1]:
reason_msg = io.StringIO()
self.assertFalse(
compiler_version_filter_typechecked(
OD(
{
HOST_COMPILER: ppv((CLANG_CUDA, clang_cuda_version)),
ALPAKA_ACC_GPU_CUDA_ENABLE: ppv((ALPAKA_ACC_GPU_CUDA_ENABLE, 11.2)),
DEVICE_COMPILER: ppv((CLANG_CUDA, clang_cuda_version)),
CMAKE: ppv((CMAKE, 3.22)),
}
),
reason_msg,
)
)
self.assertEqual(
reason_msg.getvalue(),
"all clang versions older than 14 are disabled as CUDA Compiler",
)
3 changes: 2 additions & 1 deletion tests/test_expected_parameter_value_pairs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pylint: disable=missing-docstring
import unittest
import copy
from typing import List, Dict
from collections import OrderedDict
import io
Expand Down Expand Up @@ -635,7 +636,7 @@ def test_remove_parameter_value_pair_all_versions(self):

expected_number_of_reduced_pairs = len(reduced_param_value_pairs)

expected_reduced_param_value_pairs = reduced_param_value_pairs.copy()
expected_reduced_param_value_pairs = copy.deepcopy(reduced_param_value_pairs)

# remove single value to verify that default flag is working
example_single_pair = create_parameter_value_pair(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_filter_compiler_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def test_valid_combination_rule_v1(self):
compiler_version_filter_typechecked(
OD(
{
HOST_COMPILER: ppv((CLANG_CUDA, 10)),
HOST_COMPILER: ppv((CLANG_CUDA, 14)),
ALPAKA_ACC_GPU_CUDA_ENABLE: ppv((ALPAKA_ACC_GPU_CUDA_ENABLE, 11.2)),
DEVICE_COMPILER: ppv((CLANG_CUDA, 10)),
DEVICE_COMPILER: ppv((CLANG_CUDA, 14)),
CMAKE: ppv((CMAKE, 3.18)),
}
)
Expand Down
Loading

0 comments on commit 3c778af

Please sign in to comment.