From dc431ef2bf34465b382cd1866f8220b675b400a8 Mon Sep 17 00:00:00 2001 From: Markus Holzer <markus.holzer@fau.de> Date: Thu, 4 Jul 2024 12:55:44 +0200 Subject: [PATCH] Fix original tests --- tests/test_gpu.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/test_gpu.py b/tests/test_gpu.py index 589da44e..7e35a4f9 100644 --- a/tests/test_gpu.py +++ b/tests/test_gpu.py @@ -2,6 +2,7 @@ import pytest import numpy as np import sympy as sp +import math from scipy.ndimage import convolve from pystencils import Assignment, Field, fields, CreateKernelConfig, create_kernel, Target, get_code_str @@ -231,15 +232,26 @@ def test_guards_with_iteration_slices(start, end, step, shape): field_1 = fields(f"f(1) : double{list(shape)}") assignment = Assignment(field_1.center, 1) ast = create_kernel(assignment, config=kernel_config_gpu) - code_str = get_code_str(ast) test_strings = list() + iteration_ranges = list() for i, s in enumerate(iter_slice): - end = shape[i] + s.stop - end = end // s.step - test_strings.append(f"{s.start} < {end}") - + e = ((shape[i] + end) - s.start) / s.step + e = math.ceil(e) + s.start + test_strings.append(f"{s.start} < {e}") + + a = s.start + counter = 0 + while a < e: + a += 1 + counter += 1 + iteration_ranges.append(counter) + + # check if the expected if statement is in the GPU code for s in test_strings: assert s in code_str + # check if these bounds lead to same lengths as the range function would produce + for i in range(len(iter_slice)): + assert iteration_ranges[i] == len(range(iter_slice[i].start, shape[i] + end, iter_slice[i].step)) -- GitLab