MemoryBeginner~60 min

Matrix Transpose — Three Ways

Implement matrix transpose three times — naive, shared memory, and bank-conflict-free — and benchmark each version. This project exposes why memory access patterns dominate GPU performance.

global-memoryshared-memorybank-conflictscoalescingcudaEvent

// PREREQUISITES

// TUTORIAL

GPU execution
1 / 3

Step 1 — Naive transpose

In a matrix transpose, element at (row, col) moves to (col, row).

Each thread handles one element: it reads A[row * N + col] and writes B[col * N + row].

Access pattern analysis:
- The read A[row * N + col] — threads in a warp have consecutive col → coalesced ✓
- The write B[col * N + row] — threads in a warp have consecutive row in the output → non-coalesced ✗

This non-coalesced write is the performance bottleneck you'll fix in Step 2.

Task: Implement the naive transpose kernel, allocate GPU memory, and verify correctness against the CPU reference.
main.cu
loading editor…

// expected output

Naive transpose: CORRECT

// YOUR PROGRESS

Log in to save progress

// DETAILS

Category
Memory
Difficulty
Beginner
Est. time
~60 min
Prerequisites
1

// LEARN THE THEORY

Memory concepts