taskgraph

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 7 Imported by: ? 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 cudataskgraph validates finite task DAGs and tracks epoch-scoped publication and abort state.

This package is outside the compatibility promise of github.com/tmc/lib/nvidia. Its API may change or be removed in patch releases.

Example
package main

import (
	"fmt"
	"github.com/tmc/lib/nvidia/x/host/taskgraph"
)

func main() {
	g, _ := taskgraph.New([]taskgraph.Task{{ID: "p", Rank: 0, Scope: taskgraph.ScopeCTA}})
	fmt.Println(len(g.Tasks()))
}
Output:
1

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Epoch

type Epoch struct {
	Number uint64
	// contains filtered or unexported fields
}

func NewEpoch

func NewEpoch(n uint64) *Epoch

func (*Epoch) Abort

func (e *Epoch) Abort()

func (*Epoch) Aborted

func (e *Epoch) Aborted() bool

func (*Epoch) Claim

func (e *Epoch) Claim(id string, g Graph) error

Claim records that the device owns task id's output storage for this epoch.

func (*Epoch) Clone

func (e *Epoch) Clone() *Epoch

Clone returns an independent snapshot of the epoch, including its publication and ownership records. Later changes to either epoch do not affect the other. Like the other epoch methods, Clone does not synchronize direct assignments to the public Number field.

Example
package main

import (
	"fmt"

	"github.com/tmc/lib/nvidia/x/host/taskgraph"
)

func main() {
	e := taskgraph.NewEpoch(1)
	clone := e.Clone()
	clone.Abort()
	fmt.Println(e.Aborted(), clone.Aborted())
}
Output:
false true

func (*Epoch) Drain

func (e *Epoch) Drain()

Drain records that the host has observed the launch finish, so nothing is still storing into the claimed buffers.

func (*Epoch) Drained

func (e *Epoch) Drained() bool

Drained reports whether the launch has been observed to finish.

func (*Epoch) Publish

func (e *Epoch) Publish(id string, g Graph) error

func (*Epoch) PublishEpoch

func (e *Epoch) PublishEpoch(epoch uint64, id string, g Graph) error

PublishEpoch publishes a completion only for the epoch that owns it.

func (*Epoch) Published

func (e *Epoch) Published(id string) bool

func (*Epoch) Release

func (e *Epoch) Release(id string) error

Release relinquishes ownership of task id's output storage.

It refuses while an abort is outstanding and the launch has not been drained. That refusal is the point: an aborted launch is the case where freeing looks safest and is not.

func (*Epoch) Retained

func (e *Epoch) Retained() []string

Retained returns the tasks whose output storage is still owned, sorted.

type Graph

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

func New

func New(tasks []Task) (Graph, error)

func (Graph) Clone

func (g Graph) Clone() Graph

Clone returns an independent graph snapshot, including dependency slices.

func (Graph) Identity

func (g Graph) Identity() string

Identity returns a stable identity for the validated graph: every task's ID, rank, shared-memory bytes, scope, extent, dependencies and data inputs, in task order.

Each string and list is written with its length before it, so no arrangement of bytes inside an ID can be read as a field of another task.

Example
package main

import (
	"fmt"

	"github.com/tmc/lib/nvidia/x/host/taskgraph"
)

func main() {
	build := func(inputs []string, extent uint64) string {
		g, err := taskgraph.New([]taskgraph.Task{
			{ID: "x", Rank: 0, Scope: taskgraph.ScopeDevice},
			{ID: "y", Rank: 0, Scope: taskgraph.ScopeDevice},
			{ID: "sum", Deps: []string{"x", "y"}, Inputs: inputs, Rank: 1, Scope: taskgraph.ScopeDevice, Extent: extent},
		})
		if err != nil {
			return err.Error()
		}
		return g.Identity()
	}
	first := build([]string{"x"}, 256)
	fmt.Println(first == build([]string{"x", "y"}, 256))
	fmt.Println(first == build([]string{"x"}, 512))
	fmt.Println(first == build([]string{"x"}, 256))
}
Output:
false
false
true

func (Graph) Tasks

func (g Graph) Tasks() []Task

type Scope

type Scope uint8
const (
	ScopeCTA Scope = iota + 1
	ScopeCluster
	ScopeDevice
	ScopeSystem
)

type Task

type Task struct {
	ID   string
	Deps []string

	// Inputs names the dependencies whose outputs the task reads, in operand
	// order. Each must also appear in Deps, at most once; a dependency not
	// named here orders the task without supplying it data.
	//
	// An empty Inputs declares nothing. Consumers that predate this field
	// read such a task's first dependency, if any, as its only data input.
	Inputs []string

	Rank int

	// Bytes is the task's dynamic shared-memory claim, in bytes. It is not
	// the size of the task's output and not a cost: a scheduler that reads
	// it as either will rank tasks by a quantity that says nothing about
	// them. The megakernel executor budgets it against the shared memory the
	// compiled worker admits (cudamega.Progress); apart from that it is only
	// hashed into the graph fingerprint.
	Bytes uint64

	Scope Scope

	// Extent is the number of elements the task produces. Zero means the
	// extent is undeclared, not that the task is empty. New records Extent
	// in the identity but checks it against nothing; whoever runs the task
	// decides whether the elements it is given match.
	Extent uint64
}

Jump to

Keyboard shortcuts

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