Skip to content
Snippets Groups Projects
Commit eb6e8c0f authored by Richard Angersbach's avatar Richard Angersbach
Browse files

Check if reduction symbol is (illegally) accessed before/after reduction assignment

parent f0aba2e9
No related branches found
No related tags found
1 merge request!438Reduction Support
...@@ -189,22 +189,12 @@ class FreezeExpressions: ...@@ -189,22 +189,12 @@ class FreezeExpressions:
def map_ReductionAssignment(self, expr: ReductionAssignment): def map_ReductionAssignment(self, expr: ReductionAssignment):
assert isinstance(expr.lhs, TypedSymbol) assert isinstance(expr.lhs, TypedSymbol)
# make sure that either: # make sure that lhs symbol never occurred before ReductionAssignment
# 1) lhs symbol never occurred
# 2) that it is at least known as lhs of an existing reduction operation
if self._ctx.find_symbol(expr.lhs.name): if self._ctx.find_symbol(expr.lhs.name):
# make sure that reduction operations are not mixed within a kernel raise FreezeError(
if info := self._ctx.find_reduction_info(expr.lhs.name): f"Left-hand side {expr.lhs} of ReductionAssignment already exists in symbol table. "
if info.op is not expr.reduction_op: f"Make sure that it is only used once in a kernel's ReductionAssignment."
raise FreezeError( )
f"Different reduction operation {info.op} already exists "
f"for {expr.lhs} with target reduction op {expr.reduction_op}."
)
else:
raise FreezeError(
f"Left-hand side {expr.lhs} of ReductionAssignment already exists in symbol table."
f"Make sure that it is exclusively used within the kernel to conduct ReductionAssignment's."
)
lhs = self.visit(expr.lhs) lhs = self.visit(expr.lhs)
rhs = self.visit(expr.rhs) rhs = self.visit(expr.rhs)
...@@ -340,6 +330,16 @@ class FreezeExpressions: ...@@ -340,6 +330,16 @@ class FreezeExpressions:
def map_TypedSymbol(self, expr: TypedSymbol): def map_TypedSymbol(self, expr: TypedSymbol):
dtype = self._ctx.resolve_dynamic_type(expr.dtype) dtype = self._ctx.resolve_dynamic_type(expr.dtype)
# check if symbol is referenced after freezing a ReductionAssignment
if self._ctx.find_reduction_info(expr.name):
# check if types do not align since a ReductionAssignment modifies
# the symbol's type to PsPointerType in the context's symbol table
if (symbol := self._ctx.find_symbol(expr.name)) and symbol.dtype != dtype:
raise FreezeError(
f"Illegal access to reduction symbol {symbol.name} after freezing a kernel's ReductionAssignment. "
)
symb = self._ctx.get_symbol(expr.name, dtype) symb = self._ctx.get_symbol(expr.name, dtype)
return PsSymbolExpr(symb) return PsSymbolExpr(symb)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment