Nine pixels, four regions
Here are nine pixels. Five are dark, and every dark pixel touches another one. The bottom one touches only at its corners, but corners count here, so the five form one region. Add the two blue pixels, one region each, and the grey pair in the middle: four regions in all.
NPP 13.2 says five. It cuts the top-right dark pixel off into a region of its own, every run, on an RTX 3070 and an RTX 4060 Ti (on the A100, whose driver only runs NPP 12, versions 12.3 and 12.4 do the same):
That is one call to nppiLabelMarkersUF_8u32u_C1R_Ctx, made the way NVIDIA's sample makes it. Our standalone test makes that one call, checks the answer, and exits with status 2 when it is wrong. Every NPP we tested from 12.3.3 to 13.2.0 is wrong on every run; 11.8.0 gets these nine pixels right and fails the same way once the shape is a pixel taller.
Nine pixels is the smallest case. The same cut happens wherever two arms of one colour meet at the bottom:
Not our pictures, not our program
Before calling a vendor library wrong, we took our own code out of the picture. The CUDA samples include a program for exactly this function, with five sample images. We ran NPP on those images the way that program does, then built the program itself, unchanged, and ran that too.
Move over any picture (or tap it) and the frame follows in all four, or step through NPP's mistakes one by one. Pictures are coloured by true region; NPP's labels take the colour of the true region they mostly cover, so where NPP is right its picture matches cc3d's, and every piece it cut off has a strong colour of its own. cc3d is a CPU library; "ours" is the GPU labeller from our last post. The two share no code and write the same files, byte for byte.
| NVIDIA sample image | cc3d | ours | NVIDIA's committed output (tag v12.8, NPP 12.0.0) | NVIDIA's sample program, NPP 12.4.1, RTX 3070, run 1 | NPP 13.2.0, RTX 3070, 30 runs |
|---|---|---|---|---|---|
| teapot | 155,343 | 155,343 | 155,333 | 155,343 | 155,343 every run |
| PCB_METAL | 3,732 | 3,732 | 3,732 | 3,733 | 3,732–3,735; wrong in 28 |
| CT_skull | 407 | 407 | 415 | 434 | 431–439; wrong in 30 |
| PCB2 | 1,202 | 1,202 | 1,225 | 1,272 | 1,270–1,277; wrong in 30 |
| PCB | 1,436 | 1,436 | 1,441 | 1,469 | 1,473–1,481; wrong in 30 |
8 neighbours throughout; counts are for the single-image call. cc3d and our kernel give identical label files on all five images. NPP's count changes from run to run. With 12.4.1 and later it is never below the truth, because those versions only cut regions; NPP 12.0.0 (NVIDIA's files) and 11.8 also join regions across row ends, which is how the teapot comes out with too few labels. NVIDIA's committed files are judged by our checker; the report links each one.
The sample program, built unmodified against NPP 12.4.1, writes wrong labels on three or four of its five images in every run: over twenty runs, the fourth came out right only once. The samples repository also includes the files that program wrote when NVIDIA ran it, around the CUDA 12.0 release, twice: at tag v12.8 (its log says NPP 12.0.0) four of the five images are wrong, and at the earlier tag v12.5 all five are. Here is every mistake in the PCB file from tag v12.8:
Left: the whole image, grey where NPP is right; each red number is a cut, each purple one a pair of regions joined across a row end. Right: the 48 × 48 pixels around the selected mistake, in the input, in the right answer and in NPP's labels.
Same picture, different answer
Run NVIDIA's sample ten times on the same machine with the same input, and it prints four different region counts for the CT skull: 433, 434, 435 and 437. The answer is 407.
Labelling has one right answer. Which pixels belong together is fixed by the picture; only the numbers on the groups are free, and NPP's documentation says its numbers come in no particular order. So we never compare numbers. A labelling is wrong in exactly two ways: two touching pixels of one colour carry different labels (a region split), or one label covers two regions (two regions merged). NPP's runs differ in which regions they split.
Small shapes are wrong the same way every time: inside a 16 × 16 block of pixels, a variant of the nine-pixel picture failed in 200 of 200 runs at each of 15 positions. Moved so that it straddles the edge of such a block, NPP 13 labels it correctly, which suggests NPP labels the image in 16 × 16 tiles and then joins the tiles. Once regions span many tiles, the wrong answer changes from run to run, as if the order in which threads happen to finish decides which joins are lost.
A GPU labeller does not have to behave like that. Ours numbers each region by its first pixel in reading order, so even the numbers are fixed: 50 runs of each image on the same GPU give byte-identical files, and right ones.
Everything we could have done wrong
A wrong answer from a vendor library is usually the caller's fault. So we tried every misuse we could think of, one at a time, on every version: bigger and pre-filled buffers, other streams, other input types, the batch API. None makes the images right.
The full list
- Scratch buffer zeroed, left uninitialised, filled with 0xFF, or four and sixteen times the size NPP asks for.
- Output buffer zeroed or pre-filled; rows pitched with
cudaMallocPitch; row steps in bytes, as documented. - The default stream, our own stream, NPP's own
nppGetStreamContext, and a context zeroed except for the stream. - 8-, 16- and 32-bit input; values 0/255 as well as 0/1/2;
nppiNormInffor 8 neighbours. - The batch API, called with two images per call as its documentation asks: wrong on 40 of 40 random 64 × 64 images, and so is the single-image call on the same images, on NPP 11.8, 12.4 and 13.2.
- Labels read before and after
nppiCompressMarkerLabelsUF.
Our test program is plain CUDA C++ with no framework. It loads NPP at run time, so one binary tests every version, and it checks every call against a simple CPU labeller.
And NVIDIA's newer library
NVIDIA also publishes NPP+, a separate library with its own C++ interface, its own copy of the sample, and its own committed output files. All ten of those files are wrong, and so are all ten of the first run when we build that sample and run it ourselves. NPP+ 0.10.0 reports its version as 12.4.0 and fails exactly where NPP 12.4.1 fails, on every small shape we tried.
Point the leader, not the neighbour
Almost every fast labeller is built on union-find. Each pixel stores one number, the pixel it points at; follow the arrows and you reach the region's leader, a pixel that points at itself. To join two regions, you point one region's leader at the other's. Step through the nine pixels of Fig. 1, done right:
NPP returns, for each pixel, the index of its leader, so its output shows the arrows. They look as if NPP pointed the neighbour at the other region's leader, instead of the neighbour's own leader. Locally that looks the same. But the old leader is left behind, pointing at itself, leading a region of its own. Replayed that way, the nine pixels come out exactly as NPP labelled them:
We measured every pair of arm heights from 1 to 5, in two shapes and three versions. A rule built on that reading has six numbers, one per shape and version: how far up the arm NPP re-points. We fitted them by hand to these measurements, so the rule describes them rather than predicts them; with them it agrees with measured cases:
NPP is closed source, so this is its behaviour seen from outside, not its code. In the code we can see, our own, the safe join is a loop: find both leaders, point one at the other with an atomic minimum, and look again if someone moved first.
How it went unnoticed
We are not the first to see this. Two NVIDIA forum threads from 2021 (184854, 188097) report regions split by this function, and the CUDA 11.5 release notes list a fix for "column processing incorrect results" in it. The first thread's own example is labelled correctly by NPP 11.8.0, 12.4.1 and 13.2.0, so what we see is either a different trigger or a fix that was not complete. It is in every version we tested, 11.8.0 to 13.2.0.
It is easy to miss. The sample program checks NPP's status codes, not the labels it writes. On a photograph most regions are small: NPP 13.2 labelled the teapot correctly in all 30 runs, and random images with 256 values never failed. Where it is wrong, the count is off by a few percent (431 to 439 labels for the skull's 407 regions) or not at all (3,732 to 3,735 for the 3,732 regions of PCB_METAL, right in 2 of 30 runs), and a region split in two looks like two regions. Because the answer changes from run to run, a failure is hard to show twice.
Drawings are different. A wall line, or the paper itself, crosses thousands of tiles, which is exactly where NPP goes wrong, and where we first saw it.
What to do today
Check the labels, not just the status code. It takes ten lines: label each colour on the CPU, then count the regions that got more than one label and the labels that cover more than one region. Both should be zero.
- Expect it on large regions. Small, compact regions mostly come out right; long thin ones and big ones are where it splits.
- Watch the size.
nppiLabelMarkersUFGetBufferSize_32u_C1Rreturns its size in anint: at 33,600 × 24,000 pixels it returned −1,069,367,288, although the documentation says these functions handle up to 4 gigapixels. - Upgrade when CUDA 13.6 ships. It carries NVIDIA's fix.
- Other labellers give the right answer. RAPIDS cuCIM's
labelagreed with our ground truth at every size it fit in memory, and so does the labeller from our last post.
Reported, reproduced, fixed
Bugs like this turn up in every large library; what counts is how quickly they get fixed. NVIDIA's NPP team reproduced this one within a day and had a verified fix a week later. We are grateful to them.
- 20 October 2026. Filed as NVIDIA bug 6963973, with the nine-pixel program and every file, and posted on NVIDIA's developer forum. Two issues note the committed sample outputs: cuda-samples #468 and CUDALibrarySamples #374 (NPP+).
- 21 October. NVIDIA reproduced it and passed it to the NPP engineering team.
- 28 October. Closed as fixed, verified on the reproducer, scheduled for CUDA 13.6.
- Next. When CUDA 13.6 is out, we will rerun the tests in this post against it and update this page.