From 82ce1d7dcc28c621889699ef02821549d516ae43 Mon Sep 17 00:00:00 2001 From: Christoph Alt <christoph.alt@fau.de> Date: Tue, 15 Aug 2023 12:37:10 +0200 Subject: [PATCH] Fix the missing constants for the gpu main file and added a kernel with a constant to the gpu tests --- pystencils_benchmark/templates/gpu/main.c | 6 ++++++ tests/test_benchmark.py | 8 +++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pystencils_benchmark/templates/gpu/main.c b/pystencils_benchmark/templates/gpu/main.c index b2f3571..1373048 100644 --- a/pystencils_benchmark/templates/gpu/main.c +++ b/pystencils_benchmark/templates/gpu/main.c @@ -32,6 +32,12 @@ int main(int argc, char **argv) cudaMemset({{field_name}}, 0.23, {{elements}}); {% endfor %} + {% for constantName, dataType in kernel.constants %} + // Constant {{constantName}} + {{dataType}} {{constantName}}; + {{constantName}} = 0.23; + {% endfor %} + dim3 blocks({{kernel.blocks[0]}}, {{kernel.blocks[1]}}, {{kernel.blocks[2]}}); dim3 grid({{kernel.grid[0]}}, {{kernel.grid[1]}}, {{kernel.grid[2]}}); diff --git a/tests/test_benchmark.py b/tests/test_benchmark.py index 62881ec..fe3946b 100755 --- a/tests/test_benchmark.py +++ b/tests/test_benchmark.py @@ -48,14 +48,20 @@ gpu_kwargs = ({}, {'launch_bounds': (256,)}, {'launch_bounds': (256, 2)}) def test_generate_gpu(kwargs): compiler = Compiler.NVCC a, b, c = ps.fields(a=np.ones(4000000), b=np.ones(4000000), c=np.ones(4000000)) + alpha = sp.symbols('alpha') @ps.kernel_config(ps.CreateKernelConfig(target=ps.Target.GPU)) def vadd(): a[0] @= b[0] + c[0] kernel_vadd = ps.create_kernel(**vadd) + @ps.kernel_config(ps.CreateKernelConfig(target=ps.Target.GPU)) + def daxpy(): + b[0] @= alpha * a[0] + b[0] + kernel_daxpy = ps.create_kernel(**daxpy) + with tempfile.TemporaryDirectory(dir=Path.cwd()) as temp_dir: temp_dir = Path(temp_dir) - pb.gpu.generate_benchmark(kernel_vadd, temp_dir, compiler=compiler, **kwargs) + pb.gpu.generate_benchmark([kernel_vadd, kernel_daxpy], temp_dir, compiler=compiler, **kwargs) subprocess.run(['make', '-C', f'{temp_dir}'], check=True) subprocess.run([f'{temp_dir}/benchmark-{compiler.name}', '10'], check=True) -- GitLab