Skip to content

Commit 1fedfd1

Browse files
committed
feat(export): add shared graph export contracts
Closes #688
1 parent 21f9a71 commit 1fedfd1

5 files changed

Lines changed: 893 additions & 0 deletions

File tree

docs/modules/ROOT/nav.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
** xref:how-to/arduino-c-codegen.adoc[Generate C for Arduino]
1515
* Reference
1616
** xref:reference/architecture.adoc[Architecture]
17+
** xref:reference/graph-export-architecture.adoc[Graph export architecture]
1718
** xref:reference/operators/generated/index.adoc[Operator reference]
1819
** xref:reference/ops-status-matrix.adoc[Operator coverage matrix]
1920
** xref:reference/api.adoc[API reference (Dokka)]
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
= Graph Export Architecture
2+
3+
SKaiNET export backends should share the same graph-export workflow while keeping backend writers separate.
4+
5+
The shared boundary is the captured graph representation. The shared contracts live in `skainet-compile-core` under `sk.ainet.compile.export` and cover diagnostics, generated artifact metadata, result envelopes, mutable export contexts, writers, verifiers, and component naming conventions.
6+
7+
== Shared workflow
8+
9+
[source,text]
10+
----
11+
source model or imported model
12+
-> graph capture
13+
-> validation
14+
-> backend lowering
15+
-> backend writer
16+
-> optional packaging
17+
-> optional verification
18+
----
19+
20+
Backends can skip stages that do not apply. For example, StableHLO does not need a project packager, while Minerva does.
21+
22+
== Backend writers
23+
24+
StableHLO and Minerva should not be forced into one writer abstraction beyond the common result and diagnostic model.
25+
26+
[cols="1,2,2", options="header"]
27+
|===
28+
| Backend
29+
| Lowering model
30+
| Writer output
31+
32+
| StableHLO
33+
| Individual graph operations are lowered through operation converters.
34+
| MLIR module text represented by `StableHloModule`.
35+
36+
| Minerva
37+
| Supported graph patterns are lowered into sequential layer descriptors.
38+
| Minerva intermediate model, `.npz` compiler input, generated C artifacts, packaged host and firmware project.
39+
|===
40+
41+
== Naming conventions
42+
43+
Use the following suffixes consistently for export components:
44+
45+
[cols="1,2", options="header"]
46+
|===
47+
| Suffix
48+
| Responsibility
49+
50+
| `Converter`
51+
| Lower source graph structures into a backend intermediate.
52+
53+
| `Context`
54+
| Carry backend state, diagnostics, and generated artifacts.
55+
56+
| `Registry`
57+
| Map operation names or graph patterns to backend converters.
58+
59+
| `Factory`
60+
| Construct a backend exporter with standard converter registrations.
61+
62+
| `Writer`
63+
| Write a backend intermediate to files, text, or model bytes.
64+
65+
| `Verifier`
66+
| Run backend-specific validation after writing artifacts.
67+
|===
68+
69+
== StableHLO alignment
70+
71+
The current StableHLO implementation already follows most of this shape:
72+
73+
* `StableHloConverter` is the backend converter.
74+
* `ConversionContext` is the backend context.
75+
* `StableHloOperationRegistry` maps operation names to converters.
76+
* `StableHloConverterFactory` creates standard converter sets.
77+
* `StableHloModule` is the backend result object.
78+
79+
StableHLO should keep its public API and MLIR output stable while adopting shared diagnostics where useful.
80+
81+
== Minerva direction
82+
83+
Minerva should start as a sibling backend, not as a hidden mode of the Arduino/C99 exporter.
84+
85+
The first Minerva implementation should use this shape:
86+
87+
[source,text]
88+
----
89+
ComputeGraph
90+
-> MinervaCompatibilityValidator
91+
-> MinervaLayerPatternRegistry
92+
-> MinervaLayerPatternConverter
93+
-> MinervaIntermediate
94+
-> MinervaNpzWriter
95+
-> PythonMinervaCompilerAdapter
96+
-> MinervaProjectPackager
97+
-> MinervaHostVerifier
98+
----
99+
100+
Minerva should fail fast for unsupported graphs. StableHLO may keep comments or fallback paths where that behavior is already part of its compatibility story, but Minerva export should not invoke the compiler after a compatibility error.

0 commit comments

Comments
 (0)