Skip to content

Commit

Permalink
Error out cleanly for gt:gpu and CUDA < 12
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Deconinck committed Sep 19, 2024
1 parent 2846713 commit 8fb7452
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
19 changes: 14 additions & 5 deletions src/gt4py/cartesian/frontend/gtscript_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ def __init__(
fields: dict,
parameters: dict,
local_symbols: dict,
backend_name: str,
*,
domain: nodes.Domain,
temp_decls: Optional[Dict[str, nodes.FieldDecl]] = None,
Expand All @@ -721,6 +722,7 @@ def __init__(
isinstance(value, (type, np.dtype)) for value in local_symbols.values()
)

self.backend_name = backend_name
self.fields = fields
self.parameters = parameters
self.local_symbols = local_symbols
Expand Down Expand Up @@ -1437,15 +1439,21 @@ def visit_Assign(self, node: ast.Assign) -> list:
message="Assignment to non-zero offsets is not supported in IJ.",
loc=nodes.Location.from_ast_node(t),
)
# Case of K-offset
if (
len(spatial_offset) == 3
and spatial_offset[2] != 0
and self.iteration_order == nodes.IterationOrder.PARALLEL
):
raise GTScriptSyntaxError(
message="Assignment to non-zero offsets in K is not available in PARALLEL. Choose FORWARD or BACKWARD.",
loc=nodes.Location.from_ast_node(t),
)
if (self.iteration_order == nodes.IterationOrder.PARALLEL):
raise GTScriptSyntaxError(
message="Assignment to non-zero offsets in K is not available in PARALLEL. Choose FORWARD or BACKWARD.",
loc=nodes.Location.from_ast_node(t))
if self.backend_name == "gt:gpu":
import cupy as cp
if cp.cuda.get_local_runtime_version() < 12000:
raise GTScriptSyntaxError(
message="Assignment to non-zero offsets in K is not available in gt:gpu for CUDA<12. Please update CUDA.",
loc=nodes.Location.from_ast_node(t))

if not self._is_known(name):
if name in self.temp_decls:
Expand Down Expand Up @@ -2064,6 +2072,7 @@ def run(self):
fields=fields_decls,
parameters=parameter_decls,
local_symbols={}, # Not used
backend_name=self.options.backend_opts["backend_name"],
domain=domain,
temp_decls=temp_decls,
dtypes=self.dtypes,
Expand Down
1 change: 1 addition & 0 deletions src/gt4py/cartesian/stencil_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ def pkg_path(self) -> pathlib.Path:

@property
def gtir_pipeline(self) -> GtirPipeline:
self.options.backend_opts["backend_name"] = self.backend.name
return self._build_data.get("gtir_pipeline") or self._build_data.setdefault(
"gtir_pipeline",
GtirPipeline(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,10 +655,16 @@ def backward(A: Field[np.float64], B: Field[np.float64], scalar: np.float64):
assert (B[:, :, :] == A[:, :, :]).all()


@pytest.mark.parametrize("backend", ALL_BACKENDS)
@pytest.mark.parametrize("backend", ["gt:gpu"])
def test_K_offset_write_conditional(backend):
if backend == "cuda":
pytest.skip("Cuda backend is not capable of K offset write")
if backend == "gt:gpu":
import cupy as cp
if cp.cuda.get_local_runtime_version() < 12000:
pytest.skip(
"gt:gpu backend with CUDA 11 is not capable of K offset write, update CUDA if possible"
)

arraylib = get_array_library(backend)
array_shape = (1, 1, 4)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


def test_AugAssign():
ir_maker = IRMaker(None, None, None, domain=None)
ir_maker = IRMaker(None, None, None, None, domain=None)
aug_assign = ast.parse("a += 1", feature_version=PYTHON_AST_VERSION).body[0]

_, result = ir_maker.visit_AugAssign(aug_assign)
Expand Down

0 comments on commit 8fb7452

Please sign in to comment.