Energy / time profiling on Loihi

Hello,
I’d be interested in profiling time and energy spent in spiking phase on Loihi. I’ve run into similar issues as this post.
When using nxSDK I would create probes like so:

board = nx.N2Compiler().compile(net)
profile_probe_cond = PerformanceProbeCondition(tStart=1, tEnd=run_time, bufferSize=1000, binSize=100)
time_probe = board.probe(nx.ProbeParameter.EXECUTION_TIME, profile_probe_cond)
energy_probe = board.probe(nx.ProbeParameter.ENERGY, profile_probe_cond)
board.run(run_time)
board.disconnect()

However this does not work when using Nengo:

nengo_loihi.hardware.interface.HostSnip.recv_timeout = 1.0  # Default is 0.01 (10 ms)
nengo_loihi.hardware.interface.HostSnip.recv_retries = 100  # Default is 10

with nengo_loihi.Simulator(model, dt = 0.001) as sim:
    profile_probe_cond = PerformanceProbeCondition(tStart=1, tEnd=10000, bufferSize=1024, binSize=100)
    energy_probe = sim.sims["loihi"].nxsdk_board.probe(nx.ProbeParameter.ENERGY, profile_probe_cond)
    sim.run(10)

It ends up in a stacktrace.
You mentioned in the post above that you were running energy profiling succesfully. Could you post your code for comparison please?

1 Like

Hello @biphasic,

Here is a code example that should work:

import nengo
import nengo_loihi
from nxsdk.graph.monitor.probes import PerformanceProbeCondition
from nxsdk.api.n2a import ProbeParameter

with nengo.Network() as net:
    a = nengo.Ensemble(10, 1)
    p = nengo.Probe(a)

run_time = 0.1
dt = 0.001

sim = nengo_loihi.Simulator(net, dt=dt)
board = sim.sims["loihi"].nxsdk_board
probe_cond = PerformanceProbeCondition(
    tStart=1, tEnd=int(run_time / dt) * 10, bufferSize=1024 * 5, binSize=4
)
e_probe = board.probe(ProbeParameter.ENERGY, probe_cond)

with sim:
    sim.run(run_time)

Note that the important difference is that we’re adding the energy probe before the with sim block. with sim will run some NxSDK initialization code, and NxSDK gives that error if you try to add energy probes after that initialization code is run.

1 Like

that worked! thanks so much for the quick help