Skip to main content

CUDA performance basics

Fixing CUDA Memory Coalescing: Lab Walkthrough Video

Published 2 min 30 sMeasured on NVIDIA RTX 3090

What this video shows

About this walkthrough

A SAXPY kernel gives correct results, but neighboring threads read elements that are far apart. The walkthrough measures the baseline at 12.5% coalescing efficiency, changes the index expression so that neighboring lanes touch neighboring elements, and confirms 100% on the same memory instructions. In this pair of runs kernel time falls from 1.97 ms to about 239 microseconds, while the whole unprofiled harness is only 15.7% shorter.

Read along

Transcript

Select a time to play the video from that chapter.

0:00Understand the memory-access problem

Last time, we improved the launch configuration. Now, let's improve how threads access memory. This lab computes SAXPY: alpha times x, plus y. The result is correct, but neighboring threads access elements far apart.

0:17Know what success means

Our goal is to keep every output correct, including the small boundary cases, and reach at least 80% coalescing efficiency.

0:27Measure the original kernel

Here is our baseline on the RTX 3090. Correctness passes, but coalescing efficiency is only 12.5%. Open the full session to investigate.

0:40Read the diagnosis

Under Source and SASS, open Analysis. The profile flags extra global-memory traffic. Its recommendation is to inspect lane stride, change one access pattern, and measure again.

0:54Inspect the memory instructions

In the listing, turn on memory percentages. The two global loads and the store each show about 13% efficiency, rounded from 12.5%.

1:05Change the thread-to-element mapping

Back in the editor, change the index expression. Use block index times block size, plus thread index. Now neighboring lanes process neighboring elements. Keep the arithmetic, bounds check, and 256 threads per block. Run it on the same GPU.

1:24Check correctness and the target

The new run passes correctness and reaches 100% coalescing efficiency. That clears the 80% target. Now check the detailed profile.

1:36Verify the same memory instructions

Open the new session's Source and SASS listing. The same two loads and store now show 100%. The indexing change improved the measured memory access pattern.

1:48Compare the measured results

Compare runs nine and ten. Kernel time drops from 1.97 ms to about 239 μs. But the full unprofiled harness is only 15.7% shorter. These are different measurements, from one pair of runs.

2:07Explain the remaining time

The timeline helps explain the difference. Zoom in: the green kernels are short, while repeated blue host-to-device transfers remain.

2:17Measure. Change. Verify.

Select a transfer to inspect its size and duration. That's the learning loop: measure, change one thing, and verify. Try this lab in GPUFlight.

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 SAXPY coalescing lab