Plain DuckDB SQL on the GPU

Illustration: columns become resident in short row-id segments while your connection is idle, each lane at the narrowest width its values fit.

On Apple Silicon (Metal) and NVIDIA (CUDA). Write the SQL you already write: the GPU answers a statement when that is measured faster, and DuckDB answers everything else, with the same rows either way.

gpudb is a DuckDB community extension, a Python package and a gpudb shell. No hints, no schema changes, no query changes.

Python and the gpudb shell
$ pip install duckdb-gpudb
Any DuckDB 1.5.5 or later client, for the gpu_* functions
INSTALL gpudb FROM community; LOAD gpudb;
gpudb> SELECT l_partkey, sum(l_quantity) AS qty FROM lineitem GROUP BY l_partkey ORDER BY qty DESC LIMIT 5;
┌───────────┬───────────────┐
│ l_partkey │      qty      │
│   int64   │ decimal(38,2) │
├───────────┼───────────────┤
│    125009 │       1642.00 │
│    140633 │       1562.00 │
│     49981 │       1553.00 │
│    149443 │       1537.00 │
│     10426 │       1513.00 │
└───────────┴───────────────┘
DuckDB (not_resident: the resident set is not ready yet) · 32.5 ms

Ten seconds later, the same statement:

gpudb> SELECT l_partkey, sum(l_quantity) AS qty FROM lineitem GROUP BY l_partkey ORDER BY qty DESC LIMIT 5;
… the same five rows …
GPU (topk: the resident GROUP BY) · 33.9 ms
The footer under every result says where the statement ran and why. One session on an Apple M4 Max over TPC-H SF1, DuckDB 2.0.1, pip 0.7.2. Nine more runs each way: median 29.3 ms on DuckDB, 21.5 ms on the GPU, 1.36×.

How a statement reaches the GPU

The extension alone gives the gpu_* functions. Plain SQL reaches the GPU through a client that sees the statement before DuckDB plans it.

  1. You write ordinary SQL

    Through the gpudb shell or gpudb.connect() in Python. duckdb.connect becomes gpudb.connect(); the SQL is untouched.

  2. DuckDB parses, gpudb rewrites

    Before DuckDB plans it, the statement goes through DuckDB's own parser (json_serialize_sql) and a pure function in the extension (gpu_rewrite_ast). No plan surgery, no C++ API.

  3. Resident columns answer it

    A shape measured to win, over a table past the 1,000,000-row floor, runs on columns already in GPU memory. Tables become resident in the background, between your statements.

  4. Everything else is DuckDB

    Any other statement runs on DuckDB unchanged, at DuckDB's speed. Any error on the rewritten path re-runs your original statement on DuckDB.

Two rules

Never a different answer than DuckDB

A rewritten statement returns what native DuckDB returns: the same rows, the same order where native guarantees one, the same column names and the same column types. Integer and DECIMAL aggregates are bit-exact, with 128-bit sums on the device.

Where “the same as native” is not definable, the shape is never rewritten: sum(DOUBLE), which DuckDB itself computes in an order-dependent way, and an ORDER BY … LIMIT k whose first k rows tie, which goes back to DuckDB.

Never slower than DuckDB

Not on average: per statement, per shape, per size. Which shapes may be rewritten comes from bounds a gate measures against native before a release, and the losing measurements stay published.

Your machine is not the gate's, so the decision is taken again there. After a statement template's first three rewritten runs, the wrapper times the native form once on a side cursor in your own process, hands the template back to DuckDB if the rewritten runs were not faster, and measures again every 60 seconds.

Measured on TPC-H

Plain SQL through the transparent path, every table the query reads already resident, every row compared with native DuckDB before any time was counted. Two machines; yours will differ.

DuckDB 2.0.1 with pip 0.7.2, measured 2026-11-25 and not re-measured since (pip 0.7.3 and 0.7.5 are correctness fixes), default memory budget, N=5. sql() is the lazy-relation path the gpudb shell takes; both entry points are timed separately.
TPC-HMachineAsked throughOn the GPURows differingSpeed-up on those queries
SF1, 6M-row lineitemMacBook M4 Max, Metalexecute()16 of 2201.46× (Q15) – 12.36× (Q13)
SF1, 6M-row lineitemMacBook M4 Max, Metalsql()16 of 2201.53× (Q15) – 10.58× (Q13)
SF10, 60M-row lineitemMacBook M4 Max, Metalexecute()18 of 2201.03× (Q11) – 30.39× (Q5)
SF10, 60M-row lineitemMacBook M4 Max, Metalsql()18 of 2201.00× (Q11) – 17.76× (Q5)
SF10, 60M-row lineitemRTX 4090 Laptop, CUDAexecute()18 of 2201.59× (Q11) – 45.72× (Q9)

On DuckDB 2 avg over DECIMAL is not rewritten, so Q1 stays on DuckDB. The CUDA row was taken on a machine doing other work, so read its ratios as approximate.

Earlier, for comparison: DuckDB 1.5.5 with the v0.7.0 release build of 2026-09-20, the same script and settings. There Q1 runs on the GPU as well.
TPC-HMachineAsked throughOn the GPURows differingSpeed-up on those queries
SF1, 6M-row lineitemMacBook M4 Max, Metalexecute()17 of 2201.52× (Q15) – 15.32× (Q9)
SF1, 6M-row lineitemMacBook M4 Max, Metalsql()17 of 2201.37× (Q15) – 9.49× (Q13)
SF10, 60M-row lineitemMacBook M4 Max, Metalexecute()19 of 2201.06× (Q11) – 48.10× (Q5)
SF10, 60M-row lineitemMacBook M4 Max, Metalsql()19 of 2200.92× (Q11) – 26.39× (Q5)
SF1, 6M-row lineitemRTX 4090 Laptop, CUDAexecute()17 of 2201.21× (Q15) – 31.44× (Q9)
SF1, 6M-row lineitemRTX 4090 Laptop, CUDAsql()17 of 2201.66× (Q15) – 16.27× (Q9)

Query by query, Apple M4 Max, DuckDB 2.0.1

  • execute()
  • sql(), the shell's path
  • below 1.0×
  • stays on DuckDB

TPC-H SF10 (60M-row lineitem)

  • Q1on DuckDB: avg over DECIMAL is not rewritten on DuckDB 2——
  • Q2on DuckDB: a correlated inner statement that does not bind on its own——
  • Q3 execute() 3.52× sql() 3.27×
  • Q4 execute() 10.98× sql() 8.45×
  • Q5 execute() 30.39× sql() 17.76×
  • Q6 execute() 1.95× sql() 1.82×
  • Q7 execute() 3.36× sql() 2.62×
  • Q8 execute() 3.94× sql() 3.58×
  • Q9 execute() 21.17× sql() 17.54×
  • Q10 execute() 6.60× sql() 6.31×
  • Q11 execute() 1.03× sql() 1.00×
  • Q12 execute() 3.07× sql() 3.19×
  • Q13 execute() 11.08× sql() 11.66×
  • Q14 execute() 6.19× sql() 5.27×
  • Q15 execute() 1.53× sql() 1.57×
  • Q16on DuckDB: its inner GROUP BY is below a measured threshold——
  • Q17 execute() 8.39× sql() 9.16×
  • Q18 execute() 18.32× sql() 16.56×
  • Q19 execute() 5.88× sql() 4.83×
  • Q20on DuckDB: a correlated inner statement that does not bind on its own——
  • Q21 execute() 3.57× sql() 3.64×
  • Q22 execute() 10.62× sql() 12.35×

TPC-H SF1 (6M-row lineitem)

  • Q1on DuckDB: avg over DECIMAL is not rewritten on DuckDB 2——
  • Q2on DuckDB: below a measured size threshold——
  • Q3 execute() 2.72× sql() 1.76×
  • Q4 execute() 5.14× sql() 3.32×
  • Q5 execute() 5.08× sql() 2.13×
  • Q6on DuckDB: its inner GROUP BY is below a measured threshold——
  • Q7 execute() 3.20× sql() 2.12×
  • Q8 execute() 3.44× sql() 1.96×
  • Q9 execute() 11.45× sql() 7.05×
  • Q10 execute() 4.67× sql() 2.95×
  • Q11on DuckDB: below a measured size threshold——
  • Q12 execute() 2.61× sql() 2.12×
  • Q13 execute() 12.36× sql() 10.58×
  • Q14 execute() 3.27× sql() 2.67×
  • Q15 execute() 1.46× sql() 1.53×
  • Q16on DuckDB: below a measured size threshold——
  • Q17 execute() 3.89× sql() 2.81×
  • Q18 execute() 9.01× sql() 5.78×
  • Q19 execute() 4.37× sql() 3.66×
  • Q20on DuckDB: a correlated inner statement that does not bind on its own——
  • Q21 execute() 4.14× sql() 3.47×
  • Q22 execute() 10.00× sql() 6.88×
The same runs as a table, with times
SF10, milliseconds. Native is plain DuckDB; gpudb is the transparent path.
QueryRan onexecute() nativegpudbratiosql() nativegpudbratio
Q1DuckDB (shape)54.2——55.9——
Q2DuckDB (shape)8.7——9.8——
Q3GPU (plain)30.48.63.52×31.69.73.27×
Q4GPU (plain)30.82.810.98×30.83.78.45×
Q5GPU (plain)34.11.130.39×35.82.017.76×
Q6GPU (projected)11.86.11.95×12.36.71.82×
Q7GPU (plain)31.79.43.36×32.312.32.62×
Q8GPU (projected)32.58.33.94×36.910.33.58×
Q9GPU (plain)128.56.121.17×138.37.917.54×
Q10GPU (topk)61.99.46.60×77.712.36.31×
Q11GPU (nested)6.46.31.03×7.47.41.00×
Q12GPU (plain)32.610.63.07×36.411.43.19×
Q13GPU (nested)132.111.911.08×144.212.411.66×
Q14GPU (projected)28.94.76.19×31.05.95.27×
Q15GPU (nested)19.512.71.53×20.513.11.57×
Q16DuckDB (threshold)35.7——38.8——
Q17GPU (projected)31.23.78.39×36.74.09.16×
Q18GPU (plain)99.75.418.32×110.36.716.56×
Q19GPU (projected)26.94.65.88×26.45.54.83×
Q20DuckDB (shape)32.6——32.6——
Q21GPU (plain)72.120.23.57×76.721.03.64×
Q22GPU (plain)19.31.810.62×19.01.512.35×
SF1, milliseconds.
QueryRan onexecute() nativegpudbratiosql() nativegpudbratio
Q1DuckDB (shape)7.2——6.8——
Q2DuckDB (threshold)3.4——3.8——
Q3GPU (plain)5.32.02.72×5.63.21.76×
Q4GPU (plain)4.70.95.14×5.01.53.32×
Q5GPU (plain)5.81.15.08×6.33.02.13×
Q6DuckDB (threshold)1.6——2.1——
Q7GPU (plain)6.52.03.20×6.53.12.12×
Q8GPU (projected)5.81.73.44×6.13.11.96×
Q9GPU (plain)17.91.611.45×18.22.67.05×
Q10GPU (topk)12.12.64.67×12.74.32.95×
Q11DuckDB (threshold)2.9——3.0——
Q12GPU (plain)4.71.82.61×4.82.32.12×
Q13GPU (nested)18.71.512.36×18.81.810.58×
Q14GPU (projected)5.41.73.27×5.82.22.67×
Q15GPU (nested)3.12.11.46×3.12.01.53×
Q16DuckDB (threshold)12.3——12.6——
Q17GPU (projected)5.21.33.89×5.01.82.81×
Q18GPU (plain)11.41.39.01×11.62.05.78×
Q19GPU (projected)7.01.64.37×7.42.03.66×
Q20DuckDB (shape)7.0——7.5——
Q21GPU (plain)10.12.44.14×12.33.53.47×
Q22GPU (plain)9.61.010.00×10.01.56.88×

Where it stays on DuckDB

  • At SF10, four queries. Q1 uses avg over DECIMAL, which is not rewritten on DuckDB 2. Q2 and Q20 each read a subquery from inside another subquery; the inner statement is correlated and does not bind on its own, so there is nothing to hand the device. Q16's inner GROUP BY declines on its own threshold; forced past it on the v0.7.0 build, Q16 measured 0.02–0.08×.
  • At SF1, six. Those four, plus Q6 and Q11, which sit below the measured size floors at 6M rows.
  • Each of them runs on DuckDB unchanged, at DuckDB's speed.

Results at or below 1.0×

  • Q11 at SF10 on Metal sits at parity. A 6–7 ms statement: 1.03× through execute() and 1.00× through sql() on DuckDB 2.0.1. On DuckDB 1.5.5 with the v0.7.0 build it measured 1.06× and 0.92×, then 1.06× and 0.89× in two immediate re-runs. This is the case the per-process measured rule exists to settle.
  • TPC-H Q1 on CUDA first measured 0.96× and 0.98× on the release build: a few-group key was being answered by sorting the whole column. CUDA got a direct grouped reduce for such keys, and Q1 now measures 1.99× through execute() and 2.07× through sql().
  • A predicate that matches nothing, on CUDA at SF1: 0.76 ms on the device against 0.21 ms native, 0.28×. DuckDB skips the table through its zone maps; the measured rule declines it after one run.

Every per-query table and the commands that take the runs again are in BENCHMARK.md and the reading guide.

The operators underneath, asked by name

These rows call the gpu_* functions directly rather than plain SQL, and were measured when each operator shipped: streaming SUM at v0.4.0, joins at v0.5.0, GROUP BY at v0.6.0. TPC-H lineitem, warm cache, every result verified equal to native before timing counted. GROUP BY rows: statement against statement in one embedded DuckDB v1.5.2 process, after the one-time upload and sort. Aggregate and join rows: DuckDB CLI, v1.5.5 for CUDA and the Metal SUM, v1.5.2 for the Metal joins; 5-run medians.

WorkloadHardwareNativegpudbSpeed-up
SF50, 300M rows: SUM BIGINTMacBook M4 Max, Metal46 ms5 ms8.5×
SF50, 300M rows: SUM BIGINTRTX 4090 Laptop, CUDA99 ms4 ms25×
SF50, 300M ⋈ 75M: JOIN + SUM BIGINTMacBook M4 Max, Metal429 ms37 ms11.7×
SF50, 300M ⋈ 75M: JOIN + SUM BIGINTRTX 4090 Laptop, CUDA998 ms27–37 ms27–37×
SF50, 75M groups: Q18 inner, HAVING on the deviceMacBook M4 Max, Metal462–476 ms78 ms5.9–6.1×
SF50, 75M groups: Q18 inner, HAVING on the deviceRTX 4090 Laptop, CUDA1012–1039 ms42–78 ms13–24×
SF50, all 75M groups returnedMacBook M4 Max, Metal347–355 ms120–123 ms2.8–2.9×
SF50, all 75M groups returnedRTX 4090 Laptop, CUDA681–718 ms458–471 ms1.5× end-to-end

Where these lose, it is published too. A GROUP BY with a handful of groups is a native win on Metal (0.56–0.65× at SF10–SF50, a tie at SF1). Whole-column min/max on stored tables is a native win, because zonemap statistics answer without scanning. A one-time upload breaks even after about 100–150 repeated aggregate queries. The CUDA all-groups row is bounded by copying 24 bytes per group over PCIe, which unified memory does not pay.

What runs where

On the GPU
Aggregating statements over tables past the 1,000,000-row floor: sum, count, min, max and avg with or without GROUP BY, WHERE filters, HAVING, ORDER BY … LIMIT k, DISTINCT and count(DISTINCT), joins, EXISTS / IN subqueries, CTEs, views and derived tables.
On DuckDB
Window functions, sum / avg over DOUBLE, median / stddev, prepared-statement parameters, statements inside an explicit transaction, tables under the floor, a handful of groups, and sets over the memory budget.

A statement that stays on DuckDB returns the same answer at DuckDB's speed, in the same session; nothing fails. Full list

Three ways to use it

All three talk to the same extension and the same resident columns.

Python: import gpudb

For applications, notebooks and pipelines. gpudb.connect() takes the same arguments as duckdb.connect, anything it does not define is delegated to the underlying DuckDB connection, and last_rewrite() says what happened to the last statement.

The Python guide

import gpudb

con = gpudb.connect("my.duckdb")
con.execute("SELECT k, sum(v) FROM t GROUP BY k").fetchall()
con.last_rewrite()                # what happened to that statement

The gpudb shell

For exploring and ad-hoc SQL. Under every result is one line: where the statement ran, why, and how long it took. .gpu prints the whole record including the SQL that actually ran, .gpu off turns the path off for a comparison, and .residents and .memory show what is on the device.

The shell guide

gpudb                             # in-memory database
gpudb my.duckdb                   # a file
gpudb my.duckdb --readonly        # nobody writes while you look
python -m gpudb                   # the same entry point
GPU (plain: the resident GROUP BY) · 3.3 ms
DuckDB (threshold: 7 groups < 1000) · 5.0 ms
DuckDB (not_resident: the resident set is not ready yet) · 12.0 ms

Footer lines as the shell prints them, collected from different statements and sessions.

The gpu_* functions, in any DuckDB client

Full manual control from any client in any language, and the only route from the stock duckdb CLI: DuckDB's stable C extension API has no hook that sees a statement before it is planned, so there LOAD gpudb gives the functions, not the rewrite. Upload a column once, then ask it many times.

The resident model

INSTALL gpudb FROM community;
LOAD gpudb;

CREATE TABLE sales AS
  SELECT (range % 1000)::BIGINT AS store, (range * 7 % 10007)::BIGINT AS amount
  FROM range(10000000);
SELECT gpu_upload_pair('sales_by_store', store, amount) FROM sales;   -- resident, once

SELECT * FROM gpu_groupby_sum_resident_topk('sales_by_store', 5, 'desc');
-- (282, 50037056, 10000) … top 5 stores by sum(amount): (store, sum, count)

SELECT gpu_last_stats();
-- op=groupby_sum_resident_topk backend=Metal reason=Hot_GpuAlwaysWins
--   rows_in=10000000 groups=1000 rows_out=5 wall_ms=39.568 kernel_ms=17.752 transfer_ms=0.000

Platforms and requirements

FeatureMetal (Apple Silicon)CUDA (NVIDIA)No GPU
Plain SQL on the GPU, through the shell or gpudb.connect()YesYes, on by default, from a CUDA buildNo: everything runs on DuckDB
Explicit gpu_* functionsYesYesYes, on the CPU backend, same answers
From the community registryYesA registry Linux binary may report compiled=cpu; SELECT gpu_build_info(); answers this for whichever binary is in front of youYes
Apple Silicon
macOS 15.0 or later. Nothing has been tested on an older macOS.
Linux
x86-64 with glibc 2.34 or newer (Ubuntu 22.04 and later). For the GPU: an NVIDIA driver R525 or newer and a card in the sm_75 – sm_90 range (Turing, Ampere, Ada, Hopper). With no NVIDIA driver it loads and falls back to the CPU backend.
pip install duckdb-gpudb
Python 3.9 or later and the duckdb module 1.4 or later. On Apple Silicon and x86-64 Linux the platform wheel carries the extension too, so it is the whole install; the Linux wheel is the CUDA-enabled build and bundles its own libgomp.so.1. Elsewhere it installs the wrapper alone and the extension comes from the registry.
INSTALL gpudb FROM community
Any DuckDB 1.5.5 or later client, signed, no flags. On Linux the registry binary may be a CPU-only build that reports compiled=cpu: for CUDA, use the pip wheel, the release binary or a build from source.
Release binary
Built against the stable C API v1.2.0, so it loads in any DuckDB 1.2 or later, started with -unsigned. On Linux it needs libgomp.so.1 (apt install libgomp1).
Which binary do I have?
SELECT gpu_build_info(); lists the backends it was built with (compiled=) and the one it chose (runtime=).