From cbae1775bdfe68265935e623570973bf44dc8613 Mon Sep 17 00:00:00 2001 From: cephi Date: Wed, 11 Dec 2024 15:00:37 -0500 Subject: [PATCH] Resolved conflict --- pytorch/run.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/pytorch/run.py b/pytorch/run.py index 92abd81..0b66f5c 100644 --- a/pytorch/run.py +++ b/pytorch/run.py @@ -57,6 +57,17 @@ def run_program(program: list[str]) -> tuple[dict, str]: print(process.stderr) return (json.loads(process.stdout), process.stderr) +def trapezoidal_rule(power: list[float], time_s: float) -> float: + from math import ceil + from itertools import pairwise + result = 0.0 + relevant_power = power[-int(time_s):] + relevant_pairs = [pair for pair in zip(relevant_power, relevant_power[1:])] + for pair in relevant_pairs: + result += 0.5 * (pair[0] + pair[1]) + result += (time_s % 1) * (power[-1]) + return result + result = dict() result[Stat.CPU.name] = args.cpu.name result[Stat.ITERATIONS.name] = args.iterations @@ -90,11 +101,13 @@ if args.power: print(result) result[Stat.POWER.name] = [float(x) for x in power_process.communicate()[0].strip().split('\n')] - # Riemann Sum across the last (s) power recordings. - from math import ceil - result[Stat.JOULES.name] = ( - sum(result[Stat.POWER.name][-ceil(result[Stat.TIME_S_OVERALL.name]):-1]) - + (result[Stat.POWER.name][-1] * (result[Stat.TIME_S_OVERALL.name] % 1))) + # Trapezoidal Rule across the last (s) power recordings. + #result[Stat.JOULES.name] = ( + # sum(result[Stat.POWER.name][-ceil(result[Stat.TIME_S.name]):]) + # + (result[Stat.POWER.name][-1] * (result[Stat.TIME_S.name] % 1))) + result[Stat.JOULES.name] = trapezoidal_rule( + result[Stat.POWER.name], + result[Stat.TIME_S.name]) elif args.cpu == Cpu.EPYC_7313P: power_process = subprocess.Popen(