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

Enable Solver Parallelization with Loihi2 Backend #197

Merged
merged 34 commits into from
Mar 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c9d5a13
Expose cost from CostIntegrator on the OptimizationSolver.
GaboFGuerra Feb 1, 2023
ec3c065
Enable cost tracking on the OptimizationSolver.
GaboFGuerra Feb 1, 2023
5d1a35c
Merge branch 'main' of https://github.com/lava-nc/lava-optimization
GaboFGuerra Feb 14, 2023
db392e5
Merge local and remote mains which diverged.
GaboFGuerra Mar 8, 2023
8cf27f5
Remove obsolete code.
GaboFGuerra Mar 8, 2023
cb49032
Solve merging issues.
GaboFGuerra Mar 9, 2023
a668841
Merge-in remote into local changes.
GaboFGuerra Mar 10, 2023
b4cc0c6
Resolve import issue for ReadGate.
GaboFGuerra Mar 13, 2023
90887dc
solve linting issue
GaboFGuerra Mar 13, 2023
1d8480c
Solve linting issue.
GaboFGuerra Mar 13, 2023
5981f6a
Split Py and C read gate models.
GaboFGuerra Mar 14, 2023
1613fdf
Use different function for generating py and C ReadGate models.
GaboFGuerra Mar 14, 2023
51c5916
Change assertion to raise a ValueError instead.
GaboFGuerra Mar 15, 2023
0694242
Merge branch 'main' into hp_parallel_l2
GaboFGuerra Mar 16, 2023
06a67f8
Solve linting inssues.
GaboFGuerra Mar 16, 2023
86ba199
Merge remote into local.
GaboFGuerra Mar 16, 2023
98081e3
Reformat file.
GaboFGuerra Mar 16, 2023
57c1d78
Solve linting.
GaboFGuerra Mar 16, 2023
221d951
Reformat files.
GaboFGuerra Mar 16, 2023
e975c09
Merge branch 'hp_parallel_l2' of https://github.com/lava-nc/lava-opti…
GaboFGuerra Mar 16, 2023
551e717
merge remote into local
GaboFGuerra Mar 16, 2023
804910b
Correct test for membership.
GaboFGuerra Mar 16, 2023
9c9cf2a
Optimize imports.
GaboFGuerra Mar 16, 2023
0ce5ca7
Solve linting.
GaboFGuerra Mar 16, 2023
99efed9
Solve linting issue.
GaboFGuerra Mar 16, 2023
4ce3786
Update function name.
GaboFGuerra Mar 16, 2023
61015db
Update function name.
GaboFGuerra Mar 16, 2023
058d522
Add default backend to function.
GaboFGuerra Mar 16, 2023
1c1506e
Add missing white spaces.
GaboFGuerra Mar 16, 2023
d606bd6
Add default value for argument in funciton.
GaboFGuerra Mar 16, 2023
d05b931
Add missing white spaces.
GaboFGuerra Mar 17, 2023
0f4a6be
Remove backend param as obsolete after separation of backends.
GaboFGuerra Mar 20, 2023
2f6cc33
Complete conditional for reading state.
GaboFGuerra Mar 23, 2023
a9ae2ec
Remove sconfig.py as not needed anymore.
GaboFGuerra Mar 23, 2023
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
79 changes: 40 additions & 39 deletions src/lava/lib/optimization/solvers/generic/read_gate/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
# SPDX-License-Identifier: BSD-3-Clause
# See: https://spdx.org/licenses/
import numpy as np

from lava.lib.optimization.solvers.generic.read_gate.process import ReadGate

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, PyRefPort
from lava.magma.core.model.py.type import LavaPyType
from lava.magma.core.resources import CPU
from lava.magma.core.resources import CPU, LMT
from lava.magma.core.sync.protocols.loihi_protocol import LoihiProtocol


Expand Down Expand Up @@ -52,56 +52,56 @@ def readgate_run_post_mgmt(self):


def get_readgate_members(num_in_ports):
in_ports = {
f"cost_in_{id}": LavaPyType(PyInPort.VEC_DENSE, np.int32,
precision=32)
readgate_members = dict(min_cost=None, min_cost_id=None, solution=None)

in_ports_py = {
f"cost_in_{id}": LavaPyType(PyInPort.VEC_DENSE, np.int32, precision=32)
for id in range(num_in_ports)
}
readgate_members = {
"target_cost": LavaPyType(int, np.int32, 32),
"best_solution": LavaPyType(int, np.int32, 32),
"cost_out": LavaPyType(PyOutPort.VEC_DENSE, np.int32,
precision=32),
"solution_out": LavaPyType(PyOutPort.VEC_DENSE, np.int32,
precision=32),
"send_pause_request": LavaPyType(

class_members_py = dict(
target_cost=LavaPyType(int, np.int32, 32),
best_solution=LavaPyType(int, np.int32, 32),
cost_out=LavaPyType(PyOutPort.VEC_DENSE, np.int32, precision=32),
solution_out=LavaPyType(PyOutPort.VEC_DENSE, np.int32, precision=32),
send_pause_request=LavaPyType(
GaboFGuerra marked this conversation as resolved.
Show resolved Hide resolved
PyOutPort.VEC_DENSE, np.int32, precision=32
),
"solution_reader": LavaPyType(
PyRefPort.VEC_DENSE, np.int32, precision=32
),
"min_cost": None,
"min_cost_id": None,
"solution": None,
"post_guard": readgate_post_guard,
"run_spk": readgate_run_spk,
"run_post_mgmt": readgate_run_post_mgmt,
}
readgate_members.update(in_ports)
solution_reader=LavaPyType(PyRefPort.VEC_DENSE, np.int32, precision=32),
)

cpu_specific = dict(
post_guard=readgate_post_guard,
run_spk=readgate_run_spk,
run_post_mgmt=readgate_run_post_mgmt,
)

readgate_members.update(in_ports_py)
readgate_members.update(class_members_py)
readgate_members.update(cpu_specific)
return readgate_members


def get_read_gate_model_class(num_in_ports: int):
def get_read_gate_py_model_class(num_in_ports: int):
"""Produce CPU model for the ReadGate process.

The model verifies if better payload (cost) has been notified by the
downstream processes, if so, it reads those processes state and sends
out to
the upstream process the new payload (cost) and the network state.
"""
ReadGatePyModelBase = type(
"ReadGatePyModel",
(PyLoihiProcessModel,),
super_class = PyLoihiProcessModel
resource = CPU
ReadGateModelBase = type(
"ReadGateModel",
(super_class,),
get_readgate_members(num_in_ports),
)
ReadGatePyModelImpl = implements(ReadGate, protocol=LoihiProtocol)(
ReadGatePyModelBase
ReadGateModelImpl = implements(ReadGate, protocol=LoihiProtocol)(
ReadGateModelBase
)
ReadGatePyModel = requires(CPU)(ReadGatePyModelImpl)
return ReadGatePyModel


ReadGatePyModel = get_read_gate_model_class(num_in_ports=1)
ReadGateModel = requires(resource)(ReadGateModelImpl)
return ReadGateModel


@implements(ReadGate, protocol=LoihiProtocol)
Expand All @@ -110,13 +110,14 @@ class ReadGatePyModelD(PyLoihiProcessModel):
"""CPU model for the ReadGate process.

The model verifies if better payload (cost) has been notified by the
downstream processes, if so, it reads those processes state and sends out to
downstream processes, if so, it reads those processes state and sends
out to
the upstream process the new payload (cost) and the network state.
"""

target_cost: int = LavaPyType(int, np.int32, 32)
best_solution: int = LavaPyType(int, np.int32, 32)
cost_in: PyInPort = LavaPyType(PyInPort.VEC_DENSE, np.int32,
precision=32)
cost_in: PyInPort = LavaPyType(PyInPort.VEC_DENSE, np.int32, precision=32)
cost_out: PyOutPort = LavaPyType(
PyOutPort.VEC_DENSE, np.int32, precision=32
)
Expand All @@ -142,7 +143,7 @@ def run_spk(self):
self.min_cost = cost[0]
self.cost_out.send(np.array([0]))
elif self.solution is not None:
timestep = - np.array([self.time_step])
timestep = -np.array([self.time_step])
if self.min_cost <= self.target_cost:
self._req_pause = True
self.cost_out.send(np.array([self.min_cost]))
Expand Down
1 change: 0 additions & 1 deletion src/lava/lib/optimization/solvers/generic/sconfig.py

This file was deleted.

Loading