Energy Accounting
Per-spike, per-synapse, per-layer energy accounting mapped to hardware.
EnergyAccountant — Track energy consumption of every operation (spike generation, synaptic transmission, membrane update) using hardware-calibrated cost models. Reports in picojoules per inference.
Supported hardware targets: 45nm CMOS, 28nm, 7nm, Loihi, SpiNNaker.
from sc_neurocore.energy_accounting import EnergyAccountant
accountant = EnergyAccountant(technology="7nm")
accountant.track(model, inputs)
print(f"Total: {accountant.total_pj:.1f} pJ")
See Tutorial 72: Energy Accounting.
sc_neurocore.energy_accounting
Per-spike, per-synapse, per-layer energy accounting mapped to hardware.
EnergyAccountant
Per-spike energy accounting system.
Parameters
hardware : str or HardwareCostModel
Target hardware for cost mapping.
Source code in src/sc_neurocore/energy_accounting/accountant.py
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220 | class EnergyAccountant:
"""Per-spike energy accounting system.
Parameters
----------
hardware : str or HardwareCostModel
Target hardware for cost mapping.
"""
def __init__(self, hardware: str | HardwareCostModel = "loihi2"):
if isinstance(hardware, str):
self.cost_model = HARDWARE_COSTS.get(hardware)
if self.cost_model is None:
raise ValueError(
f"Unknown hardware '{hardware}'. Available: {list(HARDWARE_COSTS.keys())}"
)
else:
self.cost_model = hardware
def account(
self,
layer_names: list[str],
layer_sizes: list[tuple[int, int]],
spike_counts: list[int],
n_timesteps: int,
) -> EnergyReport:
"""Compute energy breakdown from spike activity.
Parameters
----------
layer_names : list of str
layer_sizes : list of (n_inputs, n_neurons)
spike_counts : list of int
Total spikes per layer across all timesteps.
n_timesteps : int
Returns
-------
EnergyReport
"""
c = self.cost_model
report = EnergyReport(hardware=c.name)
total_spikes_all = 0
for name, (n_in, n_out), n_spikes in zip(layer_names, layer_sizes, spike_counts):
# Synaptic operations: each spike activates n_out synapses
n_synops = n_spikes * n_in
synop_e = n_synops * c.synop_pj
# Membrane updates: all neurons updated every timestep
n_mem = n_out * n_timesteps
mem_e = n_mem * c.membrane_update_pj
# Spike generation
spike_e = n_spikes * c.spike_generation_pj
# Memory: each synop reads a weight
mem_read_e = n_synops * c.memory_read_pj
total = synop_e + mem_e + spike_e + mem_read_e
report.layers.append(
LayerEnergy(
name=name,
synop_energy_pj=synop_e,
membrane_energy_pj=mem_e,
spike_gen_energy_pj=spike_e,
memory_energy_pj=mem_read_e,
total_pj=total,
n_synops=n_synops,
n_spikes=n_spikes,
n_membrane_updates=n_mem,
)
)
total_spikes_all += n_spikes
# Routing energy: each spike routed between layers
report.routing_energy_pj = total_spikes_all * c.routing_pj
report.total_energy_pj = sum(l.total_pj for l in report.layers) + report.routing_energy_pj
report.total_energy_nj = report.total_energy_pj / 1000.0
return report
|
account(layer_names, layer_sizes, spike_counts, n_timesteps)
Compute energy breakdown from spike activity.
Parameters
layer_names : list of str
layer_sizes : list of (n_inputs, n_neurons)
spike_counts : list of int
Total spikes per layer across all timesteps.
n_timesteps : int
Returns
EnergyReport
Source code in src/sc_neurocore/energy_accounting/accountant.py
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220 | def account(
self,
layer_names: list[str],
layer_sizes: list[tuple[int, int]],
spike_counts: list[int],
n_timesteps: int,
) -> EnergyReport:
"""Compute energy breakdown from spike activity.
Parameters
----------
layer_names : list of str
layer_sizes : list of (n_inputs, n_neurons)
spike_counts : list of int
Total spikes per layer across all timesteps.
n_timesteps : int
Returns
-------
EnergyReport
"""
c = self.cost_model
report = EnergyReport(hardware=c.name)
total_spikes_all = 0
for name, (n_in, n_out), n_spikes in zip(layer_names, layer_sizes, spike_counts):
# Synaptic operations: each spike activates n_out synapses
n_synops = n_spikes * n_in
synop_e = n_synops * c.synop_pj
# Membrane updates: all neurons updated every timestep
n_mem = n_out * n_timesteps
mem_e = n_mem * c.membrane_update_pj
# Spike generation
spike_e = n_spikes * c.spike_generation_pj
# Memory: each synop reads a weight
mem_read_e = n_synops * c.memory_read_pj
total = synop_e + mem_e + spike_e + mem_read_e
report.layers.append(
LayerEnergy(
name=name,
synop_energy_pj=synop_e,
membrane_energy_pj=mem_e,
spike_gen_energy_pj=spike_e,
memory_energy_pj=mem_read_e,
total_pj=total,
n_synops=n_synops,
n_spikes=n_spikes,
n_membrane_updates=n_mem,
)
)
total_spikes_all += n_spikes
# Routing energy: each spike routed between layers
report.routing_energy_pj = total_spikes_all * c.routing_pj
report.total_energy_pj = sum(l.total_pj for l in report.layers) + report.routing_energy_pj
report.total_energy_nj = report.total_energy_pj / 1000.0
return report
|
HardwareCostModel
dataclass
Energy costs for a specific hardware target.
All values in picojoules (pJ).
Source code in src/sc_neurocore/energy_accounting/accountant.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 | @dataclass
class HardwareCostModel:
"""Energy costs for a specific hardware target.
All values in picojoules (pJ).
"""
name: str
# Per-operation costs (pJ)
synop_pj: float = 23.6 # synaptic operation
membrane_update_pj: float = 1.0 # LIF membrane update
spike_generation_pj: float = 0.5 # comparator + reset
memory_read_pj: float = 5.0 # weight read from SRAM
memory_write_pj: float = 8.0 # weight write (for plasticity)
routing_pj: float = 2.0 # inter-core spike routing
# Static
leakage_pw_per_neuron: float = 10.0 # picoWatts per neuron
|
EnergyReport
dataclass
Complete energy accounting report.
Source code in src/sc_neurocore/energy_accounting/accountant.py
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135 | @dataclass
class EnergyReport:
"""Complete energy accounting report."""
hardware: str
layers: list[LayerEnergy] = field(default_factory=list)
total_energy_pj: float = 0.0
total_energy_nj: float = 0.0
routing_energy_pj: float = 0.0
def summary(self) -> str:
lines = [
f"Energy Report [{self.hardware}]: {self.total_energy_nj:.2f} nJ total",
"",
]
for le in self.layers:
pct = le.total_pj / max(self.total_energy_pj, 1e-12) * 100
lines.append(
f" {le.name}: {le.total_pj:.1f} pJ ({pct:.0f}%) — "
f"{le.n_synops} synops, {le.n_spikes} spikes"
)
lines.append(f" Routing: {self.routing_energy_pj:.1f} pJ")
return "\n".join(lines)
@property
def dominant_layer(self) -> str | None:
if not self.layers:
return None
return max(self.layers, key=lambda l: l.total_pj).name
@property
def energy_per_spike_pj(self) -> float:
total_spikes = sum(l.n_spikes for l in self.layers)
if total_spikes == 0:
return 0.0
return self.total_energy_pj / total_spikes
|