techlist.io

Cuda

4 posts

Meta2026-04-023 min readCurated summary

KernelEvolve: How Meta’s Ranking Engineer Agent Optimizes AI Infrastructure

KernelEvolve is Meta’s agentic system for automating the creation and optimization of low-level AI kernels across diverse hardware. It treats kernel tuning as a search problem rather than one-shot code generation, evaluating hundreds of alternatives with profiling and diagnostics. The system reduces optimization work from weeks to hours and has delivered over 60% higher inference throughput for an Ads model on NVIDIA GPUs and over 25% higher training throughput on Meta’s MTIA chips. ## Kernel Optimization at Meta - AI models rely on optimized kernels that translate high-level operations into hardware-specific instructions. - Meta runs models across NVIDIA GPUs, AMD GPUs, custom MTIA accelerators, and CPUs. - Production workloads require many custom operators beyond standard GEMMs and convolutions available in vendor libraries. - Kernels must be developed and tuned for each combination of: - Hardware type and generation - Model architecture - Operator type ## The Challenge of Hardware Heterogeneity - NVIDIA, AMD, MTIA, and CPU platforms differ in: - Memory architectures and hierarchies - Instruction sets - Execution models - Supported numeric data types - A kernel optimized for one platform may perform poorly or fail on another. - Hardware generations also require new optimization strategies. Meta’s MTIA roadmap includes four generations, from MTIA 300 through MTIA 500, in two years. - Manual tuning by kernel specialists cannot keep pace with these changes. ## Increasing Model and Operator Complexity - Meta’s recommendation systems have evolved from embedding-based models to sequence models with attention, GEM, and LLM-scale models such as Meta Adaptive Ranking Model. - Each new model generation introduces operators that earlier systems did not require. - Multiple model families may be involved in a single ads-serving request. - As model architectures and operator inventories grow, the number of kernel configurations expands rapidly into the thousands. ## How KernelEvolve Works - KernelEvolve generates candidate implementations in languages and DSLs including: - Triton, Cute DSL, and FlyDSL - CUDA, HIP, and MTIA C++ - A dedicated job harness compiles, runs, profiles, and evaluates each candidate. - Performance results, correctness checks, and diagnostic information are fed back to the LLM. - The system continuously searches through hundreds of alternatives instead of stopping at the first plausible implementation. - Its automated workflow includes profiling, optimization, testing, and cross-hardware debugging. ## Results and Broader Impact - KernelEvolve improved Andromeda Ads inference throughput by more than 60% on NVIDIA GPUs. - It improved training throughput for an ads model by more than 25% on Meta’s MTIA silicon. - The system operates across both public and proprietary hardware. - In production, it optimizes code supporting trillions of daily inference requests. - By automating kernel development, Meta can enable new hardware and adapt to changing model architectures with substantially less engineering effort. KernelEvolve turns kernel development from a manual, expert-driven bottleneck into a continuous automated process. Its search-based approach is particularly valuable as Meta’s hardware portfolio and model architectures continue to diversify.

Pinterest2026-02-024 min readCurated summary

Beyond Two Towers: Re-architecting the Serving Stack for Next-Gen Ads Lightweight Ranking Models…

Two-Tower models make retrieval and lightweight ranking highly efficient by scoring user and item embeddings with a dot product, but they cannot represent rich user-item interactions or deep feature crossings. This post describes an ads-serving redesign that introduces general-purpose GPU models while preserving end-to-end latency. The main strategy is to reduce data movement, move filtering logic onto the GPU, and optimize inference from an initial 4-second p90 latency to about 20 milliseconds. ## Why Move Beyond Two-Tower Models - Two-Tower architectures independently encode users and items, enabling fast scoring across millions of candidates. - Their decoupled structure limits: - User-item interaction features - Target attention - Early feature crossing - Deep architectures requiring simultaneous access to user and candidate data - More expressive models require GPU-based general-purpose inference rather than specialized dot-product or ANN retrieval. - The existing retrieval stack was not designed to transfer large candidate and feature sets to a GPU, creating a major latency challenge. ## Restructuring the Serving Funnel The traditional funnel consisted of: - Feature expansion for thousands of candidates - Retrieval and Two-Tower lightweight ranking - Heavy ranking and auction processing for the top documents Adding GPU inference directly to this flow would require fetching, serializing, transferring, and returning features for tens of thousands of documents. The authors therefore redesigned the entire early-stage serving pipeline instead of optimizing the model alone. ## Segmenting the Inventory for Feature Fetching Feature retrieval was a major latency source, often taking longer than model inference for workloads ranging from 10,000 to 100,000 documents. - **High-value inventory:** Roughly 1 million documents responsible for a substantial share of revenue have their features embedded in the PyTorch model as registered buffers. - Features become part of the model state, similar to weights. - They remain in GPU high-bandwidth memory. - Requests avoid remote feature-service calls and host-to-device transfers. - The model file must be periodically updated to refresh features. - Future work may include GPU-based caching. - **Long-tail inventory:** The remaining roughly 1 billion documents use a high-performance key-value store with in-host caching. - The post focuses on the first strategy, which is already running in production. ## Moving Business Logic onto the GPU Previously, the model returned scores for approximately 100,000 candidates, while CPU-side code handled utility calculation, filtering, diversity, deduplication, and top-k selection. - The new PyTorch model performs these operations directly: - Combines pCTR, pCVR, bid, and other signals into utility scores. - Applies diversity and filtering rules. - Performs top-k selection. - The GPU returns only the final winners—typically around 1,000 documents—instead of all candidate scores. - This reduces device-to-host data transfer and takes advantage of GPU parallelism. - The approach works because lightweight-ranking business rules are sufficiently simple to express with tensor operations. ## Reducing GPU Inference Latency Initial GPU inference measured roughly 4,000 ms at p90, far too slow for real-time serving. Several systems optimizations reduced this to approximately 20 ms: - **Multiple CUDA streams:** Separate streams for workers allow host-to-device transfers, computation, and device-to-host transfers to overlap. - **Worker alignment:** Worker threads are matched and pinned to physical CPU cores to reduce context switching and lock contention. - **Kernel fusion:** Triton kernels combine operations such as linear layers and activations, reducing memory traffic. - **BF16 computation:** Brain Floating Point 16 lowers memory usage and accelerates arithmetic compared with FP32. - **Profiling tools:** PyTorch Profiler and NVIDIA Nsight Systems were used to identify bottlenecks. ## Practical Recommendation Deploying more expressive ranking models requires rethinking the serving architecture around data movement and execution placement. Embedding frequently used features, executing business logic on the GPU, and applying low-level CUDA and kernel optimizations can make complex neural ranking feasible without increasing end-to-end latency.

OpenAI2021-07-274 min readCurated summary

Introducing Triton: Open-source GPU programming for neural networks

# Triton: Open-Source Python-Like GPU Programming for Neural Networks Triton 1.0 is an open-source, Python-like language that lets researchers with little or no CUDA experience write GPU kernels that usually approach expert-level CUDA performance. Its main claim is that it automates the hardest parts of GPU optimization, such as memory coalescing, shared memory management, and within-SM scheduling, so developers can focus on high-level logic. The post argues this makes it practical to write fused kernels, including FP16 matrix multiplication that matches cuBLAS in under 25 lines, some up to 2x faster than equivalent PyTorch implementations. ## Why Fused Kernels Matter - Research code typically chains native framework operators, which creates many temporary tensors and data movement that hurt performance at scale. - Custom GPU kernels can fix this, but writing them is difficult. - Existing alternatives were either too verbose, too inflexible, or produced code noticeably slower than hand-tuned baselines. - Triton extends an earlier language and compiler of the same name, originally created by Philippe Tillet, who now works at OpenAI. ## The Challenges of GPU Programming Optimizing CUDA code requires attention to three components of modern GPUs: - **DRAM:** memory transfers must be coalesced into large transactions to use the wide memory bus. - **SRAM (shared memory):** data must be staged manually for reuse and arranged to avoid bank conflicts. - **ALUs:** computations must be partitioned and scheduled across and within Streaming Multiprocessors (SMs) to exploit parallelism and specialized units like tensor cores. Triton automates memory coalescing, shared memory management, and within-SM scheduling. It deliberately leaves cross-SM scheduling to the developer, since tiling and inter-SM synchronization remain algorithmic decisions that should stay flexible. ## Programming Model - Triton resembles Numba: kernels are decorated Python functions launched over a grid of program instances identified by `program_id`. - Unlike Numba, Triton parallelizes within an instance through operations on blocks (small power-of-two-sized arrays) rather than the SIMT thread model. This hides intra-block concurrency issues such as coalescing, shared memory synchronization, and tensor core scheduling. - Element-wise operations gain little, but complex kernels become much simpler. - **Fused softmax example:** each instance loads and normalizes one row using NumPy-like primitives, avoiding the explicit inter-thread synchronization that a CUDA version requires. - Triton JIT treats tensors as raw pointers, preserving low-level control needed for complex structures such as block-sparse tensors. - This softmax keeps each row in SRAM throughout normalization, maximizing reuse for up to about 32K columns. PyTorch's general-purpose CUDA implementation uses temporary memory, making it more flexible but slower. The post frames the lesson as simplifying specialized kernels, not Triton being inherently superior. - The Torch JIT (v1.9) performed worse on the same operation, illustrating how hard it is to automatically generate efficient CUDA from high-level tensor operations. ## Matrix Multiplication - Fused element-wise operations and reductions are necessary, but matrix multiplication is central to neural networks. - A Triton matmul reaches peak performance in about 25 lines of Python. The equivalent CUDA would take considerably more effort and would likely be slower. - The kernel groups programs together to improve L2 cache hit rates, loads blocks of A and B in a loop, accumulates with `tl.dot`, and stores results with boundary masks. - Handwritten kernels can be customized with fused input transformations (such as slicing) and output transformations (such as Leaky ReLU), which would be out of reach for most developers without Triton. ## System Architecture and Compiler - Triton's performance comes from Triton-IR, an LLVM-based intermediate representation where multi-dimensional blocks of values are first-class. - The `@triton.jit` decorator walks the Python AST and builds Triton-IR using an SSA construction algorithm. - The compiler simplifies and optimizes the IR, automatically parallelizes it, and lowers it through LLVM-IR to PTX for recent NVIDIA GPUs. - Stashing data in shared memory is automated by analyzing operands of block-level operations like `tl.dot`, with allocation and synchronization handled by standard liveness analysis. - Programs are parallelized across SMs by running kernel instances concurrently, and within SMs by partitioning block-level iteration spaces across SIMD units. - At the time of the post, CPUs and AMD GPUs were unsupported, and the authors invited community contributions. ## Conclusion Triton is open source on GitHub and the authors want it to become a community-driven project. For developers who need custom GPU kernels but lack deep CUDA expertise, it offers a practical path to near-expert performance with far less code.

OpenAI2017-12-053 min readCurated summary

Block-sparse GPU kernels

# Block-Sparse GPU Kernels for Neural Networks OpenAI releases highly optimized GPU kernels for neural networks whose weight matrices are block-sparse, meaning most blocks are exactly zero. Depending on the sparsity level, these kernels run orders of magnitude faster than cuBLAS or cuSPARSE, and the authors use them to reach state-of-the-art results in text sentiment analysis and in generative modeling of text and images. The post presents the kernels as a promising but not definitive foundation, and invites the community to explore the architectures they make practical. ## Why Sparse Weights Matter - Sparse weight matrices contain a large number of entries exactly equal to zero. - Matrix multiplication and convolution with block-sparse weights cost only in proportion to the number of non-zero blocks. - For a fixed parameter and compute budget, sparsity allows much wider and deeper networks, such as LSTMs with tens of thousands of hidden units, while the largest LSTMs trained at the time had only thousands. ## The Kernels - They support block-sparse weights in both fully connected and convolutional layers. - In convolutional layers, sparsity applies to input and output feature dimensions, while spatial connectivity is unchanged. - Sparsity is defined per block, with kernels optimized for 8x8, 16x16, and 32x32 blocks. The block-level pattern is fully configurable. - Skipped zero blocks mean compute and parameter storage scale with the number of non-zero weights rather than the number of input and output features. - Benchmarks on a Titan X Pascal GPU (CUDA 8), with 12288 hidden units, 32x32 blocks, and minibatch size 32, show speed-ups over cuBLAS at various sparsity levels. Speed-ups over cuSPARSE were even larger. ## Using the Kernels - The post includes a TensorFlow example that creates a random block-level sparsity pattern, builds a `BlocksparseMatMul` object with a chosen block size, initializes block-sparse weights from `bsmm.w_shape`, and runs the multiplication as a graph operation. ## Small-World LSTMs - Small-world graphs connect any two nodes through a small number of steps, even at very large scale, and brain connectivity shows similar properties. - The authors hypothesized that small-world sparse connectivity keeps information propagating quickly despite high sparsity. - Using this structure, they trained LSTMs with nearly 20,000 hidden units, about 5 times wider than a dense network with similar parameter counts, improving results on text generation and semi-supervised sentiment classification. ## Results - **Sentiment:** Using the setup from their sentiment neuron experiment, the sparse model beat the dense model on all sentiment datasets. On the document-level IMDB dataset, error dropped from 5.91% (Miyato et al., 2016) to 5.01%, a state-of-the-art result. Previous results had only performed best on shorter sentence-level datasets. - **Text compression:** With equal parameter counts (about 100 million), bits-per-character fell from 1.059 to 1.048 using sparse, wide LSTMs. - **Images:** Replacing regular 2D convolutions with sparse kernels in PixelCNN++ on CIFAR-10, while deepening the network and keeping other hyperparameters fixed, reduced bits-per-dimension from 2.92 to 2.90, a new state of the art on that dataset. ## Open Research Directions - **Inference speed-up:** How much wall-clock speed-up can pruning after training achieve when combined with these kernels? - **Learning sparsity structure:** Can gradients learn the sparsity pattern as well as the weights, similar to how biological brains partly determine connectivity during development? Related work includes learning block-sparse RNNs and L0 regularization. - **Application domains:** Sparse layers allow huge weight matrices at the same parameter count and compute cost as smaller dense models. Which domains will benefit most?