diff --git a/src/lava/proc/clp/id_broadcast/models.py b/src/lava/proc/clp/id_broadcast/models.py new file mode 100644 index 000000000..96b7f283b --- /dev/null +++ b/src/lava/proc/clp/id_broadcast/models.py @@ -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) diff --git a/src/lava/proc/clp/id_broadcast/process.py b/src/lava/proc/clp/id_broadcast/process.py new file mode 100644 index 000000000..f63788ca3 --- /dev/null +++ b/src/lava/proc/clp/id_broadcast/process.py @@ -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)