b_asic.architecture¶

B-ASIC architecture classes.
- class b_asic.architecture.Architecture(processing_elements: ProcessingElement | Iterable[ProcessingElement], memories: Memory | Iterable[Memory], entity_name: str = 'arch', direct_interconnects: ProcessCollection | None = None)¶
Class representing an architecture.
- Parameters:
- processing_elements
ProcessingElementor iterable ofProcessingElement The processing elements in the architecture.
- memories
Memoryor iterable ofMemory The memories in the architecture.
- entity_namestr, default: “arch”
Name for the top-level entity.
- direct_interconnects
ProcessCollection, optional Process collection of zero-time memory variables used for direct interconnects.
- processing_elements
- add_resource(resource: Resource) None¶
Add a new
Resourceto the architecture.- Parameters:
- resource
Resource The resource to add.
- resource
- assign_resources(strategy: Literal['left_edge'] = 'left_edge') None¶
Assign all resources in the architecture.
- Parameters:
- strategystr, default: “left_edge”
The heurstic to use.
See also
- property direct_interconnects: ProcessCollection | None¶
- get_interconnects_for_memory(mem: Memory | str) tuple[list[dict[tuple[Resource, int], int]], list[dict[tuple[Resource, int], int]]]¶
Return per-port interconnect information for a Memory.
- Parameters:
- mem
Memoryor str The memory or entity name to obtain information about.
- mem
- Returns:
- list
One dictionary per write port, mapping
(source resource, output port index)to the number of accesses.- list
One dictionary per read port, mapping
(destination resource, input port index)to the number of accesses. Resources may be processing elements or other memories for chained variables.
- get_interconnects_for_pe(pe: str | ProcessingElement) tuple[list[dict[tuple[Resource, int], int]], list[dict[tuple[Resource, int], int]]]¶
Return with interconnect information for a ProcessingElement.
The information is tuple, where each element is a lists of dictionaries.
- Parameters:
- pe
ProcessingElementor str The processing element or entity name to get information for.
- pe
- Returns:
- list
List of dictionaries indicating the sources for each input port and the frequency of accesses.
- list
List of dictionaries indicating the destinations for each output port and the frequency of accesses.
- get_multiplexer_input_count(multiplexed_only: bool = False) int¶
Return the number of multiplexer inputs in the architecture.
This corresponds to the total number of interconnect connections, where each source feeding a destination input contributes one multiplexer input.
- Parameters:
- multiplexed_onlybool, default: False
If
True, only destinations with fan-in greater than one are included. IfFalse, all connections are counted.
- Returns:
- int
Total number of multiplexer inputs (connections).
- move_process(proc: str | Process, source: str | Resource, destination: str | Resource, assign: bool = False) None¶
Move a
Processfrom oneResourceto another.Both the resource moved from and will become unassigned after a process has been moved, unless assign is True.
- Parameters:
- proc
Processor str The process (or its name) to move.
- source
Resourceor str The resource (or its entity name) to move the process from.
- destination
Resourceor str The resource (or its entity name) to move the process to.
- assignbool, default=False
Whether to perform assignment of the resources after moving.
- proc
- Raises:
KeyErrorIf proc is not present in resource source.
- property processing_elements: list[ProcessingElement]¶
- remove_resource(resource: str | Resource) None¶
Remove an empty
Resourcefrom the architecture.- Parameters:
- resource
Resourceor str The resource or the resource name to remove.
- resource
- resource_from_name(name: str) Resource¶
Get
Resourcebased on name.- Parameters:
- namestr
Name of the resource.
- Returns:
ResourceThe memory or processing element with the given entity name.
- set_entity_name(entity_name: str) None¶
Set entity name of hardware block.
- Parameters:
- entity_namestr
The entity name.
- show(fmt: str | None = None, branch_node: bool = True, cluster: bool = True, splines: Literal['spline', 'line', 'ortho', 'polyline', 'curved'] = 'spline', io_cluster: bool = True, multiplexers: bool = True, colored: bool = True, engine: str = 'dot', ranksep: float = 0.5, nodesep: float = 0.25, wire_labels: bool = True, orientation: Literal['horizontal', 'vertical'] = 'horizontal', mux_label: bool = True, fontname: str = 'DejaVu Serif', fontsize: int = 14, size: tuple[float, float] | None = None, show_edge_counts: bool = False) None¶
Display a visual representation of the Architecture using the default system viewer.
- Parameters:
- fmtstr, optional
File format of the generated graph. Output formats can be found at https://www.graphviz.org/doc/info/output.html Most common are “pdf”, “eps”, “png”, and “svg”. Default is None which leads to PDF.
- branch_nodebool, default: True
Whether to create a branch node for outputs with fan-out of two or higher.
- clusterbool, default: True
Whether to draw memories and PEs in separate clusters.
- splines{“spline”, “line”, “ortho”, “polyline”, “curved”}, default: “spline”
Spline style, see https://graphviz.org/docs/attrs/splines/ for more info.
- io_clusterbool, default: True
Whether Inputs and Outputs are drawn inside an IO cluster. Only relevant if cluster is True.
- multiplexersbool, default: True
Whether input multiplexers are included.
- coloredbool, default: True
Whether to color the nodes.
- enginestr, default: “dot”
Graphviz engine to use. See https://graphviz.org/docs/layouts/ for more info.
- ranksepfloat, default: 0.5
Horizontal distance (in inches) between ranks, e.g. between the memory column and the PE column.
- nodesepfloat, default: 0.25
Vertical distance (in inches) between nodes on the same rank.
- wire_labelsbool, default: True
When True, PE output connections are shown as small named stubs at the destination instead of routed arrows, reducing visual clutter from feedback paths.
- orientation{“horizontal”, “vertical”}, default: “horizontal”
Rendering orientation of the graph.
- mux_labelbool, default: True
Whether to include labels on the multiplexer nodes.
- fontnamestr, optional
Font to use for node labels. Defaults to
b_asic._preferences.DEFAULT_FONT_FAMILY.- fontsizeint, default: 14
Font size to use for node labels.
- size(float, float), optional
Maximum drawing size in inches as
(width, height).- show_edge_countsbool, default: False
Whether to display the number of times each connection is accessed as a label on the edge.
- write_component_declaration(f: TextIO, dt: _VhdlDataType, indent: int = 1) None¶
Write component declaration of hardware block.
- Parameters:
- fTextIO
File object (or other TextIO object) to write the declaration to.
- indentint, default: 1
Indentation level to use for this process.
- write_component_instantiation(f: TextIO, dt: _VhdlDataType, indent: int = 1, enable_pin: bool = True) None¶
Write component instantiation of hardware block.
- Parameters:
- fTextIO
File object (or other TextIO object) to write the instantiation to.
- indentint, default: 1
Indentation level to use for this process.
- write_signal_declarations(f: TextIO, dt: _VhdlDataType, indent: int = 1) None¶
- class b_asic.architecture.ControlTable(name: str, wl: tuple[int, int], values: dict[int, int], is_signed: bool)¶
Control table for PEs.
One control table per PE parameter is generated as part of the code generation.
- Parameters:
- namestr
The parameter name.
- wl(int, int)
Word length specification.
- valuesdict(int, int)
Dictionary with clock cycle and bit pattern.
- is_signedbool
Whether the parameter is signed or unsigned.
- class b_asic.architecture.HardwareBlock(entity_name: str | None = None)¶
Base class for architectures and resources.
- Parameters:
- entity_namestr, optional
The name of the resulting entity.
- set_entity_name(entity_name: str) None¶
Set entity name of hardware block.
- Parameters:
- entity_namestr
The entity name.
- class b_asic.architecture.Memory(process_collection: ProcessCollection, memory_type: Literal['RAM', 'register'] = 'RAM', entity_name: str | None = None, read_ports: int | None = None, write_ports: int | None = None, total_ports: int | None = None, assign: bool = False)¶
Create a memory from a ProcessCollection with memory variables.
- Parameters:
- process_collection
ProcessCollection The ProcessCollection to create a Memory for.
- memory_type{‘RAM’, ‘register’}, default: ‘RAM’
The type of memory.
- entity_namestr, optional
Name of memory entity.
- read_portsint, optional
Number of read ports for memory.
- write_portsint, optional
Number of write ports for memory.
- total_portsint, optional
Total number of read and write ports for memory.
- assignbool, default False
Perform assignment when creating the Memory (using the default properties).
- process_collection
- assign(strategy: Literal['left_edge', 'greedy_graph_color', 'ilp_graph_color'] = 'left_edge', **kwargs) None¶
Perform assignment of the memory variables.
- Parameters:
- strategystr, default: ‘left_edge’
The assignment algorithm. Depending on memory type the following are available:
- ‘RAM’
‘left_edge’: Left-edge algorithm.
‘greedy_graph_color’: Greedy graph-coloring based on exclusion graph.
‘ilp_graph_color’: Optimal graph-coloring based on exclusion graph.
- ‘register’
Forward-backward register allocation (automatic).
- **kwargsdict
Additional keyword arguments are passed to ~ProcessCollection.split_on_execution_time.
See also
ProcessCollection.split_on_execution_time
- property assignment: list[ProcessCollection]¶
Return the cell assignment.
- property collection: ProcessCollection¶
- property content: Figure¶
Return a graphical representation of the content.
This is visible in enriched shells, but the object itself has no further meaning (it is a Matplotlib Figure).
- property operation_type: type[MemoryProcess]¶
- plot_content(ax: Axes, **kwargs) None¶
Plot the content of the resource.
This plots the assigned processes executed on this resource.
- Parameters:
- axAxes
Matplotlib Axes to plot in.
- **kwargs
Passed to
plot().
- property port_assignment: dict[tuple[MemoryProcess, int | None], int]¶
Return the physical port for each memory access.
Keys are
(variable, delay);Nonedenotes the write access. Solver-selected ports are retained. Otherwise consecutive ports are allocated independently for each read/write cycle, wrapping at the declared port count. This allows temporary port conflicts while moving processes between memories;assign()rejects unresolved conflicts.
- remove_process(proc: Process, assign: bool = False) None¶
Remove a
Processfrom thisResource.Raises
KeyErrorif the process being added is not of the same type as the other processes.
- set_entity_name(entity_name: str) None¶
Set entity name of hardware block.
- Parameters:
- entity_namestr
The entity name.
- show_content(title=None, **kwargs) None¶
Display the content of the resource.
This displays the assigned processes executed on this resource.
- Parameters:
- titlestr, optional
Figure title.
- **kwargs
Passed to
plot().
- write_component_declaration(f: TextIO, dt: DataType, indent: int = 1, control_ports=(), include_schedule_counter: bool = True) None¶
Write component declaration of hardware block.
- Parameters:
- fTextIO
File object (or other TextIO object) to write the declaration to.
- indentint, default: 1
Indentation level to use for this process.
- write_component_instantiation(f: TextIO, indent: int = 1, en_sig: str = 'en', control_ports=(), include_schedule_counter: bool = True) None¶
Write component instantiation of hardware block.
- Parameters:
- fTextIO
File object (or other TextIO object) to write the instantiation to.
- indentint, default: 1
Indentation level to use for this process.
- class b_asic.architecture.ProcessingElement(process_collection: ProcessCollection, entity_name: str | None = None, assign: bool = True)¶
Create a processing element for a ProcessCollection with OperatorProcesses.
- Parameters:
- process_collection
ProcessCollection Process collection containing operations to map to processing element.
- entity_namestr, optional
Name of processing element entity.
- assignbool, default True
Perform assignment when creating the ProcessingElement.
- process_collection
- assign(strategy: Literal['left_edge', 'greedy_graph_color', 'ilp_graph_color'] = 'left_edge', **kwargs) None¶
Perform assignment of the processes.
- Parameters:
- strategy{‘left_edge’, ‘greedy_graph_color’, ‘ilp_graph_color’}, default: ‘left_edge’
The assignment algorithm.
‘left_edge’: Left-edge algorithm.
‘greedy_graph_color’: Greedy graph-coloring based on exclusion graph.
‘ilp_graph_color’: Optimal graph-coloring based on exclusion graph.
- **kwargsdict
Additional keyword arguments are passed to ~ProcessCollection.split_on_execution_time.
See also
ProcessCollection.split_on_execution_time
- property assignment: list[ProcessCollection] | None¶
- property collection: ProcessCollection¶
- property content: Figure¶
Return a graphical representation of the content.
This is visible in enriched shells, but the object itself has no further meaning (it is a Matplotlib Figure).
- property control_table: dict[str, ControlTable]¶
- plot_content(ax: Axes, **kwargs) None¶
Plot the content of the resource.
This plots the assigned processes executed on this resource.
- Parameters:
- axAxes
Matplotlib Axes to plot in.
- **kwargs
Passed to
plot().
- property processes: list[OperatorProcess]¶
- remove_process(proc: Process, assign: bool = False) None¶
Remove a
Processfrom thisResource.Raises
KeyErrorif the process being added is not of the same type as the other processes.
- set_entity_name(entity_name: str) None¶
Set entity name of hardware block.
- Parameters:
- entity_namestr
The entity name.
- show_content(title=None, **kwargs) None¶
Display the content of the resource.
This displays the assigned processes executed on this resource.
- Parameters:
- titlestr, optional
Figure title.
- **kwargs
Passed to
plot().
- write_component_declaration(f: TextIO, dt: _VhdlDataType, indent: int = 1, control_ports=()) None¶
Write component declaration of hardware block.
- Parameters:
- fTextIO
File object (or other TextIO object) to write the declaration to.
- indentint, default: 1
Indentation level to use for this process.
- write_component_instantiation(f: TextIO, dt: _VhdlDataType, indent: int = 1, en_sig: str = 'en', input_register: bool = False, output_register: bool = False, control_ports=()) None¶
Write component instantiation of hardware block.
- Parameters:
- fTextIO
File object (or other TextIO object) to write the instantiation to.
- indentint, default: 1
Indentation level to use for this process.
- write_signal_declarations(f: TextIO, dt: _VhdlDataType, indent: int = 1) None¶
- class b_asic.architecture.Resource(process_collection: ProcessCollection, entity_name: str | None = None)¶
Base class for resource.
- Parameters:
- process_collection
ProcessCollection The process collection containing processes to be mapped to resource.
- entity_namestr, optional
The name of the resulting entity.
- process_collection
- assign(strategy: Literal['left_edge'] = 'left_edge') NoReturn¶
Perform assignment of processes to resource.
- Parameters:
- strategystr
See the specific resource types for more information.
See also
- property assignment: list[ProcessCollection] | None¶
- property collection: ProcessCollection¶
- property content: Figure¶
Return a graphical representation of the content.
This is visible in enriched shells, but the object itself has no further meaning (it is a Matplotlib Figure).
- property operation_type: type[MemoryProcess] | type[Operation]¶
- plot_content(ax: Axes, **kwargs) None¶
Plot the content of the resource.
This plots the assigned processes executed on this resource.
- Parameters:
- axAxes
Matplotlib Axes to plot in.
- **kwargs
Passed to
plot().
- remove_process(proc: Process, assign: bool = False) None¶
Remove a
Processfrom thisResource.Raises
KeyErrorif the process being added is not of the same type as the other processes.
- set_entity_name(entity_name: str) None¶
Set entity name of hardware block.
- Parameters:
- entity_namestr
The entity name.
- show_content(title=None, **kwargs) None¶
Display the content of the resource.
This displays the assigned processes executed on this resource.
- Parameters:
- titlestr, optional
Figure title.
- **kwargs
Passed to
plot().
get_interconnects_for_memory returns two lists, indexed by the memory’s
write and read ports respectively, like get_interconnects_for_pe. Each
list entry maps (connected_resource, connected_port_index) to an access
count. Unused ports have empty dictionaries; memory-to-memory connections
are included.
Simultaneous accesses use distinct physical ports, except consumers reading
the same variable at the same delay, which share a broadcast read.
Memory.port_assignment exposes the read and write ports selected by the
joint mux assignment strategies. The architecture retains these choices when
built or rebuilt from the assigned collections. Memories without an optimized
assignment allocate consecutive ports within each cycle. Adding or removing
processes through the collection’s methods invalidates its saved port assignment.
With wire_labels=True, multi-output memories and PEs use labels such as
memory0_0 and memory0_1. The suffix is retained even if only one of
their outputs is connected.