Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speeding up snips by communicating less often #26

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions nengo_loihi/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ def __init__(self, network, dt=0.001, seed=None, model=None, # noqa: C901
self.precompute = precompute
self.snip_io_steps = snip_io_steps

if target is None:
try:
import nxsdk
target = 'loihi'
except ImportError:
target = 'sim'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to what's being done here, but it might be nice to have some sort of output (print statements? logger statements?) that indicate which target has been chosen. I would probably do it even in the case that the user has explicitly specified target (so after this if block).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly, although I'm not sure what the best sort of message would be. I'd definitely leave it for a separate PR, though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure we already have these logging statements, they're just not raised here.


self.chip2host_sent_steps = 0 # how many timesteps have been sent
if network is not None:
nengo.rc.set("decoder_cache", "enabled", "False")
Expand All @@ -180,8 +187,10 @@ def __init__(self, network, dt=0.001, seed=None, model=None, # noqa: C901
progress_bar=False)
else:
# we need online communication
spiking_interneurons_on_host = target != 'loihi'
host, chip, h2c, c2h_params, c2h = splitter.split(
network, INTER_RATE, INTER_N)
network, INTER_RATE, INTER_N,
spiking_interneurons_on_host=spiking_interneurons_on_host)
network = chip
self.chip2host_receivers = c2h
self.host2chip_senders = h2c
Expand All @@ -208,13 +217,6 @@ def __init__(self, network, dt=0.001, seed=None, model=None, # noqa: C901
self.loihi = None
self.simulator = None

if target is None:
try:
import nxsdk
target = 'loihi'
except ImportError:
target = 'sim'

if target == 'simreal':
logger.info("Using real-valued simulator")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E.g. here

self.simulator = self.model.get_simulator(seed=seed)
Expand Down
40 changes: 29 additions & 11 deletions nengo_loihi/splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def __init__(self, dimensions):
super(ChipReceiveNeurons, self).__init__(dimensions, dimensions)


def split(model, inter_rate, inter_n): # noqa: C901
def split(model, inter_rate, inter_n,
spiking_interneurons_on_host=True): # noqa: C901
"""Split a model into code running on the host and on-chip"""

logger.info("Splitting model into host and chip parts")
Expand Down Expand Up @@ -180,7 +181,6 @@ def split(model, inter_rate, inter_n): # noqa: C901
with host:
max_rate = inter_rate * inter_n
assert max_rate <= 1000
# TODO: move the above check elsewhere

# scale the input spikes based on the radius of the
# target ensemble
Expand All @@ -189,15 +189,33 @@ def split(model, inter_rate, inter_n): # noqa: C901
else:
scaling = 1.0

logger.debug("Creating HostSendNode for %s", c)
send = HostSendNode(dim)
nengo.Connection(c.pre, send,
function=c.function,
solver=c.solver,
eval_points=c.eval_points,
scale_eval_points=c.scale_eval_points,
synapse=c.synapse,
transform=c.transform * scaling)
if spiking_interneurons_on_host:
logger.debug("Creating NIF ensemble for %s", c)
ens = nengo.Ensemble(
2 * dim, dim, neuron_type=NIF(tau_ref=0.0),
encoders=np.vstack([np.eye(dim), -np.eye(dim)]),
max_rates=[max_rate] * dim + [max_rate] * dim,
intercepts=[-1] * dim + [-1] * dim)
logger.debug("Creating HostSendNode for %s", c)
send = HostSendNode(dim * 2)
nengo.Connection(c.pre, ens,
function=c.function,
solver=c.solver,
eval_points=c.eval_points,
scale_eval_points=c.scale_eval_points,
synapse=None,
transform=c.transform * scaling)
nengo.Connection(ens.neurons, send, synapse=None)
else:
logger.debug("Creating HostSendNode for %s", c)
send = HostSendNode(dim)
nengo.Connection(c.pre, send,
function=c.function,
solver=c.solver,
eval_points=c.eval_points,
scale_eval_points=c.scale_eval_points,
synapse=c.synapse,
transform=c.transform * scaling)
host2chip_senders[send] = receive
elif pre_onchip and not post_onchip:
dim = c.size_out
Expand Down