Skip to content

Commit

Permalink
feat: alt values for rapl and energy measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
JuanPedroGHM committed Apr 16, 2024
1 parent 6ba0f70 commit 0fe9b94
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 9 deletions.
21 changes: 17 additions & 4 deletions perun/data_model/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ class RawData:
values: np.ndarray
t_md: MetricMetaData
v_md: MetricMetaData
alt_values: Optional[np.ndarray] = None
alt_v_md: Optional[MetricMetaData] = None

@classmethod
def fromDict(cls, rawDataDict: Dict):
Expand All @@ -197,11 +199,22 @@ def fromDict(cls, rawDataDict: Dict):
"""
t_md = MetricMetaData.fromDict(rawDataDict["t_md"])
v_md = MetricMetaData.fromDict(rawDataDict["v_md"])
alt_v_md = (
MetricMetaData.fromDict(rawDataDict["alt_v_md"])
if "alt_v_md" in rawDataDict
else None
)
return cls(
np.array(rawDataDict["timesteps"], dtype=t_md.dtype),
np.array(rawDataDict["values"], dtype=t_md.dtype),
t_md,
v_md,
timesteps=np.array(rawDataDict["timesteps"], dtype=t_md.dtype),
values=np.array(rawDataDict["values"], dtype=t_md.dtype),
alt_values=(
np.array(rawDataDict["alt_values"], dtype=alt_v_md.dtype)
if "alt_values" in rawDataDict
else None
),
t_md=t_md,
v_md=v_md,
alt_v_md=alt_v_md,
)


Expand Down
13 changes: 13 additions & 0 deletions perun/io/hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,18 +207,31 @@ def _addRawData(h5Group: h5py.Group, rawData: RawData):
values_ds = rawDataGroup.create_dataset("values", data=rawData.values)
_addMetricMetadata(values_ds, rawData.v_md)

if rawData.alt_values is not None:
print(rawData.alt_values)
print(rawData.alt_v_md)
alt_values_ds = rawDataGroup.create_dataset(
"alt_values", data=rawData.alt_values
)
_addMetricMetadata(alt_values_ds, rawData.alt_v_md) # type: ignore


def _readRawData(group: h5py.Group) -> RawData:
"""Read raw data from into hdf5."""
timesteps = group["timesteps"][:] # type: ignore
values = group["values"][:] # type: ignore
t_md = _readMetricMetadata(group["timesteps"]) # type: ignore
v_md = _readMetricMetadata(group["values"]) # type: ignore

alt_values = group["alt_values"][:] if "alt_values" in group else None # type: ignore
alt_v_md = _readMetricMetadata(group["alt_values"]) if alt_values is not None else None # type: ignore
return RawData(
timesteps=timesteps, # type: ignore
values=values, # type: ignore
alt_values=alt_values,
t_md=t_md,
v_md=v_md,
alt_v_md=alt_v_md,
)


Expand Down
28 changes: 23 additions & 5 deletions perun/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def processEnergyData(
) -> Tuple[Any, Any]:
"""Calculate energy and power from an accumulated energy vector. (SEE RAPL).
Using the start and end parameters the results can be limited to certain areas of the application run.
Using the start and end parameters does the calculation within the selected time range.
Parameters
----------
Expand Down Expand Up @@ -72,13 +72,31 @@ def processEnergyData(
d_energy[idx] = d_energy[idx] + maxValue

d_energy = d_energy.astype("float32")

total_energy = d_energy.sum()
total_energy = d_energy.cumsum()[-1]

magFactor = raw_data.v_md.mag.value / Magnitude.ONE.value

# Transform the energy series to a power series
if not start and not end:
print(t_s)
print(d_energy)
power_W = d_energy / np.diff(t_s)
power_W *= magFactor
raw_data.alt_values = power_W
raw_data.alt_v_md = MetricMetaData(
Unit.WATT,
Magnitude.ONE,
np.dtype("float32"),
np.float32(0),
np.finfo("float32").max,
np.float32(-1),
)

energy_J = total_energy * magFactor
power_W = energy_J / runtime
return energy_J, power_W
avg_power_W = energy_J / runtime
print(avg_power_W, np.mean(power_W))
print(np.abs(avg_power_W - np.mean(power_W)))
return energy_J, avg_power_W


def processPowerData(
Expand Down

0 comments on commit 0fe9b94

Please sign in to comment.