← Writing

A GPU that answers 13 times faster than the CPU, and still loses

Contents

A laptop GPU answers a learned Bloom filter’s queries in 0.046 nanoseconds each, 13 times faster than all 32 threads of the CPU beside it. Getting each query to the GPU takes 1.35 nanoseconds, so for any query that starts on the CPU, the GPU is the slower choice, at every filter size I tried. Building the filter goes the other way: 141 times faster than one CPU thread at the scale of the paper’s DNA dataset, and still 16 times faster with the copy in, and every filter the GPU builds is bit-identical to the CPU’s. This is how the port reached the GPU without a second implementation to keep in step, what its tests can and cannot see, and the arithmetic that decides where a filter should live.

Part 10 of the Bloom filter saga: a partitioned learned Bloom filter in CUDA, held bit-identical to the CPU, and the 17 bytes per query that decide where it should run.

Part 8 ported Sato and Matsui’s fast construction of a partitioned learned Bloom filter to C++ and held it to the Python reference to the last bit. Part 9 made its queries faster with AVX2, and spent most of its length on the benchmarks that lied about it. This part moves the same filter onto an NVIDIA GPU, an RTX 4090 Laptop GPU in the same machine. The code is the same repository, learned-bloom-filter, and every number below comes from running it; the files are named as we go.

How to read this. Where you see a Predict box, stop and answer it before reading on. The three figures draw only recorded measurements. The box marked “safe to skip” holds detail the main text never depends on.

What you need to know already: Part 9’s first section, on what a query does, helps but is not required. GPUs, kernels, PCIe and atomics are explained where they first matter.


1. What moves to the GPU

A GPU is a processor built for doing the same small piece of work on a great many inputs at once. The 4090 Laptop GPU has 76 streaming multiprocessors, which between them can keep more than 100,000 threads in flight, and it reaches its speed by keeping all of them busy. A program hands it work as a kernel, a function that runs once per thread, launched over a grid of threads from the CPU. The GPU has its own memory, and anything a kernel reads has to get there first, over the PCIe link that connects the card to the rest of the machine.

Building the filter, as Part 8 described it, has four steps:

  1. Histogram the scores. One pass over every key’s score and every non-key’s score, counting how many land in each of the N=1000N = 1000 segments.
  2. Search for the layout. The dynamic program of Part 8, over those 2,000 counts. It costs about half a millisecond, and its cost depends on NN and the number of regions kk, not on how many keys there are.
  3. Size the region filters, and lay out their blocks.
  4. Insert every key: route it to its region by score, and set eight bits in one block.

Steps 1 and 4 are passes over the data, the same small operation on millions of independent items, and they are what a GPU is for. Step 2 is the opposite. It is a sequential dynamic program over a few thousand numbers, it already takes half a millisecond, and on the GPU it would mostly wait for kernel launches. So the port splits the build: the histograms run on the GPU and send back two arrays of 1,000 counts; the search runs on the CPU; the region tables, about 10 KB, go back up; and the GPU inserts the keys. The filter’s blocks are built on the GPU and never cross the link. Queries are simpler: each one is a hash and a score in, one byte of answer out.

What crosses the link

At the paper’s DNA scale, 50 million keys and 50 million non-keys, the build’s one big copy is the input: 1.2 GB of hashes and scores, which takes longer to move than everything the GPU then does with it. The query view shows the same shape at the scale of one query, and that shape is the subject of the second half of this post.

2. One implementation, compiled twice

The obvious way to port a data structure to a GPU is to write a GPU version of it. The trouble with two versions is that they drift. A key inserted by one and looked up by the other has to be found, and a filter the GPU builds should be the filter the CPU would have built, or a test cannot tell a bug from a difference of opinion. So the CUDA backend in cuda/filter.cuh holds itself to the same standard as Part 8’s port: bit for bit. A GPU-built filter’s layout, tables and every block are compared with the CPU’s, and must be identical.

That is less work than it sounds, because almost all of a build is integer arithmetic, and integers do not round. The places where the two could have diverged are few, and each has a specific guard:

  • The segment index is the one floating-point step on the GPU. It uses Part 9’s argument directly: ⌈sN⌉\lceil sN \rceil is off by at most one each way, so the device version is two comparisons, not two loops. The multiply is written as __dmul_rn(score, n), CUDA’s explicitly rounded double multiply, which the compiler will never fuse into a multiply-add, whatever optimisation flags the including file was built with. Part 8 showed what a fused multiply-add does to agreement.
  • The block index is the multiply-shift from Part 9, (hhigh×count)≫32(h_{\text{high}} \times \text{count}) \gg 32. CUDA has an instruction for exactly that, __umulhi, the high 32 bits of a 32-by-32-bit product.
  • The salts. Device code cannot read the host’s constexpr array of Parquet’s eight constants, so the kernels carry their own copy, and a static_assert compares the two at compile time.
  • The tables are built by one host function, region_tables::build, which both backends call; the GPU receives the result.
  • The histograms are integer counts. Each block of threads counts into its own shared-memory array, when NN counts fit in the 48 KB a block gets by default, and adds its totals to the global array once; otherwise every score is a global atomic add. Integer addition is exact and does not care about order, so thousands of threads racing to count produce exactly the counts one thread would. The CPU then turns those counts into probabilities with the same function it always uses, and the search that follows is the same code on the same inputs.
  • The inserts are where threads really do collide: two keys in one block, inserted by two threads at once. Each key’s eight bits go into the block’s eight 32-bit words as four 64-bit atomic ORs. OR is commutative and idempotent, so it does not matter which thread lands first, or whether two set the same bit: the final block is the same bits in every order.

The result is a GPU backend that does not contain a second algorithm. It contains the CPU’s algorithm, the same tables and the same constants, executed by different hardware, and the parts that could differ are pinned down one by one.

3. The tests that hold it there

test_cuda.cu makes 38 checks, and every one is an equality, never a tolerance:

  • the device segment index against the CPU’s on Part 9’s 54,543,918 edge scores, every threshold of ten grids and the doubles either side of it;
  • the GPU histograms against the CPU’s, through both the shared-memory path (N=1000N = 1000) and the global-atomic path (N=20,011N = 20{,}011), on about two million scores each;
  • a CPU-built filter, uploaded, answering 1.2 million queries exactly as contains() does, every threshold’s edge scores among them;
  • GPU-built filters against CPU-built ones in five configurations, covering three search methods, three targets, the memory-budget mode, nine regions over 997 segments and seven over 20,011. Layout, tables and every block must be identical, and so must the answers, on the GPU and after downloading the filter back.

As in Part 9, a passing test only counts if it can fail, so I broke the backend twice and ran the suite against each break (test_cuda_mutant_index.txt, test_cuda_mutant_atomic.txt):

  1. The device index without its downward step, the same mutant Part 9 ran on the CPU.
  2. The insert kernel with its last atomic OR dropped, so a quarter of every key’s bits are never set.

Predict. The five “GPU-built filter is bit-identical” configurations compare every block of every filter. Which of the two mutants do they catch?

Only the second. Dropping an OR fails 15 checks: every configuration’s blocks, its GPU answers and its downloaded answers. The index mutant fails only 2 of the 38: the index check itself, on 11,541 scores, the same count as on the CPU, and the histogram at N=20,011N = 20{,}011. All five bit-identical-filter checks pass it.

The reason is Part 9’s finding, seen from the other side. At N=1000N = 1000, no threshold inside (0,1)(0, 1) needs the downward step, so a broken downward step changes nothing about a build or a query at the paper’s NN, edge scores included. At 997 segments 8 thresholds need it, and at 20,011, 1,153, but the filters there are built from random scores, which essentially never sit exactly on a threshold. The histogram at N=20,011N = 20{,}011 catches it because its scores start from every threshold’s edge scores; the test then overwrites half of its scores with skewed random ones, and 577 of the 1,153 thresholds that need the step survive that. A test that compares whole filters is a good test of the inserts and a poor one of the index; the suite needs both kinds.

4. Building it

Here is the build on both of the paper’s scales, timed in bench_cuda against the CPU build on one thread (bench_cuda_msvc.txt):

Building the filter, CPU against GPU

CPU work GPU work copying the data in

Medians from one run on 30 October 2026; the CPU build is single-threaded. Every GPU-built filter was checked bit-identical to the CPU's.

At the URL scale, 223,088 keys, the GPU build takes 0.95 milliseconds against the CPU’s 5.52, 5.8 times faster, and the search is more than half of it: 0.54 of the 0.95 milliseconds run on the CPU, between the two GPU phases. Copying the keys and scores in first adds 0.77 milliseconds, which leaves the GPU 3.2 times ahead.

Predict. At the DNA scale there are 224 times as many keys. The search’s cost does not depend on the number of keys. What fraction of the GPU build is the search there?

Four per cent. At 50 million keys and 50 million non-keys the CPU takes 2.07 seconds and the GPU 14.63 milliseconds, 141.5 times faster, and of that the search is still 0.56 milliseconds. The histograms take 3.64 and the insert and its allocation 10.43. Copying the 1.2 GB of input in takes 112.52 milliseconds, nearly eight times the GPU’s whole build, and even with it the GPU is 16.3 times faster. Two caveats keep that honest. The CPU build is one thread, and its histogram and insert would both spread over 32. The copy is from ordinary, pageable memory, as a program holding its keys in vectors would do; pinned memory, below, moves faster. Every GPU filter in the run came back bit-identical to the CPU’s.

5. Querying it

The query kernel is contains() on every thread at once: route the score to a block, probe it, write one byte. Three filter sizes, 100 million queries each, half keys and half unseen non-keys:

Nanoseconds per query, GPU against CPU

Three filter sizes. Toggle where the queries start: a program on the CPU, or a model that already runs on the GPU.

GPU kernel copy in and out CPU, AVX2 batch

One run, 100 million queries per size, medians; 30 October 2026. The copies use pinned memory, at 11.9–12.4 GB/s.

With the queries already on the GPU, the kernel answers in 0.046 nanoseconds a query with a 3.4 MB filter, 0.059 with a 43.7 MB filter and 0.186 with a 169.7 MB one. That is 13, 15 and 6.4 times faster than the CPU’s AVX2 batch on all 32 threads (0.613, 0.912 and 1.184 nanoseconds). The jump between the second and third sizes lines up with the GPU’s L2 cache, 64 MiB (67 MB): the middle filter fits in it and the largest does not.

Now start the queries on the CPU, as most programs would. Every query has to cross the link as 16 bytes, an 8-byte hash and an 8-byte score, and every answer has to come back as one byte. In the recorded run that costs 1.35 nanoseconds in and 0.09 out, and the GPU’s total becomes 1.48, 1.47 and 1.57 nanoseconds a query: slower than 32 CPU threads at every size, by 2.4, 1.6 and 1.3 times. It is still 3 to 7 times faster than one CPU thread, so a single-threaded program would gain by shipping its queries to the GPU. A program that can use the CPU’s cores would lose.

6. The copy

The copy’s cost is not overhead in any loose sense. It is bytes divided by bandwidth, and nothing else: the 16-byte queries go in at 0.084 nanoseconds a byte, and the 1-byte answers, timed separately, come back at 0.086, the same rate within a few per cent. So the arithmetic of where a query should run fits on one line: the GPU wins when

tkernel+17 bytesbandwidth<tCPU. t_{\text{kernel}} + \frac{17\ \text{bytes}}{\text{bandwidth}} < t_{\text{CPU}} .

Predict. With the 3.4 MB filter, the kernel takes 0.046 nanoseconds and 32 CPU threads 0.613. How fast would the link have to be for the GPU to win?

About 30 GB/s, two and a half times what this link delivers, and about the theoretical peak of a 16-lane PCIe 4.0 link; PCIe 5.0 doubles that. With the larger filters the kernel is slower and so is the CPU, and the break-even falls to 20 GB/s and 17 GB/s; an x16 link in practice might just win those. That is arithmetic from the measured numbers, not a measurement on such a machine.

This machine’s link is narrower than that. Before the runs, nvidia-smi reported it 8 lanes wide, though 16 are possible, and capable of PCIe 4.0, and 12 GB/s fits what 4.0 delivers over 8 lanes in practice. It also turned out to have a second speed. The reducer in section 9 measures the same copy, and in all ten runs I recorded (pcie_ten_runs.txt) it measured 6.5 GB/s, about what PCIe 3.0 delivers over 8 lanes. Some earlier runs of the same program, not kept, had measured 12.7, and bench_cuda measured 12.2 the same afternoon (bench_cuda_msvc_rerun_4m.txt). Power management can change a PCIe link’s speed at run time, but I did not record the link’s state during the runs, so I cannot say that is what happened here. Keeping the GPU busy with kernels before the copies did not reliably select the faster one. At 6.5 GB/s a query from the host costs 2.7 nanoseconds, and the conclusion only gets stronger: the copy, not the GPU, is what a host-side query pays for.

7. Two more benchmarks that said otherwise

Part 9 was about benchmarks that measured something other than the code. The GPU work produced two more.

The build that was quietly Debug

On Windows, CUDA’s compiler hands host code to Microsoft’s, so the CUDA build of this project is an MSVC build. Its first numbers came out many times slower than g++’s, and the reason was CMake. For a single-configuration generator such as Ninja, CMake’s MSVC platform file sets the default build type to Debug while project() enables the language, before any line after project() runs. The common guard for “no build type given, so use Release”, if(NOT CMAKE_BUILD_TYPE) after project(), therefore never fires under MSVC, while under g++ it does. With CMake 4.2.1, a minimal project shows it (msvc_default_build_type.cmake): under cl the build type is already Debug, with /Zi /Ob0 /Od /RTC1; under g++ the guard fires and sets Release. The port’s fix is to set the default before project(), where the platform file has not yet had its say.

What Debug costs, I measured for this post by building the same two benchmarks with the flags CMake’s Debug and Release configurations pass to MSVC (msvc_debug_vs_release.txt). Queries ran 3.5 to 24 times slower and construction 2.8 to 13.6 times. The worse problem is that Debug does not slow everything equally. The AVX2 lookup from Part 9, 2.52 nanoseconds in Release, took 61.05 in Debug, against 26.52 for the scalar lookup it replaced, so the vector code looked more than twice as slow as the code it beats by 1.75 times. The usual reason is that an unoptimised build keeps every intermediate vector in memory between intrinsics; I did not read the disassembly. Among the searches, on the ideal shape at five regions, Fast PLBF++ came out 2.3 times faster than Fast PLBF# in Debug, where in Release the two are within 6%. A Debug build is not a slow version of the program; it is a different program, with different winners.

The GPU that got faster when the CPU throttled

The first attempt to record these numbers ran while the laptop was throttling, the run Part 9 described. Once the throttling took hold, its CPU figures came out 3 to 9 times too slow (throttled/bench_cuda_msvc.txt). The GPU’s query-kernel figures in the same run were not slower. At the two smaller filter sizes they were faster, 0.034 nanoseconds against the recorded run’s 0.046, and 0.046 against 0.059. At the largest size, where the kernel most likely waits on the GPU’s memory, the two runs agree to the picosecond. A laptop’s CPU and GPU share one power and cooling budget, and when the CPU’s share was cut, the GPU’s clock may have had room to rise. The picture is mixed, though: the DNA-scale build’s GPU phases, which also wait on the CPU to launch kernels and allocate memory, were 14 to 32% slower. I did not record the clocks, so this is a plausible explanation, not a demonstrated one. Either way the throttled run’s GPU-over-CPU ratios, 359 times for the DNA-scale build among them, are ratios between two power allocations, not between two processors.

8. When to use it, and where it should run

The measurements answer two questions, in order: whether a learned filter is the right tool at all, and then, if it is, whether the CPU or the GPU should hold it.

Is a learned filter the right tool? It is when all four of these hold.

  • The set is fixed once built. The filter has no insert and no delete. Rebuilding is cheap enough to do often: 5.5 milliseconds for the URL-scale set on one CPU thread, and 14.6 milliseconds on the GPU for 50 million keys and 50 million non-keys.
  • A model separates keys from non-keys. All of the saving comes from that separation, the divergence of Part 8. A model that scores keys and non-keys alike saves nothing, and every query still pays for its lookup.
  • Memory matters. At a 1% target the learned filter holds a key in about 7 bits, against 10.5 for a plain split-block filter: a third less, as Part 9 measured.
  • The score is there anyway, or is cheap next to what a “no” saves. Every query needs its score. If the model runs regardless, because it is the classifier deciding what happens to the item, the filter costs almost nothing extra. If the model runs only for the filter, its cost has to be weighed against the disk read or network call that a correct “no” avoids. I did not measure a model here; that cost depends entirely on the model.

If the set changes all the time, or there is no model worth having, a plain Bloom filter is the better tool.

Then, where should it run? Where the queries are decides it.

When the queries…usebecause, on this machine
come from a model running on the GPUthe GPU kernel0.046 to 0.186 ns a query, 6 to 15 times all 32 CPU threads, and nothing crosses the link
start in a CPU program with cores to sparethe CPU’s AVX2 batch, on every thread0.61 to 1.18 ns a query, faster than any way of sending them to this GPU
start in a CPU program whose cores are busythe GPU, with 32-bit scores1.1 to 1.6 ns a query, about the work of 3 to 7 CPU threads, done by the GPU’s copy engines and kernel instead

The last row is the one place the GPU earns its keep for host-side queries without being faster: it gives back CPU time. I did not measure how busy the CPU stays while the copies run; the copies themselves are done by the GPU’s copy engines, not by CPU threads. Every row assumes large batches. The copies and the kernel launch have a fixed cost that a single query cannot spread out, and I measured only batches of 100 million.

Building follows the same rule: build where the data is. From keys already on the GPU, the GPU build is 141 times faster at the DNA scale; from keys on the CPU, it is still 16 times faster there after the copy. At the URL scale either is fine, 5.5 milliseconds against 1.7 with the copy.

Can a smaller question make the GPU win? While preparing this post I added two smaller query formats to the library (a50ed38): a 32-bit score, 12 bytes a query, and a 16-bit segment number, 10 bytes, which the CPU works out from the score. Both give exactly the double path’s answers. The same benchmark, extended and run again on 31 October (bench/results/2026-10-31/), timed all three on the same filters in one run:

Filter16 bytes12 bytes10 bytesCPU, 32 threads
3.4 MB1.459 ns1.124 ns0.932 ns0.421 ns
43.7 MB1.476 ns1.126 ns0.939 ns0.825 ns
169.7 MB1.589 ns1.250 ns1.085 ns1.058 ns

The copy shrinks exactly in step with the bytes, but on this 8-lane link the CPU still wins at every size. With the largest filter the segment format comes within 3%, and it adds about a nanosecond a query of score-to-segment work on one CPU thread, which is the work it moves off the GPU. By the arithmetic of section 6, a full 16-lane PCIe 4.0 link would turn the two larger sizes into wins for the GPU, and PCIe 5.0 all three; that is arithmetic, not a measurement. The 32-bit format costs nothing in accuracy when the model emits 32-bit scores, as most do. Every 32-bit float widens to a double exactly, so a filter built from the widened values looks every key up in the segment it was inserted from.

This is one machine’s verdict. The tables above are true of this laptop: an 8-lane link that moves about 12 GB/s, and a 32-thread CPU. The rule underneath them holds anywhere. A query that starts on the CPU belongs on the GPU when the kernel plus the copy, tkernel+bytes/bandwidtht_{\text{kernel}} + \text{bytes} / \text{bandwidth}, beats the CPU’s own time on all its threads, and changing either side of that moves the verdict. Worked from this run’s kernel and CPU times, with the link speeds as assumptions, this is arithmetic, not measurement:

On a machine where the link…a 16-byte query from the host costsand the GPU
moves 12 GB/s, as this laptop’s 8 lanes do1.47 to 1.57 nsloses at every size
moves 25 GB/s, as a 16-lane PCIe 4.0 link might0.73 to 0.87 nswins with the two larger filters
moves 50 GB/s, as a 16-lane PCIe 5.0 link might0.39 to 0.53 nswins at every size
is not crossed: the queries are produced in GPU memory0.046 to 0.186 nswins at every size, by 6 to 15 times

The CPU side moves the line as well. A CPU with fewer cores than this one’s 32 threads takes longer on its own (one thread here takes 4.7 to 9.8 ns a query), so it hands the GPU the win sooner; a server with many more cores raises the bar. What does not change from machine to machine is the shape. On any PCIe machine the copy, not the kernel, is most of a host-side query, so the choice is always between the link and the CPU, and the reducer in the next section measures the link on yours.

The bit-identical build makes the choice cheap to change. A filter built on the GPU can be downloaded with to_host() and queried on the CPU, and one built on the CPU can be uploaded, with no difference in any answer.

9. Run it yourself

The figures are one machine. This file measures yours: a plain split-block filter with Part 9’s salts, 2252^{25} queries, about 33.5 million, of 16 bytes each from pinned host memory, the probe on the GPU, and one byte per answer back, every answer checked against the CPU. It needs a CUDA toolkit and a GPU; on Windows, run it from a Visual Studio developer prompt, since nvcc needs Microsoft’s compiler there.

// What a query that starts on the CPU costs a GPU filter: 16 bytes in, the
// probe, 1 byte out. The filter is a plain split-block filter with the Parquet
// salts, as in Part 9; the answers are checked against the CPU's.
//   nvcc -O3 -std=c++17 pcie.cu -o pcie && ./pcie
#include <cuda_runtime.h>

#include <algorithm>
#include <cstdint>
#include <cstdio>
#include <vector>

#define CHECK(x)                                                                  \
    do {                                                                          \
        if (cudaError_t err = (x); err != cudaSuccess) {                          \
            std::printf("%s failed: %s\n", #x, cudaGetErrorString(err));          \
            return 1;                                                             \
        }                                                                         \
    } while (0)

struct query {
    std::uint64_t hash;
    double score;  // unused by a plain filter, but it crosses the bus all the same
};

__host__ __device__ inline std::uint64_t mix(std::uint64_t x) {  // splitmix64's finaliser
    x ^= x >> 30; x *= 0xbf58476d1ce4e5b9ULL;
    x ^= x >> 27; x *= 0x94d049bb133111ebULL;
    return x ^ (x >> 31);
}

__host__ __device__ inline bool probe(const std::uint32_t* blocks, std::uint32_t count, std::uint64_t h) {
    const std::uint32_t salt[8] = {0x47b6137bU, 0x44974d91U, 0x8824ad5bU, 0xa2b7289dU,
                                   0x705495c7U, 0x2df1424bU, 0x9efc4947U, 0x5c6bfb31U};
    const std::uint32_t* b = blocks + 8 * (((h >> 32) * count) >> 32);
    const auto x = static_cast<std::uint32_t>(h);
    std::uint32_t missing = 0;
    for (int i = 0; i < 8; ++i) missing |= (1U << ((x * salt[i]) >> 27)) & ~b[i];
    return missing == 0;
}

__global__ void answer(const std::uint32_t* blocks, std::uint32_t count, const query* q, std::uint8_t* out,
                       std::size_t n) {
    for (std::size_t i = blockIdx.x * std::size_t(blockDim.x) + threadIdx.x; i < n;
         i += std::size_t(blockDim.x) * gridDim.x) {
        out[i] = probe(blocks, count, q[i].hash);
    }
}

int main() {
    // 4 million keys in 131,072 blocks: a 4 MB filter, about 8.4 bits a key.
    const std::uint32_t count = 131072;
    const std::size_t keys = 4000000, n = 32 << 20;  // 32 Mi queries: 512 MB in, 32 MB out
    std::vector<std::uint32_t> blocks(8 * std::size_t(count), 0);
    const std::uint32_t salt[8] = {0x47b6137bU, 0x44974d91U, 0x8824ad5bU, 0xa2b7289dU,
                                   0x705495c7U, 0x2df1424bU, 0x9efc4947U, 0x5c6bfb31U};
    for (std::size_t k = 0; k < keys; ++k) {
        const std::uint64_t h = mix(k);
        std::uint32_t* b = blocks.data() + 8 * (((h >> 32) * count) >> 32);
        for (int i = 0; i < 8; ++i) b[i] |= 1U << ((std::uint32_t(h) * salt[i]) >> 27);
    }

    query* hq;  // pinned host memory: what the link really runs at
    std::uint8_t* ha;
    CHECK(cudaMallocHost(&hq, n * sizeof(query)));
    CHECK(cudaMallocHost(&ha, n));
    for (std::size_t i = 0; i < n; ++i) hq[i] = {i % 2 ? mix(i / 2 % keys) : mix((1ULL << 40) + i), 0.5};  // half keys

    std::uint32_t* db;
    query* dq;
    std::uint8_t* da;
    CHECK(cudaMalloc(&db, blocks.size() * 4));
    CHECK(cudaMalloc(&dq, n * sizeof(query)));
    CHECK(cudaMalloc(&da, n));
    CHECK(cudaMemcpy(db, blocks.data(), blocks.size() * 4, cudaMemcpyHostToDevice));

    cudaEvent_t t0, t1, t2, t3;
    for (cudaEvent_t* ev : {&t0, &t1, &t2, &t3}) CHECK(cudaEventCreate(ev));
    std::vector<float> in, kernel, out;
    for (int rep = 0; rep < 7; ++rep) {
        CHECK(cudaEventRecord(t0));
        CHECK(cudaMemcpy(dq, hq, n * sizeof(query), cudaMemcpyHostToDevice));
        CHECK(cudaEventRecord(t1));
        answer<<<1024, 256>>>(db, count, dq, da, n);
        CHECK(cudaEventRecord(t2));
        CHECK(cudaMemcpy(ha, da, n, cudaMemcpyDeviceToHost));
        CHECK(cudaEventRecord(t3));
        CHECK(cudaEventSynchronize(t3));
        float a, b, c;
        CHECK(cudaEventElapsedTime(&a, t0, t1));
        CHECK(cudaEventElapsedTime(&b, t1, t2));
        CHECK(cudaEventElapsedTime(&c, t2, t3));
        in.push_back(a), kernel.push_back(b), out.push_back(c);
    }
    auto median_ns = [&](std::vector<float> v) {
        std::sort(v.begin(), v.end());
        return v[v.size() / 2] * 1e6 / double(n);  // ms per batch -> ns per query
    };
    const double ns_in = median_ns(in), ns_kernel = median_ns(kernel), ns_out = median_ns(out);

    std::size_t wrong = 0, present = 0;
    for (std::size_t i = 0; i < n; ++i) {
        wrong += ha[i] != std::uint8_t(probe(blocks.data(), count, hq[i].hash));
        present += ha[i];
    }
    std::printf("copy in:  %.3f ns per 16-byte query (%.1f GB/s)\n", ns_in, 16 / ns_in);
    std::printf("kernel:   %.3f ns per query\n", ns_kernel);
    std::printf("copy out: %.3f ns per 1-byte answer (%.1f GB/s)\n", ns_out, 1 / ns_out);
    std::printf("a query that starts on the host: %.3f ns, %.0f%% of it the kernel\n", ns_in + ns_kernel + ns_out,
                100 * ns_kernel / (ns_in + ns_kernel + ns_out));
    std::printf("answers equal the CPU's: %s (%zu wrong; %.1f%% present)\n", wrong ? "no" : "yes", wrong,
                100.0 * double(present) / double(n));
}
$ nvcc -O3 -std=c++17 pcie.cu -o pcie && ./pcie   # your numbers will differ
copy in:  2.460 ns per 16-byte query (6.5 GB/s)
kernel:   0.061 ns per query
copy out: 0.155 ns per 1-byte answer (6.5 GB/s)
a query that starts on the host: 2.676 ns, 2% of it the kernel
answers equal the CPU's: yes (0 wrong; 51.4% present)

That is the first of the ten recorded runs, with the link in its slower state. The repository’s tools/pcie.cu is this program extended to the three query formats of section 8. The kernel is 2% of the round trip. On a desktop with a full 16-lane PCIe 4.0 link, the copy lines should come out several times faster, and the kernel line will move with the GPU; the last line should read the same everywhere, since the queries and the filter are deterministic. 51.4% of the queries come back “present”: the half that are keys, plus about 2.8% of the non-keys, the false positives of a filter this full.

10. The takeaway

The GPU part of this port was mostly an exercise in not writing a second implementation. Every floating-point step the GPU takes is one Part 9 had already proved exact, every integer step commutes, and the tables come from the same function, so the GPU’s filter is the CPU’s filter, checked block for block, and a mutant that a whole-filter comparison misses is caught by a test aimed at the one step that could differ.

The speed told a story in two halves. On a build from data already on the GPU, a hundred times is real, and the search Part 8 spent so long on has become 4% of it. On queries, the kernel is an order of magnitude ahead of the CPU and does not matter, because 17 bytes over this laptop’s PCIe link cost more than the CPU’s whole answer. The question to ask of a GPU filter is not how fast it answers, but where the question is when it is asked.

Corrections

  • “20–60× slower” in Debug. The port’s README, from its first commit through a15af76, said an MSVC Debug build “runs 20–60× slower here”. No measurement behind that range was kept, and measured for this post, Debug is 3.5 to 24 times slower on queries and 2.8 to 13.6 on construction. The README says 3–24× as of e2a8ec4, and the same comment in CMakeLists.txt as of 5498b80.
  • “4 to 12 times” throttled. The README of the results folder, from c645643 on, said every CPU figure of the throttled attempt was 4 to 12 times slow. The committed files show 2.5 to 9.6 once the throttling took hold, and no slowdown in the sections before it. It also said the throttle probe prints once a second, where it prints about twice, and the main README went on calling the DRAM-sized query result inconclusive after Part 9’s rerun had settled it. All three are corrected in b8bb6d4, with the throttling ranges made per file in 5498b80. A pre-publication check of these drafts caught them.

A note on the evidence

Observed, and committed. The build and query figures are one run of bench_cuda, built with CUDA 13.0.88 and MSVC 19.44, on the RTX 4090 Laptop GPU (76 SMs, sm_89) and i9-13980HX of the earlier parts, on 30 October 2026, in bench/results/2026-10-30/ with the machine and its power state described in the folder’s README. Every GPU filter and every GPU answer in that run was checked equal to the CPU’s before its time was reported. The rerun at 4 million keys, the mutant runs, the Debug and Release comparison, the CMake demonstration and the reducer’s ten runs are in the same folder, made the same day.

The query formats. The comparison of 16-, 12- and 10-byte queries in section 8 is a later run of the same benchmark, extended to time them, on 31 October 2026, with tools/pcie.cu’s five runs of the same three formats beside it, in bench/results/2026-10-31/. Every answer in all three formats was checked equal to the CPU’s. Its numbers are compared only with each other.

Compare within a run. The rerun, later the same afternoon with Windows reporting a different power scheme, measured the one-thread CPU batch at 9.90 nanoseconds where the recorded run had 4.66, while the 32-thread figure and the GPU barely moved. Every comparison above is between numbers from one run.

Observed during development. The port’s README quotes an earlier GPU run made while the backend was being written: 135 times for the DNA-scale build and 0.034 nanoseconds for the kernel. That run was in the laptop’s quieter power mode, which, as section 7 suggests, may give the GPU more room. Its raw output was not kept, so this post quotes the recorded run instead.

Not measured, or not kept. The GPU clocks during the throttled run; the PCIe link’s state during the copies, and what picks its speed; the earlier reducer runs at 12.7 GB/s, which were not saved; a multithreaded CPU build; and any machine with a 16-lane link. The break-even link speeds in section 6 are arithmetic from the measured kernel and CPU times.

What I would still change. The answers could come back as bits rather than bytes, an eighth of the outgoing copy, which section 8’s formats leave as it is. And the formats are measured on one laptop’s 8-lane link, not on a desktop with 16 lanes, where the arithmetic says they would win.

More