Skip to content

Commit 5ab889a

Browse files
author
gkarray
committed
Merge branch 'learning-engine-bit-acc' of https://github.com/lava-nc/lava into learning-engine-bit-acc
2 parents 887cffa + 320dde6 commit 5ab889a

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

src/lava/magma/runtime/message_infrastructure/multiprocessing.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,13 @@ def start(self):
113113

114114
def build_actor(self, target_fn: ty.Callable, builder: ty.Union[
115115
ty.Dict['AbstractProcess', 'PyProcessBuilder'], ty.Dict[
116-
SyncDomain, 'RuntimeServiceBuilder']]) -> ty.Any:
116+
SyncDomain, 'RuntimeServiceBuilder']],
117+
exception_q: mp.Queue = None) -> ty.Any:
117118
"""Given a target_fn starts a system (os) process"""
118119
system_process = SystemProcess(target=target_fn,
119120
args=(),
120-
kwargs={"builder": builder})
121+
kwargs={"builder": builder,
122+
"exception_q": exception_q})
121123
system_process.start()
122124
self._actors.append(system_process)
123125
return system_process

src/lava/magma/runtime/runtime.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
from lava.magma.core.run_conditions import (AbstractRunCondition,
4343
RunContinuous, RunSteps)
4444
from lava.magma.compiler.channels.watchdog import WatchdogManagerInterface
45+
from multiprocessing import Queue
4546

4647
"""Defines a Runtime which takes a lava executable and a pluggable message
4748
passing infrastructure (for instance multiprocessing+shared memory or ray in
@@ -94,13 +95,15 @@ def target_fn(*args, **kwargs):
9495
"""
9596
try:
9697
builder = kwargs.pop("builder")
98+
exception_q = kwargs.pop('exception_q')
9799
actor = builder.build()
100+
# No exception occured
101+
exception_q.put(None)
98102
actor.start(*args, **kwargs)
99103
except Exception as e:
100-
print("Encountered Fatal Exception: " + str(e))
101-
print("Traceback: ")
102-
print(traceback.format_exc())
103-
raise e
104+
e.trace = traceback.format_exc()
105+
exception_q.put(e)
106+
raise(e)
104107

105108

106109
class Runtime:
@@ -134,6 +137,7 @@ def __init__(self,
134137
self.num_steps: int = 0
135138

136139
self._watchdog_manager = None
140+
self.exception_q = []
137141

138142
def __del__(self):
139143
"""On destruction, terminate Runtime automatically to
@@ -160,6 +164,15 @@ def initialize(self, node_cfg_idx: int = 0):
160164
self._build_processes()
161165
self._build_runtime_services()
162166
self._start_ports()
167+
168+
# Check if any exception was thrown
169+
for q in self.exception_q:
170+
e = q.get()
171+
if e:
172+
print(str(e), e.trace)
173+
raise(e)
174+
del self.exception_q
175+
163176
self.log.debug("Runtime Initialization Complete")
164177
self._is_initialized = True
165178

@@ -293,17 +306,22 @@ def _build_processes(self):
293306
if isinstance(proc_builder, PyProcessBuilder):
294307
# Assign current Runtime to process
295308
proc._runtime = self
309+
exception_q = Queue()
310+
self.exception_q.append(exception_q)
296311
self._messaging_infrastructure.build_actor(target_fn,
297-
proc_builder)
312+
proc_builder,
313+
exception_q)
298314

299315
def _build_runtime_services(self):
300316
"""Builds the runtime services"""
301317
runtime_service_builders = self._executable.runtime_service_builders
302318
if self._executable.runtime_service_builders:
303319
for _, rs_builder in runtime_service_builders.items():
320+
self.exception_q.append(Queue())
304321
self._messaging_infrastructure. \
305322
build_actor(target_fn,
306-
rs_builder)
323+
rs_builder,
324+
self.exception_q[-1])
307325

308326
def _get_resp_for_run(self):
309327
"""

0 commit comments

Comments
 (0)