Skip to content

Commit

Permalink
ID Broadcast (#821)
Browse files Browse the repository at this point in the history
* id broadcast proc and model to support lava-loihi CLP

* fixed linting

---------

Co-authored-by: Marcus G K Williams <[email protected]>
  • Loading branch information
drager-intel and mgkwill authored Dec 15, 2023
1 parent bf3f3fd commit b166844
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/lava/proc/clp/id_broadcast/models.py
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)
35 changes: 35 additions & 0 deletions src/lava/proc/clp/id_broadcast/process.py
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)

0 comments on commit b166844

Please sign in to comment.