GPU Programming Insights

Explore top LinkedIn content from expert professionals.

  • View profile for Devansh Devansh
    Devansh Devansh Devansh Devansh is an Influencer

    Chocolate Milk Cult Leader| Machine Learning Engineer| Writer | AI Researcher| | Computational Math, Data Science, Software Engineering, Computer Science

    15,738 followers

    AI Inference costs are killing your profit margins. Let me teach you how to reduce your Inference Overhead with Compiler & Graph Execution Running an LLM under PyTorch or TensorFlow looks simple, but the framework issues thousands of separate GPU kernel calls for every forward pass. Each kernel executes a small unit of work—like normalization or matrix multiplication—and writes the result to global GPU memory (HBM) before reading it back. While HBM bandwidth reaches 2–3 TB/s on an H100, that is 10–50x slower than the GPU’s on-chip registers. Every unnecessary trip to HBM is wasted potential. Worse, each kernel launch requires the CPU to coordinate with the GPU, adding tens of microseconds of overhead. Across thousands of tokens, this becomes milliseconds of latency. Three techniques—kernel fusion, CUDA graphs, and FlashAttention—target these bottlenecks. Kernel Fusion: Combining Operations Instead of launching separate kernels for LayerNorm and matrix multiplication, you fuse them into one. The compiler rewrites the computational graph to combine operations, ensuring intermediate results stay in the GPU’s fast on-chip registers instead of touching global HBM. This cuts memory traffic and eliminates redundant kernel launches. The tax: irregular shapes or dynamic padding can block fusion, leading to a mix of fused and unfused kernels. CUDA Graphs: Bypassing the CPU Inference involves repeating the same sequence of kernels for every generated token. Rather than the CPU re-issuing commands, CUDA graphs allow you to record the sequence once and replay it directly on the GPU. This bypasses the CPU scheduler entirely, eliminating launch overhead. The tax: graphs are tied to specific tensor shapes, requiring effective systems to capture "hot" shapes and fall back to standard execution for others. FlashAttention: Avoiding the Quadratic Wall Standard attention computes an N x N score matrix between queries and keys, which creates gigabytes of memory traffic per token. FlashAttention tiles this computation, loading small blocks of queries and keys into on-chip SRAM to compute partial attention scores incrementally. The result is mathematically identical, but the memory footprint is a fraction of the original. The tax: gains depend on sequence length, and for very short sequences, the overhead of tiling can outweigh benefits. Summary: The Performance Compound Kernel fusion ensures fewer writes and more work per cycle. CUDA graphs remove launch overhead, keeping the GPU in constant motion. FlashAttention prevents memory blowup, freeing bandwidth for compute.

  • View profile for Kumaran Ponnambalam

    AI / ML Leader & Author

    22,255 followers

    𝗪𝗵𝘆 𝗱𝗼 𝗹𝗼𝗻𝗴-𝗰𝗼𝗻𝘁𝗲𝘅𝘁 𝗟𝗟𝗠 𝗱𝗲𝗽𝗹𝗼𝘆𝗺𝗲𝗻𝘁𝘀 𝗵𝗶𝘁 𝗮 𝘄𝗮𝗹𝗹 𝗲𝘃𝗲𝗻 𝘄𝗵𝗲𝗻 𝘆𝗼𝘂 𝗵𝗮𝘃𝗲 𝗽𝗹𝗲𝗻𝘁𝘆 𝗼𝗳 𝗚𝗣𝗨 𝗰𝗼𝗺𝗽𝘂𝘁𝗲? The bottleneck is often the KV cache: it avoids recomputing attention, but it grows with context length and quickly becomes a GPU memory and bandwidth problem A recent paper ( https://lnkd.in/gRqBt6dd ) maps the KV-cache optimization space into five practical levers: 𝗘𝘃𝗶𝗰𝘁: keep only the most useful history (windowing, top-K, learned eviction). 𝗖𝗼𝗺𝗽𝗿𝗲𝘀𝘀: quantize/compress KV tensors to cut footprint with controlled quality tradeoffs. 𝗛𝘆𝗯𝗿𝗶𝗱 𝗺𝗲𝗺𝗼𝗿𝘆: keep hot KV on GPU and page cold KV to CPU/NVMe with smart prefetch. 𝗥𝗲𝘁𝗵𝗶𝗻𝗸 𝗮𝘁𝘁𝗲𝗻𝘁𝗶𝗼𝗻: use mechanisms that reduce dependence on full-history KV. 𝗖𝗼𝗺𝗯𝗶𝗻𝗲: use adaptive pipelines that mix these based on workload and hardware limits. 𝗞𝗲𝘆 𝘁𝗮𝗸𝗲𝗮𝘄𝗮𝘆: there’s no single winner; the right KV strategy depends on your serving mode (multi-turn chat vs long-context analysis vs high-throughput serving), and the best results often come from hybrid, scenario-driven combinations.

  • View profile for Hao Hoang

    I share daily insights on AI agents, LLMs, Data Science, Machine Learning | I help AI engineers crack top-tier interviews | 68K+ community | LLM System Design, RAG, Agents

    67,713 followers

    You're in a Senior ML Interview at NVIDIA. The interviewer sets a trap: "Your 7B model fits comfortably on a 24GB GPU. Yet, 10 minutes into a conversation, the service crashes with an Out-Of-Memory (OOM) error. Do we upgrade to an A100?" 90% of candidates walk right into it: "Yes, we need more VRAM." They think: "The model is running out of space, so we need a bigger bucket." This is the "Brute Force" approach. It solves the symptom for exactly one week until their users type longer prompts, and then they crash an 80GB card too. They just 4x'd the cloud bill without solving the physics of the problem. The reality is that they aren't optimizing for 𝐒𝐭𝐚𝐭𝐢𝐜 𝐌𝐞𝐦𝐨𝐫𝐲 (𝐖𝐞𝐢𝐠𝐡𝐭𝐬). They are dying from 𝐃𝐲𝐧𝐚𝐦𝐢𝐜 𝐒𝐭𝐚𝐭𝐞 (𝐂𝐨𝐧𝐭𝐞𝐱𝐭). In a production environment, GPU memory is consumed by two things: - 𝘔𝘰𝘥𝘦𝘭 𝘞𝘦𝘪𝘨𝘩𝘵𝘴: Fixed. (e.g., ~14GB for a 7B param model in FP16). - 𝘒𝘝 𝘊𝘢𝘤𝘩𝘦: Variable. This grows linearly with every single token generated. A 7B model with a batch size of 64 and a context length of 2048 tokens can generate over 30GB of KV cache. The "Ghost Memory" is larger than the model itself. ----- 𝐓𝐡𝐞 𝐒𝐨𝐥𝐮𝐭𝐢𝐨𝐧: The real problem isn't just the size of the cache - it's Memory Fragmentation. Standard PyTorch allocates contiguous memory blocks. As requests grow and shrink, they leave "holes" in your VRAM that are too small to use but add up to gigabytes of wasted space. This is The Swiss Cheese Effect. The fix isn't hardware. It's Architecture: 1️⃣ 𝘗𝘢𝘨𝘦𝘥𝘈𝘵𝘵𝘦𝘯𝘵𝘪𝘰𝘯 (𝘷𝘓𝘓𝘔): Treat GPU memory like an Operating System treats RAM. Break the KV cache into non-contiguous "pages" so you can fill every byte of VRAM without needing a continuous block. 2️⃣ 𝘒𝘝 𝘊𝘢𝘤𝘩𝘦 𝘖𝘧𝘧𝘭𝘰𝘢𝘥𝘪𝘯𝘨: If a user pauses for 30 seconds, move their KV cache to CPU RAM (cheap) and swap it back to GPU (expensive) only when they type again. 𝐓𝐡𝐞 𝐀𝐧𝐬𝐰𝐞𝐫 𝐓𝐡𝐚𝐭 𝐆𝐞𝐭𝐬 𝐘𝐨𝐮 𝐇𝐢𝐫𝐞𝐝: "Buying GPUs is a band-aid. The bottleneck is the KV Cache growing linearly with context. I would implement PagedAttention to eliminate memory fragmentation and KV Offloading to handle idle sessions. We only upgrade hardware if the active computation, not the idle state, saturates the compute units." #MachineLearning #DeepLearning #GenerativeAI #LLM #AIEngineering #MLOps #NVIDIA

  • View profile for Rishabh Misra

    Principal ML Lead - Generative Personalization | ML Book and Course Author | Researcher - LLMs & RecSys - 1k+ citations | Advisory @ Startups | Featured in TechCrunch, NBC, TheSun | AI Consultant

    7,754 followers

    I watched a senior engineer spend three weeks quantizing an LLM to 4-bit. The P99 latency got worse. The issue wasn’t the technique; it was treating quantization as a storage problem instead of a memory-bandwidth problem. At Twitter, I spent a month debugging why our "optimized" models ran slower than the originals. The models were smaller. The math was correct. Yet latency regressed. The missing piece: the *unpacking tax*. Here’s the reality most benchmarks hide: Time ≈ Total bytes moved / Memory bandwidth On paper, moving from FP16 (16-bit) to INT4 (4-bit) means 4× less data moving across the memory bus per token. In a memory-bound regime, that translates to 3–4× higher throughput. But there’s a catch. GPUs don’t compute in 4-bit or 8-bit. Those weights are dequantized back to FP16/BF16 in the local cache before computation. That dequantization costs clock cycles and creates production surprises: → High batch sizes: Time saved on memory movement dominates = throughput improves → Batch size of 1: Unpacking overhead dominates = latency gets worse Quantization is not a free win. It’s a tradeoff. If you’re choosing a method, align it with your deployment reality: → GPTQ: Effective for static weights, but sensitive to outliers → AWQ: Preserves critical weights at higher precision for better quality → GGUF: Excellent for CPU/Metal inference, less relevant for H100/A100 clusters This is Part 4 of a deep dive into inference optimization. Previous posts: Memory Wall: https://lnkd.in/gdT26UTV KV Cache: https://lnkd.in/gKkrqVzf Paged Attention: https://lnkd.in/gX5JNZhn Next up: I will break down the closest thing to "cheating physics" in ML - Speculative Decoding. What’s the most expensive quantization mistake you’ve seen in production - latency, quality, or operability?

  • View profile for Parth Kalkar

    Builder | Full-Stack AI/ML Engineer | LLMs, Agentic Systems & On-Device Intelligence | ex AI @ BMW

    10,082 followers

    I sped up our LLM inference by 300% without buying a single new GPU. We didn't change the model (Llama-3-70B). We didn't change the hardware (A100s). We just changed how we asked for the tokens. If you are running raw inference, you are wasting 90% of your GPU's potential.  LLMs are Memory Bound, not Compute Bound.  The GPU spends most of its time waiting to fetch weights from VRAM, not actually calculating. The Lesson: We implemented Speculative Decoding. Here is the "Big vs. Small" trick: We run a tiny, cheap model (like Llama-8B) to "guess" the next 5 tokens. It does this instantly. We ask the giant model (70B) to verify those 5 tokens in a single parallel batch. It is much faster to say: "Check these 5 words" than to say: "Generate word 1... wait... Generate word 2... wait..." The Math:  • If the tiny model guesses right (which is easy for common phrases), you get 5 tokens for the latency cost of 1.  • If it guesses wrong, you just discard them and fall back to the big model. No accuracy loss. You are effectively trading "Compute" (which you have in surplus) for "Memory Bandwidth" (which is your bottleneck). The Result:  • Latency: Dropped from 40ms/token to 12ms/token.  • User Experience: Real-time.  • Accuracy: Identical (Verified). You don't need to write this from scratch. The vLLM library supports this out of the box. (𝘓𝘪𝘯𝘬 𝘪𝘯 𝘤𝘰𝘮𝘮𝘦𝘯𝘵𝘴) #MachineLearning #LLM #SystemDesign

  • View profile for Pranali Desai

    Senior Software Engineer - Trajectory Generation | Cuda Developer

    3,229 followers

    I cut my kernel runtime from 𝟭𝟮𝗺𝘀 𝘁𝗼 𝟭.𝟰𝗺𝘀. I didn't change the math. I changed where the data lived. Every thread in my kernel was reading the same values — straight from global memory. 500 cycles of latency. Every. Single. Time. The GPU was computing fast. But it was spending most of its time waiting for data. The fix: __𝘴𝘩𝘢𝘳𝘦𝘥__ memory. Load data once per block, then every thread reuses it on-chip at ~5 cycle latency. Same math. 100× faster memory access. One thing that caught me: __syncthreads() is non-negotiable. Skip it and some threads will read shared memory before others finish writing. Silent bugs that are nearly impossible to debug. The rule I follow now: if multiple threads in a block touch the same data, it belongs in shared memory. What optimization unlocked the biggest speedup for you? #CUDA #GPU #SharedMemory #PerformanceEngineering #NVIDIA #ParallelProgramming #GPUProgramming

  • View profile for Manish Jain

    Head of AI Architecture, Engineering, Research | AI, ML, DL, LLM, Gen AI, Agentic AI | Builder | Mentor | Advisor | AI75 Honoree

    13,066 followers

    We hit a wall with our A100 last month. 40GB VRAM, could barely serve 6 concurrent users without memory errors. Spent two days convinced it was a batching problem. Turns out it was a Memory fragmentation issue. Our KV cache allocator was treating GPU memory like it needed to be contiguous , leaving these massive unusable gaps between requests. Switched to vLLM which uses PagedAttention, basically the same virtual memory tricks from old school operating systems. Break memory into fixed pages, scatter them wherever there's space, use a block table to track everything. Now we're running 100+ concurrent users on the same GPU. Cost per million tokens dropped from ~$8 to under $0.50. Not flashy but this is the stuff that actually matters when you're trying to serve real traffic. Most LLM optimization content focuses on model architecture. Memory management is where some of the actual bottlenecks are. Wrote a deep dive on paged attentions here.  https://lnkd.in/gDFB3j34 #LLM #AIInfrastructure #MachineLearning #GPUOptimization #vLLM #AIEngineering #ProductionAI

  • View profile for Sanjay Basu PhD

    Ex-AWS|MIT|Cambridge|Oxford|Fellow IETE |AI/Quantum|Author|5x Patents|Life Member-ACM,AAAI,Futurist

    17,766 followers

    GPU memory is the most expensive real estate in modern computing. And most inference deployments waste 60-80% of it. That's the uncomfortable truth I explore in Part 3 of my cache economics series. It took more than two weeks to write because every configuration, every deployment script, every benchmark in this article has been validated on real GPU clusters running real workloads. I used Oracle Code Assist tools throughout, leveraging our external partner integrations to iterate rapidly between hypothesis and validation. The tooling is internally available for now, but it transformed how quickly I could move from "this should work" to "this definitely works." The article includes OCI Terraform examples with WEKA NeuralMesh Axon configuration for production KV cache deployments on bare-metal H100 clusters. What you'll find inside: PagedAttention fundamentals. How vLLM reduced KV cache waste from 60-80% to under 4%, enabling 2-4x throughput on identical hardware. Block tables, virtual memory for attention, and the tuning parameters that matter. FP8 KV cache compression. Halving memory consumption with minimal accuracy impact on Hopper and Blackwell GPUs. LMCache tiered architecture. Extending KV cache from GPU HBM to CPU DRAM to NVMe to network storage. The latency math that determines when offloading beats recomputation. WEKA Augmented Memory Grid. 1000x more KV cache capacity, 20x faster time-to-first-token at 128K context, 192 GB/s sequential reads via GPUDirect Storage. The token warehouse concept that treats KV cache as persistent infrastructure rather than ephemeral GPU state. NetApp ONTAP integration. NFS-over-RDMA with GPUDirect, S3 backends, and the enterprise features that matter for production deployments. DDN Infinia and the broader storage ecosystem. The industry is racing to support KV cache tiering because the economics are too compelling to ignore. NVIDIA Dynamo and NIXL. The coordination layer that makes disaggregated prefill/decode and cache-aware routing possible across GPU fleets. The core insight remains the same. For agentic workloads with long-running context, cache efficiency determines whether the economics work at all. The teams that figure this out will operate at a fraction of the cost with multiples of the performance. Most teams haven't figured it out yet. Link below! #OracleCloudInfrastructure #OCI #NVIDIA #vLLM #LMCache #WEKA #NetApp #DDN #VASTData #Anthropic #Kubernetes #Terraform #GenAI #LLM #AgenticAI #AIInfrastructure #GPUCloud #PagedAttention #KVCache #InferenceOptimization #OracleCodeAssist #GPUDirect #H100 #Blackwell

  • View profile for Paolo Perrone

    Shipping Production AI: Agents, Inference, GPU. Read by 1M+ AI engineers.

    135,549 followers

    How to cut inference costs 5x without killing latency. Most engineers throw GPUs at the problem. The fix is architecture. 𝗟𝗮𝘆𝗲𝗿 𝟭: 𝗤𝘂𝗮𝗻𝘁𝗶𝘇𝗮𝘁𝗶𝗼𝗻 → FP8 cuts memory 50% with minimal quality loss → AWQ preserves important weights at higher precision → A 70B model in 40GB VRAM instead of 140GB → This alone is 2x cost reduction 𝗟𝗮𝘆𝗲𝗿 𝟮: 𝗦𝗽𝗲𝗰𝘂𝗹𝗮𝘁𝗶𝘃𝗲 𝗗𝗲𝗰𝗼𝗱𝗶𝗻𝗴 → EAGLE-3 predicts multiple tokens, verifies in one pass → 2-3x faster generation without quality loss → Perfect for interactive workloads where TTFT matters → SGLang has the best implementation right now 𝗟𝗮𝘆𝗲𝗿 𝟯: 𝗣𝗿𝗲𝗳𝗶𝘅 𝗖𝗮𝗰𝗵𝗶𝗻𝗴 → Reuse KV cache across requests with shared prefixes → System prompts computed once, not every request → 40-60% latency reduction on multi-turn conversations → Free performance. Most engineers don't enable it. 𝗟𝗮𝘆𝗲𝗿 𝟰: 𝗔𝘂𝘁𝗼𝘀𝗰𝗮𝗹𝗶𝗻𝗴 → GPU memory snapshotting: cold starts from minutes to seconds → Scale to zero when idle. Pay nothing. → Bursty workloads: 100x spike for 5 minutes, then nothing → Stop paying for peak capacity 24/7 𝗧𝗵𝗲 𝗺𝗶𝘀𝘁𝗮𝗸𝗲: Applying all optimizations to all workloads. Batch jobs don't need speculative decoding. Interactive apps don't need maximum batching. Bursty pipelines don't need always-on GPUs. Match the optimization to the workload. Stack the right layers. 5x isn't magic. It's architecture. What's eating your inference budget? 👇 💾 Save this before your next GPU bill arrives.

  • View profile for Bijit Ghosh

    CTO & CAIO | Board Member | Advisor

    11,131 followers

    As agents scale, memory becomes the real inference bottleneck. At small scale, every agent can carry the full conversation, system prompt, customer profile, and task history. It works because concurrency is low. At 100-1000x scale, that same design breaks. KV cache fills GPU memory. Long context increases prefill cost. Repeated prompts waste compute. Stale history weakens reasoning. The architecture needs separation. Keep active context near the model. Move facts to SQL. Store past cases in vector memory. Put relationships in a graph. Cache stable prompts. Inference optimization is memory-first design, running alongside compute optimization. The next generation of agents will become faster, cheaper, and more reliable by knowing what to keep close, what to store, and what to forget. https://lnkd.in/eyEy6rQH

Explore categories