Task 1 of 6

Map: One Thread, One Value

Nearly every GPU program you'll ever write is built from a handful of patterns, and the first one has a name: map. Each output cell is a pure function of the input cell at the same index — no neighbors, no shared state, no "first do cell 3, then cell 4". That independence is exactly what lets the GPU run all the cells at once.

Here celsius holds 64 temperature readings. Converting them to Fahrenheit is a textbook map: reading 7 becomes output 7, and nothing else matters to thread 7.

Goal: map every Celsius reading to Fahrenheit — °F = °C × 9/5 + 32 — one thread per reading.

Requirements

Hint 1 — the shape of a map

A map kernel touches exactly one input cell and one output cell, both at index this.thread.x. If you find yourself reading any other index, it's not a map any more.

Hint 2 — the one-liner
return celsius[this.thread.x] * 9 / 5 + 32;

Same idea elsewhere

Map is the hello-world of every GPU API: a CUDA grid where each thread transforms one element of a device array, a WebGPU compute shader dispatched once per buffer entry, a Metal compute encoder doing the same. If a problem is a pure map, it parallelizes for free.

All tasks in Thinking in Parallel

  1. Map: One Thread, One Value
  2. Gather: Read Anywhere
  3. No Scatter Allowed
  4. Life on the Edge
  5. Smooth a Signal
  6. The Two-Pass Blur

This page is an interactive exercise — the editor, the GPU runner and your saved progress need JavaScript. The text above is the full brief.