arXiv(opens in a new tab)cs.CLAug 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2608.25061

DataKernelBench: Can LLMs Optimize Database Queries on GPUs?

Gokul Karthik Kumar, Yotam Perlitz, Corey Lammie, Andrea Giovannini, Katja Hose

Abstract

GPUs increasingly accelerate database systems, but query-specific peak performance still often relies on hand-written kernels. Existing LLM kernel benchmarks focus on machine learning operators, leaving irregular, heterogeneous, data-movement-heavy database-style operators untested. We introduce DataKernelBench 1^{1}, which translates SQL into validated PyTorch TorchPlan programs and evaluates LLMs that optimize either the core tensor-bounded snippet or the full query in CUDA or Triton through execution-guided repair. Across ten proprietary and open-weight models on TPC-H SF10 with an H100 GPU, the strongest full-query CUDA configuration achieves 2.11×2.11\times speedup over torch.compile at full pass rate. We find that higher-performing implementations commonly use kernel fusion and execution-strategy changes, stronger models benefit most from full-query specialization, and workload context matters more than hardware context. To handle data larger than GPU memory, we extend TorchPlan with Dask-cuDF for on-demand partition loading on TPC-H SF100 with four H100 GPUs, achieving 2.54×2.54\times speedup.

1 Introduction

Massive AI infrastructure investments (International Data Corporation (IDC), 2025) have made GPUs increasingly common in enterprise environments (Gartner, Inc., 2025). At the same time, many analytical workloads have execution patterns that can benefit from GPU hardware: large scans, predicate evaluation, joins, and aggregations over columnar data expose substantial data parallelism and place heavy demand on memory bandwidth. This combination makes GPU acceleration an increasingly attractive direction for analytical data.

Figure

Figure 1: DataKernelBench tests LLMs on GPU kernel generation for database query optimization, where multiple models achieve 100% pass rate and substantial speedups over the TorchPlan baseline on TPC-H SF10 with NVIDIA H100. See Table 1 and Section 4.2.

processing (Yogatama et al., 2026), especially for frequently executed queries whose cost can justify query-specific optimization.

One practical approach is Tensor Query Processing (TQP) (He et al., 2022; Asada et al., 2022), which maps relational operators such as joins, filters, and aggregations to tensor computations so that database workloads can run on mature machine learning (ML) frameworks such as PyTorch. Recent work shows that this approach supports terabyte-scale analytics on modern multi-GPU systems (Wu et al., 2025). These trends raise a natural question: if analytical queries can be expressed as tensor programs, can latest code LLMs synthesize specialized GPU kernels that outperform generic compilation?

This question matters because generic ML compilers often fall short of peak performance on analytical workloads. Although torch.compile is effective for regular, compute-bound neural operators, analytical queries often involve irregular memory access, complex predicates, heteroge-

1^{1} https://kerneldf.github.io/datakernelbench neous operator combinations, and query-specific fusion opportunities. Peak performance therefore still often requires hand-written bespoke GPU kernels, yet writing and maintaining them is expensive even when specialization pays off for frequently executed reporting queries (Marcus, 2023; Wehrstein et al., 2026).

Recent progress in LLMs (OpenAI, 2023; Bai et al., 2022; Qwen Team, 2026a; Team, 2024; Jain et al., 2024; Liu et al., 2024) suggests a promising path toward reducing this engineering burden. Prior work shows that LLMs can generate specialized CUDA and Triton kernels for hardware acceleration (Woo et al., 2025; Dai et al., 2026; Liao et al., 2025; Lange et al., 2025; Baronio et al., 2026), and recent benchmarks such as KernelBench (Ouyang et al., 2025), TritonBench (Li et al., 2025), and MultiKernelBench (Ouyang et al., 2025) evaluate this capability on ML operators. However, these benchmarks focus on regular tensor computations with predictable structure. Analytical queries can instead involve substantial data movement, combine multiple relational operators, and require strict correctness under data-dependent control flow. Strong performance on ML-centric kernel synthesis benchmarks therefore does not establish that LLMs can handle database-style workloads.

To address this gap, we introduce DataKernelBench for evaluating LLM-generated GPU kernels for analytical query processing. For each query, we first translate SQL into a validated PyTorch tensor program, which we call TorchPlan. TorchPlan serves as a benchmarkable intermediate representation: it preserves SQL semantics while exposing a stable optimization target for kernel synthesis. It separates table handling in run_query from the tensor-intensive hot path in _query_core, enabling controlled specialization at two levels: core, where only the hot path may be replaced, and full, where the full internal query implementation may be rewritten while preserving the external API. Each baseline TorchPlan is validated by comparing its outputs to DuckDB (Raasveldt and Mühleisen, 2019) before kernel generation. We then ask LLMs to inject optimized Triton or CUDA kernels under a multi-round execution-guided repair loop.

Our primary baseline is compiled TorchPlan execution, since TorchPlan provides a validated tensor reference and torch.compile is the strongest generic baseline within this execution model. The benchmark therefore measures the incremental gain of bespoke LLM-generated kernels over a strong compiled tensor baseline. We also compare against external systems such as Sirius (Yogatama et al., 2026) and DuckDB, but these answer a different systems question: how fast does an independent execution engine run the workload? Sirius is best viewed as a generic GPU-specialized database system that provides drop-in GPU acceleration for existing CPU database engines, whereas our method targets bespoke kernels for specific, frequently executed queries.

DataKernelBench targets recurring queries such as scheduled reports and dashboard refreshes, where the same query template runs on refreshed data, with different user-supplied parameters, or both. Before specialization, a deployment can compare predicted generation cost with the expected reduction in execution time or compute cost over future runs. A generated kernel is adopted only after validation and when the expected savings justify specialization; otherwise, execution falls back to compiled TorchPlan or a general-purpose GPU query engine. Table 1 reports one such runtime threshold through Nsave1hN_{save1h}. As one possible integration path, a generated CUDA kernel could be wrapped as a GPU operator in an extensible engine such as Velox's experimental cuDF backend, whose DriverAdapter supports operator replacement, fusion, and addition (Velox, 2022).

With DataKernelBench, we evaluate ten proprietary and open-weight LLMs across CUDA and Triton backends and both optimization levels (Section 4). Gains are highly query-dependent, and the best LLM-optimized kernels complement rather than uniformly replace a generic GPU database system. Plan inspection attributes the largest gains to kernel fusion and execution-strategy changes that avoid intermediate materialization. We also provide preliminary evidence beyond a single GPU's memory by executing TPC-H SF100 in on-demand Dask-cuDF partitions distributed across four H100 GPUs (Section 4.5).

This work makes three contributions. First, we introduce, to the best of our knowledge, the first systematic benchmark for LLM-generated GPU kernels for database queries, as opposed to ML operators. Second, we provide a validated SQL-to-TorchPlan pipeline and modular Python TorchPlan programs that expose an LLM-friendly optimization target and serve as pluggable reference implementations for kernel synthesis. Third, our evaluation of ten LLMs characterizes how model strength, optimization scope, prompt context, programming interface, and query structure affect correctness and performance, and uses plan-level comparisons to explain where the largest gains arise.

References (30)