Skip to content

Commit

Permalink
Merge branch 'main' into demo
Browse files Browse the repository at this point in the history
  • Loading branch information
srrisbud committed May 9, 2024
2 parents 974b487 + bcc3b1a commit c4c329f
Show file tree
Hide file tree
Showing 43 changed files with 3,243 additions and 491 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Run CD
permissions: read-all
on:
workflow_dispatch:

Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Run CI
permissions: read-all
on:
push:
branches:
Expand Down Expand Up @@ -54,7 +55,7 @@ jobs:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-latest, windows-latest, macos-latest]
operating-system: [ubuntu-latest, windows-latest, macos-13]
steps:
- uses: actions/checkout@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codacy_coverage_reporter.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Codacy Coverage Reporter

permissions: read-all
on:
workflow_run:
workflows: ["Run CI"]
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/issues.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Add new issues to the NCL planning project and label them

permissions: {}
on:
issues:
types:
Expand All @@ -10,6 +10,7 @@ on:
jobs:
add-to-project:
name: Add issue to project
permissions: {}
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,5 @@ dmypy.json
.idea/
.vscode/
.history/
.flakeheaven_cache/
tutorials/in_depth/results/
687 changes: 378 additions & 309 deletions poetry.lock

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions src/lava/magma/core/learning/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,24 @@ def stochastic_round(values: np.ndarray,
return (values + (random_numbers < probabilities).astype(int)).astype(int)


def apply_mask(int_number: int, nb_bits: int) -> int:
def apply_mask(item: ty.Union[np.ndarray, int], nb_bits: int) \
-> ty.Union[np.ndarray, int]:
"""Get nb_bits least-significant bits.
Parameters
----------
int_number : int
Integer number.
item : np.ndarray or int
Item to apply mask to.
nb_bits : int
Number of LSBs to keep.
Returns
----------
result : int
result : np.ndarray or int
Least-significant bits.
"""
mask = ~(~0 << nb_bits)
return int_number & mask
return item & mask


def float_to_literal(learning_parameter: float) -> str:
Expand Down
4 changes: 2 additions & 2 deletions src/lava/magma/core/model/py/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,8 @@ def _update_synaptic_variable_random(self) -> None:
pass

def _update_dependencies(self) -> None:
self.x0[self.tx > 0] = True
self.y0[self.ty > 0] = True
self.x0 = self.tx > 0
self.y0 = self.ty > 0

@abstractmethod
def _compute_trace_histories(self) -> typing.Tuple[np.ndarray, np.ndarray]:
Expand Down
20 changes: 20 additions & 0 deletions src/lava/magma/core/process/ports/ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,17 @@ class OutPort(AbstractIOPort, AbstractSrcPort):
sub processes.
"""

def __init__(self, shape: ty.Tuple[int, ...]):
super().__init__(shape)
self.external_pipe_flag = False
self.external_pipe_buffer_size = 64

def flag_external_pipe(self, buffer_size=None):
self.external_pipe_flag = True

if buffer_size is not None:
self.external_pipe_buffer_size = buffer_size

def connect(
self,
ports: ty.Union["AbstractIOPort", ty.List["AbstractIOPort"]],
Expand Down Expand Up @@ -493,6 +504,15 @@ def __init__(
super().__init__(shape)
self._reduce_op = reduce_op

self.external_pipe_flag = False
self.external_pipe_buffer_size = 64

def flag_external_pipe(self, buffer_size=None):
self.external_pipe_flag = True

if buffer_size is not None:
self.external_pipe_buffer_size = buffer_size

def connect(self,
ports: ty.Union["InPort", ty.List["InPort"]],
connection_configs: ty.Optional[ConnectionConfigs] = None):
Expand Down
46 changes: 44 additions & 2 deletions src/lava/magma/runtime/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
if ty.TYPE_CHECKING:
from lava.magma.core.process.process import AbstractProcess
from lava.magma.compiler.channels.pypychannel import CspRecvPort, CspSendPort, \
CspSelector
CspSelector, PyPyChannel
from lava.magma.compiler.builders.channel_builder import (
ChannelBuilderMp, RuntimeChannelBuilderMp, ServiceChannelBuilderMp,
ChannelBuilderPyNc)
Expand All @@ -38,7 +38,7 @@
ChannelType
from lava.magma.compiler.executable import Executable
from lava.magma.compiler.node import NodeConfig
from lava.magma.core.process.ports.ports import create_port_id
from lava.magma.core.process.ports.ports import create_port_id, InPort, OutPort
from lava.magma.core.run_conditions import (AbstractRunCondition,
RunContinuous, RunSteps)
from lava.magma.compiler.channels.watchdog import WatchdogManagerInterface
Expand Down Expand Up @@ -308,6 +308,10 @@ def _build_processes(self):
proc._runtime = self
exception_q = Queue()
self.exception_q.append(exception_q)

# Create any external pypychannels
self._create_external_channels(proc, proc_builder)

self._messaging_infrastructure.build_actor(target_fn,
proc_builder,
exception_q)
Expand All @@ -323,6 +327,44 @@ def _build_runtime_services(self):
rs_builder,
self.exception_q[-1])

def _create_external_channels(self,
proc: AbstractProcess,
proc_builder: AbstractProcessBuilder):
"""Creates a csp channel which can be connected to/from a
non-procss/Lava python environment. This enables I/O to Lava from
external sources."""
for name, py_port in proc_builder.py_ports.items():
port = getattr(proc, name)

if port.external_pipe_flag:
if isinstance(port, InPort):
pypychannel = PyPyChannel(
message_infrastructure=self._messaging_infrastructure,
src_name="src",
dst_name=name,
shape=py_port.shape,
dtype=py_port.d_type,
size=port.external_pipe_buffer_size)

proc_builder.set_csp_ports([pypychannel.dst_port])

port.external_pipe_csp_send_port = pypychannel.src_port
port.external_pipe_csp_send_port.start()

if isinstance(port, OutPort):
pypychannel = PyPyChannel(
message_infrastructure=self._messaging_infrastructure,
src_name=name,
dst_name="dst",
shape=py_port.shape,
dtype=py_port.d_type,
size=port.external_pipe_buffer_size)

proc_builder.set_csp_ports([pypychannel.src_port])

port.external_pipe_csp_recv_port = pypychannel.dst_port
port.external_pipe_csp_recv_port.start()

def _get_resp_for_run(self):
"""
Gets response from RuntimeServices
Expand Down
Loading

0 comments on commit c4c329f

Please sign in to comment.