Skip to content

smart_formatter

CostFormatter

Bases: SmartFormatter

Source code in src/finch/autoschedule/formatter/smart_formatter.py
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
class CostFormatter(SmartFormatter):
    candidates: tuple[LevelOption, ...]

    def __init__(self, loader: LogicLoader | None = None):
        super().__init__(loader)
        self._stats_factory = None

    @abstractmethod
    def leaf_cost_fn(self, num_pos, val_size, pos_size): ...

    def lower(self, prgm, bindings, stats, stats_factory):
        """
        get_tensor_ftype is called by lower which needs stats_factory which
        isn't passed by smart formatter lower
        """
        self._stats_factory = stats_factory
        return super().lower(prgm, bindings, stats, stats_factory)

    def get_tensor_ftype(self, fill_value, shape_type, stats):
        if self._stats_factory is None:
            raise ValueError("CostFormatter requires StatsFactory")
        lvl = optimize_format(
            stats.index_order,
            shape_type,
            stats,
            self._stats_factory,
            fill_value,
            self.candidates,
            self.leaf_cost_fn,
        )
        return fiber_tensor(lvl)

lower(prgm, bindings, stats, stats_factory)

get_tensor_ftype is called by lower which needs stats_factory which isn't passed by smart formatter lower

Source code in src/finch/autoschedule/formatter/smart_formatter.py
304
305
306
307
308
309
310
def lower(self, prgm, bindings, stats, stats_factory):
    """
    get_tensor_ftype is called by lower which needs stats_factory which
    isn't passed by smart formatter lower
    """
    self._stats_factory = stats_factory
    return super().lower(prgm, bindings, stats, stats_factory)