Manuscript Offprint

arXiv:2610.33647

Speeding up Log-Sum-Exp: Kernel Fusion at the Memory Wall, Integer Arithmetic at the Compute Wall

Lingyun Yao, Martin Andraud, Niki Loppi, Andrea Pilzer, Anji Liu, Guy Van den Broeck, Martin Trapp

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Lingyun Yao *

Aalto University

Espoo, Finland

Martin Andraud

UC Louvain

Louvain-la-Neuve, Belgium

Niki Loppi

NVIDIA

Helsinki, Finland

Andrea Pilzer

NVIDIA

Bologna, Italy

Anji Liu

National University of Singapore

Singapore

Guy Van den Broeck

University of California

Los Angeles, USA

Martin Trapp

KTH Royal Institute of Technology

Stockholm, Sweden

Abstract

While the Log-Sum-Exp (LSE) function is a foundational numerical primitive for stable log-domain computation in modern machine learning, its fast and efficient computation on generic platforms (i.e., CPUs and GPUs) has been underexplored, potentially creating execution bottlenecks for large workloads. On GPU, the de facto implementation torch.logsumexp dispatches a chain of nine sub-kernels per call, incurring redundant High Bandwidth Memory (HBM) traffic and launch overhead. On CPU, exp and log operations are hardware-hungry, limiting the computing efficiency. To address these bottlenecks, we propose two kernels to significantly accelerate LSE computation on both GPUs and CPUs: FuseLSE, a single-pass fused kernel that evaluates LSE's exp and log functions on the GPU's Special Function Unit (SFU); and IntLSE, which further replaces the LSE computation with approximated integer arithmetic for CPU computation. Our experiments, validated by benchmarks across workload sizes and hardware platforms, show that both kernels are ∼10−11×\sim10-11\times faster than PyTorch at small workloads and ∼6×\sim6\times faster on larger ones on GPUs, where the speed-up is attributed to reduced launch overhead and HBM traffic. On CPU, where no SFU is available, LSE computation dominates the cost, allowing IntLSE to gain ∼3−6×\sim3-6\times execution speed over FuseLSE.

1 Introduction

The Log-Sum-Exp (LSE) function is one of the most widespread numerical primitives in modern machine learning, whenever numerically stable logarithmic computation is required. For example, LSE is used to compute per-token log-probabilities of Large Language Models (LLMs) during reinforcement learning, where every token's forward pass calls one LSE over the vocabulary size [37]; to normalize particle weights at every time step of a particle filter computation [2, 16, 7]; to enable log-domain probabilistic inference, for instance in probabilistic circuits [23, 5, 19]; or to stabilize the Sinkhorn algorithm for entropy-regularized optimal transport [10, 29].

*Correspondence to: lingyun.yao@aalto.fi. Code: https://github.com/lingyunyao/fuselse

Accepted at the 40th Conference on Neural Information Processing Systems (NeurIPS 2026).

Despite this ubiquity, LSE itself is rarely an optimization target on generic CPUs and GPUs, where efforts focused on dense matrix multiplications and standard reduction primitives. To illustrate this gap, PyTorch's torch.logsumexp function can be ∼6×\sim6\times slower than the analogous torch.sum reduction over the same tensor on a given GPU (1.95 ms vs. 0.31 ms in Fig. 1). On GPUs, although log computation libraries exist, they either support only element-wise operations [3] based on Mitchell's approximation [21], or are not fully optimized for LSE [27, 35, 20, 8]. On CPUs, ML applications requiring LSE rely on generic libraries (scipy, numpy, torch) (Section 5.3), all of which implement LSE via the same multi-step primitives. However, LSE optimization has shown promising gains to push the efficiency of specialized hardware for AI inference, including efficient FPGA implementations [38], integer approximations on 16 nm CMOS [41, 42], or alternative arithmetic in place of log-domain math on dedicated hardware [31, 40, 24].

Considering the growing model sizes and interest around probabilistic and symbolic models that perform extensive log-space computation [11], LSE plays an ever-increasing role in optimizing their training and inference time. Hence, this work targets the optimization of LSE on both CPU and GPU by exploiting two key opportunities. First, current baseline implementations dispatch a chain of sub-kernels per call, each paying a fixed launch overhead. Second, four of these sub-kernels touch the full input tensor and round-trip it through High-Bandwidth Memory (HBM) roughly 6×6\times per call (Section 2.1). We instantiate two acceleration strategies as kernel replacements: FuseLSE, which fuses the sub-kernel chain to eliminate the launch overhead and reduce HBM traffic, and IntLSE, which further replaces the exp and log functions with integer approximations [41, 21].

In terms of results, our experiments show that both kernels achieve a ∼10−11×\sim10-11\times speed-up over torch.logsumexp at small workloads and ∼6×\sim6\times at large workloads, confirmed by single-kernel benchmarks and three ML applications. We trace this gain through a time-breakdown analysis across workload sizes, GPUs with varying HBM bandwidths, and input distributions. Our results show that the choice of arithmetic is a second-order factor on GPU: FuseLSE and IntLSE achieve nearly identical speed, and both outpace HBM transfers. On CPU, where no Special Function Unit (SFU) is available, the choice can no longer be ignored: IntLSE's integer pipeline beats FuseLSE by 3−6×3-6\times on the microbenchmark and torch.logsumexp by 2.8−5.2×2.8-5.2\times for particle filters.

References (31)