Documentation
¶
Overview ¶
Package lane holds the resources of one execution lane on a CUDA device: a stream, a tracked device memory arena, and the per-lane resources, such as modules and matrix plans, built for that stream.
A lane lets a second step run beside the first, for example on another green context's stream, while sharing state such as weights that the lane does not own. New takes ownership of the stream and runs an init function that builds the lane's resources, registering each one's release with Lane.Defer. If init fails, New releases everything init made and closes the stream, so a caller never cleans up a half-built lane. Lane.Close closes the stream, then runs the deferred releases in reverse order, then closes the arena.
This package is outside the compatibility promise of github.com/tmc/lib/nvidia. Its API may change or be removed in patch releases.
Example ¶
This example builds a lane with its own module and activations on a new stream. It needs a CUDA device, so it has no output to check.
package main
import (
"fmt"
"log"
"github.com/tmc/lib/nvidia/x/cuda"
"github.com/tmc/lib/nvidia/x/cuda/lane"
)
// This example builds a lane with its own module and activations on a new
// stream. It needs a CUDA device, so it has no output to check.
func main() {
dev, err := cuda.NewDevice(0)
if err != nil {
log.Fatal(err)
}
defer dev.Close()
stream, err := dev.NewStream()
if err != nil {
log.Fatal(err)
}
var x cuda.Slice[float32]
l, err := lane.New(stream, nil, func(l *lane.Lane) error {
mod, err := cuda.LoadModule(dev, ptx)
if err != nil {
return fmt.Errorf("load kernels: %w", err)
}
l.Defer(mod.Close)
x = cuda.AllocIn[float32](l.Arena(), "x", 1024)
return nil
})
if err != nil {
log.Fatal(err) // New has closed stream.
}
defer l.Close()
fmt.Println(x.Len())
}
var ptx []byte
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Lane ¶
type Lane struct {
// contains filtered or unexported fields
}
A Lane owns a stream, an arena that allocates on the stream's device, and the releases registered with Lane.Defer.
func New ¶
New returns a lane on stream whose arena's allocations are accounted by tracker, which may be nil. It takes ownership of stream, then calls init, which builds the lane's resources. If init returns an error or an allocation from the arena failed, New closes the lane, stream included, and returns the error.
func (*Lane) Close ¶
Close closes the lane's stream, which waits for the work on it, runs the releases registered with Defer in reverse order, and closes the arena. It runs every step whatever errors earlier steps report, and returns them joined. Closing a closed lane does nothing.
func (*Lane) Defer ¶
Defer registers release to run when the lane closes, after the stream has closed and before the arena is closed. Releases run in the reverse order of their registration, so a resource registered after the ones it uses is released before them. A release must not use the lane's stream.