cuda

package
v0.21.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cuda runs compute kernels on an NVIDIA GPU through the CUDA driver API, loaded at run time (no cgo, no CUDA toolkit: the driver compiles the kernels' PTX for the GPU it has).

A Context is the GPU's: device memory, modules of kernels, launches, all in order on the context's one stream. Its methods may be called from any goroutine, one at a time (the context is made current on the calling thread for each).

Index

Constants

This section is empty.

Variables

View Source
var ErrUnavailable = errors.New("cuda: not available")

ErrUnavailable says there is no CUDA here: no driver, no NVIDIA GPU, or a system the package does not run on.

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	Size int // bytes
	// contains filtered or unexported fields
}

Buffer is device memory.

func (*Buffer) Ptr

func (b *Buffer) Ptr() uintptr

Ptr is the buffer's device address.

type Context

type Context struct {
	Name string // the GPU's
	Mem  int64  // its memory, in bytes
	SMs  int    // its multiprocessors
	// contains filtered or unexported fields
}

Context is a CUDA context on a GPU.

func New

func New() (*Context, error)

New makes a context on the first GPU.

func (*Context) Alloc

func (c *Context) Alloc(n int) (*Buffer, error)

Alloc allocates n bytes of device memory.

func (*Context) Close

func (c *Context) Close()

Close frees the context and everything in it.

func (*Context) Copy

func (c *Context) Copy(dst *Buffer, do int, src *Buffer, so, n int) error

Copy copies n bytes from src (at byte offset so) to dst (at do).

func (*Context) Download

func (c *Context) Download(dst []float32, src *Buffer) error

Download copies the start of src to dst (once the kernels before have run).

func (*Context) DownloadBytes

func (c *Context) DownloadBytes(dst []byte, src *Buffer) error

DownloadBytes copies the start of src to dst (once the kernels before have run).

func (*Context) Free

func (c *Context) Free(b *Buffer)

Free frees a buffer.

func (*Context) Load

func (c *Context) Load(image []byte) (*Module, error)

Load loads a module from its PTX (or a cubin), compiled by the driver for the GPU.

func (*Context) Sync

func (c *Context) Sync() error

Sync waits for every kernel launched to have run, and reports a failure of any.

func (*Context) Upload

func (c *Context) Upload(dst *Buffer, src []float32) error

Upload copies src to the start of dst.

func (*Context) UploadBytes

func (c *Context) UploadBytes(dst *Buffer, off int, src []byte) error

UploadBytes copies src to dst at byte offset off.

func (*Context) UploadU64

func (c *Context) UploadU64(dst *Buffer, src []uint64) error

UploadU64 copies 64-bit values (device addresses, say) to the start of dst.

func (*Context) Zero

func (c *Context) Zero(b *Buffer) error

Zero clears a buffer.

type Dim

type Dim struct{ X, Y, Z int }

Dim is a grid's or a block's size.

type Kernel

type Kernel struct {
	Name string
	// contains filtered or unexported fields
}

Kernel is a module's kernel.

func (*Kernel) Launch

func (k *Kernel) Launch(grid, block Dim, shared int, args ...any) error

Launch queues a kernel: its grid of blocks, each of block threads, with shared bytes of dynamic shared memory. The arguments are *Buffer (its address), uintptr (an address), int (as a 32-bit int), int32, uint32, float32, float64, int64 or []uint64 (a struct of so many 64-bit fields, passed by value: device addresses, say), in the kernel's order.

type Module

type Module struct {
	// contains filtered or unexported fields
}

Module is a loaded module of kernels.

func (*Module) Kernel

func (m *Module) Kernel(name string) (*Kernel, error)

Kernel finds a kernel by its name.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL