Skip to content
Snippets Groups Projects
Commit ca67a0ce authored by Markus Holzer's avatar Markus Holzer
Browse files

Added supported vector set to vectorisation tests

parent 372cf9b6
No related branches found
No related tags found
1 merge request!196FIX Quicktests
...@@ -7,6 +7,8 @@ from pystencils.cpu.vectorization import vectorize ...@@ -7,6 +7,8 @@ from pystencils.cpu.vectorization import vectorize
from pystencils.fast_approximation import insert_fast_sqrts, insert_fast_divisions from pystencils.fast_approximation import insert_fast_sqrts, insert_fast_divisions
from pystencils.transformations import replace_inner_stride_with_one from pystencils.transformations import replace_inner_stride_with_one
supported_instruction_sets = get_supported_instruction_sets() if get_supported_instruction_sets() else []
instruction_set = "avx" if "avx" in supported_instruction_sets else "sse"
def test_vector_type_propagation(): def test_vector_type_propagation():
a, b, c, d, e = sp.symbols("a b c d e") a, b, c, d, e = sp.symbols("a b c d e")
...@@ -19,7 +21,7 @@ def test_vector_type_propagation(): ...@@ -19,7 +21,7 @@ def test_vector_type_propagation():
ps.Assignment(g[0, 0], b + 3 + f[0, 1])] ps.Assignment(g[0, 0], b + 3 + f[0, 1])]
ast = ps.create_kernel(update_rule) ast = ps.create_kernel(update_rule)
vectorize(ast) vectorize(ast, instruction_set=instruction_set)
func = ast.compile() func = ast.compile()
dst = np.zeros_like(arr) dst = np.zeros_like(arr)
...@@ -43,7 +45,6 @@ def test_inplace_update(): ...@@ -43,7 +45,6 @@ def test_inplace_update():
f2 @= 2 * s.tmp0 f2 @= 2 * s.tmp0
ast = ps.create_kernel(update_rule, cpu_vectorize_info={'instruction_set': 'sse'}) ast = ps.create_kernel(update_rule, cpu_vectorize_info={'instruction_set': 'sse'})
print(ps.show_code(ast))
kernel = ast.compile() kernel = ast.compile()
kernel(f=arr) kernel(f=arr)
np.testing.assert_equal(arr, 2) np.testing.assert_equal(arr, 2)
...@@ -68,7 +69,7 @@ def test_vectorization_fixed_size(): ...@@ -68,7 +69,7 @@ def test_vectorization_fixed_size():
update_rule = [ps.Assignment(g[0, 0], f[0, 0] + f[-1, 0] + f[1, 0] + f[0, 1] + f[0, -1] + 42.0)] update_rule = [ps.Assignment(g[0, 0], f[0, 0] + f[-1, 0] + f[1, 0] + f[0, 1] + f[0, -1] + 42.0)]
ast = ps.create_kernel(update_rule) ast = ps.create_kernel(update_rule)
vectorize(ast) vectorize(ast, instruction_set=instruction_set)
func = ast.compile() func = ast.compile()
dst = np.zeros_like(arr) dst = np.zeros_like(arr)
...@@ -82,7 +83,7 @@ def test_vectorization_variable_size(): ...@@ -82,7 +83,7 @@ def test_vectorization_variable_size():
ast = ps.create_kernel(update_rule) ast = ps.create_kernel(update_rule)
replace_inner_stride_with_one(ast) replace_inner_stride_with_one(ast)
vectorize(ast) vectorize(ast, instruction_set=instruction_set)
func = ast.compile() func = ast.compile()
arr = np.ones((23 + 2, 17 + 2)) * 5.0 arr = np.ones((23 + 2, 17 + 2)) * 5.0
...@@ -103,7 +104,7 @@ def test_piecewise1(): ...@@ -103,7 +104,7 @@ def test_piecewise1():
ps.Assignment(g[0, 0], sp.Piecewise((b + 3 + f[0, 1], c), (0.0, True)))] ps.Assignment(g[0, 0], sp.Piecewise((b + 3 + f[0, 1], c), (0.0, True)))]
ast = ps.create_kernel(update_rule) ast = ps.create_kernel(update_rule)
vectorize(ast) vectorize(ast, instruction_set=instruction_set)
func = ast.compile() func = ast.compile()
dst = np.zeros_like(arr) dst = np.zeros_like(arr)
func(g=dst, f=arr) func(g=dst, f=arr)
...@@ -122,7 +123,7 @@ def test_piecewise2(): ...@@ -122,7 +123,7 @@ def test_piecewise2():
g[0, 0] @= s.result g[0, 0] @= s.result
ast = ps.create_kernel(test_kernel) ast = ps.create_kernel(test_kernel)
vectorize(ast) vectorize(ast, instruction_set=instruction_set)
func = ast.compile() func = ast.compile()
func(f=arr, g=arr) func(f=arr, g=arr)
np.testing.assert_equal(arr, np.ones_like(arr)) np.testing.assert_equal(arr, np.ones_like(arr))
...@@ -138,7 +139,7 @@ def test_piecewise3(): ...@@ -138,7 +139,7 @@ def test_piecewise3():
g[0, 0] @= 1.0 / (s.b + s.k) if f[0, 0] > 0.0 else 1.0 g[0, 0] @= 1.0 / (s.b + s.k) if f[0, 0] > 0.0 else 1.0
ast = ps.create_kernel(test_kernel) ast = ps.create_kernel(test_kernel)
vectorize(ast) vectorize(ast, instruction_set=instruction_set)
ast.compile() ast.compile()
...@@ -152,7 +153,7 @@ def test_logical_operators(): ...@@ -152,7 +153,7 @@ def test_logical_operators():
g[0, 0] @= sp.Piecewise([1.0 / f[1, 0], s.c], [1.0, True]) g[0, 0] @= sp.Piecewise([1.0 / f[1, 0], s.c], [1.0, True])
ast = ps.create_kernel(kernel_and) ast = ps.create_kernel(kernel_and)
vectorize(ast) vectorize(ast, instruction_set=instruction_set)
ast.compile() ast.compile()
@ps.kernel @ps.kernel
...@@ -162,7 +163,7 @@ def test_logical_operators(): ...@@ -162,7 +163,7 @@ def test_logical_operators():
g[0, 0] @= sp.Piecewise([1.0 / f[1, 0], s.c], [1.0, True]) g[0, 0] @= sp.Piecewise([1.0 / f[1, 0], s.c], [1.0, True])
ast = ps.create_kernel(kernel_or) ast = ps.create_kernel(kernel_or)
vectorize(ast) vectorize(ast, instruction_set=instruction_set)
ast.compile() ast.compile()
@ps.kernel @ps.kernel
...@@ -172,7 +173,7 @@ def test_logical_operators(): ...@@ -172,7 +173,7 @@ def test_logical_operators():
g[0, 0] @= sp.Piecewise([1.0 / f[1, 0], s.c], [1.0, True]) g[0, 0] @= sp.Piecewise([1.0 / f[1, 0], s.c], [1.0, True])
ast = ps.create_kernel(kernel_equal) ast = ps.create_kernel(kernel_equal)
vectorize(ast) vectorize(ast, instruction_set=instruction_set)
ast.compile() ast.compile()
...@@ -193,27 +194,27 @@ def test_vectorised_pow(): ...@@ -193,27 +194,27 @@ def test_vectorised_pow():
as6 = ps.Assignment(g[0, 0], sp.Pow(f[0, 0], -1)) as6 = ps.Assignment(g[0, 0], sp.Pow(f[0, 0], -1))
ast = ps.create_kernel(as1) ast = ps.create_kernel(as1)
vectorize(ast) vectorize(ast, instruction_set=instruction_set)
ast.compile() ast.compile()
ast = ps.create_kernel(as2) ast = ps.create_kernel(as2)
vectorize(ast) vectorize(ast, instruction_set=instruction_set)
ast.compile() ast.compile()
ast = ps.create_kernel(as3) ast = ps.create_kernel(as3)
vectorize(ast) vectorize(ast, instruction_set=instruction_set)
ast.compile() ast.compile()
ast = ps.create_kernel(as4) ast = ps.create_kernel(as4)
vectorize(ast) vectorize(ast, instruction_set=instruction_set)
ast.compile() ast.compile()
ast = ps.create_kernel(as5) ast = ps.create_kernel(as5)
vectorize(ast) vectorize(ast, instruction_set=instruction_set)
ast.compile() ast.compile()
ast = ps.create_kernel(as6) ast = ps.create_kernel(as6)
vectorize(ast) vectorize(ast, instruction_set=instruction_set)
ast.compile() ast.compile()
...@@ -224,16 +225,16 @@ def test_vectorised_fast_approximations(): ...@@ -224,16 +225,16 @@ def test_vectorised_fast_approximations():
expr = sp.sqrt(f[0, 0] + f[1, 0]) expr = sp.sqrt(f[0, 0] + f[1, 0])
assignment = ps.Assignment(g[0, 0], insert_fast_sqrts(expr)) assignment = ps.Assignment(g[0, 0], insert_fast_sqrts(expr))
ast = ps.create_kernel(assignment) ast = ps.create_kernel(assignment)
vectorize(ast) vectorize(ast, instruction_set=instruction_set)
ast.compile() ast.compile()
expr = f[0, 0] / f[1, 0] expr = f[0, 0] / f[1, 0]
assignment = ps.Assignment(g[0, 0], insert_fast_divisions(expr)) assignment = ps.Assignment(g[0, 0], insert_fast_divisions(expr))
ast = ps.create_kernel(assignment) ast = ps.create_kernel(assignment)
vectorize(ast) vectorize(ast, instruction_set=instruction_set)
ast.compile() ast.compile()
assignment = ps.Assignment(sp.Symbol("tmp"), 3 / sp.sqrt(f[0, 0] + f[1, 0])) assignment = ps.Assignment(sp.Symbol("tmp"), 3 / sp.sqrt(f[0, 0] + f[1, 0]))
ast = ps.create_kernel(insert_fast_sqrts(assignment)) ast = ps.create_kernel(insert_fast_sqrts(assignment))
vectorize(ast) vectorize(ast, instruction_set=instruction_set)
ast.compile() ast.compile()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment