gpu

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 5 Imported by: 2 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 gpu runs compute kernels on the system's graphics processor through Apple's Metal, for the work celestial does many million times over: an orbit for every star, a pixel for every direction.

Kernels compile from their source when a session opens, so building celestial needs no Metal compiler toolchain.

Each kernel package under gpu carries a reference in plain Go beside its kernel, and its tests state and measure how closely the two agree: the processor computes in 32-bit floats and Go in 64, so they agree closely and not bit for bit.

Only darwin has Metal, so only darwin has a device to open a session on. Everywhere else the package is its documentation and its mock.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NoDevice

func NoDevice(err error) bool

NoDevice says whether an error is for want of a gpu. Tests that need the gpu skip on this, and only this: a kernel that fails to compile must fail its test, not skip it.

Types

type Buffer

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

Buffer is a session's buffer of numbers.

func (Buffer) Numbers

func (buffer Buffer) Numbers() []float32

Numbers is the buffer's numbers, where they lie: what Go writes there the gpu reads, and what the gpu wrote there Go reads, between batches.

type Device

type Device interface {
	// Open compiles a source and its named kernels. When it cannot, it
	// says why, and whether that is for want of a gpu at all.
	Open(source string, kernels []string) (noDevice bool, why string)
	// Buffer makes a shared buffer of so many bytes, zeroed, and is its
	// number and its bytes, where the cpu and the gpu both see them.
	Buffer(bytes int) (index int, at []byte, why string)
	// Dispatch adds a kernel to the batch, its buffers bound from zero
	// in order and the params' bytes after them, over width by height
	// threads.
	Dispatch(kernel int, bound []int32, params []byte, width,
		height int) string
	// Commit runs the batch, in order, and waits for it.
	Commit() string
	// Seconds is how long the gpu has spent on every command run, by
	// the system's own timestamps on them.
	Seconds() float64
	// Close lets the kernels and the buffers go.
	Close()
}

Device is what a session runs on: the gpu through its bridge, or a stand-in. It holds one source's kernels, opened once, and every call after is on them. Each call that can fail says why, and says nothing when it did not.

type Session

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

Session is many kernels compiled once from one source on a device, buffers that live there as long as it does, and dispatches gathered into a batch and run as one command: for work that steps many times without coming back.

Its buffers are memory the cpu and the gpu share, so Go reads and writes them where they lie. They lie there until Close, and nothing closes a session but Close: a session left open keeps its buffers, and a buffer's numbers read after Close are nobody's.

func Open

func Open(device Device, source string, kernels ...string) (*Session,
	error)

Open compiles a source and each named kernel in it on a device.

func (*Session) Buffers

func (session *Session) Buffers(counts ...int) ([]Buffer, error)

Buffers is a new buffer for each count of numbers, all zero; or none of them, when one could not be made. The ones made before the one that could not be stay on the device until Close.

func (*Session) Close

func (session *Session) Close()

Close lets the session and its buffers go; their numbers are not to be read after. Closing twice is harmless.

func (*Session) Commit

func (session *Session) Commit() error

Commit runs the batch, in the order it was given, and waits for it.

func (*Session) Dispatch

func (session *Session) Dispatch(kernel string, width, height int,
	params []byte, buffers ...Buffer) error

Dispatch adds a kernel to the batch, over width by height threads, its buffers bound in order and its params after them.

func (*Session) GPUTime

func (session *Session) GPUTime() time.Duration

GPUTime is how long the gpu has spent on the session's batches, by the system's own timestamps on its commands: the time the work took on the gpu, which is less than the time a caller waited for it.

Directories

Path Synopsis
Package orbit is celestial/orbit's stepping as a kernel on the gpu: every star at once, each on its own thread, in 32-bit floats, by the same kick, drift, kick.
Package orbit is celestial/orbit's stepping as a kernel on the gpu: every star at once, each on its own thread, in 32-bit floats, by the same kick, drift, kick.

Jump to

Keyboard shortcuts

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