ml_switcheroo.compiler.backends.sass¶
SASS Backend Package.
Contains the backend implementation for synthesizing NVIDIA SASS assembly from the Logical Graph representation.
Submodules¶
Classes¶
Bidirectional transpiler component. |
|
Compiler Backend implementation for NVIDIA SASS. |
|
Converts SASS AST nodes into textual assembly code. |
Package Contents¶
- class ml_switcheroo.compiler.backends.sass.SassSynthesizer(semantics: ml_switcheroo.semantics.manager.SemanticsManager)[source]¶
Bidirectional transpiler component.
Handles: 1. Forward (Graph -> SASS): Synthesizes Assembly from Logical Graphs.
Delegates high-level ops (Conv2d, Linear) to Macros, and low-level ops (Add, Mul) to Semantic Opcode Lookup.
Reverse (SASS -> Python): Synthesizes Python AST from Assembly nodes.
- semantics¶
- allocator¶
- macro_registry: Dict[str, Callable]¶
- from_graph(graph: ml_switcheroo.compiler.ir.LogicalGraph) List[ml_switcheroo.compiler.frontends.sass.nodes.SassNode][source]¶
Converts a LogicalGraph into a list of SASS AST nodes.
Process: 1. Sorts nodes topologically. 2. Traverses nodes. 3. For each node:
Check if it matches a Macro (e.g. Conv2d). If so, expand kernel.
If not, lookup abstract opcode mapping (e.g. Add -> FADD).
Allocate/Resolve Input Registers.
Allocate Output Register.
Construct Instruction node.
Handles Input nodes by pre-allocating registers (Contract: R0, R1…).
- Parameters:
graph (LogicalGraph) – The input computation graph.
- Returns:
A structured list of assembly nodes.
- Return type:
List[SassNode]
- to_python(sass_nodes: List[ml_switcheroo.compiler.frontends.sass.nodes.SassNode]) libcst.Module[source]¶
Converts SASS AST nodes into a Python source structure representation.
Used for analysis or round-trip verification. Registers are treated as variables. Instructions map to function calls sass.OPCODE(args).
- Structure:
R0 = sass.FADD(R1, R2)
- Parameters:
sass_nodes (List[SassNode]) – List of parsed SASS nodes.
- Returns:
A LibCST module containing the Python representation.
- Return type:
cst.Module
- class ml_switcheroo.compiler.backends.sass.SassBackend(semantics: ml_switcheroo.semantics.manager.SemanticsManager | None = None)[source]¶
Bases:
ml_switcheroo.compiler.backend.CompilerBackendCompiler Backend implementation for NVIDIA SASS. Orchestrates the synthesis (Graph -> AST) and emission (AST -> Text).
- synthesizer¶
- emitter¶
- compile(graph: ml_switcheroo.compiler.ir.LogicalGraph) str[source]¶
Compiles LogicalGraph to SASS Assembly string.
- Parameters:
graph – The intermediate representation.
- Returns:
The SASS code.
- Return type:
str
- class ml_switcheroo.compiler.backends.sass.SassEmitter[source]¶
Converts SASS AST nodes into textual assembly code.
- emit(nodes: List[ml_switcheroo.compiler.frontends.sass.nodes.SassNode]) str[source]¶
Generates the SASS source string from a list of nodes.
Formatting Rules: - Labels (e.g. L_1:) are rendered flush-left. - All other nodes are indented by 4 spaces.
- Parameters:
nodes (List[SassNode]) – AST nodes.
- Returns:
The formatted SASS source code string.
- Return type:
str