惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
博客园_首页
罗磊的独立博客
云风的 BLOG
云风的 BLOG
J
Java Code Geeks
Last Week in AI
Last Week in AI
D
DataBreaches.Net
Jina AI
Jina AI
博客园 - Franky
大猫的无限游戏
大猫的无限游戏
Apple Machine Learning Research
Apple Machine Learning Research
V
V2EX
D
Docker
MongoDB | Blog
MongoDB | Blog
B
Blog RSS Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
宝玉的分享
宝玉的分享
Engineering at Meta
Engineering at Meta
The Cloudflare Blog
博客园 - 三生石上(FineUI控件)
有赞技术团队
有赞技术团队
人人都是产品经理
人人都是产品经理
H
Help Net Security
T
The Blog of Author Tim Ferriss

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Deleting the 8.4GB Python Sidecar: Pure Go + CUDA with `C...
Eitamos Ring · 2026-05-20 · via DEV Community

TL;DR: I built gocudrv so Go services can talk directly to NVIDIA GPUs — no cgo, no CUDA toolkit, no bloated Python dependencies. One static binary.

Last month I was reviewing a production AI service. The core business logic was clean, efficient Go (15MB binary), but GPU access was routed through a Python sidecar.

The results were painful:

  • 8.4GB Docker images — bloated with unused CUDA toolkits and PyTorch dependencies
  • 4-minute cold starts during autoscaling
  • Extra serialization + network hops between Go → Python → GPU

We had accepted this because “GPUs belong to Python.” I decided to challenge that assumption.

The Impossible Build: CGO_ENABLED=0

Most Go developers assume you need cgo for CUDA. Instead, I used the CUDA Driver API (already present wherever an NVIDIA driver is installed) together with purego to bypass the C compiler entirely.

// internal/platform/platform_linux.go
func LibraryCandidates() []string {
    return []string{
        "libcuda.so.1",
        "/usr/lib/x86_64-linux-gnu/libcuda.so.1",
        "/usr/lib/wsl/lib/libcuda.so.1", // Works seamlessly in WSL2
    }
}

Enter fullscreen mode Exit fullscreen mode

gocudrv loads libcuda.so at runtime. Standard go build works — even when building on a Mac targeting Linux.

The Receipts: Size & Build Comparison

Metric Python Sidecar Approach gocudrv (Pure Go)
Artifact Size ~8,400 MB 2.4 MB
Build Time 5–10 minutes (Docker) < 2 seconds
External Dependencies Python + PyTorch + CUDA Toolkit NVIDIA Driver only
Deployment Simplicity Multiple processes + networking Single static binary

Low-Level Kernel Performance (10M element vector add on RTX 4070 Ti)

For a simple vector addition (~114 MB data):

  • H→D Copy: 19.3 ms
  • Kernel Launch: 3.4 ms
  • D→H Copy: 25.6 ms
  • Total GPU Pipeline: 48.3 ms

These numbers represent the raw GPU work. In the previous Python sidecar setup, we also paid extra for:

  • JSON/Protobuf serialization
  • Local network socket transfer (Go → Python)
  • Python interpreter + PyTorch overhead

The real win is not necessarily beating PyTorch on micro-benchmarks, but removing the entire sidecar layer and its operational complexity.

Beyond a Simple Wrapper

Pure Go doesn’t mean slow. I focused on asynchronous overlap from the beginning to hide PCIe transfer latency:

stream, _ := ctx.NewStream()

// Start DMA transfer — returns immediately
err := buf.CopyFromHostAsync(ctx, stream, hostBuffer)

// Go can do useful work while the GPU is computing
// ...

// Synchronize only when needed
err = stream.Synchronize(ctx)

Enter fullscreen mode Exit fullscreen mode

Why This Matters in 2026

AI is shifting from research demos to critical infrastructure. Go excels at stability, concurrency, observability, and operational predictability — exactly what production model serving demands.

Removing the Python sidecar gives you:

  • Dramatically smaller images and faster deploys.
  • Much better cold start times.
  • Single language and single binary (much simpler observability and debugging).
  • No GIL, better P99 tail latencies.

Current State (Honest)

gocudrv is still early and experimental. Core functionality works today (device management, memory management, PTX loading, streams, async copies), but it is not yet ready for complex high-performance inference serving.

I’m actively working on CUDA Graphs, Events & Timing, and multi-GPU support.

If you’re a Go engineer tired of carrying heavy Python AI runtimes in production, I’d love your feedback and contributions.

link