Skip to content
Snippets Groups Projects
Commit f8ed8ad8 authored by Christoph Alt's avatar Christoph Alt
Browse files

Added a generator script to test the sycl accessors

parent 0ee586ef
No related branches found
No related tags found
1 merge request!3Add support for sycl accessors
import pystencils as ps
import sympy as sp
from pystencilssfg import SourceFileGenerator
from pystencilssfg.lang.cpp.sycl_accessor import sycl_accessor_ref
import pystencilssfg.extensions.sycl as sycl
with SourceFileGenerator() as sfg:
sfg = sycl.SyclComposer(sfg)
u_src, u_dst, f = ps.fields("u_src, u_dst, f : double[2D]", layout="fzyx")
h = sp.Symbol("h")
jacobi_update = [
ps.Assignment(
u_dst.center(),
(h**2 * f[0, 0] + u_src[1, 0] + u_src[-1, 0] + u_src[0, 1] + u_src[0, -1])
/ 4,
)
]
kernel_config = ps.CreateKernelConfig(target=ps.Target.SYCL)
jacobi_kernel = sfg.kernels.create(jacobi_update, config=kernel_config)
cgh = sfg.sycl_handler("handler")
rang = sfg.sycl_range(2, "range")
mappings = [
sfg.map_field(u_src, sycl_accessor_ref(u_src)),
sfg.map_field(u_dst, sycl_accessor_ref(u_dst)),
sfg.map_field(f, sycl_accessor_ref(f)),
]
sfg.function("jacobiUpdate")(
cgh.parallel_for(rang)(*mappings, sfg.call(jacobi_kernel)),
)
......@@ -74,7 +74,7 @@ SCRIPTS = [
"--sfg-file-extensionss",
".c++,.h++",
),
should_fail=True
should_fail=True,
),
ScriptInfo.make(
"TestExtraCommandLineArgs",
......@@ -85,13 +85,19 @@ SCRIPTS = [
"--precision",
"float32",
"test1",
"test2"
"test2",
),
),
ScriptInfo.make("Structural", ("hpp", "cpp")),
ScriptInfo.make("SimpleJacobi", ("hpp", "cpp"), compilable_output="cpp"),
ScriptInfo.make("SimpleClasses", ("hpp", "cpp")),
ScriptInfo.make("Variables", ("hpp", "cpp"), compilable_output="cpp"),
ScriptInfo.make(
"TestSyclBuffer",
("hpp", "cpp"),
compilable_output="cpp" if shutil.which("icpx") else None,
compile_cmd="icpx -fsycl -std=c++20" if shutil.which("icpx") else "",
),
]
......@@ -113,13 +119,17 @@ def test_generator_script(script_info: ScriptInfo):
shutil.rmtree(output_dir)
os.makedirs(output_dir, exist_ok=True)
args = ["python", script_file, "--sfg-output-dir", output_dir] + list(script_info.args)
args = ["python", script_file, "--sfg-output-dir", output_dir] + list(
script_info.args
)
result = subprocess.run(args)
if script_info.should_fail:
if result.returncode == 0:
pytest.fail(f"Generator script {script_name} was supposed to fail, but didn't.")
pytest.fail(
f"Generator script {script_name} was supposed to fail, but didn't."
)
return
if result.returncode != 0:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment