Skip to content
Snippets Groups Projects
Commit a2060520 authored by Richard Angersbach's avatar Richard Angersbach
Browse files

Get rid of reduction_assignment_from_str

parent bd99cd11
No related branches found
No related tags found
1 merge request!438Reduction Support
...@@ -56,21 +56,18 @@ The following reduction assignment classes are available in pystencils: ...@@ -56,21 +56,18 @@ The following reduction assignment classes are available in pystencils:
* `MaxReductionAssignment`: Finds maximum element * `MaxReductionAssignment`: Finds maximum element
:::{note} :::{note}
Alternatívely, you can also make use of the `reduction_assignment` or `reduction_assignment_from_str` functions Alternatívely, you can also make use of the `reduction_assignment` function
to specify reduction assignments: to specify reduction assignments:
::: :::
```{code-cell} ipython3 ```{code-cell} ipython3
from pystencils.sympyextensions import reduction_assignment, reduction_assignment_from_str from pystencils.sympyextensions import reduction_assignment
from pystencils.sympyextensions.reduction import ReductionOp from pystencils.sympyextensions.reduction import ReductionOp
assign_sum = reduction_assignment(r, ReductionOp.Add, x.center()) assign_sum = reduction_assignment(r, ReductionOp.Add, x.center())
assign_sum = reduction_assignment_from_str(r, "+", x.center())
``` ```
For other reduction operations, the following enums can be passed to `reduction_assignment` For other reduction operations, the following enums can be passed to `reduction_assignment`.
or the corresponding strings can be passed to `reduction_assignment_from_str`.
```{code-cell} python3 ```{code-cell} python3
class ReductionOp(Enum): class ReductionOp(Enum):
......
from .astnodes import ConditionalFieldAccess from .astnodes import ConditionalFieldAccess
from .typed_sympy import TypedSymbol, CastFunc, tcast, DynamicType from .typed_sympy import TypedSymbol, CastFunc, tcast, DynamicType
from .pointers import mem_acc from .pointers import mem_acc
from .reduction import reduction_assignment, reduction_assignment_from_str, ReductionOp from .reduction import reduction_assignment, ReductionOp
from .math import ( from .math import (
prod, prod,
...@@ -35,7 +35,6 @@ from .math import ( ...@@ -35,7 +35,6 @@ from .math import (
__all__ = [ __all__ = [
"ConditionalFieldAccess", "ConditionalFieldAccess",
"reduction_assignment", "reduction_assignment",
"reduction_assignment_from_str",
"ReductionOp", "ReductionOp",
"TypedSymbol", "TypedSymbol",
"CastFunc", "CastFunc",
......
...@@ -2,17 +2,17 @@ import pytest ...@@ -2,17 +2,17 @@ import pytest
import numpy as np import numpy as np
import pystencils as ps import pystencils as ps
from pystencils.sympyextensions import reduction_assignment_from_str from pystencils.sympyextensions import ReductionOp, reduction_assignment
INIT_W = 5 INIT_W = 5
INIT_ARR = 2 INIT_ARR = 2
SIZE = 15 SIZE = 15
SOLUTION = { SOLUTION = {
"+": INIT_W + INIT_ARR * SIZE, ReductionOp.Add: INIT_W + INIT_ARR * SIZE,
"-": INIT_W - INIT_ARR * SIZE, ReductionOp.Sub: INIT_W - INIT_ARR * SIZE,
"*": INIT_W * INIT_ARR**SIZE, ReductionOp.Mul: INIT_W * INIT_ARR**SIZE,
"min": min(INIT_W, INIT_ARR), ReductionOp.Min: min(INIT_W, INIT_ARR),
"max": max(INIT_W, INIT_ARR), ReductionOp.Max: max(INIT_W, INIT_ARR),
} }
...@@ -21,14 +21,14 @@ def get_reduction_assign_ast(dtype, op, config): ...@@ -21,14 +21,14 @@ def get_reduction_assign_ast(dtype, op, config):
x = ps.fields(f"x: {dtype}[1d]") x = ps.fields(f"x: {dtype}[1d]")
w = ps.TypedSymbol("w", dtype) w = ps.TypedSymbol("w", dtype)
red_assign = reduction_assignment_from_str(w, op, x.center()) red_assign = reduction_assignment(w, op, x.center())
return ps.create_kernel([red_assign], config, default_dtype=dtype) return ps.create_kernel([red_assign], config, default_dtype=dtype)
@pytest.mark.parametrize("instruction_set", ["sse", "avx"]) @pytest.mark.parametrize("instruction_set", ["sse", "avx"])
@pytest.mark.parametrize("dtype", ["float64", "float32"]) @pytest.mark.parametrize("dtype", ["float64", "float32"])
@pytest.mark.parametrize("op", ["+", "-", "*", "min", "max"]) @pytest.mark.parametrize("op", [ReductionOp.Add, ReductionOp.Sub, ReductionOp.Mul, ReductionOp.Min, ReductionOp.Max])
def test_reduction_cpu(instruction_set, dtype, op): def test_reduction_cpu(instruction_set, dtype, op):
vectorize_info = { vectorize_info = {
"instruction_set": instruction_set, "instruction_set": instruction_set,
...@@ -51,7 +51,7 @@ def test_reduction_cpu(instruction_set, dtype, op): ...@@ -51,7 +51,7 @@ def test_reduction_cpu(instruction_set, dtype, op):
@pytest.mark.parametrize("dtype", ["float64", "float32"]) @pytest.mark.parametrize("dtype", ["float64", "float32"])
@pytest.mark.parametrize("op", ["+", "-", "*", "min", "max"]) @pytest.mark.parametrize("op", [ReductionOp.Add, ReductionOp.Sub, ReductionOp.Mul, ReductionOp.Min, ReductionOp.Max])
@pytest.mark.parametrize("assume_warp_aligned_block_size", [True, False]) @pytest.mark.parametrize("assume_warp_aligned_block_size", [True, False])
@pytest.mark.parametrize("use_block_fitting", [True, False]) @pytest.mark.parametrize("use_block_fitting", [True, False])
def test_reduction_gpu( def test_reduction_gpu(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment