GPU 101

CUDA = NVIDIA-only, low-level, maximum control

wgpu = portable, safe-ish, modern GPU abstraction used by Rust

What is wgpu?

wgpu is a Rust library that exposes modern GPU features in a portable way.

Under the hood, it runs on:

  • Vulkan (Linux, Windows)
  • Metal (macOS)
  • DirectX 12 (Windows)
  • WebGPU (the web!)

Programming model

CUDA

  • Thread-centric
  • You explicitly think in:
    • threads
    • blocks
    • warps
  • Memory hierarchy is explicit:
    • global
    • shared
    • local
    • registers

wgpu

  • Pipeline-centric
  • You think in:
    • buffers
    • bind groups
    • pipelines
    • dispatch sizes
  • Memory hierarchy is mostly abstracted

This is closer to how modern GPUs are actually programmed today.

Language & safety

CUDA

  • C++ (unsafe, manual memory, footguns)
  • Kernel launches are unchecked
  • Out-of-bounds = UB or silent wrong answers

wgpu

  • Rust on host side
  • WGSL shaders are:
    • bounds-checked
    • validated before running
  • Many classes of GPU bugs become compile-time or validation errors

This is huge for learning.

Mental mapping (very important)

Here’s how concepts translate:

ConceptCUDAwgpu
Kernel__global__ fncompute shader
Thread IDthreadIdx + blockIdxglobal_invocation_id
Blockthread blockworkgroup
Shared memory__shared__var<workgroup>
Launch<<<>>>dispatch_workgroups
Device memorycudaMallocstorage buffers

graphics / compute APIs — think of them as standardized ways to talk to a GPU.

The common idea (important first)

All modern GPUs expose the same fundamental hardware:

  • many parallel cores
  • fast on-chip memory
  • slow global memory
  • command queues
  • pipelines

But every OS/vendor exposes this differently.

So we have GPU APIs:

“Here is how you submit work to the GPU on this platform.”


1️⃣ Vulkan (Linux, Windows)

What it is

  • A low-level, cross-platform GPU API
  • Maintained by the Khronos Group
  • Designed as the successor to OpenGL

Where it runs

  • Linux ✅
  • Windows ✅
  • Android ✅

Key characteristics

  • Very explicit
  • Very verbose
  • Very fast
  • Minimal driver “magic”

You must manage:

  • memory allocation
  • synchronization
  • pipelines
  • command buffers

Mental model

“I want full control over the GPU.”

This makes Vulkan:

  • great for engines and compute
  • painful for humans

2️⃣ Metal (macOS)

What it is

  • Apple’s proprietary GPU API
  • Only works on macOS / iOS
  • Replaced OpenGL on Apple platforms

Where it runs

  • macOS ✅
  • iOS / iPadOS ✅
  • Apple Silicon GPUs

Key characteristics

  • Clean, opinionated API
  • Excellent tooling
  • Tight hardware integration

Mental model

“One vendor, one OS, optimized end-to-end.”

Metal is:

  • very fast
  • relatively ergonomic
  • completely locked to Apple

3️⃣ DirectX 12 (Windows)

What it is

  • Microsoft’s low-level GPU API
  • Part of DirectX
  • Successor to DirectX 11

Where it runs

  • Windows only

Key characteristics

  • Similar philosophy to Vulkan
  • Explicit resource management
  • Required for modern Windows games

Mental model

“Vulkan, but Microsoft-flavored.”


4️⃣ WebGPU (the web!)

What it is

  • A new web standard for GPU access
  • Runs inside browsers (Chrome, Firefox, Safari)
  • Designed to be:
    • safe
    • sandboxed
    • portable

Where it runs

  • Web browsers
  • Also usable natively (wgpu!)

Key characteristics

  • Strong validation
  • No undefined behavior
  • No direct access to raw hardware

Mental model

“Modern GPU programming, but safe enough for the web.”

  • WebGPU = a standard API / programming model
  • wgpu = a native implementation of that model (in Rust)
  • WebGPU can be implemented on top of Vulkan / Metal / DX12

So yes:

WebGPU maps to other GPU APIs, not by translating code line-by-line, but by mapping the model.

WebGPU is a portable GPU contract; wgpu is a Rust implementation of it; the contract can be backed by Vulkan, Metal, or DX12.

Leave a Reply

Your email address will not be published. Required fields are marked *