From d9515d8fd65077029fac760f4fcb948e19b95513 Mon Sep 17 00:00:00 2001 From: yang1556 <92725391+yang1556@users.noreply.github.com> Date: Fri, 29 Nov 2024 23:50:09 +0800 Subject: [PATCH 1/2] support rinbuffer --- paibox/components/_modules.py | 5 +++-- paibox/components/functional.py | 15 +++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/paibox/components/_modules.py b/paibox/components/_modules.py index ea22fbe3..41da1bca 100644 --- a/paibox/components/_modules.py +++ b/paibox/components/_modules.py @@ -212,13 +212,14 @@ def _input_buffer_len_check( math.ceil(in_channels * in_h * kw / HwConfig.N_FANIN_PER_DENDRITE_ANN) ) ) - - if not kw * valid_interval > HwConfig.N_TIMESLOT_MAX / (2**E): + deep = min(in_h - kw, kw - 1) * valid_interval + 1 + if not HwConfig.N_TIMESLOT_MAX / (2**E) > deep: raise ResourceError( f"the input size of {self.name} is too large. Please adjust the input size or the number of channels." ) + class _LinearBase(FunctionalModule): def __init__( self, diff --git a/paibox/components/functional.py b/paibox/components/functional.py index 423af93c..732dd2f0 100644 --- a/paibox/components/functional.py +++ b/paibox/components/functional.py @@ -910,8 +910,13 @@ def build( ) -> BuiltComponentType: assert len(self.source[0].shape_out) == 2 self.ostream_attr = incoming_stream_attr + twe = 1 + self.ostream_attr.t_last_vld + ich, ih = self.source[0].shape_out + + if build_options.get("check_before_compile"): + self._input_buffer_len_check(ich, ih, ih, incoming_stream_attr.interval) n_delays = NodeList() s_delays = NodeList() s_weight = NodeList() @@ -932,7 +937,7 @@ def build( shape=(ich, ih), delay=incoming_stream_attr.interval * i + 1, tick_wait_start=self.tick_wait_start, - tick_wait_end=self.tick_wait_end, + tick_wait_end=twe - incoming_stream_attr.interval * i, keep_shape=self.keep_shape, name=f"n{i}_{self.name}", ) @@ -1049,7 +1054,6 @@ def build( ow, ) twe = 1 + self.ostream_attr.t_last_vld - if build_options.get("check_before_compile"): self._input_buffer_len_check(cin, ih, kw, incoming_stream_attr.interval) @@ -1069,13 +1073,12 @@ def build( keep_shape=self.keep_shape, name=f"nd_{self.name}", ) - for i in range(kw): neuron = ANNBypassNeuron( (cin, ih), delay=incoming_stream_attr.interval * i + 1, tick_wait_start=self.tick_wait_start, - tick_wait_end=twe, + tick_wait_end=twe - incoming_stream_attr.interval * i, name=f"n{i}_delay_{self.name}", ) n_delays.append(neuron) @@ -1235,7 +1238,7 @@ def build( (cin, ih), delay=incoming_stream_attr.interval * i + 1, tick_wait_start=self.tick_wait_start, - tick_wait_end=twe, + tick_wait_end=twe - incoming_stream_attr.interval * i, keep_shape=self.keep_shape, name=f"n{i}_{self.name}", ) @@ -1367,7 +1370,7 @@ def build( (cin, ih), delay=incoming_stream_attr.interval * i + 1, tick_wait_start=self.tick_wait_start, - tick_wait_end=twe, + tick_wait_end=twe - incoming_stream_attr.interval * i, keep_shape=self.keep_shape, name=f"n{i}_{self.name}", ) From 1a8372e112c3807822a2daf20932ff65360b3e84 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 2 Dec 2024 00:51:05 +0000 Subject: [PATCH 2/2] :rotating_light: auto fix by pre-commit hooks --- paibox/components/_modules.py | 1 - paibox/components/functional.py | 1 - 2 files changed, 2 deletions(-) diff --git a/paibox/components/_modules.py b/paibox/components/_modules.py index 41da1bca..990b5a77 100644 --- a/paibox/components/_modules.py +++ b/paibox/components/_modules.py @@ -219,7 +219,6 @@ def _input_buffer_len_check( ) - class _LinearBase(FunctionalModule): def __init__( self, diff --git a/paibox/components/functional.py b/paibox/components/functional.py index 732dd2f0..37aa6fc9 100644 --- a/paibox/components/functional.py +++ b/paibox/components/functional.py @@ -912,7 +912,6 @@ def build( self.ostream_attr = incoming_stream_attr twe = 1 + self.ostream_attr.t_last_vld - ich, ih = self.source[0].shape_out if build_options.get("check_before_compile"):