79 lines
2.6 KiB
Python
79 lines
2.6 KiB
Python
from ScEpTIC.exceptions import ConfigurationException
|
|
|
|
|
|
class StateRetentionEnergyModel:
|
|
"""
|
|
Energy model of a state retention technique.
|
|
"""
|
|
|
|
def __init__(self):
|
|
self.max_registers = 0
|
|
self.max_memory_cells = 0
|
|
self.n_state_save = 0
|
|
self.n_state_restore = 0
|
|
|
|
def attach_system_model(self, system_model):
|
|
"""
|
|
Attaches the system model to the state retention technique
|
|
:param system_model: the system model
|
|
"""
|
|
from ScEpTIC.emulator.energy.system_energy_model import SystemEnergyModel
|
|
|
|
if not isinstance(system_model, SystemEnergyModel):
|
|
raise ConfigurationException(f"Invalid class {system_model.__class__.__name__} for system_model. SystemEnergyModel required!")
|
|
|
|
self.system_model = system_model
|
|
|
|
|
|
def set_max_regs(self, n_regs):
|
|
"""
|
|
Update the statistic on maximum number of register saved
|
|
:param n_regs: the number of registers saved
|
|
"""
|
|
self.max_registers = max(self.max_registers, n_regs)
|
|
|
|
|
|
def set_max_memory_cells(self, n_memory_cells):
|
|
"""
|
|
Update the statistic on maximum number of memory cells saved
|
|
:param n_regs: the number of registers saved
|
|
"""
|
|
self.max_memory_cells = max(self.max_memory_cells, n_memory_cells)
|
|
|
|
|
|
def execute_probe_energy_buffer(self):
|
|
"""
|
|
Probes the energy buffer to identify if the state needs to be saved
|
|
:return: the number of executed clock cycles
|
|
"""
|
|
raise NotImplementedError(f"{self.__class__.__name__} does not implement execute_probe_energy_buffer()")
|
|
|
|
|
|
def execute_save_state(self, save_only_pc, n_registers, n_memory_cells):
|
|
"""
|
|
Calculate the cost of saving the state
|
|
:param save_only_pc: if the checkpoint saves only the program counter
|
|
:param n_registers: number of general purpose registers saved
|
|
:param n_memory_cells: number of memory cells saved
|
|
:return: number of executed clock cycles
|
|
"""
|
|
raise NotImplementedError(f"{self.__class__.__name__} does not implement execute_save_state()")
|
|
|
|
|
|
def execute_restore_state(self):
|
|
"""
|
|
Calculate the cost of restoring the state
|
|
:return: the number of executed clock cycles
|
|
"""
|
|
raise NotImplementedError(f"{self.__class__.__name__} does not implement execute_restore_state()")
|
|
|
|
|
|
def reset(self):
|
|
"""
|
|
Resets statistics
|
|
"""
|
|
self.n_state_save = 0
|
|
self.n_state_restore = 0
|
|
self.max_registers = 0
|
|
self.max_memory_cells = 0
|