Skip to content
Snippets Groups Projects

[BUGFIX] GPU slicing

Merged Markus Holzer requested to merge holzer/pystencils:FixGPUIndexing into master
Viewing commit dc431ef2
Prev
Show latest version
1 file
+ 17
5
Preferences
Compare changes
+ 17
5
@@ -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))