Skip to content

Index

CostProtocolizer

Bases: FormattedForm, LogicLoader

Pass a program in FormattedForm to ctx, after choosing the protocol which each table reads each level of its formatted tensor with, as optimize_protocols does under cost_model.

Source code in src/finch/autoschedule/protocolizer/protocolize.py
class CostProtocolizer(FormattedForm, LogicLoader):
    """
    Pass a program in FormattedForm to ctx, after choosing the protocol which
    each table reads each level of its formatted tensor with, as
    optimize_protocols does under cost_model.
    """

    def __init__(
        self,
        ctx: LogicLoader,
        cost_model: CostModel[ProtocolChoice] = PROTOCOL_COST_MODEL,
    ):
        self.ctx = ctx
        self.cost_model = cost_model

    def lower(
        self,
        prgm: lgc.LogicStatement,
        bindings: dict[lgc.Alias, TensorFType],
        stats: dict[lgc.Alias, TensorStats],
        stats_factory: StatsFactory,
    ) -> tuple[AssemblyLibrary, dict[lgc.Alias, TensorFType]]:
        prgm = optimize_protocols(prgm, bindings, stats, stats_factory, self.cost_model)
        return self.ctx(prgm, bindings, stats, stats_factory)

LogicProtocolizer

Bases: FormattedForm, LogicLoader

Pass a program in FormattedForm to ctx, after reading each level of a formatted tensor with an explicit protocol, as protocolize does.

Source code in src/finch/autoschedule/protocolizer/protocolize.py
class LogicProtocolizer(FormattedForm, LogicLoader):
    """
    Pass a program in FormattedForm to ctx, after reading each level of a
    formatted tensor with an explicit protocol, as protocolize does.
    """

    def __init__(self, ctx: LogicLoader):
        self.ctx = ctx

    def lower(
        self,
        prgm: lgc.LogicStatement,
        bindings: dict[lgc.Alias, TensorFType],
        stats: dict[lgc.Alias, TensorStats],
        stats_factory: StatsFactory,
    ) -> tuple[AssemblyLibrary, dict[lgc.Alias, TensorFType]]:
        return self.ctx(protocolize(prgm, bindings), bindings, stats, stats_factory)

optimize_protocols(prgm, bindings, stats, stats_factory, cost_model=PROTOCOL_COST_MODEL)

prgm, reading each level with the protocol which costs least under cost_model, as choose_protocols chooses them.

Source code in src/finch/autoschedule/protocolizer/protocolize.py
def optimize_protocols(
    prgm: lgc.LogicStatement,
    bindings: Mapping[lgc.Alias, TensorFType],
    stats: Mapping[lgc.Alias, TensorStats],
    stats_factory: StatsFactory,
    cost_model: CostModel[ProtocolChoice] = PROTOCOL_COST_MODEL,
) -> lgc.LogicStatement:
    """prgm, reading each level with the protocol which costs least under
    cost_model, as choose_protocols chooses them."""
    return choose_protocols(prgm, bindings, stats, stats_factory, cost_model)[0]