We put a tiny LLM on an FPGA. How fast could it go?
Our tiny, useless transformer on the Kria KV260

A chip that can change its job
A field-programmable gate array, or FPGA, is a chip whose internal circuit we can configure after manufacture. Think of it as blank slate of of available logic blocks and wires arranged in a grid which we can connect in almost any way we'd like.1 The transistors and metal wires already exist, but logic outputs and signal pathways can be written into small SRAM memory blocks spread throughout the chip.
In this article we will demonstrate the basic workings of an FPGA along with all its advantages, such as configurability (they are Programmable in the Field), speed, parallelisability and ability to simultaneously read and control huge numbers of inputs and outputs. Its disadvantages include high cost and power consumption, and complexity. Later we will use our FPGA (AMD's KRIA KV260) to run inference of a tiny LLM, and explore ways of improving performance.
Around the edge of the chip, input/output blocks connect the internal circuit to physical pins and thus the outside world. Pins can be configured to receive signals, send them, or do both.2 Other dedicated pins such as the power supply are not shown.
This large number of connections lets an FPGA exchange several streams of data at once. This is useful anywhere needing lots of fast data movement: cameras, large displays, robots and drones. However the achievable data rate depends also on the user's custom design implemented within the FPGA's circuits, not simply the number of pins.3
The larger squares are configurable logic blocks, or CLBs. Each contains circuitry with stored settings that we can choose, dictating how it transforms its incoming signals into outputs. Later, we will open one up and see how it stores and performs a simple task.4
The CLBs and I/Os are interconnected by many wires carrying electrical signals.
The routes these wires take is chosen by electrically controlled, configurable switches. Stored settings at the wire junctions choose which wire segments they connect, directing signals through the chip.5
Let’s configure our first circuit. We can represent one bit, either 0 or 1, using a low or high voltage respectively. A logic gate is a circuit that takes one or several inputs and produces an output bit according to a set rule.
We choose two pins as inputs, A and B, and one as an output. Our selected paths lead through the upper-left CLB, which we have configured to perform the logic gate AND: its output is 1 only when both inputs are 1. With A = 1 and B = 1, the output is 1.
Say B now changes to 0. The inputs are no longer both 1, so the output becomes 0. The AND rule and connections stay in place: the circuit responds to a new input without being reconfigured.
Now keep A at 1 and B at 0, and change the stored rule in the CLB to OR. OR outputs 1 if at least one input is 1, so our output changes to 1. The same block and paths perform a different function because we changed a setting inside the CLB.
Changing an input supplies new data. Changing the stored rule reconfigures how that data is processed. Before peering inside a CLB to explore how they work, let’s consider why engineers use FPGAs at all.
Why use an FPGA?
Imagine our chip among the electronics of the ATLAS particle detector at CERN. Particles produced in a collision scatter and pass through layers of sensors, which produce electrical signals for the processing electronics.6 There is far too much data to record in full.
The first stage of filtering looks at signals from several parts of the detector. FPGAs help identify promising events from the energy measured by the detector. The first stage can take in about 40 million events per second and passes on around 100,000 for closer analysis.7
Now imagine the same chip sits between incoming live video and a set of large LED displays, perhaps at a live concert. Each display tile needs the correct pixels at the correct time, with as little delay as possible. The FPGA organises the picture and sends several streams of pixels to the LED display circuits in parallel.8
This case requires a large amount of both input and output data processing each second, and very meticulous and coordinated timing. A good FPGA design can do all of this at once.
And for perhaps our most relevant use case: testing a circuit we might eventually manufacture as an application-specific integrated circuit, or ASIC: a chip designed to accelerate a particular tast, but unalterable once mass-produced. Engineers can load a proposed design, supply test inputs, read the results and reconfigure the FPGA to correct mistakes before making the final custom chip.9 The prototype tests behaviour rather than the final ASIC’s speed or power consumption.
These examples show the advantages we introduced at the start. At CERN, an FPGA processes many inputs in parallel to make fast decisions. For the display, it coordinates many outputs with precise timing. In the prototype, reconfigurability lets engineers correct and test a design without manufacturing another chip.
The trade-offs matter too: our design must fit the chip’s available resources, and making it work can be complex. We’ll also consider cost and power consumption, which often make other chips a better choice for most tasks. First, let’s return to the chip and open one logic block to understand how these capabilities work.
Inside a logic block
Let's zoom in on one configurable logic block.
A CLB contains several look-up tables, or LUTs: small circuits that store an output for each possible combination of inputs. It also contains flip-flops, which remember results. We’ll examine each in turn. CLBs in our FPGA contain eight LUTs and sixteen flip-flops, alongside other circuitry.4
We will follow one LUT and one flip-flop. We’ll start with how the LUT produces a result in a small corner of the FPGA chip, then see how the flip-flop remembers and moves it.
A LUT implements a logical rule by storing the output bit for every possible combination of inputs. Our example has two inputs, A and B, giving four combinations: AB = 00, 01, 10 and 11. This means we need four storage bits to decide what the output should be for each of these inputs.
In the figure, the AB column labels these input combinations. For each input, there is a stored output answer in SRAM, resulting in four bits of SRAM. The input signals A = 1 and B = 0, select the SRAM answer bit for 10. For AND, shown in the figure now, that answer is 0: only 11 gives 1. Changing the stored answers in SRAM changes the logic rule. OR, for example, gives 1 whenever either input is 1:
A |
B |
Stored SRAM for AND | Stored SRAM for OR |
|---|---|---|---|
0 |
0 |
0 |
0 |
0 |
1 |
0 |
1 |
1 |
0 |
0 |
1 |
1 |
1 |
1 |
1 |
Selection circuits called multiplexers, labelled MUX, connect one of those answers to the output. A two-input MUX uses a selection bit to choose its first input for 0 or its second for 1.10
Here, the input B is connected to the first two MUXes, and selects within each pair of answers. A is connected to the final MUX and selects between the pairs. With A = 0 and B = 1, the final MUX selects the top channel and the top MUX selects its lower input, resulting in a final output with the answer from SRAM row 01, which is 0, as expected for AND. The input signals are designed to select a path through the circuit. They do not search the rows one after another or rewrite the stored answers.11
Let’s make the same change we saw at the start, from AND to OR, by rewriting those two bits.
Writing the stored rule
Let's zoom into the SRAM block for row 01. Static random-access memory, or SRAM, uses the feedback principle we explored in Sand to Thought’s Memory chapter. In this case, two connected NOT gates reinforce opposite values (while power is supplied).12
The triangles with small circles at their tips represent NOT gates, each built from two transistors. The two dots on the wires show where each NOT gate’s output connects to the other’s input. The right side of the cell holds the LUT’s stored answer. The left side of the cell holds the opposite value. The two access transistors act as switches that connect each side of the cell to its writing wire. Together, the NOT gates and switches use just six transistors, making a compact, rewritable cell.12
With access set to 0, the switches are off and the cell holds 0, even though the writing wires are ready to change it.
To store a 1, we set the left writing wire to 0 and the right one to 1. Turning access on connects the writing wires to the cell. The left side of the cell goes low. The right side of the cell goes high, changing the stored answer to 1.12
Don't we get a short circuit?
Yes, briefly. During a write, current can flow from the power supply to ground (0 V).
The writing circuit pulls the left side of the cell low. The right side goes high, switching off the transistor at the top left. That cuts off the current.12
Turn access off again. The writing wires are isolated from the storage circuit, and powered feedback maintains the new answer. We have successfully programmed this storage cell from a 0 to a 1.
Now zoom back out to the complete LUT. We changed row AB = 01 from 0 to 1. Repeating that write for row 10 completes the change from AND’s 0, 0, 0, 1 to OR’s 0, 1, 1, 1. The selector circuit formed of MUXes stays the same, all that needs to change are the SRAM answer bits. We have rewritten the answers to convert this LUT into an OR gate.
For a LUT with n inputs and one output, we need 2ⁿ SRAM answers: four inputs need 2⁴ = 16, while six need 2⁶ = 64. Several LUTs can be stacked together to perform more complex functions.11 A larger LUT can reduce the number of logic stages and wired connections, but each extra input doubles its answer storage. In our MUX design, it also doubles the number of branches. Manufacturers balance these costs against speed.13
We will return to how this SRAM configuration data reaches the chip later.
Keeping a result
Let's zoom back out to our CLB. After the LUT comes a flip-flop: a circuit whose output remembers one bit. It is designed to hold, at its output, the last bit value fed into its input, when the clock was last triggered. Between clock triggers, it holds that saved value even if the input changes, which allows the LUT's previous result to be held steady and passed into later LUTs/CLBs for processing while the preceding LUT calculates the next value. Here, the LUT has prepared 1, but the flip-flop still holds 0 from an earlier capture.14
For a closer look inside a flip-flop, see MIT’s illustrated explanation.15
Now the clock is triggered, and the flip-flop captures the waiting 1 from the LUT. The bit's signal moves from the input side to the output side, and the saved value becomes 1. Each later clock pulse captures the input again. Between pulses, the saved output stays in place.
Now let's pause the clock and change the LUT’s inputs, forcing its output become 0. With no new trigger, the flip-flop’s saved value stays 1.
The MUX on the right chooses what leaves the logic block. It can send the LUT’s new 0 straight through to be immediately processed or pass on the 1 the flip-flop has buffered from the last clock pulse.
A stored setting chooses between the LUT’s direct output and its saved result.4 In our diagram, an SRAM bit tells the MUX which path to use. Here the setting is 1, so the MUX selects the flip-flop and the block sends out the saved 1.
The LUT’s SRAM configuration remembers the logic or function the LUT should enact, while the flip-flop's memory remembers and buffers a result produced as the circuit runs. We will introduce more kinds of memory and their uses in our FPGA later.
Choosing the connections
Now we zoom back out to see the whole chip. While one CLB can only perform simple calculations among its array of LUTs and flip-flops, combining blocks introduces the possibility to perform much larger, more complex maths and functions. This programmable routing is achieved using the wires and configurable switches between CLBs.
Let's zoom into one particular switch at the junction between four CLBs. This switch is connected to, at its inputs, a wire from the upper-left CLB 1 and the one below it (4). Its output feeds into the central CLB 5.
Inside, another MUX connects one of two incoming wires to an outgoing wire.10 A configuration SRAM cell holds a bit whose voltage controls the MUX's transistors. With its SRAM set to 0, the CLB 1 is connected to CLB 5, carrying signal 1. The lower wire remains unselected.
This is another important use of SRAM configuration memory: here it remembers a connection choice rather than a LUT answer. This setting stays in place while data signals pass through, and the MUX behaves as a railway switch for voltage. Each junction contains many MUXes and configuration bits, giving us much freedom in the connections between CLBs.
Rewrite the SRAM setting to 1. Now, CLB 4 is connected to CLB 5, carrying signal 0. The transistors inside the MUX now select a different existing path - the wires themselves have not moved.
Each of these switches take up space. Compared with a hardwired chip wired for the same job, signals may travel along longer wires or through more switches. Charging and discharging those longer wires and extra connections can use more energy and take more time, but this is the trade-off for configurability.16
We changed one connection by rewriting a single bit. How do we load all the SRAM settings for a whole circuit?
Configuring the whole chip
Let’s widen the circuit to allow more blocks on our chip. To configure an FPGA, we load a file of settings called a bitstream. In this example, the bitstream is stored in off-chip flash memory.17 Flash retains its contents when the power is off.18 On our KV260, Linux loads the inference bitstream from microSD.19 The configuration block on the chip receives these settings and writes them into memory spread throughout the logic and routing. AMD calls the cells that hold the settings configuration latches. They can be rewritten and hold their settings while the chip is powered, like the SRAM cell we drew earlier.20
Before we can load a bitstream, design tools have to fit our circuit into the available blocks, find routes between them and check that signals arrive in time for the next clock edge. A design can give the right answers in simulation and still miss its timing target. An early version of our inference circuit missed its target of 100 MHz, or 100 million clock cycles per second.
The configuration block has a dedicated path for loading settings.17 Here we show it writing a red 0 into the routing MUX’s storage cell. This selects the upper incoming wire connecting CLB 1 to CLB 5.
Looking inside CLB 1 we see four simplified LUTs, each with four SRAM answer bits. Our configuration block sends data to each, setting each LUT to respectively perform AND, OR, NOR (NOT OR) and NAND (NOT AND) operations. In reality this writing occurs in batches.21
All the many flip-flops inside CLBs also need a shared clock to coordinate when to move results across to their next position. Let's add a clock system to distribute an incoming clock through a dedicated network of wires and buffers, separate from ordinary data routing. This delivers the oscillating clock signal across the chip with minimal difference in arrival times.22
Memory and arithmetic
So far, we have used SRAM to hold settings, and flip-flops to hold results. But suppose our circuit receives a stream of, say, sensor readings and needs to keep many of them for later. We need somewhere to store a collection of numbers.
Some LUTs can use their SRAM to hold working data. This use is called distributed RAM.23 It is useful for small memories, but storing larger collections this way can use up the CLBs we need for calculations and control.
To fix this problem, let’s introduce block RAM, or BRAM, a dedicated memory for working data. Each address selects a group of bits that the circuit can read or write together. We could save one reading at address 0, the next at 1 and so on, to read them back when needed, much like the memory array we built in Sand to Thought’s Memory chapter.
Let’s zoom into that memory block. Like the LUT storage, BRAM uses SRAM cells. Here we will store information for the circuit to work on, rather than the answers that define a LUT’s logic rule. Saving a new reading changes the data at the chosen address.
Our KV260’s FPGA has 144 BRAM blocks, together providing about 660 kilobytes (KB) of storage. Its LUTs can also provide up to roughly 450 KB of distributed RAM.24
Our FPGA also has 64 larger dedicated SRAM blocks called UltraRAM, providing another 2.4 megabytes (MB) of storage.24 Each holds eight times as much as a BRAM block and can be linked to others to store larger collections of data, such as model weights, without using LUTs for storage.25
Our example has four memory locations, each holding four bits. The thick lines with slashes represent bundles of wires, called buses. The address bus has two wires, each carrying one bit. Together they carry the signals 00, 01, 10 or 11, selecting locations 0, 1, 2 or 3. Each data bus (read or write) has four wires and carries four bits at once, such as 0011 for the number 3. To read, the circuit supplies an address and receives the stored bits. To write, it supplies an address, the new bits and a write-enable signal, set to 1 to allow writing or 0 to prevent it. The clock pulse determines when the memory carries out the read or write.26
In the figure, each square is one SRAM bit, with green 1s and red 0s. Our example begins with a BRAM full of SRAM zeros, then automatically writes random values to different addresses. You can pause it and choose your own address and data. Write enable opens the small gate on the data bus (this is a visual aid, not a literal moving part). The selected row saves the new bits when the clock pulse arrives.
The address, data and control wires connect to other blocks through the routing grid, allowing CLBs to control BRAM.5
We can now store our readings and processed data, but what if we want to perform the common task of multiplication? We could build a multiplier from LUTs and other CLB circuitry, but this can use up many resources.
Adding two unsigned 12-bit numbers would take roughly a dozen LUTs plus dedicated carry logic, based on AMD’s example of an eight-bit adder.27 A carry chain gives carries a dedicated path between neighbouring logic cells, speeding up addition.28 On its XCZU9EG chip, AMD reports 125 and 141 LUTs for two versions of a 12-bit multiplier built without DSPs.29 On our FPGA, the same multiplication fits into one DSP block.30
A digital signal processing block, or DSP block, provides dedicated multiplication and addition circuitry already hardwired into the silicon, leaving more CLBs free for other tasks. Its specialised circuitry can be faster and use less power than an equivalent circuit built from CLBs.
Let’s zoom into a DSP block. Here, a stored reading of 3 is multiplied by 2, producing 6. The ready-made multiplication circuitry is already there, connected to inputs. We only need to configure how to connect it, rather than constructing the multiplier from LUTs. See Xilinx’s detailed DSP block diagram.
DSP blocks can also add each new product to a running total, the sum of the products processed so far, which turns out to often be very useful.30 The DSP’s built-in output register holds this total between clock edges. It uses one flip-flop for each bit of the total. The saved register value starts at 0. The multiplier supplies 6, and the adder prepares 0 + 6 = 6. The register holds 0 until the next clock edge.
Upon a clock trigger, the register replaces 0 with 6. Its output connects back to the adder along the lower wire which lets the next addition use the running total.
Say we have a new set of inputs 2 × 2 producing 4. The adder combines this with our saved 6, preparing 6 + 4 = 10. The next clock trigger replaces the saved total with 10. We have added two products, 6 and 4, using the same multiplier, adder and register.
Finally, the I/O blocks around the chip's edge provide another source of input and output data. They receive signals from physical pins and drive signals out through them.
In this example, a signal from an input pin starts the calculation. The CLBs tell BRAM which pair of numbers to send to the DSP. The DSP updates the running total, and the result leaves through an output pin.
Our inference design will use DSPs this way, reusing the arithmetic circuitry across many pairs and we will follow how a neural network activation calculation maps on to a DSP soon.
Configuration SRAM memory holds the settings that define the circuit’s logic and connections. Flip-flops keep individual bits, such as those in the DSP’s running total, directly available to the logic that uses them. Some LUTs can store small collections of working data as distributed RAM.23 BRAM provides a dedicated data bank that packs more bits into the same chip area than a bank of flip-flops. The trade-off is that the circuit can read or write only a few bits per block at a time.31
In our inference design, we use BRAM for the model’s weights and for the KV cache.
Real FPGAs contain many copies of CLB, BRAM and DSP blocks. Different chip families provide different mixes, quantities and memory configuration.32
Together, these blocks form a simple FPGA: BRAM holds data, DSPs multiply and add, and CLBs implement the remaining logic, save results and control what happens next. Routing carries signals between them, while the clock coordinates when calculations are performed and results are captured. By configuring these blocks of specialised circuits and their connections, we can build our neural-network inference circuit.
Our FPGA’s first neuron
Our goal is to run a tiny language model on our FPGA. Given some text, it predicts the next piece of text, called a token. It then uses that token to help predict the next one.
We trained an extremely small, rather mindless model with 26,720 parameters on forty-eight chip jokes we wrote ourselves. It is heavily overfitted, so it tends to repeat the jokes it has seen. Our tiny model shares the basic architecture of much larger language models. It gives us a way to test, on a small scale, ideas that could make inference faster or more energy-efficient on larger models.
Each token starts as a list of learned numbers. Attention combines information from this token and earlier ones. The next set of results from calculations in the feed-forward network is added to those numbers again, and the model uses the final result to score possible next tokens.
Let’s zoom into one of those calculations. Each incoming number is multiplied by a weight, a number learned during training. Adding the products gives a weighted sum. This is the arithmetic at the heart of an artificial neuron.33
To make it easy to follow, we show just two inputs, 3 and 2, with weights of 2 and −1 for each connection.
The first connection contributes 3 × 2 = 6. The second contributes 2 × (−1) = −2, reducing the total. Together they give 6 + (−2) = 4. The result becomes one of the numbers used by the next calculation in the next neural network layer. The weights stay fixed throughout.
We already have the FPGA blocks needed for this sum. BRAM holds the input numbers and weights. CLBs control which pair to read next, and a DSP multiplies the pair and adds its product to a running total.
The two input–weight pairs can take turns through the same DSP. We can reuse that circuitry for other neurons too. Let’s open it and follow the same numbers.
First, memory supplies input 3 and weight 2. The multiplier produces 6. Our running total starts at 0, so the adder prepares 0 + 6 = 6. A clock edge saves 6 in the DSP’s register, just as in our earlier running-total example.
Next, memory supplies input 2 and weight −1. The same multiplier now produces −2. The adder combines it with the saved 6, and the next clock edge saves 4. We have carried out both connections using one multiplier, one adder and one register.
This is one small part of a neuron’s calculation. Neural networks also apply rules that reshape these sums before passing numbers onward. Our transformer combines many such calculations to produce its next-token scores.
Can our neural network use fixed-point numbers?
Fixed-point numbers represent fractions using integers and an agreed scale. If we count in sixteenths, stored 20 means 20 ÷ 16 = 1.25. Using fewer bits saves memory and can simplify the arithmetic, but rounding can change the model’s predictions.34
Each input and weight in our weighted sum fits in 16 bits. A product can need up to 32 bits, and adding many products can take even more room. The DSP keeps the running total in 48 bits. Once it has added all the products, we convert the total from the products’ scale to the scale used for the output, then round it to an integer for 16-bit storage.
Running a tiny transformer
The first words of a sentence can change what comes next. Our transformer uses attention to decide how much information to draw from each token it has processed so far. Each time it processes a token, it makes a key and a value, both lists of numbers. The key helps a later token decide how much to draw on this position. The value supplies the numbers it can draw on. The multiply-and-add operation we just followed helps make these lists. Let’s zoom back out from the DSP to see where we keep them.
Let’s open BRAM. The first two rows of the KV cache hold keys and values for tokens we’ve already processed. Each new token adds its own pair.35 Attention compares the current token’s query, another list of numbers, with the stored keys to decide how much of each value to mix in.36
To calculate the query, the FPGA starts with the same weighted sum we saw in the neuron example. For each sum, the FPGA reuses one DSP multiplier 32 times, multiplying one input by its learned weight each time. It adds each product to a running total. Each sum gives one number in the query. For the next number, the FPGA uses the same inputs with a different set of weights.
Each square represents one number. Each key and value has one grid per attention head. We follow the first head.
Each token adds 128 bytes to our cache. Saving those numbers lets us reuse them for later predictions. The learned weights stay the same as the cache grows.
How are the cache addresses arranged?
There is room for 256 tokens, including the start token, so the cache can hold 32 KiB. Keys and values occupy separate memory banks. In each bank, a token takes up thirty-two consecutive entries, each holding one two-byte number. The entry index is position × 32 + coordinate, where the coordinate is the number’s place within the key or value, counting from zero.
Let’s follow the first two predictions from a request containing the letter a. Once the FPGA has processed the prompt, it sends a list of scores to the CPU. The CPU picks the token with the highest score, adds it to the output and sends it back through the model. That pass adds another entry to the cache and produces scores for the next token.
Picking the highest score is a simple job for the CPU. Sending it all 320 scores also lets us compare the FPGA’s results with our software model. The round trip adds time to every prediction as the FPGA waits for the chosen token to come back. In our first experiment, we move that choice onto the FPGA and measure the time saved.
How exactly is text encoded and a token chosen?
Our model splits each byte of the prompt into two input tokens. The letter a is one byte, so it becomes two tokens after the start token. On output, each token that contributes to the reply represents one byte.
UTF-8 represents text as bytes. Split each input byte into its high and low hexadecimal digits. For byte b, the tokens are 272 + (b >> 4) and 288 + (b & 15). The start token is 256. For example, a is byte 97, hexadecimal 61. Its high digit gives 272 + 6 = 278, and its low digit gives 288 + 1 = 289. With the start token, that is [256, 278, 289]. This encoding is lossless. Inputs longer than forty-eight bytes are rejected, rather than silently cut short.
Output byte tokens are 0 through 255. The end token is 257, and the vocabulary has 320 slots in total. The CPU uses argmax, choosing the largest of all 320 scores without random sampling. There is no input hash, joke identifier, sentence lookup, retry or output replacement. Each request starts a new completion rather than retaining a chat history.
What is inside our tiny model?
Our model has one Llama-style transformer block with an attention section and a feed-forward network.37 It represents each token with thirty-two numbers, and its two attention heads each work with sixteen. The feed-forward network expands the list to 128 numbers before bringing it back to thirty-two. The model’s 16-bit weights occupy 53,440 bytes.
Let’s return to our KV260 and see where its parts sit. A smaller board mounted on it, the K26 module, carries a Zynq UltraScale+ chip. The chip combines Arm CPUs that run software with the FPGA we have introduced.38 Both are built from the kinds of logic gates we met in Sand to Thought. The larger carrier board provides power and connections to other devices.39
- DDR4 RAM, on the module, holds running programs and working data for both the CPU and FPGA. It is separate from the FPGA’s BRAM.38
- Boot flash, also on the module, holds the firmware that starts the board.40
- microSD is removable storage on the carrier. In the standard KV260 setup, it holds the Linux operating system and application files.41
- Controllers manage DDR4, boot flash and microSD. The FPGA can use the DDR4 controller without going through the CPU.42
- Power in connects and regulates an external supply.43
With the FPGA configured and the model’s weights loaded, the laptop sends a prompt to the CPU through the carrier board’s Ethernet port. The CPU sends input tokens to the FPGA. The FPGA logic does the neural-network arithmetic and holds the KV cache in BRAM. It returns a score for each possible next token. The CPU chooses the highest-scoring token and sends it back to the FPGA for the next prediction. It also sends the token’s text to the laptop, where the reply grows one character at a time.
The CPU–FPGA exchange stays inside the Zynq chip.38 The FPGA reads its weights from BRAM in this build. In experiment 12, we move some of those weights into LUT memory. In experiment 14, we will moving the weights into DDR4.
Measuring inference on the KV260
How much faster could the same FPGA run the same transformer? With GPT-6 Astra, we iterated on the circuit while keeping the model, its weights and the maths behind its predictions the same. Each experiment took roughly 1 hour. We timed the first token and the rest of the reply separately, and measured energy usage.
How did we measure speed and energy use?
For each comparison, we ran the changed circuit and the circuit it was meant to improve in adjacent runs on the same KV260.
We kept the weights loaded, started each prompt with an empty KV cache and ran one request at a time. The three fixed prompts were Hello, a six-byte gibberish prompt and a 48-byte prompt. Each point in the graph averages results from all three prompts.
For the first 24 experiments, the graph uses timing from blocks that ran all three prompts together. After warm-up, the number of timed replies was varied to obtain reasonable averages.
The board’s CPU started timing just before it prepared each prompt. We measured how long the board took to produce the first token, then how quickly it produced the rest of the reply. Communication with the laptop falls outside these timings.
Through experiment 24, we averaged first-token waits across all three prompts and pooled the decode intervals. From experiment 25, we take each prompt’s median and average the three medians. The graph shows results measured on the board with a logarithmix y axis.
We logged power roughly every 50 ms. As inference got faster, a whole reply could finish between readings, so we ran replies back to back and measured their combined energy. We divided the energy supplied to the K26 module over that time by the number of output tokens. The sensor covers both the CPU and the FPGA. The energy per token also includes energy used between requests, while checking answers and by any background activity during the measurement.
Low-hanging fruit
Here we made simple changes to remove calculation dependence on the CPU and other redundant actions our first version was taking.
In experiment 1, we removed a round trip for every output token. The FPGA used to send 320 scores to the CPU and wait for one token ID in return. Now two registers on the FPGA remember the best score and its token ID as the scores arrive, remaining entirely on-FPGA-chip. The FPGA can then start the next prediction as soon as the last score is in. Decode rose from 205 to 251 tokens per second.
In experiment 2 we also stopped scoring every prompt token. After reading the H in Hello, the next character is already available, and doesn't need to be scored, which was the case in our first version. The FPGA still saves the key and value for attention. It only needs to score the next token after the final o. Average first-token time fell from 125 to 108 ms, while decode stayed the same at 251 tokens per second.
Shortening arithmetic
The first experiments saved time by cutting out unnecessary work. For many of the next experiments, we sped up the calculations the FPGA still had to do. Much of inference is multiplication and addition. Doing that arithmetic in fewer clock cycles lets the FPGA produce tokens sooner. It can also save energy, even if the faster circuit draws a little more power while it runs.
In experiment 5, we changed when the scoring circuit reads a weight. It used to switch between reading a weight and adding its product to the score. We made the memory read the next weight from BRAM while the DSP added the current product. The board went from 422 to 461 tokens per second with the same number of DSPs.
The same idea was used over and over again in the transformer. We also shortened exact multiplication and division. The chart shows these trials in chronological order, gaps of missing experiments will be filled below.
Give more calculations their own lanes
A weighted sum builds up one product at a time. Give each arithmetic its own lane and running total, and the FPGA can advance several sums on the same clock tick. We used this to calculate several token scores at once, then to run both attention heads side by side. The trick is keeping every lane supplied with the numbers it needs. If they arrive late, the lane has to wait.
In experiment 50, small on-chip buffers kept sixteen score lanes supplied. Decode rose 15–20% across the three prompts, while first-token time barely moved, as expected. Most of the prompt processing happens before that scoring circuit kicks in. With all the later on-chip changes, the fastest measured build peaked at almost 20 thousand output tokens per second across the three prompts.
Move the weights and cache to DDR4
Our tiny model fits in the FPGA’s on-chip memory. To see what happens when a model outgrows that memory, as any useful model is expected to, in experiment 58 we moved the weights and persistent KV cache off-chip, into the board’s DDR4. The FPGA still did the arithmetic. Across the three test prompts, it spent 44–46% of its processing time waiting for data from memory. Compared with our fastest on-chip circuit, average decode speed fell from about 19,550 to 1,645 tokens per second, and module energy rose from 0.23 to 2.45 millijoules per output token. We kept the weights and cache in DDR4 for the next experiments and looked for ways to keep the FPGA busy while it fetched them.
In experiment 112, we found a way to spend less time waiting for memory. The FPGA could ask DDR4 for four groups of weights before the first group even arrived. The next requests were already underway, so there were fewer pauses between calculations. The FPGA still read the same amount of data. Compared with a fresh test of the earlier circuit, it produced 20–28% more tokens per second once the reply began and used 18% less energy per output token.
The final DDR4 circuit starts fetching the next group of weights while earlier calculations are still running. It keeps up to eight cache reads in flight and skips cached values whose attention weight is exactly zero.
By the end of this campaign, we had reached averaged 7,267 tokens per second and 4.00 ms to the first token across the three prompts. The K26 module used 0.595 millijoules per useful output token across the mixed workload.
How much of the hardware did the circuit use?
Each bar shows the share of that resource’s capacity used. CLBs contain LUTs and flip-flops. The DDR4 labels give the size of the weights and full KV cache stored off-chip, in KiB.
Outlook
We started with the basic building blocks of an FPGA and used them to build a circuit that could run a tiny transformer. With GPT-6 Astra, we tried different ways to arrange those blocks. It proposed and implemented circuit changes, then checked whether they made the same model run better on the same board.
Moving the weights and cache to DDR4 made the circuit spend much more time waiting for data. By the end of the campaign, the FPGA was producing tokens 4.4 times as fast as it had in the first DDR4 experiment. We were still finding improvements in the final rounds, often by changing when the circuit asked for data, and are not yet sure where the limit is.
Our joke model had just 26,720 parameters. The next test is how far these ideas carry over to larger models. We’re starting with text generation on Qwen3.5-0.8B, then trying a single-pass decision model OneJev1.6-0.8B.44,45 We’ll optimize each and benchmark on the KV260. As we continue to run more experiments, we’ll soon benchmark other chips in a similar way, in order to have easy side-by-side comparisons of their various characterisitics.
References
AMD. FPGA architecture. Vivado Isolation Verifier User Guide, UG1291, FPGA tiles and configuration memory (2026).
↩AMD. Input/output buffer. UltraScale Architecture Libraries Guide, UG974, Vivado 2024.2 (2024).
↩Altera. Physical AI. Sections on deterministic real-time control and complex sensor connectivity. Accessed 30 October 2026.
↩AMD. CLB overview. UltraScale Architecture Configurable Logic Block User Guide, UG574, revision 1.6 (2025).
↩1 ↩2 ↩3AMD. Interconnect resources. UltraScale Architecture Configurable Logic Block User Guide, UG574, revision 1.6, switch matrices and general-routing resources (2025).
↩1 ↩2CERN. How a detector works. Tracking devices and calorimeters. Accessed 6 November 2026.
↩ATLAS Collaboration. ATLAS event selection system readies for LHC Run 3. (2022).
↩Analog Devices. Designing an LED-based video-display board. Maxim application note, video-display architecture and video bit-stream demultiplexing (2009).
↩Synopsys. FPGA prototyping and the SoC design/verification process. Silicon to Systems Blog, introduction and “Fastest Path to a Prototype”. Accessed 5 November 2026.
↩Massachusetts Institute of Technology. 6.004 Computation Structures: Multiplexers. Lecture 4.1, annotated slides: 2-to-1 multiplexers, select inputs and MUX trees (2017).
↩1 ↩2Ward, S. A. Lookup table synthesis. Computation Structures, chapter 7, MIT course notes.
↩1 ↩2Massachusetts Institute of Technology. 6.004 Computation Structures: SRAM. Lecture 14.1, annotated slides, SRAM bit cells, access transistors and write operations (2017).
↩1 ↩2 ↩3 ↩4Feng, W., Greene, J. & Mishchenko, A. Improving FPGA performance with a S44 LUT structure. Proceedings of the 2018 ACM/SIGDA International Symposium on Field-Programmable Gate Arrays, introduction (2018).
↩Nandland. Lesson 5: What is a Flip-Flop? FPGA-101. Accessed 30 October 2026.
↩Massachusetts Institute of Technology. 6.004 Computation Structures: Sequential Logic. Lecture 5.1, annotated slides 12–13: Edge-triggered D Register and D-Register Waveforms (2017).
↩Kuon, I. & Rose, J. Measuring the gap between FPGAs and ASICs. IEEE Trans. Comput. Aided Des. Integr. Circuits Syst. 26, 203–215 (2007).
↩AMD. Zynq UltraScale+ MPSoC boot and configuration. Bootgen User Guide, UG1283, Vivado 2024.1, boot devices and configuration path (2024).
↩1 ↩2Massachusetts Institute of Technology. 6.004 Computation Structures: Flash Memory. Lecture 14.1, annotated slide on flash memory (2017).
↩AMD. FPGA Manager Architecture. Zynq UltraScale+ MPSoC Software Developer Guide, UG1137 (2024).
↩AMD. Overview. UltraScale Architecture Configuration User Guide, UG570, revision 1.20.1 (2025).
↩AMD. Configuration memory frames. UltraScale Architecture Configuration User Guide, UG570, revision 1.20.1 (2025).
↩AMD. Clocking architecture overview. UltraScale Architecture Clocking Resources User Guide, UG572, revision 1.11 (2025).
↩AMD. Distributed RAM (SLICEM only). UltraScale Architecture Configurable Logic Block User Guide, UG574, revision 1.6 (2025).
↩1 ↩2AMD. Programmable logic. Kria K26 SOM Data Sheet, DS987, revision 1.6, PL resources table (2026).
↩1 ↩2AMD. UltraRAM summary. UltraScale Architecture Memory Resources User Guide, UG573, revision 1.14 (2025).
↩Nandland. Lesson 15: What is a Block RAM (BRAM)? FPGA-101. Accessed 30 October 2026.
↩AMD. Know what you infer. UltraFast Design Methodology Guide for FPGAs and SoCs, UG949, Vivado 2023.1, carry-chain adder example (2023).
↩AMD. Carry logic. UltraScale Architecture Configurable Logic Block User Guide, UG574, revision 1.6 (2025).
↩AMD. Performance and resource utilization for Multiplier v12.0. Vivado 2025.2, Zynq UltraScale+ table, XCZU9EG unsigned 12 × 12-bit multiplier (2025).
↩Xilinx. Embedded vision with INT8 optimisation on Xilinx devices. White paper WP490, revision 1.0.1, Figure 1, p. 4: multiply and accumulate in a Zynq UltraScale+ DSP (2017).
↩1 ↩2Intel. FPGA architecture overview. Intel oneAPI DPC++/C++ Compiler Handbook for FPGAs, version 2024.2 (2024).
↩AMD. How FPGA resources are arranged. UltraScale Architecture Clocking Resources User Guide, UG572, revision 1.11, Clock Structure (2025).
↩Zhang, A., Lipton, Z. C., Li, M. & Smola, A. J. Multilayer perceptrons. Dive into Deep Learning, version 1.0.3, sections 5.1.1.3 and 5.1.2.1. Accessed 30 October 2026.
↩Hugging Face. Quantization concepts. Transformers documentation, mapping values to fewer bits. Accessed 30 October 2026.
↩Hugging Face. Caching. Transformers v4.57.0 documentation, reusing cached keys and values (2025).
↩Vaswani, A. et al. Attention is all you need. Advances in Neural Information Processing Systems 30 (2017).
↩Touvron, H. et al. LLaMA: Open and efficient foundation language models. arXiv:2302.13971, section 2.2 (2023).
↩AMD. Functional overview and block diagram. Kria K26 SOM Data Sheet, DS987, revision 1.6, functional overview and linked processing-system section (2026).
↩1 ↩2 ↩3AMD. Summary. Kria KV260 Vision AI Starter Kit User Guide, UG1089, revision 1.4 (2025).
↩AMD. Primary boot device. Kria KV260 Vision AI Starter Kit User Guide, UG1089, revision 1.4 (2025).
↩AMD. Secondary boot device. Kria KV260 Vision AI Starter Kit User Guide, UG1089, revision 1.4 (2025).
↩AMD. Slave interface. Zynq UltraScale+ MPSoC Processing System Product Guide, PG201, version 3.4, Table 4-2 (2022).
↩AMD. Powering the starter kit and power budgets. Kria KV260 Vision AI Starter Kit User Guide, UG1089, revision 1.4, Powering the K26 SOM (2025).
↩Qwen Team. Qwen3.5-0.8B. Model card, model overview and text-only inference (2026).
↩OmniJev Team. OneJev1.6-0.8B. Model card, single-pass decisions (2026).
↩