What this video shows
About this walkthrough
The lab uses a simplified decoder with 64 independent sequences. The walkthrough keeps the per-sequence calculation and moves the sequence index into the CUDA grid, which turns 128 single-block launches per batch step into two launches of 64 blocks each. Throughput goes from 20,371.6 to 813,761.6 tokens per second in this pair, about 39.95x, with correctness passing in both runs. It is an educational decoder simulation, not a full language-model benchmark.
Read along
Transcript
Select a time to play the video from that chapter.
0:00A busy GPU can still be underused
A GPU can look busy while much of its parallel capacity goes unused. Let's see why, by batching independent requests in GPUFlight Performance Lab.
0:13The simplified inference workload
This lab uses a simplified decoder, not a full language model. There are 64 independent sequences, each represented by 256 values. One step advances each sequence by one simulated token. Its next step needs the previous result. But different sequences do not depend on each other. That is the opportunity.
0:39The calculation and goal
For each step, we multiply by weights, add a bias, and keep the positive values. Then we normalize the result, so repeated steps stay numerically stable. We will keep that calculation unchanged. The goal is correct output and at least two hundred thousand total tokens per second.
1:01Read the per-sequence launch loop
Look at the loop over sequences in decode step. For every sequence, it launches the calculation kernel, then the normalization kernel. Two launches times 64 sequences means 128 launches for one batch step. Each launch here has only one block of 256 threads. A block is a group of threads that executes together on one GPU multiprocessor.
1:30Check baseline correctness and throughput
The unchanged starter passes the output check, but misses the throughput target. It reaches about twenty thousand four hundred tokens per second. Now open its profiling session.
1:44Explore the baseline timeline
The overview reports eighty-seven percent GPU activity. That alone does not tell us how much parallel work is available. Open the timeline and zoom in. A kernel is a function launched on the GPU. Here the calculation and normalization repeat for individual sequences. Select a normalization kernel. Its grid is one by one by one: just one block, matching the source.
2:13Batch independent sequences
Batching means processing several independent sequences in the same launch. We still respect the order of steps within each sequence. Instead of issuing a separate pair of launches for every sequence, we put the sequence index into the grid.
2:31Update the calculation kernel
First, update the calculation kernel to accept the whole batch. In the calculation kernel, block index y now selects the sequence. Offset the input and output pointers by the sequence number times the model dimension. Thread indexing within a sequence and the arithmetic stay the same. The same weights and bias are shared by every sequence.
2:57Update normalization
Next, update the normalization kernel. For normalization, give each sequence one block. Block index x chooses its input and output row. Each block has its own shared sum, so different sequences do not mix their values. The synchronization and normalization math stay unchanged.
3:21Replace the host loop with two launches
Finally, remove the host loop that launches each sequence separately. The calculation grid has 64 rows. The normalization launch has 64 blocks. That is two launches per batch step, instead of 128. Both use the same CUDA stream, so normalization follows the calculation before the next step begins.
3:46Verify the batched version
Run the batched version on the same L4 GPU model, with the same fixed workload. Before interpreting performance, verify that its output still passes the reference check.
3:59Compare launch grids in the timeline
Open the new timeline and zoom in to the individual events. Select the calculation kernel. Its grid is now one by 64 by one. Select normalization, and the grid is 64 by one by one. Both launches expose 64 blocks. Each pair now advances the whole batch. Fewer events in a captured window alone would not prove a speedup.
4:27Compare tokens per second
In run history, select the baseline first, then the batched run, and choose Compare. Throughput rises from twenty point four thousand to eight hundred thirteen point eight thousand tokens per second. That is about forty times the throughput in this one measured pair, with correctness preserved. Use this throughput result, not total program runtime: the harness keeps generating for about three seconds. These are direct harness results. Profiling adds overhead, so the trace is for understanding execution.
5:04Throughput versus first-token latency
Tokens per second here counts progress across all 64 sequences. It does not measure how long a new user waits for the first token. This fixed batch is already available. A production server must also balance batching against request waiting time.
5:23Try the lab yourself
The key change was where we exposed parallelism. We kept each sequence's calculation, but let the GPU work on independent sequences together. Read the code, inspect the timeline, and check the measured throughput in GPUFlight Performance Lab.
Measure it yourself
Run the same experiment on a real GPU
Edit the kernel in your browser, run it on managed hardware, and read the profile the video walks through.
Run the inference batching lab