scheduler

package
v0.1.32 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 3 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 scheduler implements the runtime execution scheduler for the Go compute backend.

It manages a persistent pool of worker goroutines and schedules tasks across three hierarchical levels of parallelism:

  1. Inter-Call: across concurrent calls to Executable.Execute() (highest priority).
  2. Intra-Op: across contiguous memory chunks within a single operation.
  3. Inter-Op: across independent graph branches within a single Execute() call (lowest priority).

When an operation spawns intra-op subtasks (via RunIntraOpTasks, ParallelizeChunks, or Saturate), the calling goroutine immediately participates in executing its own op's subtasks (work-helping) before waiting on the completion barrier. This guarantees forward progress and prevents deadlocks even under nested inter-op and intra-op parallelism.

See design details in https://github.com/gomlx/compute/blob/main/docs/GoBackendScheduler.md

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Scheduler

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

Scheduler manages persistent worker goroutines and dispatches intra-op and inter-op tasks.

func New

func New() *Scheduler

New returns a new Scheduler with the default parallelism set to runtime.GOMAXPROCS(0).

func (*Scheduler) AcquireWholeChip added in v0.1.26

func (s *Scheduler) AcquireWholeChip() bool

AcquireWholeChip acquires the fair FIFO whole-chip gate for a large operation so that concurrent large ops (across inter-op branches or concurrent Execute() calls) queue in strict FIFO order without starving or thrashing shared L2/L3 caches and SME units. The caller MUST call ReleaseWholeChip(acquired) when the operation finishes.

func (*Scheduler) AdjustedMaxParallelism

func (s *Scheduler) AdjustedMaxParallelism() int

AdjustedMaxParallelism returns the effective parallelism for the current execution. It is an alias for EffectiveParallelism() kept for convenience across op implementations.

func (*Scheduler) EffectiveParallelism

func (s *Scheduler) EffectiveParallelism() int

EffectiveParallelism returns the target number of workers an operation within the current Execute() call should use, dynamically scaled by the number of concurrent active executions:

max(1, totalParallelism / numActiveCalls)

func (*Scheduler) EnterExecution

func (s *Scheduler) EnterExecution() func()

EnterExecution registers the start of a top-level Executable.Execute() call (inter-call tracking). It returns a function that must be deferred to unregister the call when Execute() finishes.

func (*Scheduler) IsBusy added in v0.1.30

func (s *Scheduler) IsBusy() bool

IsBusy reports whether multiple top-level Execute() calls are active concurrently or a large operation holds the whole-chip gate.

func (*Scheduler) IsEnabled

func (s *Scheduler) IsEnabled() bool

IsEnabled returns whether parallelism is enabled (maxParallelism != 0).

func (*Scheduler) IsUnlimited

func (s *Scheduler) IsUnlimited() bool

IsUnlimited returns whether parallelism is unlimited (maxParallelism < 0).

func (*Scheduler) IsWholeChipHeld added in v0.1.26

func (s *Scheduler) IsWholeChipHeld() bool

IsWholeChipHeld reports whether a large operation currently holds the whole-chip gate.

func (*Scheduler) MaxParallelism

func (s *Scheduler) MaxParallelism() int

MaxParallelism returns the configured target for parallelism. If set to 0, parallelism is disabled. If set to -1, parallelism is unlimited.

func (*Scheduler) ParallelizeChunks

func (s *Scheduler) ParallelizeChunks(totalItems, minChunkSize int, fn func(start, end int))

ParallelizeChunks partitions [0, totalItems) into contiguous, cache-friendly ranges based on EffectiveParallelism() and minChunkSize, and executes fn(start, end) across the calling goroutine and available intra-op workers.

Each worker processes contiguous ranges of items to prevent false sharing and preserve L1/L2 cache locality. If EffectiveParallelism() <= 1 or totalItems <= minChunkSize, it calls fn(0, totalItems) directly inline with zero allocations.

func (*Scheduler) ReleaseWholeChip added in v0.1.26

func (s *Scheduler) ReleaseWholeChip(acquired bool)

ReleaseWholeChip releases the whole-chip gate previously acquired via AcquireWholeChip.

func (*Scheduler) RunIntraOpTasks

func (s *Scheduler) RunIntraOpTasks(tasks []func())

RunIntraOpTasks executes the given intra-op tasks for the current operation and waits for all of them to finish.

Invariant (Deadlock-Free Work-Helping): The calling goroutine immediately participates in executing tasks from this slice itself at highest priority, while available persistent workers in the scheduler assist concurrently.

func (*Scheduler) Saturate

func (s *Scheduler) Saturate(workerFn func())

Saturate fans out workerFn across the calling goroutine and up to EffectiveParallelism()-1 available scheduler workers (used by work-pulling ops like MatMul).

Each workerFn pulls work from a shared queue until no work remains and then returns.

func (*Scheduler) SaturateUpTo

func (s *Scheduler) SaturateUpTo(maxWorkers int, workerFn func())

SaturateUpTo is like Saturate, but caps the total number of participating workers (including the calling goroutine) to maxWorkers when maxWorkers > 0.

func (*Scheduler) SetMaxParallelism

func (s *Scheduler) SetMaxParallelism(maxParallelism int)

SetMaxParallelism sets the target maxParallelism.

This should be configured before workers start executing.

func (*Scheduler) SubmitInterOp

func (s *Scheduler) SubmitInterOp(task func()) bool

SubmitInterOp enqueues a coarse-grained inter-op task (such as a ready branch in executeParallel) to be executed by an available persistent worker when no higher-priority intra-op tasks are waiting. It returns true if an inter-op worker slot was claimed and the task was enqueued, or false if parallelism is disabled, the inter-op worker budget is full, intra-op tasks are already waiting, or the queue is full (so the caller can execute the branch locally or leave it in readyQueue).

func (*Scheduler) UnscaledParallelism added in v0.1.26

func (s *Scheduler) UnscaledParallelism() int

UnscaledParallelism returns the full target number of workers for the scheduler without dividing by numActiveCalls. This is used by large operations that acquire the fair FIFO whole-chip gate via AcquireWholeChip() so each large op utilizes all workers sequentially rather than thrashing shared L2/L3 caches concurrently.

func (*Scheduler) WaitToStart

func (s *Scheduler) WaitToStart(task func())

WaitToStart runs the task using an available worker from the intra-op queue, or inline if parallelism is disabled or the queue is full.

Prefer ParallelizeChunks or RunIntraOpTasks for new intra-op code so the calling goroutine participates in work-helping automatically.

Jump to

Keyboard shortcuts

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