Skip to content
Snippets Groups Projects
Commit c5f59fed authored by Stephan Seitz's avatar Stephan Seitz
Browse files

Teach SympyPrinters how to print Type

PointerType should be rendered differently in OpenCL backend
parent f1537570
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@ import numpy as np
import sympy as sp
from sympy.core import S
from sympy.printing.ccode import C89CodePrinter
from pystencils.astnodes import KernelFunction, Node
from pystencils.cpu.vectorization import vec_all, vec_any
from pystencils.data_types import (
......@@ -344,6 +345,9 @@ class CustomSympyPrinter(CCodePrinter):
result = super(CustomSympyPrinter, self)._print_Piecewise(expr)
return result.replace("\n", "")
def _print_Type(self, node):
return str(node)
def _print_Function(self, expr):
infix_functions = {
bitwise_xor: '^',
......@@ -356,7 +360,7 @@ class CustomSympyPrinter(CCodePrinter):
return expr.to_c(self._print)
if isinstance(expr, reinterpret_cast_func):
arg, data_type = expr.args
return "*((%s)(& %s))" % (PointerType(data_type, restrict=False), self._print(arg))
return "*((%s)(& %s))" % (self._print(PointerType(data_type, restrict=False)), self._print(arg))
elif isinstance(expr, address_of):
assert len(expr.args) == 1, "address_of must only have one argument"
return "&(%s)" % self._print(expr.args[0])
......
......@@ -68,6 +68,13 @@ class OpenClSympyPrinter(CudaSympyPrinter):
CustomSympyPrinter.__init__(self)
self.known_functions = OPENCL_KNOWN_FUNCTIONS
def _print_Type(self, node):
code = super()._print_Type(node)
if isinstance(node, pystencils.data_types.PointerType):
return "__global " + code
else:
return code
def _print_ThreadIndexingSymbol(self, node):
symbol_name: str = node.name
function_name, dimension = tuple(symbol_name.split("."))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment