Skip to content

Commit

Permalink
DONE - chip deployment with DVS
Browse files Browse the repository at this point in the history
config_builder.build_config() returns 'Network is valid'.
  • Loading branch information
Willian-Girao committed Oct 30, 2024
1 parent 986bdfb commit b68e588
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 24 deletions.
26 changes: 13 additions & 13 deletions sinabs/backend/dynapcnn/chips/dynapcnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def get_dvs_layer_config_dict(cls, layer: DVSLayer): ...
# def write_dvs_layer_config(cls, layer: DVSLayer, config: DVSLayerConfig):
# for param, value in layer.get_config_dict().items():
# setattr(config, param, value)


@classmethod
def write_dvs_layer_config(
Expand All @@ -51,7 +50,7 @@ def write_dvs_layer_config(
----------
- layer (DVSLayer): Layer instance from which to generate the config
- layer2core_map (Dict): Keys are layer indices, values are corresponding
cores on hardware. Needed to map the destinations.]
cores on hardware. Needed to map the destinations.
- destination_indices (List): Indices of destination layers for `layer`
- chip_layer (DVSLayerConfig): Configuration object of the corrsesponding
on-chip core. Will be changed in-place based on `layer`.
Expand Down Expand Up @@ -295,7 +294,7 @@ def build_config(
----------
- layers (Dict): Keys are layer indices, values are DynapcnnLayer instances.
- layer2core_map (Dict): Keys are layer indices, values are corresponding
cores on hardware. Needed to map the destinations.]
cores on hardware. Needed to map the destinations.
- destination_indices (List): Indices of destination layers for `layer`
- dvs_node_info (dict): contains information associated with the `DVSLayer` node (if no DVS node exists it'll return `None`).
Expand All @@ -307,16 +306,6 @@ def build_config(
config = cls.get_default_config()
config.dvs_layer.pass_sensor_events = False

# Uses the DVS camera.
if isinstance(dvs_node_info, dict):
chip_layer = config.dvs_layer
sw_layer = dvs_node_info['module']
destination_indices = dvs_node_info['destinations']
# Write camera configuration.
cls.write_dvs_layer_config(sw_layer, layer2core_map, destination_indices, chip_layer)

# TODO - for now it's being handled separatly but it might make more sense to handle it within `layers`.

# Loop over layers in network and write corresponding configurations
for layer_index, ith_dcnnl in layers.items():
if isinstance(ith_dcnnl, DynapcnnLayer):
Expand All @@ -329,6 +318,17 @@ def build_config(
chip_layer=chip_layer,
destination_indices=destination_map[layer_index],
)
elif isinstance(ith_dcnnl, DVSLayer) and isinstance(dvs_node_info, dict):
# Uses the DVS camera.
chip_layer = config.dvs_layer
sw_layer = ith_dcnnl
destination_indices = destination_map[layer_index]
# Write camera configuration.
cls.write_dvs_layer_config(
layer=sw_layer,
layer2core_map=layer2core_map,
destination_indices=destination_indices,
chip_layer=chip_layer)
else:
# shouldn't happen since type checks are made previously.
raise TypeError(
Expand Down
8 changes: 3 additions & 5 deletions sinabs/backend/dynapcnn/dynapcnn_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,6 @@ def _make_config(
the provided device can be found.
"""
config_builder = ChipFactory(device).get_config_builder()

# TODO not handling DVSLayer yet.
has_dvs_layer = self.has_dvs_layer()

if chip_layers_ordering is not None:
Expand Down Expand Up @@ -545,7 +543,7 @@ def _make_config(
)

if has_dvs_layer:
# TODO not handling DVSLayer yet.
# TODO - DVS layer has been incorporated: what should happen here?
pass
self._layer2core_map = layer2core_map

Expand All @@ -554,10 +552,10 @@ def _make_config(
layers=self.dynapcnn_layers,
destination_map=self.layer_destination_map,
layer2core_map=layer2core_map,
dvs_node_info=dvs_node_info,
dvs_node_info=self.dvs_node_info,
)

# TODO not handling DVSLayer yet (this is from the old implementation, should be revised).
# TODO - this is from the old implementation, should be revised.
if self.input_shape and self.input_shape[0] == 1:
config.dvs_layer.merge = True

Expand Down
6 changes: 1 addition & 5 deletions sinabs/backend/dynapcnn/dynapcnnnetwork_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,7 @@ def destination_map(self):
@property
def dynapcnn_layers(self):
# Convert string-indices to integers-indices
dynapcnn_layers = {int(idx): lyr for idx, lyr in self._dynapcnn_layers.items()}
# Insert DVS node if DVS was enabled.
if isinstance(self.dvs_node_info, Dict):
dynapcnn_layers[self.dvs_node_info['layer_id']] = self.dvs_node_info['module']
return dynapcnn_layers
return {int(idx): lyr for idx, lyr in self._dynapcnn_layers.items()}

@property
def entry_points(self):
Expand Down
2 changes: 1 addition & 1 deletion sinabs/backend/dynapcnn/sinabs_edges_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def fix_dvs_module_edges(edges: Set[Edge], indx_2_module_map: Dict[int, nn.Modul
if any(isinstance(module, dvs_node) for dvs_node in (DVSLayer, Crop2d, FlipDims))
}

if len(dvslayer_nodes) == 1:
if len(dvslayer_nodes) <= 1:
# No module within the DVSLayer instance appears as an independent node - nothing to do here.
return

Expand Down

0 comments on commit b68e588

Please sign in to comment.