Native CUDA Kernel Programming in Go

Hello ,

I’ve been working on an experimental project that enables writing CUDA kernels directly in Go and compiling them to NVIDIA GPU code using LLVM 22.

Project:

Motivation

Most Go GPU solutions rely on cgo wrappers, external CUDA C++ code, or runtime bindings. I wanted to explore whether Go could be used as a native language for GPU kernel development by leveraging LLVM’s NVPTX backend.

What the project does

  • Generates LLVM IR from Go code

  • Uses LLVM 22 for optimization and code generation

  • Targets NVIDIA GPUs through the NVPTX backend

  • Allows CUDA-style kernel development in Go

  • Produces PTX code that can be executed by the CUDA driver

Example

func VecAdd(a, b, c []float32) {
    idx := cuda.ThreadIdxX()
    c[idx] = a[idx] + b[idx]
}

Current Status

The project is still experimental, but core compilation functionality is working. My goal is to build a more complete ecosystem for GPU programming in Go while learning more about compiler design, LLVM internals, and GPU architectures.

Feedback Welcome

I would appreciate feedback from the Go community on:

  • API design

  • Compiler architecture

  • LLVM integration

  • GPU programming patterns in Go

  • Potential use cases

If anyone has experience with LLVM, TinyGo, GPU computing, or compiler development, I’d love to hear your thoughts.

Repository:

Thanks!

2 Likes