WebGPU comes to Cloudflare Workers

Cloudflare has announced WebGPU support in workerd, the open-source JavaScript/Wasm runtime that powers Workers. The implementation targets the general-purpose GPU (GPGPU) portion of the WebGPU specification, which means compute shaders and compute pipelines work today; vertex and fragment shaders for rendering aren't available yet and Workers doesn't render graphics anyway.

The release is aimed at local development first. Developers can run WebGPU-enabled Workers on their own machines now using Wrangler and Miniflare 3, which is powered by workerd. The code lives in the src/workerd/api/gpu directory of the workerd repo and is gated behind a flag. Cloudflare plans to bring WebGPU to its production Workers environment in the coming weeks, once it solves the stricter security and isolation requirements there — specifically around letting V8 talk directly to GPU hardware from the process sandbox.

What WebGPU adds over WebGL

WebGL has been the browser's GPU interface since 2011, with WebGL 2 arriving in 2017. Both are high-level APIs with a single-threaded model and limited compute support. WebGPU was designed by the GPU for Web Community Working Group — formed in 2017 by Google, Apple, Intel, Microsoft, Khronos, and Mozilla — to address those shortcomings. Its main advantages:

  • Lower-level access — direct GPU resource control rather than WebGL's abstractions
  • Multi-threading — better CPU/GPU parallelism versus WebGL's single thread
  • First-class compute shaders — GPGPU workloads are a core feature, not an afterthought
  • Safety — memory and GPU access are guarded, avoiding common WebGL pitfalls
  • Portability — the WGSL shader language targets cross-vendor compatibility
  • Reduced driver overhead — built on Vulkan/Metal/Direct3D 12 rather than OpenGL
  • Pipeline state objects — predefined pipeline configs avoid per-draw driver work
  • Finer-grained memory management — better buffer and resource control

Beyond graphics, WebGPU enables machine learning inference, scientific computing, and high-performance parallel workloads, particularly when paired with WebAssembly.

Built on Dawn, constrained to Durable Objects

Cloudflare's WebGPU implementation uses Dawn, Google's open-source WebGPU implementation that also powers Chromium. Dawn translates WebGPU API calls into the native graphics API of the host platform — Vulkan on Linux, Metal on macOS, Direct3D 12 on Windows — via webgpu.h, the de facto C header for the standard.

In Workers, the WebGPU API is only accessible from Durable Objects, the global singleton Workers, for two reasons:

  • GPU state such as loaded AI models needs to persist between requests, and Durable Objects can hold that state.
  • Not every Cloudflare server has a GPU. The request may land on the nearest server, but the Durable Object using WebGPU will be instantiated where GPU resources exist, potentially on a different machine.

Compute shaders in a Durable Object

A minimal WebGPU "hello world" in a Durable Object prints the name of the GPU device that workerd finds on the host machine.

A more useful example dispatches workgroups to increment a buffer in parallel using global_invocation_id. The setup requires two buffers: a storageBuffer to hold computed results and a mappedBuffer to copy results out at the end.

This parallelism is why GPU compute matters for machine learning inference. GPUs offer 10–20x the memory bandwidth of CPUs for moving model parameters and data, and far higher floating-point throughput (TFLOPs) for the matrix operations at the heart of neural networks.

Image classification with ONNX and SqueezeNet

To demonstrate real-world use, Cloudflare built a demo image classifier that runs the ONNX runtime — specifically Wonnx, the Rust implementation compiled to WebAssembly with WebGPU support — inside a Worker using workers-rs.

The demo uses SqueezeNet, a small image classification model that achieves accuracy comparable to AlexNet on ImageNet while using fewer resources. The workflow:

  1. On Durable Object instantiation, the model is loaded from R2 into GPU memory — done once.
  2. The calling Worker pre-processes an uploaded image into a model input tensor.
  3. The Durable Object runs the existing inference session on subsequent requests and returns the result tensor as JSON, from which the Worker extracts the most likely class labels.

The demo is available in a public repository. To run it locally, you need a Rust compiler, Node.js, Git, and curl:

  • Clone the repository.
  • Upload the model to the local R2 simulator.
  • Run the Worker locally with Wrangler.
  • Upload one of the included example images with curl — the response returns the image's most probable class.

What's next

Cloudflare is merging the WebGPU code into its production Workers environment over the coming weeks, on top of its growing GPU node fleet. The delay stems from production security requirements: V8 can't talk to GPU hardware directly from the process sandbox, so Cloudflare must create an architecture where a separate process sits closer to the GPU and communicates via IPC. Resource allocation and billing also need to be worked out.

For now, the local development release gives developers hands-on access to WebGPU in Workers to explore the compute capabilities and provide feedback as the feature matures.