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

Fixed operation count

parent e462d7f4
Branches
Tags
No related merge requests found
...@@ -481,7 +481,7 @@ def count_operations(term: Union[sp.Expr, List[sp.Expr]], ...@@ -481,7 +481,7 @@ def count_operations(term: Union[sp.Expr, List[sp.Expr]],
pass pass
elif t.func is sp.Mul: elif t.func is sp.Mul:
if check_type(t): if check_type(t):
result['muls'] += len(t.args) result['muls'] += len(t.args) - 1
for a in t.args: for a in t.args:
if a == 1 or a == -1: if a == 1 or a == -1:
result['muls'] -= 1 result['muls'] -= 1
...@@ -509,7 +509,8 @@ def count_operations(term: Union[sp.Expr, List[sp.Expr]], ...@@ -509,7 +509,8 @@ def count_operations(term: Union[sp.Expr, List[sp.Expr]],
if t.exp >= 0: if t.exp >= 0:
result['muls'] += int(t.exp) - 1 result['muls'] += int(t.exp) - 1
else: else:
result['muls'] -= 1 if result['muls'] > 0:
result['muls'] -= 1
result['divs'] += 1 result['divs'] += 1
result['muls'] += (-int(t.exp)) - 1 result['muls'] += (-int(t.exp)) - 1
elif sp.nsimplify(t.exp) == sp.Rational(1, 2): elif sp.nsimplify(t.exp) == sp.Rational(1, 2):
......
...@@ -116,9 +116,6 @@ def kernel_execution_jacobi(dh, target): ...@@ -116,9 +116,6 @@ def kernel_execution_jacobi(dh, target):
assert dh.is_on_gpu('f') assert dh.is_on_gpu('f')
assert dh.is_on_gpu('tmp') assert dh.is_on_gpu('tmp')
with pytest.raises(ValueError):
dh.add_array('f', gpu=test_gpu)
stencil_2d = [(1, 0), (-1, 0), (0, 1), (0, -1)] stencil_2d = [(1, 0), (-1, 0), (0, 1), (0, -1)]
stencil_3d = [(1, 0, 0), (-1, 0, 0), (0, 1, 0), (0, -1, 0), (0, 0, 1), (0, 0, -1)] stencil_3d = [(1, 0, 0), (-1, 0, 0), (0, 1, 0), (0, -1, 0), (0, 0, 1), (0, 0, -1)]
stencil = stencil_2d if dh.dim == 2 else stencil_3d stencil = stencil_2d if dh.dim == 2 else stencil_3d
...@@ -263,6 +260,9 @@ def test_get_kwarg(): ...@@ -263,6 +260,9 @@ def test_get_kwarg():
dh.fill("src", 1.0, ghost_layers=True) dh.fill("src", 1.0, ghost_layers=True)
dh.fill("dst", 0.0, ghost_layers=True) dh.fill("dst", 0.0, ghost_layers=True)
with pytest.raises(ValueError):
dh.add_array('src')
ur = ps.Assignment(src.center, dst.center) ur = ps.Assignment(src.center, dst.center)
kernel = ps.create_kernel(ur).compile() kernel = ps.create_kernel(ur).compile()
......
...@@ -119,7 +119,7 @@ def test_count_operations(): ...@@ -119,7 +119,7 @@ def test_count_operations():
expr = sympy.Pow(1/x + y * sympy.sqrt(z), 100) expr = sympy.Pow(1/x + y * sympy.sqrt(z), 100)
ops = count_operations(expr, only_type=None) ops = count_operations(expr, only_type=None)
assert ops['adds'] == 1 assert ops['adds'] == 1
assert ops['muls'] == 100 assert ops['muls'] == 99
assert ops['divs'] == 1 assert ops['divs'] == 1
assert ops['sqrts'] == 1 assert ops['sqrts'] == 1
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment