Tsetlin Machine¶
The Tsetlin IP core runs Tsetlin machine inference on Muninn clause arrays. A clause array is a content-addressable memory: each row holds the include bits of one clause, and a search compares every row against the input literals in a single cycle. The core adds the vote counting and the argmax on top.
On an ASIC the clause array is a prebuilt Muninn hard macro
(muninn_tcam_<variant>_<rows>x<cols>); its behavioural model comes from the
muninn-macros repository (MUNINN_MACROS or $NAFARR_BASE/ext/muninn-macros).
The variants share the pins and the cycle behaviour and differ in the layout:
dense and speed are full-custom arrays optimized for area and timing,
conservative is built mostly from standard cells.
On an FPGA, TcamModel implements the same behaviour with flip-flops.
All logic is bus-driven. There are no external IO signals besides the interrupt.
Features¶
One search per start: all clauses evaluated in one cycle; vote counting and argmax are combinational on the clause outputs, so the result is ready one cycle after the search
Winning class and its sum readable after a search
Several macros side by side (
tiles) for wider clausesOptional valid column: literal 0 is held at 0 during a search, so a row with include bit 0 set never matches (empty or unused clauses)
Interrupt on search completion
Supported buses: APB3, TileLink, Wishbone
Clause Mapping¶
Rows are grouped by class, class-major, clausesPerClass rows each; rows behind
the last class are unused. Inside a class,
even rows vote for the class and odd rows against it. A row matches when every included literal is 1.
The sum of a class is the number of matching even rows minus the number of matching
odd rows; the winner is the class with the highest sum, the lowest index on ties.
For a model with F boolean features, the literal columns are:
Column |
Literal |
|---|---|
|
Valid column (with |
|
Features |
|
Negated features |
|
Unused: include bit 0, searched with 1 |
Trained models and a bit-exact Python reference live in the muninn-reference-models repository.
Parameters¶
Parameter |
Default |
Description |
|---|---|---|
|
|
Clause array: rows, literal columns per macro, hard macro or |
|
|
Number of classes |
|
|
Clauses (rows) per class, even. |
|
|
Macros side by side; literals = |
|
|
Hold literal 0 at 0 during searches |
Register Map¶
The windows have a fixed size, so the register layout does not depend on the configuration.
Offset |
Name |
Description |
|---|---|---|
0x000 |
|
IP Identification header |
0x004 |
|
IP Identification version |
0x008 |
|
Clause array size: |
0x00C |
|
|
0x010 |
|
|
0x014 |
|
|
0x018 |
|
|
0x01C |
|
Row address for the next commit |
0x020 |
|
Write: copy the row buffer into the clause array row |
0x024 |
|
|
0x100 + 4w |
|
Row buffer, include bits of literals |
0x200 + 4w |
|
Search literals |
Programming¶
Writing a clause: fill data, write the row address to row, then write
commit. Rows are written whole; the include bits cannot be read back.
Running a search: fill literals, write start (keeping the interrupt enable
bit), wait for done or the interrupt, read result, and clear done.
Row data and literals share one buffer, since a commit and a search never run at the same time. Fill it completely before every commit and every search.
The C driver (software/include/tsetlin.h) wraps both:
tsetlin_write_clause(), tsetlin_search_start(), tsetlin_search_done(),
and tsetlin_result().