resource
resource
#
lock — exclusive use of a machine-wide resource, such as the GPU, for a block.
- Wait.
lock(name)opens a step labelled<name> lockbeneath the ambient step and polls the resource's flock in the active scratch, noting who holds it and for how long, so a page or terminal shows the wait. - Hold. Once acquired, the step notes
heldand stays open for the block, the lock file names the holding step, and the name is recorded in the context so a nestedlockof the same name, or apmapworker of the block, passes straight through instead of waiting on itself. - Release. The block's end, or its exception, releases the flock and closes the step; the kernel releases it on any kind of death.
GPU = 'gpu'
module-attribute
#
The one resource every GPU-bound recipe locks.
held_resources = ContextVar('cg_held_resources', default=(frozenset()))
module-attribute
#
The resources the current context holds; a nested lock of one passes through.
lock(name)
#
Hold the machine-wide resource name for the block, one holder at a time.
Holders are serialized across every thread and process sharing the active
scratch; the wait and the hold are a step in the progress tree, so a
computing page reads gpu lock waiting for train (pid 4242), held 5m
until the block gets its turn.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The resource, |
required |
Raises:
| Type | Description |
|---|---|
ScratchNotConfigured
|
If no scratch is configured. |