Skip to content

Commit

Permalink
Move some more functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
rowleya committed Nov 11, 2024
1 parent 53d5c12 commit 0bb21ea
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from spinn_utilities.config_holder import get_config_bool
from spinn_front_end_common.data import FecDataView
from spinn_front_end_common.utilities.base_database import BaseDatabase
from spinn_front_end_common.utility_models.chip_power_monitor_machine_vertex \
import PROVENANCE_CORE_KEY

_SECONDS_TO_MICRO_SECONDS_CONVERSION = 1000
#: Name of the database in the data folder
Expand Down Expand Up @@ -575,3 +577,20 @@ def get_core_name(self, x: int, y: int, p: int) -> Optional[str]:
""", (x, y, p)):
return str(row["core_name"], 'utf8')
return None

def get_power_monitor_core(self, x, y) -> int:
"""
Gets the power monitor core for chip x, y
:param str description:
:return: list of tuples x, y, value)
:rtype: list(tuple(int, int, float))
"""
for row in self.execute(
"""
SELECT the_value
FROM monitor_provenance
WHERE x = ? AND y = ? AND description = ?
""", (x, y, PROVENANCE_CORE_KEY)):
return int(row["the_value"])
raise LookupError(f"No power monitor core for {x=} {y=}")
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
.load_data_specification import load_using_advanced_monitors
from spinn_front_end_common.utility_models\
.chip_power_monitor_machine_vertex import (
PROVENANCE_CORE_KEY, RECORDING_CHANNEL, ChipPowerMonitorMachineVertex)
RECORDING_CHANNEL, ChipPowerMonitorMachineVertex)
from spinn_front_end_common.interface.buffer_management.storage_objects \
import BufferDatabase
from spinn_front_end_common.abstract_models import AbstractHasAssociatedBinary
Expand Down Expand Up @@ -174,15 +174,12 @@ def _extract_cores_active_time(
checkpoint: Optional[int], active_cores: Dict[Tuple[int, int], int],
version: AbstractVersion) -> ChipActiveTime:
sampling_frequency = get_config_int("EnergyMonitor", "sampling_frequency")
# Get the data from the cores
with ProvenanceReader() as db:
core = {
(x, y): value for x, y, value in db.get_monitor_by_chip(
PROVENANCE_CORE_KEY)}

chip_activity: ChipActiveTime = {}
with BufferDatabase() as buff_db:
for (x, y), p in core.items():
for (x, y), n_cores in active_cores.items():
# Find the core that was used on this chip for power monitoring
p = buff_db.get_power_monitor_core(x, y)
# Get time per sample in seconds (frequency in microseconds)
time_for_recorded_sample_s = sampling_frequency / _US_PER_SECOND
data, _missing = buff_db.get_recording(x, y, p, RECORDING_CHANNEL)
Expand All @@ -203,7 +200,7 @@ def _extract_cores_active_time(
# If checkpoint is specified, filter the times
if checkpoint is not None:
activity_times = activity_times[record_times < checkpoint]
chip_activity[x, y] = (activity_times.sum(), active_cores[x, y])
chip_activity[x, y] = (activity_times.sum(), n_cores)
return chip_activity


Expand Down

0 comments on commit 0bb21ea

Please sign in to comment.