Commit 0b27d3c3 authored by Stephan Seitz's avatar Stephan Seitz
Browse files

Add OpenCLBackend

parent 69f779ea
......@@ -58,6 +58,9 @@ def generate_c(ast_node: Node, signature_only: bool = False, dialect='c', custom
elif dialect == 'cuda':
from pystencils.backends.cuda_backend import CudaBackend
printer = CudaBackend(signature_only=signature_only)
elif dialect == 'opencl':
from pystencils.backends.opencl_backend import OpenCLBackend
printer = OpenCLBackend(signature_only=signature_only)
raise ValueError("Unknown dialect: " + str(dialect))
code = printer(ast_node)
from pystencils.backends.cuda_backend import CudaBackend
from pystencils.backends.cbackend import generate_c
from pystencils.astnodes import Node
def generate_opencl(astnode: Node, signature_only: bool = False) -> str:
"""Prints an abstract syntax tree node as CUDA code.
astnode: KernelFunction node to generate code for
signature_only: if True only the signature is printed
C-like code for the ast node and its descendants
return generate_c(astnode, signature_only, dialect='opencl')
class OpenCLBackend(CudaBackend):
\ No newline at end of file
import sympy as sp
import pystencils
from pystencils.backends.cuda_backend import CudaBackend
from pystencils.backends.opencl_backend import OpenCLBackend
def test_opencl_backend():
z, y, x = pystencils.fields("z, y, x: [2d]")
assignments = pystencils.AssignmentCollection({
z[0, 0]: x[0, 0] * sp.log(x[0, 0] * y[0, 0])
ast = pystencils.create_kernel(assignments, target='gpu')
code = pystencils.show_code(ast, custom_backend=CudaBackend())
opencl_code = pystencils.show_code(ast, custom_backend=OpenCLBackend())
if __name__ == '__main__':
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment