Skip to content

Commit

Permalink
Merge pull request #20 from SimeonEhrig/ruleGPUbackends
Browse files Browse the repository at this point in the history
add different rules, which handles alpaka backends with different compilers
  • Loading branch information
SimeonEhrig authored Mar 26, 2024
2 parents 4d25474 + 9472182 commit 33d0580
Show file tree
Hide file tree
Showing 12 changed files with 5,186 additions and 99 deletions.
174 changes: 170 additions & 4 deletions bashi/filter_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
"""

from typing import Optional, IO
import packaging.version as pkv
from typeguard import typechecked
from bashi.globals import * # pylint: disable=wildcard-import,unused-wildcard-import
from bashi.types import ParameterValueTuple
from bashi.versions import NVCC_GCC_MAX_VERSION, NVCC_CLANG_MAX_VERSION, CLANG_CUDA_MAX_CUDA_VERSION

from bashi.utils import reason


@typechecked
Expand All @@ -23,11 +28,13 @@ def backend_filter_typechecked(
return backend_filter(row, output)


# TODO(SimeonEhrig): remove disable=unused-argument
# only required for the CI at the moment
# pylint: disable=too-many-branches
# pylint: disable=too-many-return-statements
# pylint: disable=too-many-nested-blocks
# pylint: disable=too-many-statements
def backend_filter(
row: ParameterValueTuple, # pylint: disable=unused-argument
output: Optional[IO[str]] = None, # pylint: disable=unused-argument
row: ParameterValueTuple,
output: Optional[IO[str]] = None,
) -> bool:
"""Filter rules basing on backend names and versions.
Expand All @@ -40,4 +47,163 @@ def backend_filter(
Returns:
bool: True, if parameter-value-tuple is valid.
"""

if ALPAKA_ACC_GPU_HIP_ENABLE in row and row[ALPAKA_ACC_GPU_HIP_ENABLE].version != OFF_VER:
# Rule: b1
# related to rule c9
for compiler_type in (HOST_COMPILER, DEVICE_COMPILER):
if compiler_type in row and row[compiler_type].name != HIPCC:
reason(output, "An enabled HIP backend requires hipcc as compiler.")
return False

# Rule: b2
# related to rule c10
if ALPAKA_ACC_SYCL_ENABLE in row and row[ALPAKA_ACC_SYCL_ENABLE].version != OFF_VER:
reason(output, "The HIP and SYCL backend cannot be enabled on the same time.")
return False

# Rule: b3
# related to rule c11
if ALPAKA_ACC_GPU_CUDA_ENABLE in row and row[ALPAKA_ACC_GPU_CUDA_ENABLE].version != OFF_VER:
reason(output, "The HIP and CUDA backend cannot be enabled on the same time.")
return False

if ALPAKA_ACC_SYCL_ENABLE in row and row[ALPAKA_ACC_SYCL_ENABLE].version != OFF_VER:
# Rule: b4
# related to rule c12
for compiler_type in (HOST_COMPILER, DEVICE_COMPILER):
if compiler_type in row and row[compiler_type].name != ICPX:
reason(output, "An enabled SYCL backend requires icpx as compiler.")
return False

# Rule: b5
# related to rule c13
if ALPAKA_ACC_GPU_HIP_ENABLE in row and row[ALPAKA_ACC_GPU_HIP_ENABLE].version != OFF_VER:
reason(output, "The SYCL and HIP backend cannot be enabled on the same time.")
return False

# Rule: b6
# related to rule c14
if ALPAKA_ACC_GPU_CUDA_ENABLE in row and row[ALPAKA_ACC_GPU_CUDA_ENABLE].version != OFF_VER:
reason(output, "The SYCL and CUDA backend cannot be enabled on the same time.")
return False

if ALPAKA_ACC_GPU_CUDA_ENABLE in row and row[ALPAKA_ACC_GPU_CUDA_ENABLE].version == OFF_VER:
# Rule: b7
if DEVICE_COMPILER in row and row[DEVICE_COMPILER].name == NVCC:
reason(output, "CUDA backend needs to be enabled for nvcc")
return False

# Rule: b16
# related to rule c15
for compiler in (HOST_COMPILER, DEVICE_COMPILER):
if compiler in row and row[compiler].name == CLANG_CUDA:
reason(output, f"CUDA backend needs to be enabled for {compiler} clang-cuda")
return False

if ALPAKA_ACC_GPU_CUDA_ENABLE in row and row[ALPAKA_ACC_GPU_CUDA_ENABLE].version != OFF_VER:
# Rule: b8
# related to rule c2
if HOST_COMPILER in row and row[HOST_COMPILER].name in (
set(COMPILERS) - set([GCC, CLANG, NVCC, CLANG_CUDA])
):
reason(
output, f"host-compiler {row[HOST_COMPILER].name} does not support the CUDA backend"
)
return False

# Rule: b9
# related to rule c15
if (
DEVICE_COMPILER in row
and row[DEVICE_COMPILER].name == NVCC
and row[ALPAKA_ACC_GPU_CUDA_ENABLE].version != row[DEVICE_COMPILER].version
):
reason(output, "CUDA backend and nvcc needs to have the same version")
return False

if HOST_COMPILER in row and row[HOST_COMPILER].name == GCC:
# Rule: b10
# related to rule c5
# remove all unsupported cuda sdk gcc version combinations
# define which is the latest supported gcc compiler for a cuda sdk version

# if a cuda sdk version is not supported by bashi, assume that the version supports the
# latest gcc compiler version
if row[ALPAKA_ACC_GPU_CUDA_ENABLE].version <= NVCC_GCC_MAX_VERSION[0].nvcc:
# check the maximum supported gcc version for the given nvcc version
for nvcc_gcc_comb in NVCC_GCC_MAX_VERSION:
if row[ALPAKA_ACC_GPU_CUDA_ENABLE].version >= nvcc_gcc_comb.nvcc:
if row[HOST_COMPILER].version > nvcc_gcc_comb.host:
reason(
output,
f"CUDA {row[ALPAKA_ACC_GPU_CUDA_ENABLE].version} "
f"does not support gcc {row[HOST_COMPILER].version}",
)
return False
break

if HOST_COMPILER in row and row[HOST_COMPILER].name == CLANG:
# Rule: b11
# related to rule c8
if row[ALPAKA_ACC_GPU_CUDA_ENABLE].version >= pkv.parse("11.3") and row[
ALPAKA_ACC_GPU_CUDA_ENABLE
].version <= pkv.parse("11.5"):
reason(
output,
"clang as host compiler is disabled for CUDA 11.3 to 11.5",
)
return False

# Rule: b12
# related to rule c6
if row[ALPAKA_ACC_GPU_CUDA_ENABLE].version <= NVCC_CLANG_MAX_VERSION[0].nvcc:
# check the maximum supported clang version for the given cuda sdk version
for nvcc_clang_comb in NVCC_CLANG_MAX_VERSION:
if row[ALPAKA_ACC_GPU_CUDA_ENABLE].version >= nvcc_clang_comb.nvcc:
if row[HOST_COMPILER].version > nvcc_clang_comb.host:
reason(
output,
f"CUDA {row[ALPAKA_ACC_GPU_CUDA_ENABLE].version} "
f"does not support clang {row[HOST_COMPILER].version}",
)
return False
break

# Rule: b13
# related to rule c2
if DEVICE_COMPILER in row and row[DEVICE_COMPILER].name not in (NVCC, CLANG_CUDA):
reason(output, f"{row[DEVICE_COMPILER].name} does not support the CUDA backend")
return False

# Rule: b14
# related to rule c16
if ALPAKA_ACC_GPU_HIP_ENABLE in row and row[ALPAKA_ACC_GPU_HIP_ENABLE].version != OFF_VER:
reason(output, "The CUDA and HIP backend cannot be enabled on the same time.")
return False

# Rule: b15
# related to rule c17
if ALPAKA_ACC_SYCL_ENABLE in row and row[ALPAKA_ACC_SYCL_ENABLE].version != OFF_VER:
reason(output, "The CUDA and SYCL backend cannot be enabled on the same time.")
return False

# Rule: b17
# related to rule c16
for compiler in (HOST_COMPILER, DEVICE_COMPILER):
if compiler in row and row[compiler].name == CLANG_CUDA:
# if a clang-cuda version is newer than the latest known clang-cuda version,
# we needs to assume that it supports every CUDA SDK version
if row[compiler].version <= CLANG_CUDA_MAX_CUDA_VERSION[0].clang_cuda:
for version_combination in CLANG_CUDA_MAX_CUDA_VERSION:
if row[compiler].version >= version_combination.clang_cuda:
if row[ALPAKA_ACC_GPU_CUDA_ENABLE].version > version_combination.cuda:
reason(
output,
f"CUDA {row[ALPAKA_ACC_GPU_CUDA_ENABLE].version} is not "
f"supported by Clang-CUDA {row[compiler].version}",
)
return False
break

return True
129 changes: 127 additions & 2 deletions bashi/filter_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from typeguard import typechecked
from bashi.globals import * # pylint: disable=wildcard-import,unused-wildcard-import
from bashi.types import ParameterValueTuple
from bashi.versions import NVCC_GCC_MAX_VERSION, NVCC_CLANG_MAX_VERSION
from bashi.versions import NVCC_GCC_MAX_VERSION, NVCC_CLANG_MAX_VERSION, CLANG_CUDA_MAX_CUDA_VERSION
from bashi.utils import reason

# uncomment me for debugging
Expand All @@ -32,6 +32,7 @@ def compiler_filter_typechecked(

# pylint: disable=too-many-branches
# pylint: disable=too-many-return-statements
# pylint: disable=too-many-statements
def compiler_filter(
row: ParameterValueTuple,
output: Optional[IO[str]] = None,
Expand All @@ -48,7 +49,7 @@ def compiler_filter(
bool: True, if parameter-value-tuple is valid.
"""
# uncomment me for debugging
# print_row_nice(row)
# print_row_nice(row, bashi_validate=False)

# Rule: c1
# NVCC as HOST_COMPILER is not allow
Expand All @@ -62,6 +63,7 @@ def compiler_filter(
if HOST_COMPILER in row and DEVICE_COMPILER in row:
if NVCC in (row[HOST_COMPILER].name, row[DEVICE_COMPILER].name):
# Rule: c2
# related to rule c13
if row[HOST_COMPILER].name not in (GCC, CLANG):
reason(output, "only gcc and clang are allowed as nvcc host compiler")
return False
Expand All @@ -84,6 +86,7 @@ def compiler_filter(
if DEVICE_COMPILER in row and row[DEVICE_COMPILER].name == NVCC:
if HOST_COMPILER in row and row[HOST_COMPILER].name == GCC:
# Rule: c5
# related to rule b10
# remove all unsupported nvcc gcc version combinations
# define which is the latest supported gcc compiler for a nvcc version

Expand All @@ -104,6 +107,7 @@ def compiler_filter(

if HOST_COMPILER in row and row[HOST_COMPILER].name == CLANG:
# Rule: c7
# related to rule b11
if row[DEVICE_COMPILER].version >= pkv.parse("11.3") and row[
DEVICE_COMPILER
].version <= pkv.parse("11.5"):
Expand All @@ -114,6 +118,7 @@ def compiler_filter(
return False

# Rule: c6
# related to rule b12
# remove all unsupported nvcc clang version combinations
# define which is the latest supported clang compiler for a nvcc version

Expand All @@ -132,7 +137,29 @@ def compiler_filter(
return False
break

# Rule: c15
# related to rule b9
if (
ALPAKA_ACC_GPU_CUDA_ENABLE in row
and row[ALPAKA_ACC_GPU_CUDA_ENABLE].version != row[DEVICE_COMPILER].version
):
reason(output, "nvcc and CUDA backend needs to have the same version")
return False

# Rule: c16
# related to rule b14
if ALPAKA_ACC_GPU_HIP_ENABLE in row and row[ALPAKA_ACC_GPU_HIP_ENABLE].version != OFF_VER:
reason(output, "nvcc does not support the HIP backend.")
return False

# Rule: c17
# related to rule b15
if ALPAKA_ACC_SYCL_ENABLE in row and row[ALPAKA_ACC_SYCL_ENABLE].version != OFF_VER:
reason(output, "nvcc does not support the SYCL backend.")
return False

# Rule: c8
# related to rule b11
# 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
Expand All @@ -146,4 +173,102 @@ def compiler_filter(
reason(output, "all clang versions older than 14 are disabled as CUDA Compiler")
return False

for compiler in (HOST_COMPILER, DEVICE_COMPILER):
if compiler in row and row[compiler].name == HIPCC:
# Rule: c9
# related to rule b1
if (
ALPAKA_ACC_GPU_HIP_ENABLE in row
and row[ALPAKA_ACC_GPU_HIP_ENABLE].version == OFF_VER
):
reason(output, "hipcc requires an enabled HIP backend.")
return False

# Rule: c10
# related to rule b2
if ALPAKA_ACC_SYCL_ENABLE in row and row[ALPAKA_ACC_SYCL_ENABLE].version != OFF_VER:
reason(output, "hipcc does not support the SYCL backend.")
return False

# Rule: c11
# related to rule b2
if (
ALPAKA_ACC_GPU_CUDA_ENABLE in row
and row[ALPAKA_ACC_GPU_CUDA_ENABLE].version != OFF_VER
):
reason(output, "hipcc does not support the CUDA backend.")
return False

if compiler in row and row[compiler].name == ICPX:
# Rule: c12
# related to rule b4
if ALPAKA_ACC_SYCL_ENABLE in row and row[ALPAKA_ACC_SYCL_ENABLE].version == OFF_VER:
reason(output, "icpx requires an enabled SYCL backend.")
return False

# Rule: c13
# related to rule b5
if (
ALPAKA_ACC_GPU_HIP_ENABLE in row
and row[ALPAKA_ACC_GPU_HIP_ENABLE].version != OFF_VER
):
reason(output, "icpx does not support the HIP backend.")
return False

# Rule: c14
# related to rule b6
if (
ALPAKA_ACC_GPU_CUDA_ENABLE in row
and row[ALPAKA_ACC_GPU_CUDA_ENABLE].version != OFF_VER
):
reason(output, "icpx does not support the CUDA backend.")
return False

if compiler in row and row[compiler].name == CLANG_CUDA:
# Rule: c15
# related to rule b16
if (
ALPAKA_ACC_GPU_CUDA_ENABLE in row
and row[ALPAKA_ACC_GPU_CUDA_ENABLE].version == OFF_VER
):
reason(output, "clang-cuda requires an enabled CUDA backend.")
return False

if (
ALPAKA_ACC_GPU_CUDA_ENABLE in row
and row[ALPAKA_ACC_GPU_CUDA_ENABLE].version != OFF_VER
):
# Rule: c16
# related to rule b17
# if a clang-cuda version is newer than the latest known clang-cuda version,
# we needs to assume that it supports every CUDA SDK version
# pylint: disable=duplicate-code
if row[compiler].version <= CLANG_CUDA_MAX_CUDA_VERSION[0].clang_cuda:
# check if know clang-cuda version supports CUDA SDK version
for version_combination in CLANG_CUDA_MAX_CUDA_VERSION:
if row[compiler].version >= version_combination.clang_cuda:
if row[ALPAKA_ACC_GPU_CUDA_ENABLE].version > version_combination.cuda:
reason(
output,
f"clang-cuda {row[compiler].version} does not support "
f"CUDA {row[ALPAKA_ACC_GPU_CUDA_ENABLE].version}.",
)
return False
break

# Rule: c17
# related to rule b14
if (
ALPAKA_ACC_GPU_HIP_ENABLE in row
and row[ALPAKA_ACC_GPU_HIP_ENABLE].version != OFF_VER
):
reason(output, "clang-cuda does not support the HIP backend.")
return False

# Rule: c18
# related to rule b15
if ALPAKA_ACC_SYCL_ENABLE in row and row[ALPAKA_ACC_SYCL_ENABLE].version != OFF_VER:
reason(output, "clang-cuda does not support the SYCL backend.")
return False

return True
Loading

0 comments on commit 33d0580

Please sign in to comment.