MAVILERA GPU Laboratory

MAVILERA GPU Laboratory: documentation

Interactive Microprocessor Architecture Laboratory: Visualize. Execute. Understand.

About the laboratory

The GPU Laboratory runs a small SIMT (single instruction, multiple threads) core in the browser. Its threads are grouped in warps: the threads of a warp share one instruction fetch and run it in lock-step, one thread per lane, each with its own 32 registers. An active mask says which lanes an instruction changes, and a reconvergence stack per warp lets the threads of a warp take different paths and meet again.

Every thread runs the RISC-V base instruction set RV32I, less the few instructions the core does not need. Five warp-control instructions are added on the custom-0 opcode: tmc, wspawn, split, join and bar. Their names and their R-type format follow the Vortex research GPU as its paper describes it.

Why it matters: a graphics processor gets its speed from many simple lanes rather than one clever pipeline, and its programs from code written for one thread. The core shows what that costs: lanes left idle when the threads of a warp branch apart, and the instructions that manage the mask. The Models view adds the ideas around it, and the CPU + GPU system puts the core on the bus of a RISC-V processor.

The SIMT core and the micro-ISA are MAVILERA's teaching cores. They are not Vortex and not any product's GPU.

Getting started

  1. Open the application. The editor holds a kernel for two warps of four threads; Templates in the toolbar offers the laboratory programs, each with a note at the top on what to try.
  2. Press Assemble (Ctrl+Enter). The listing shows each instruction's 32-bit word; errors are marked in the editor and explained in the console.
  3. Press Step (F10). Each step is one clock cycle, in which one warp issues one instruction. Step back (Shift+F10) undoes a cycle; Run (F5) runs to the end or to a breakpoint.
  4. Choose Core · 2 × 4 at the top to see the same run on the drawing of the core.

The kernel of a new session: each thread writes the absolute value of its element.

        .include "simt.inc"
        .text
_start: li     t0, 2              # two warps
        la     t1, kernel
        wspawn t0, t1             # warp 1 starts at kernel; warp 0 goes on there too
kernel: csrr   t0, THREAD_INDEX   # i, the thread's index in the block (0 to 7)
        slli   t0, t0, 2          # the byte offset of x[i] and y[i]
        lw     t1, x(t0)          # t1 := x[i]
        slt    t2, t1, zero       # p := (x[i] < 0)
        split  t2                 # the threads with p = 1 first
        beqz   t2, 1f             # every active thread agrees here: no divergent branch
        sub    t1, zero, t1       # then: t1 := -x[i]
1:      join                      # first pass: to the other threads; second: reconverge
        sw     t1, y(t0)          # y[i] := |x[i]|
        tmc    zero               # this warp ends
        .data                     # the data memory, from address 0
x:      .word  5, -3, 0, -7, 2, -1, 4, -8
y:      .space 32

It ends after 28 cycles with y = 5, 3, 0, 7, 2, 1, 4, 8: 28 warp-instructions issued, 92 active lane-slots of 112, a SIMT efficiency of 82.1 %.

The workspace

The page is a workspace of panes, as in a code editor.

A one-bit register (done, fault) shows 0 or 1. The register PC (next) is the PC of the warp that issues in the next cycle.

Two instruction sets

Architecture menuMachineViews
RISC-V SIMT · 2 warps × 4 lanesThe SIMT core, two warps of four lanes (the default)Instructions, Core · 2 × 4, Core · 1 × 8, Models, CPU + GPU
RISC-V SIMT · 1 warp × 8 lanesThe same core with one warp of eight lanesas above
SIMT core · 4 lanesThe micro-ISA, an introduction: seven instructions, four lanesInstructions, Masks · 4 lanes, Masks · 8 lanes, Models, CPU + GPU
SIMT core · 8 lanesThe micro-ISA with eight lanesas above

Changing between the RISC-V SIMT core and the micro-ISA reloads the page after a question in the page itself; each instruction set keeps its own program, view and workspace in the browser.

The RISC-V SIMT core

The machine

Instructions

Per thread: RV32I without auipc, jalr, byte and half-word loads and stores, fence, ecall and ebreak. A branch, a jump, a load or a store works as in RV32I for every active thread; an operand that the warp uses as one value (the mask of tmc, the operands of wspawn and bar) comes from the lowest active thread.

InstructionWhat it does
tmc rs1The active mask becomes rs1. A zero mask ends the warp. The stack must be empty.
wspawn rs1, rs2In warp 0 only, with no other warp running: starts warps 1 to rs1 − 1 at address rs2, every lane active, registers 0.
split rs1Pushes a reconverge entry with the present mask. If bit 0 of rs1 divides the active threads, it also pushes an else entry (the other threads' mask and the address after split) and continues with the threads whose bit is 1.
joinPops the stack: an else entry sends the other threads to its address with their mask; a reconverge entry restores the mask.
bar rs1, rs2The warp waits at barrier rs1 (0 or 1) until rs2 warps have reached it.
csrr rd, csrReads an identity register of the thread (below).

The five warp-control instructions are R-type words on the custom-0 opcode (0001011), funct7 0, with funct3 0 to 4 for tmc, wspawn, split, join, bar.

Identity registerAddressValue
THREAD_INDEX0xCC0warp × lanes + lane: the thread's index in the block
LANE_ID0xCC1the lane within the warp
WARP_ID0xCC2the warp
BLOCK_INDEX0xCC30 (a host may set it in the CPU + GPU system)
BLOCK_SIZE0xCC4warps × lanes
KERNEL_ARGS0xCC50 (a host may set it in the CPU + GPU system)

Faults

The core runs divergent code only between split and join: a conditional branch on which the active threads disagree is a fault. A fault stops the run with its code and a message.

CodeFault
1divergent branch
2illegal instruction (a word outside the subset)
3reconvergence stack overflow (more than two nested divergent splits)
4join on an empty stack
5tmc with a non-empty stack
6warp-control operand error
7bad data address (not word-aligned, or past the 256 words)

Counters

cycles, issued (warp-instructions) and active_slots (the active lanes summed over the issues). SIMT efficiency = active_slots ÷ (issued × lanes).

MAVILERA's choices

Writing kernels

The pattern of an if/else:

        slt    t2, t1, zero       # p := (x < 0), per thread
        split  t2                 # the threads with p = 1 first
        beqz   t2, else           # uniform in each pass
        ...                       # then-path
        j      endif
else:   ...                       # else-path
endif:  join                      # to the other threads, then reconverge

The Core views

Core · 2 × 4 and Core · 1 × 8 draw the core of each machine in this application's own layout. Each step is one cycle: the drawing shows the coming issue, the warp the scheduler chooses, its instruction broadcast to the lanes, what each lane computes, and the write gates driven by the active mask. warp_ctrl and the gates are shown by what they do (masks, stack entries, the address a join returns to), not by their logic. The warps table under the drawing gives each warp's state, PC, mask and stack.

TabContents
IssueThe coming issue lane by lane: the mask bit, what the lane computes and whether it is written.
MasksOne row per issue, a cell per lane with its mask bit (1 active, 0 idle and shaded). Masks-only count hides warp control, branches and jumps, and each warp's launch and setup (its issues before the instruction that computes the predicate of its first split), and says how many of each it hides.
StackEach issue of one warp with the active mask and the reconvergence stack after it.
ResultsCycles, issued instructions, active lane-slots and SIMT efficiency of this program, and of the laboratory programs run here.
Waveformsdone, fault, and each warp's mask and state over the cycles run so far; select a cycle to go to it.

On a narrow screen the view shows one lane at a time: the mask strip of the coming issue, a button per lane, and what the chosen lane computes and writes. Whole drawing brings the drawing back. The drawing pans and zooms as the other drawings of MAVILERA do; Display exports it as SVG or PNG.

The micro-ISA

An introduction before the RISC-V core: one warp of four or eight lanes, a program memory of sixteen 16-bit words, four registers per lane (r0 holds the lane's index, r1 its input, r2 its output) and a mask stack of two entries. Every instruction takes one cycle.

InstructionEach active lane, or the warp
LDI rd, immrd ← imm (eight bits, sign-extended)
ADD rd, rs, rtrd ← rs + rt
SUB rd, rs, rtrd ← rs − rt
IFLT rs, rtpush the mask; the lanes with rs < rt (signed) stay active
ELSEthe other lanes of the pushed mask become active
ENDIFpop the mask
HALTstop; the output of each lane is its r2

The dialect is MAVILERA's: one instruction per line, comments after ; or //, registers r0 to r3, no labels (there are no branches); .din v0, v1, … gives the lanes' inputs and .word v places one word. A third nested IFLT, and ELSE or ENDIF with nothing pushed, stop the run before the instruction. The counters are cycles and idle_slots.

Its views are Masks · 4 lanes and Masks · 8 lanes, the mask grid of each machine; the Lanes tab of the memory pane shows every lane's registers. The default program, the absolute value of four inputs, ends after 7 cycles with 4 idle lane-slots.

The Models view

Calculators for the ideas around the core. They do not run the program in the editor. Each tab has inputs, a table and a drawing; its i button explains the model.

TabModel
Four machinesThe additions of c[i] = a[i] + b[i] framed by what one instruction covers on a scalar pipeline, packed SIMD, a vector unit and a SIMT machine, with the instruction counts.
AmdahlS = 1 / ((1 − f) + f / n) and efficiency S / n for a parallel fraction f on n lanes; the ceiling 1 / (1 − f).
StripsA loop strip-mined with a run-time vector length: AVL and vl of each strip, with VLMAX = VLEN / SEW. The rule: vl = AVL when AVL ≤ VLMAX, VLMAX when AVL ≥ 2 VLMAX, else any value from ⌈AVL / 2⌉ to VLMAX.
IndexingA launch over n elements: grid_size = ⌈n / block_size⌉ blocks, thread i = block_index × block_size + thread_index, the warps, the tail and the masks of the warps that are not full; where element i lies.
Blocks and SMsWhole blocks assigned to streaming multiprocessors, in waves, and the warps of one block.
LatencyA timeline of W warps that each issue k instructions per load of latency L; the warps needed, (L − 1) / k + 1; and the occupancy a register file allows, with the share of cycles that issue, k W / (k − 1 + L).
CoalescingThe aligned blocks one warp's load needs at a stride: transactions, bytes delivered and bytes used.
BanksThe banks of a shared memory a warp's access touches; the access takes as many cycles as the busiest bank has distinct words, and a word read by several lanes is broadcast.

Where a model needs a rule that the idea itself does not fix, the rule is MAVILERA's, stated in the tab's i button: the remainder of packed SIMD is done by scalar instructions; block b goes to SM b mod (number of SMs), a set number at a time; the scheduler stays with a warp until it has issued its load, then takes the next ready warp in turn. None of them is the rule of a product.

The CPU + GPU system

The CPU + GPU view of this laboratory opens the RISC-V Laboratory with the SIMT core (two warps of four lanes) on the bus of its single-cycle processor at 0x5000_1000. A host program copies a kernel into the core's instruction memory and its data into the data memory, writes 1 to CTRL, polls STATUS while the core issues one warp-instruction per clock cycle, and reads the results back. That page's views are ISA, Single-cycle (the datapath with the GPU on the data bus) and GPU (the core's drawing, warps, masks and stack as the host steps, and an Interface tab with the registers and the bus log). It keeps its own program and opens, on a first visit, with its template: the host running the absolute-value kernel.

OffsetRegisterMeaning
0x000CTRL (write)Bit 0 starts the kernel: warp 0 at address 0, every lane active, registers and counters 0. Bit 1 clears DONE and FAULT. Both bits: clear, then start.
0x004STATUS (read)Bit 0 BUSY, bit 1 DONE, bit 2 FAULT, bits 11:8 the fault code (1 to 7 the core's; 8 a deadlock at a barrier).
0x008ARGSkernel_args at launch
0x00CBLOCKblock_index at launch
0x010, 0x014, 0x018CYCLES, ISSUED, ACTIVE (read)The counters of the kernel
0x400 to 0x4FCIMEMThe instruction memory, 64 words
0x800 to 0xBFCDMEMThe data memory, 256 words; a read while the GPU is busy gives the word as it is then

Writes to the GPU while it is busy are ignored, and the bus log marks them; whole words only. This register map is MAVILERA's own design, one way to attach such a core; a laboratory may ask for a design of your own.

The host's RISC-V assembler has no warp-control instructions, so a host program carries its kernel as words. The CPU + GPU view of this laboratory gives the program in its editor that way, under Kernel for a host: its instruction words as .word lines, each with its source line as a comment, and its data words, with Copy and Download .s. Assemble the kernel for RISC-V SIMT · 2 warps × 4 lanes, the machine on the host's bus.

Walkthroughs

1. The first kernel

  1. Assemble the kernel of a new session and choose Core · 2 × 4.
  2. Step three times: warp 0 runs li and the two instructions of la; warp 1 has not started yet. The next step issues wspawn; from then on the warps take turns.
  3. Step to the first split of warp 0. Its threads hold 5, −3, 0, −7: the Issue tab shows the predicate 0101 (lane 0 first), so the then-path runs with mask 0101 and the stack gets a reconverge entry R 1111 and an else entry for 1010.
  4. Run to the end. The Results tab gives 28 cycles, 92 active lane-slots of 112, 82.1 %.

2. Seeing the cost of divergence

  1. Open the template An if/else with split and join and open the Masks tab.
  2. Turn on Masks-only count: the rows left are the work under a mask, and the line below says how many launch, setup, warp-control and branch issues it hides.
  3. Compare with No divergence: every thread takes the same path, where every row is full.

3. Two warps and a barrier

  1. Open Reverse an array through a barrier. Step until a warp reaches bar: its state becomes waiting at bar in the warps table, and only the other warp issues.
  2. When the second warp arrives, both continue. The run ends after 71 cycles with 244 active lane-slots, an efficiency of 85.9 %.
  3. Open Fault: a divergent branch to see a branch without split stop the core with fault 1.

4. The Models view

  1. In Indexing, set n = 21, block size 8, warp size 4: three blocks, and the last warp runs with mask 1000.
  2. In Latency, keep W = 4, k = 3, L = 9: an instruction issues in every cycle. Change W to 3: two idle cycles (– in the Issue row) appear before the first warp's second round.
  3. In Banks, change the stride from 1 to 2, then to 8; then try 9.

5. The CPU + GPU system

  1. Choose CPU + GPU and Open the CPU + GPU system. The page opens with the host program and its template kernel.
  2. Assemble and step in the GPU view. The host first copies the 14 kernel words and the 8 inputs into the GPU, then writes 1 to CTRL; from the next cycle the GPU issues one warp-instruction in every cycle while the host polls STATUS.
  3. Run to the end: the kernel takes 28 cycles, the host program 231, and the Interface tab reads STATUS = DONE. Step back into the run to see both machines at work in the same cycle.

Exercises

File ▸ Exercise… lists practice exercises written for MAVILERA, for the RISC-V SIMT core: Two warps: the difference of two arrays, Clamp to a range with split and join and The sign of each element: a split inside a split. Each opens with a starter program on its machine.

  1. Pick an exercise and read its task; Load the starter program puts it in the editor.
  2. Write your kernel in place of the line # your code, keeping the data labels the task names.
  3. Press the Exercise button, then Run the tests. Each test writes words of the data memory, runs your program until every warp has ended, and compares the words it leaves with the expected values.

No solutions are included. A teacher's exercise file (JSON, with "arch": "gpu" and a profile, lab or lab-l8) opens with File ▸ Open; its tests write and check data-memory words. Exercises are not offered with the micro-ISA.

Files, sharing and exports

ExportContents
.hex, .binThe instruction memory's words, one per line for $readmemh, or raw bytes. Import .hex/.bin… loads one; the data memory then starts as zeros.
ListingAddresses, words and source lines
Golden dumpThe 256 data-memory words, then cycles, issued, active_slots and the fault code, one word per line in hexadecimal (the micro-ISA: each lane's output, cycles, idle_slots and the final mask)
Waveform, VCDThe signals of the Core or Masks views, one clock per cycle
Drawing (SVG, PNG)The core drawing of the present cycle, from the Display menu
Trace (JSON lines, CSV)The micro-ISA only: one record per cycle from reset to the end

The run exports replay the program from reset to its end; the session you are in is not changed.

Offline use and privacy

Keyboard reference

KeysAction
Ctrl+EnterAssemble
F5Run or pause
F10 / Shift+F10Step / step back (one cycle)
Ctrl+F10Run to the editor's line
Ctrl+FFind in the editor
Esc, then TabLeave the editor (inside it, Tab indents)
Arrow keys on a dividerResize panes (Shift for larger steps; Enter restores)
Arrow keys on the Models tabsMove between the models
Enter on a drawn elementOpen its details

How the models were checked

No comparison with a hardware description of the core is recorded. Agreement between models is evidence about the models, not about any physical chip.

Limits of the model

Licence and notices

© 2026 Sajid Muhaimin Choudhury. MAVILERA and its content (drawings, help texts, this documentation, example programs and exercises) are licensed under the Apache License, Version 2.0. The names and the logo are not licensed as trademarks.

The SIMT core and the micro-ISA are MAVILERA's teaching cores; they are not Vortex and not any product's GPU, and MAVILERA makes no claim about the Vortex hardware or source code and is not affiliated with its authors. RISC-V® is a registered trademark of RISC-V International; MAVILERA uses the name only to identify the instruction set it simulates, uses no RISC-V logo, and is not affiliated with or endorsed by RISC-V International.