-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* id broadcast proc and model to support lava-loihi CLP * fixed linting --------- Co-authored-by: Marcus G K Williams <[email protected]>
- Loading branch information
1 parent
bf3f3fd
commit b166844
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright (C) 2022 Intel Corporation | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# See: https://spdx.org/licenses/ | ||
|
||
import numpy as np | ||
from lava.magma.core.decorator import implements, requires | ||
from lava.magma.core.model.py.model import PyLoihiProcessModel | ||
from lava.magma.core.model.py.ports import PyInPort, PyOutPort | ||
from lava.magma.core.model.py.type import LavaPyType | ||
from lava.magma.core.resources import CPU | ||
from lava.magma.core.sync.protocols.loihi_protocol import LoihiProtocol | ||
|
||
from lava.proc.clp.id_broadcast.process import IdBroadcast | ||
|
||
|
||
@implements(proc=IdBroadcast, protocol=LoihiProtocol) | ||
@requires(CPU) | ||
class IdBroadcastModel(PyLoihiProcessModel): | ||
"""CPU model for the IdBroadcast process. | ||
The process sends out a graded spike with payload equal to a_in. | ||
""" | ||
a_in: PyInPort = LavaPyType(PyInPort.VEC_DENSE, int) | ||
s_out: PyOutPort = LavaPyType(PyOutPort.VEC_DENSE, int) | ||
val: np.ndarray = LavaPyType(np.ndarray, np.int32) | ||
|
||
def run_spk(self): | ||
"""Execute spiking phase, send value of a_in.""" | ||
|
||
a_in_data = self.a_in.recv() | ||
self.val = a_in_data | ||
self.s_out.send(a_in_data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright (C) 2022 Intel Corporation | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# See: https://spdx.org/licenses/ | ||
|
||
import typing as ty | ||
|
||
import numpy as np | ||
from lava.magma.core.process.ports.ports import InPort, OutPort | ||
from lava.magma.core.process.variable import Var | ||
from lava.magma.core.process.process import AbstractProcess, LogConfig | ||
|
||
|
||
class IdBroadcast(AbstractProcess): | ||
"""Process that sends out a graded spike with payload equal to a_in. | ||
Parameters | ||
---------- | ||
shape : tuple(int) | ||
Shape of the population of process units. | ||
name : str | ||
Name of the Process. Default is 'Process_ID', where ID is an | ||
integer value that is determined automatically. | ||
log_config : LogConfig | ||
Configuration options for logging. | ||
""" | ||
|
||
def __init__(self, *, | ||
shape: ty.Tuple[int, ...] = (1,), | ||
name: ty.Optional[str] = None, | ||
log_config: ty.Optional[LogConfig] = None) -> None: | ||
super().__init__(shape=shape, name=name, log_config=log_config) | ||
self.a_in = InPort(shape=shape) | ||
self.s_out = OutPort(shape=shape) | ||
|
||
self.val = Var(shape=shape, init=0) |