Skip to content
Snippets Groups Projects

Vectorize all scalar symbols in vector expressions

Merged Daniel Bauer requested to merge terraneo/pystencils:bauerd/fix-vectorize into master
1 file
+ 24
3
Compare changes
  • Side-by-side
  • Inline
@@ -41,7 +41,7 @@ def test_vector_type_propagation(instruction_set=instruction_set):
@@ -41,7 +41,7 @@ def test_vector_type_propagation(instruction_set=instruction_set):
np.testing.assert_equal(dst[1:-1, 1:-1], 2 * 10.0 + 3)
np.testing.assert_equal(dst[1:-1, 1:-1], 2 * 10.0 + 3)
def test_vectorize_moved_constants(instruction_set=instruction_set):
def test_vectorize_moved_constants1(instruction_set=instruction_set):
opt = {'instruction_set': instruction_set, 'assume_inner_stride_one': True}
opt = {'instruction_set': instruction_set, 'assume_inner_stride_one': True}
f = ps.fields("f: [1D]")
f = ps.fields("f: [1D]")
@@ -49,10 +49,10 @@ def test_vectorize_moved_constants(instruction_set=instruction_set):
@@ -49,10 +49,10 @@ def test_vectorize_moved_constants(instruction_set=instruction_set):
kernel_func = ps.create_kernel(
kernel_func = ps.create_kernel(
[ast.SympyAssignment(x, 2.0), ast.SympyAssignment(f[0], x)],
[ast.SympyAssignment(x, 2.0), ast.SympyAssignment(f[0], x)],
cpu_prepend_optimizations=[ps.transformations.move_constants_before_loop], # explicitly move constants
cpu_prepend_optimizations=[ps.transformations.move_constants_before_loop], # explicitly move constants
cpu_vectorize_info=opt,
cpu_vectorize_info=opt,
)
)
ps.show_code(kernel_func) # fails if `x` on rhs was not correctly vectorized
ps.show_code(kernel_func) # fails if `x` on rhs was not correctly vectorized
kernel = kernel_func.compile()
kernel = kernel_func.compile()
f_arr = np.zeros(9)
f_arr = np.zeros(9)
@@ -61,6 +61,27 @@ def test_vectorize_moved_constants(instruction_set=instruction_set):
@@ -61,6 +61,27 @@ def test_vectorize_moved_constants(instruction_set=instruction_set):
assert(np.all(f_arr == 2))
assert(np.all(f_arr == 2))
 
def test_vectorize_moved_constants2(instruction_set=instruction_set):
 
opt = {'instruction_set': instruction_set, 'assume_inner_stride_one': True}
 
 
f = ps.fields("f: [1D]")
 
x = ast.TypedSymbol("x", np.float64)
 
y = ast.TypedSymbol("y", np.float64)
 
 
kernel_func = ps.create_kernel(
 
[ast.SympyAssignment(x, 2.0), ast.SympyAssignment(y, 3.0), ast.SympyAssignment(f[0], x + y)],
 
cpu_prepend_optimizations=[ps.transformations.move_constants_before_loop], # explicitly move constants
 
cpu_vectorize_info=opt,
 
)
 
ps.show_code(kernel_func) # fails if `x` on rhs was not correctly vectorized
 
kernel = kernel_func.compile()
 
 
f_arr = np.zeros(9)
 
kernel(f=f_arr)
 
 
assert(np.all(f_arr == 5))
 
 
@pytest.mark.parametrize('openmp', [True, False])
@pytest.mark.parametrize('openmp', [True, False])
def test_aligned_and_nt_stores(openmp, instruction_set=instruction_set):
def test_aligned_and_nt_stores(openmp, instruction_set=instruction_set):
domain_size = (24, 24)
domain_size = (24, 24)
Loading