← BACK TO NOTES
2026-09-04 |
HDK HOUDINI

I Put Nodes on the GPU, and They Got Both Faster and Slower

Putting a node on the GPU does not always make it faster.
In my terrain nodes (prefix TERA), changing a parameter got 5 to 10 times faster or more, but the very first cook was sometimes quicker on the CPU.

How it is built

The GPU work is written in OpenCL, with four design choices:

  • Kernels are C++ strings. There are no .cl files; the source is embedded as a raw string. MSVC limits the length of a string literal, so long ones are split into adjacent literals.
  • The node does not pick the device. It only gets Houdini's Compute Engine context, and which GPU is used is decided by Houdini's environment variables (HOUDINI_OCL_DEVICETYPE and so on).
  • Without a GPU, it falls back to the CPU. A "Use GPU" toggle (on by default) exists, and when OpenCL is unavailable or throws, the node warns and runs the CPU path.
  • GPU code lives per project. The common code library (HDK_Shared) is CPU only and holds no OpenCL.

Getting the device takes two lines:

CE_Context *openCLContext() { return CE_Context::getContext(true, true); }
bool openCLReady() { CE_Context *ctx = openCLContext(); return ctx && ctx->isValid(); }

And a real node falls back like this (shortened):

if (!ctx || !ctx->isValid()) { error = "OpenCL unavailable; using CPU."; return false; }
try {
    // build the program, upload, run
} catch (const cl::Error &e) {
    // turn the error into a warning and take the CPU path
}

Cut the transfers

GPU work tends to lose more time to handing data back and forth than to the math.
So buffers are kept and reallocated only when the size changes, each input carries a revision number and only changed inputs are uploaded, and the result is read back by mapping pinned memory straight into the output.

Actual numbers

At a terrain resolution of 1025², these are whole-node cook times, including transfers and output:

Node Operation CPU GPU
Adjust First cook 20.42 ms 175.13 ms
Adjust Edit gamma 18.12 ms 3.23 ms
Adjust Edit curve 17.58 ms 3.09 ms
Adjust Update height input 20.42 ms 6.37 ms
Coastal erosion First cook 343 ms 306 ms
Coastal erosion Edit strength about 293 ms about 27.7 ms
Coastal erosion Update height input 363 ms 75.4 ms

The first cook is slow because it includes starting OpenCL and compiling the program.
Later cooks reuse the built program and the buffers, which is where the gap comes from. For the "touch it many times while tuning" workflow, the GPU wins by a wide margin.

Where it did not get faster

The node that builds canyon and mesa terrain bundles several steps into one GPU node.
Its first cook took 1420.59 ms (including OpenCL startup) and a cache hit took 1.94 ms, but when I changed the layer or talus settings, it lost to the chain of separate nodes it replaced. Changing Talus Angle took 159.79 ms on the bundled version and 12.55 ms on the chain.

The notes I kept for the advection node say, in so many words, "no universal speedup is claimed".
In fact, for Smooth with wind off, 34.72 ms became 37.72 ms, slightly slower.

Precision

GPU and CPU results are not bit-identical.
So I compare them within a tolerance. Adjust stays within 3e-5 (largest measured 1.049e-5), and canyon and mesa stay within 0.005 m, with a largest height difference of 0.00181 m. Both are written on the assumption that identical results are not guaranteed.

I also dropped a method for precision reasons: blurring with a prefix sum amplified rounding error at some points when the radius was large and the iteration count was 5, so I did not use it.

A bug that came before the speed

The old GPU kernel of the advection node wrote to the same destination from several threads at once without atomics.
I rewrote it with ordered blending. While there, I also removed a repeated conversion and three program compilations per cook.

Summary

Moving a node to the GPU pays off most for nodes you touch again and again.
For a node that runs once, or one where the bundled version loses to the existing chain, leaving it on the CPU can be better. Measure the first cook and the cook after a settings change separately before deciding.

Next: the traps of handling attributes and groups inside a node.

Related articles

2026-08-30

Caching: Making a Heavy Node Feel Light

A heavy terrain node can take hundreds of milliseconds every time you touch a parameter. Here is how I remember the last result so that untouched parts are never recomputed, and the three kinds of "key" that decide when to throw it away.

2026-09-13

UVs in C++: Points vs Vertices

Whether a UV lives on a point or on a vertex changes how seams behave. A tour of my UV nodes (prefix PRIME), covering Promote to points, projection, island detection and trim-sheet placement.

2026-08-26

Houdini to Unreal: Nodes That Carry Intent by Name

To hand Houdini geometry to Unreal Engine correctly, you have to write attribute and group names correctly. Here are the naming rules for collision, materials and landscapes, and the nodes that write them.

Comments