Binding a model to a design
One classmethod on the design says which model prices it:
class VecMult(FreeRunMod):
@classmethod
def get_rm(cls, platform):
...
Return None — or do not define it at all — to take the default
lookup against the platform’s measurement store. That is the right answer whenever you can
afford to measure every configuration you will ask about, so most designs write nothing here.
A model that derives its counters also declares
resource_structure(); that is a VitisResourceModel concept and
lives with it.
get_rm(platform) — which model, on this platform
@classmethod
def get_rm(cls, platform):
part = getattr(platform, "part", None) or PART
require_same_device(part, PART, what="VecMult's resource model")
store = ModuleStore(getattr(platform, "dir", None) or COMMITTED_CALIB)
return VitisResourceModel(
name="vec_mult", part=part, platform=platform,
cls_name="VecMult", comp_class=cls, store=store,
).load_or_fit()
Why a classmethod
Because a model must not close over an instance, and having no self makes that impossible
rather than merely discouraged.
The model is handed the component to predict for. The same object has to price every point of a corpus
during fit and every sibling during compose — bind it to one instance
and every row of the fit becomes identical, silently.
Everything configuration-specific still reaches the model, just later: through resource_structure()
on whatever component it is asked about, at predict time.
The key is (class, platform) — not the parameters
The base caches what get_rm returns:
bound to an instance ✗ breaks fit() and compose()
a class variable ✗ coefficients depend on the platform
keyed (class, platform) ✓ one object, cached, prices every configuration
Parameters are absent from the key, and that is a direct consequence of the model being
instance-agnostic. One VitisResourceModel for VecMult prices dwid=64, vlen=4096 and
dwid=256, vlen=1024 equally well. Had the structure been bound, the key would have needed every
parameter and the cache would be one entry per design point.
Refuse the wrong platform
get_rm is where a platform this class cannot be modelled on gets rejected. Returning a model that
silently applies another technology’s geometry is the worse failure — see
guarding the part.
What the base does with it
top.add_rm(platform) # once, on the top — post-order over the whole hierarchy
For each module: resolve get_rm (cached), install it, or fall back to the store lookup. A module
with no model contributes zero and reports UNCALIBRATED — never silently skipped, because a
missing contribution makes a design read as cheaper than it is.
Next
- Predicting — turning installed models into an estimate.
- Fitting — where the coefficients in
load_or_fitcome from.