Skip to content

analyze

Facts about Julia kernels used to manage reusable result buffers.

reset_argument_positions(function)

Return arguments reset before the kernel reads their previous values.

Source code in src/finch/compile_jl/analyze.py
70
71
72
73
74
75
76
def reset_argument_positions(function: ntn.Function) -> frozenset[int]:
    """Return arguments reset before the kernel reads their previous values."""
    return frozenset(
        position
        for position, argument in enumerate(function.args)
        if _is_reset_before_read(function.body, _argument_aliases(function, argument))
    )

returned_argument_positions(function)

Return the formal argument positions returned by a Julia kernel.

Source code in src/finch/compile_jl/analyze.py
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
def returned_argument_positions(function: ntn.Function) -> tuple[int, ...]:
    """Return the formal argument positions returned by a Julia kernel."""
    positions = {
        argument.name: position for position, argument in enumerate(function.args)
    }
    returned: list[tuple[Any, ...] | None] = []
    Rewrite(PostWalk(partial(_return_rule, values=returned)))(function.body)
    if len(returned) != 1 or returned[0] is None:
        raise ValueError("Julia kernels must contain one concrete return")
    values = returned[0]
    if not all(
        isinstance(value, ntn.Variable) and value.name in positions for value in values
    ):
        raise ValueError("Julia kernels must return formal arguments")
    return tuple(positions[value.name] for value in values)