Documentation
¶
Overview ¶
Package stage builds and pins CUDA host-glue libraries with the entry ABI int stage(struct stage_ctx *). Context carries named device addresses, a stream and caller-retained CUDA function handles. Every registered native entry receives a pointer; no aggregate is passed by value.
Builder uses cc or nvcc in a caller-owned retained directory. Load compares the library's compiler-evaluated context layout with the actual Go layout. Library pins protect code lifetime only: the caller must also retain device allocations and function generation pins until stream completion. A zero host return establishes submission, not device completion. Failed unload is retryable. Compiler source, output and logs remain for qualification receipts.
Stage libraries are C host code, not Go c-shared libraries with a second Go runtime. Go plugins also cannot be unloaded and require a matching toolchain. Loading C libraries runs arbitrary host constructors and is not isolation. Linux and Darwin are supported; other platforms refuse native loading.
This package is outside the compatibility promise of github.com/tmc/lib/nvidia. Its API may change or be removed in patch releases.
Example ¶
ctx, err := NewContext(nil, 0, nil) fmt.Println(err, ctx.BufferCount, ctx.FunctionCount)
Output: <nil> 0 0
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrPinned = errors.New("stage library is pinned")
ErrPinned means a library still has retained calls or submitted device work. Release the pins only after actual completion, then retry Close if necessary.
Functions ¶
This section is empty.
Types ¶
type Artifact ¶
type Artifact struct {
// contains filtered or unexported fields
}
Artifact is one compiler result. Its source, generation file and digest are private so Load cannot accept a result with substituted identity metadata. Retain its directory until the library and all pins have closed.
func (*Artifact) Generation ¶
Generation identifies this build within the process. Path also has a random generation-directory suffix, preventing reuse after a process restart.
Example ¶
var artifact *Artifact fmt.Println(artifact.Generation())
Output: 0
func (*Artifact) Path ¶
Path returns the unique generation library path.
Example ¶
var artifact *Artifact
fmt.Printf("%q\n", artifact.Path())
Output: ""
func (*Artifact) SHA256 ¶
SHA256 returns the digest of the compiler's shared library bytes. Load verifies the file still matches this digest before and after opening it.
func (*Artifact) SourceDigest ¶
SourceDigest identifies the supplied stage body, independently of compiler output. Build does not claim identity for external headers or loaded libraries.
Example ¶
var artifact *Artifact
fmt.Printf("%q\n", artifact.SourceDigest())
Output: ""
type Buffer ¶
Buffer identifies one retained device allocation. Name is a NUL-terminated string that remains live through the call. Pointer is a CUDA device address, not host storage. Bytes is its declared accessible extent.
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder compiles libraries in an explicit retained directory. Its zero value is not usable. Compiler names cc or nvcc, or their explicit executable path.
func NewBuilder ¶
NewBuilder resolves compiler and creates dir. It does not load a library or perform CUDA work. Use a task-owned directory, not a shared temporary root.
Example ¶
_, err := NewBuilder("", "cc")
fmt.Println(err)
Output: create stage builder: directory and compiler are required
func (*Builder) Build ¶
Build compiles the fixed pointed-to ABI and its compiler layout witness in the same translation unit as Source. It leaves source and output for receipts.
Example ¶
var builder *Builder
_, err := builder.Build(context.Background(), Source{})
fmt.Println(err)
Output: build stage: context, builder and code are required
type Context ¶
type Context struct {
Version uint32
Size uint32
Buffers *Buffer
BufferCount uint64
Stream uintptr
Functions *Function
FunctionCount uint64
}
Context is the pointed-to stage_ctx ABI. The caller retains all named storage, stream and function pins until actual GPU completion, including on errors. Stage code may use this storage during Call but must not retain its address.
func NewContext ¶
NewContext creates the fixed versioned descriptor. buffers/functions and their names remain caller-owned; their addresses must not move during Call.
Example ¶
_, err := NewContext(make([]Buffer, 65), 0, nil) fmt.Println(err)
Output: stage context exceeds 64 named buffers or functions
type Function ¶
Function identifies a CUDA function retained by the caller's generation pin. A stage library does not acquire or release this pin.
type Library ¶
type Library struct {
// contains filtered or unexported fields
}
Library owns one loaded host library. Close refuses new pins; existing pins remain usable until released. Failed unload retains its handle for retry. Its zero value is closed. A Library must not be copied after use.
func Load ¶
Load verifies output identity and compiler-evaluated ABI before admitting calls. A nonnil result with an error retains an unload owner; Close it before removing the artifact. Loading runs host library constructors, not a sandbox.
Example ¶
_, err := Load(nil) fmt.Println(err)
Output: load stage: invalid artifact
type Pin ¶
type Pin struct {
// contains filtered or unexported fields
}
Pin retains a host stage generation. It does not itself retain the device allocations, stream or CUDA function pins supplied in Context.
func (*Pin) Call ¶
Call invokes int stage(stage_ctx*) synchronously on the host. Success means only that host submission returned zero; it does not establish GPU completion. Keep this pin and every Context dependency until actual stream completion.
Example ¶
var pin *Pin fmt.Println(pin.Call(nil))
Output: call stage: nil pin