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

ID Broadcast #821

Merged
merged 4 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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)