Newer
Older
from subprocess import CalledProcessError
import pytest
import pystencils
import pystencils.cpu.cpujit
from pystencils.backends.cbackend import CBackend
from pystencils.backends.cuda_backend import CudaBackend
class ScreamingBackend(CBackend):
def _print(self, node):
normal_code = super()._print(node)
return normal_code.upper()
class ScreamingGpuBackend(CudaBackend):
def _print(self, node):
normal_code = super()._print(node)
return normal_code.upper()
normal_assignments = pystencils.AssignmentCollection([pystencils.Assignment(
ast = pystencils.create_kernel(normal_assignments, target=Target.CPU)
pystencils.show_code(ast, ScreamingBackend())
with pytest.raises(CalledProcessError):
pystencils.cpu.cpujit.make_python_function(ast, custom_backend=ScreamingBackend())
pytest.importorskip('cupy')
import cupy
import pystencils.gpu.cudajit
z, x, y = pystencils.fields("z, y, x: [2d]")
normal_assignments = pystencils.AssignmentCollection([pystencils.Assignment(
ast = pystencils.create_kernel(normal_assignments, target=Target.GPU)
pystencils.show_code(ast, ScreamingGpuBackend())
with pytest.raises(cupy.cuda.compiler.JitifyException):
pystencils.gpu.cudajit.make_python_function(ast, custom_backend=ScreamingGpuBackend())