Dagger Functions
Base.fetch
Base.wait
Dagger.Sch.add_thunk!
Dagger.Sch.exec!
Dagger.Sch.get_dag_ids
Dagger.Sch.halt!
Dagger.Sch.sch_handle
Dagger.addprocs!
Dagger.compute
Dagger.constrain
Dagger.default_enabled
Dagger.default_option
Dagger.delayed
Dagger.dependents
Dagger.domain
Dagger.execute!
Dagger.get_options
Dagger.get_parent
Dagger.get_processors
Dagger.get_tls
Dagger.in_thunk
Dagger.iscompatible
Dagger.move
Dagger.noffspring
Dagger.order
Dagger.rmprocs!
Dagger.scope
Dagger.set_tls!
Dagger.shard
Dagger.spawn
Dagger.thunk_processor
Dagger.tochunk
Dagger.treereduce
Dagger.with_options
Dagger.@option
Dagger.@par
Dagger.@shard
Dagger.@spawn
Task Functions/Macros
Dagger.@spawn
— Macro@spawn [opts] f(args...) -> Thunk
Convenience macro like Dagger.@par
, but eagerly executed from the moment it's called (equivalent to spawn
).
See the docs for @par
for more information and usage examples.
Dagger.spawn
— Functionspawn(f, args...; kwargs...) -> EagerThunk
Spawns a task with f
as the function, args
as the arguments, and kwargs
as the keyword arguments, returning an EagerThunk
. Uses a scheduler running in the background to execute code.
Dagger.delayed
— Functiondelayed(f, options=Options())(args...; kwargs...) -> Thunk
-delayed(f; options...)(args...; kwargs...) -> Thunk
Creates a Thunk
object which can be executed later, which will call f
with args
and kwargs
. options
controls various properties of the resulting Thunk
.
Dagger.@par
— Macro@par [opts] f(args...; kwargs...) -> Thunk
Convenience macro to call Dagger.delayed
on f
with arguments args
and keyword arguments kwargs
. May also be called with a series of assignments like so:
x = @par begin
+Functions and Macros · Dagger.jl Dagger Functions
Base.fetch
Base.wait
Dagger.Sch.add_thunk!
Dagger.Sch.exec!
Dagger.Sch.get_dag_ids
Dagger.Sch.halt!
Dagger.Sch.sch_handle
Dagger.addprocs!
Dagger.compute
Dagger.constrain
Dagger.default_enabled
Dagger.default_option
Dagger.delayed
Dagger.dependents
Dagger.domain
Dagger.execute!
Dagger.get_options
Dagger.get_parent
Dagger.get_processors
Dagger.get_tls
Dagger.in_thunk
Dagger.iscompatible
Dagger.move
Dagger.noffspring
Dagger.order
Dagger.rmprocs!
Dagger.scope
Dagger.set_tls!
Dagger.shard
Dagger.spawn
Dagger.thunk_processor
Dagger.tochunk
Dagger.treereduce
Dagger.with_options
Dagger.@option
Dagger.@par
Dagger.@shard
Dagger.@spawn
Task Functions/Macros
Dagger.@spawn
— Macro@spawn [opts] f(args...) -> Thunk
Convenience macro like Dagger.@par
, but eagerly executed from the moment it's called (equivalent to spawn
).
See the docs for @par
for more information and usage examples.
sourceDagger.spawn
— Functionspawn(f, args...; kwargs...) -> EagerThunk
Spawns a task with f
as the function, args
as the arguments, and kwargs
as the keyword arguments, returning an EagerThunk
. Uses a scheduler running in the background to execute code.
sourceDagger.delayed
— Functiondelayed(f, options=Options())(args...; kwargs...) -> Thunk
+delayed(f; options...)(args...; kwargs...) -> Thunk
Creates a Thunk
object which can be executed later, which will call f
with args
and kwargs
. options
controls various properties of the resulting Thunk
.
sourceDagger.@par
— Macro@par [opts] f(args...; kwargs...) -> Thunk
Convenience macro to call Dagger.delayed
on f
with arguments args
and keyword arguments kwargs
. May also be called with a series of assignments like so:
x = @par begin
a = f(1,2)
b = g(a,3)
h(a,b)
-end
x
will hold the Thunk representing h(a,b)
; additionally, a
and b
will be defined in the same local scope and will be equally accessible for later calls.
Options to the Thunk
can be set as opts
with namedtuple syntax, e.g. single=1
. Multiple options may be provided, and will be applied to all generated thunks.
sourceTask Options Functions/Macros
Dagger.with_options
— Functionwith_options(f, options::NamedTuple) -> Any
-with_options(f; options...) -> Any
Sets one or more options to the given values, executes f()
, resets the options to their previous values, and returns the result of f()
. This is the recommended way to set options, as it only affects tasks spawned within its scope. Note that setting an option here will propagate its value across Julia or Dagger tasks spawned by f()
or its callees (i.e. the options propagate).
sourceDagger.get_options
— Functionget_options(key::Symbol, default) -> Any
-get_options(key::Symbol) -> Any
Returns the value of the option named key
. If option
does not have a value set, then an error will be thrown, unless default
is set, in which case it will be returned instead of erroring.
get_options() -> NamedTuple
Returns a NamedTuple
of all option key-value pairs.
sourceDagger.@option
— Macro@option name myfunc(A, B, C) = value
A convenience macro for defining default_option
. For example:
Dagger.@option single mylocalfunc(Int) = 1
The above call will set the single
option to 1
for any Dagger task calling mylocalfunc(Int)
with an Int
argument.
sourceDagger.default_option
— Functiondefault_option(::Val{name}, Tf, Targs...) where name = value
Defines the default value for option name
to value
when Dagger is preparing to execute a function with type Tf
with the argument types Targs
. Users and libraries may override this to set default values for tasks.
An easier way to define these defaults is with @option
.
Note that the actual task's argument values are not passed, as it may not always be possible or efficient to gather all Dagger task arguments on one worker.
This function may be executed within the scheduler, so it should generally be made very cheap to execute. If the function throws an error, the scheduler will use whatever the global default value is for that option instead.
sourceData Management Functions
Dagger.tochunk
— Functiontochunk(x, proc::Processor, scope::AbstractScope; device=nothing, kwargs...) -> Chunk
Create a chunk from data x
which resides on proc
and which has scope scope
.
device
specifies a MemPool.StorageDevice
(which is itself wrapped in a Chunk
) which will be used to manage the reference contained in the Chunk
generated by this function. If device
is nothing
(the default), the data will be inspected to determine if it's safe to serialize; if so, the default MemPool storage device will be used; if not, then a MemPool.CPURAMDevice
will be used.
All other kwargs are passed directly to MemPool.poolset
.
sourceMissing docstring. Missing docstring for @mutable
. Check Documenter's build log for details.
Dagger.@shard
— MacroCreates a Shard
. See Dagger.shard
for details.
sourceDagger.shard
— Functionshard(f; kwargs...) -> Chunk{Shard}
Executes f
on all workers in workers
, wrapping the result in a process-scoped Chunk
, and constructs a Chunk{Shard}
containing all of these Chunk
s on the current worker.
Keyword arguments:
procs
– The list of processors to create pieces on. May be any iterable container of Processor
s.workers
– The list of workers to create pieces on. May be any iterable container of Integer
s.per_thread::Bool=false
– If true
, creates a piece per each thread, rather than a piece per each worker.
sourceScope Functions
Dagger.scope
— Functionscope(scs...) -> AbstractScope
+end
x
will hold the Thunk representing h(a,b)
; additionally, a
and b
will be defined in the same local scope and will be equally accessible for later calls.
Options to the Thunk
can be set as opts
with namedtuple syntax, e.g. single=1
. Multiple options may be provided, and will be applied to all generated thunks.
sourceTask Options Functions/Macros
Dagger.with_options
— Functionwith_options(f, options::NamedTuple) -> Any
+with_options(f; options...) -> Any
Sets one or more options to the given values, executes f()
, resets the options to their previous values, and returns the result of f()
. This is the recommended way to set options, as it only affects tasks spawned within its scope. Note that setting an option here will propagate its value across Julia or Dagger tasks spawned by f()
or its callees (i.e. the options propagate).
sourceDagger.get_options
— Functionget_options(key::Symbol, default) -> Any
+get_options(key::Symbol) -> Any
Returns the value of the option named key
. If option
does not have a value set, then an error will be thrown, unless default
is set, in which case it will be returned instead of erroring.
get_options() -> NamedTuple
Returns a NamedTuple
of all option key-value pairs.
sourceDagger.@option
— Macro@option name myfunc(A, B, C) = value
A convenience macro for defining default_option
. For example:
Dagger.@option single mylocalfunc(Int) = 1
The above call will set the single
option to 1
for any Dagger task calling mylocalfunc(Int)
with an Int
argument.
sourceDagger.default_option
— Functiondefault_option(::Val{name}, Tf, Targs...) where name = value
Defines the default value for option name
to value
when Dagger is preparing to execute a function with type Tf
with the argument types Targs
. Users and libraries may override this to set default values for tasks.
An easier way to define these defaults is with @option
.
Note that the actual task's argument values are not passed, as it may not always be possible or efficient to gather all Dagger task arguments on one worker.
This function may be executed within the scheduler, so it should generally be made very cheap to execute. If the function throws an error, the scheduler will use whatever the global default value is for that option instead.
sourceData Management Functions
Dagger.tochunk
— Functiontochunk(x, proc::Processor, scope::AbstractScope; device=nothing, kwargs...) -> Chunk
Create a chunk from data x
which resides on proc
and which has scope scope
.
device
specifies a MemPool.StorageDevice
(which is itself wrapped in a Chunk
) which will be used to manage the reference contained in the Chunk
generated by this function. If device
is nothing
(the default), the data will be inspected to determine if it's safe to serialize; if so, the default MemPool storage device will be used; if not, then a MemPool.CPURAMDevice
will be used.
All other kwargs are passed directly to MemPool.poolset
.
sourceMissing docstring. Missing docstring for @mutable
. Check Documenter's build log for details.
Dagger.@shard
— MacroCreates a Shard
. See Dagger.shard
for details.
sourceDagger.shard
— Functionshard(f; kwargs...) -> Chunk{Shard}
Executes f
on all workers in workers
, wrapping the result in a process-scoped Chunk
, and constructs a Chunk{Shard}
containing all of these Chunk
s on the current worker.
Keyword arguments:
procs
– The list of processors to create pieces on. May be any iterable container of Processor
s.workers
– The list of workers to create pieces on. May be any iterable container of Integer
s.per_thread::Bool=false
– If true
, creates a piece per each thread, rather than a piece per each worker.
sourceScope Functions
Dagger.scope
— Functionscope(scs...) -> AbstractScope
scope(;scs...) -> AbstractScope
Constructs an AbstractScope
from a set of scope specifiers. Each element in scs
is a separate specifier; if scs
is empty, an empty UnionScope()
is produced; if scs
has one element, then exactly one specifier is constructed; if scs
has more than one element, a UnionScope
of the scopes specified by scs
is constructed. A variety of specifiers can be passed to construct a scope:
:any
- Constructs an AnyScope()
:default
- Constructs a DefaultScope()
(scs...,)
- Constructs a UnionScope
of scopes, each specified by scs
thread=tid
or threads=[tids...]
- Constructs an ExactScope
or UnionScope
containing all Dagger.ThreadProc
s with thread ID tid
/tids
across all workers.worker=wid
or workers=[wids...]
- Constructs a ProcessScope
or UnionScope
containing all Dagger.ThreadProc
s with worker ID wid
/wids
across all threads.thread=tid
/threads=tids
and worker=wid
/workers=wids
- Constructs an ExactScope
, ProcessScope
, or UnionScope
containing all Dagger.ThreadProc
s with worker ID wid
/wids
and threads tid
/tids
.
Aside from the worker and thread specifiers, it's possible to add custom specifiers for scoping to other kinds of processors (like GPUs) or providing different ways to specify a scope. Specifier selection is determined by a precedence ordering: by default, all specifiers have precedence 0
, which can be changed by defining scope_key_precedence(::Val{spec}) = precedence
(where spec
is the specifier as a Symbol)
. The specifier with the highest precedence in a set of specifiers is used to determine the scope by calling to_scope(::Val{spec}, sc::NamedTuple)
(where sc
is the full set of specifiers), which should be overriden for each custom specifier, and which returns an AbstractScope
. For example:
# Setup a GPU specifier
Dagger.scope_key_precedence(::Val{:gpu}) = 1
Dagger.to_scope(::Val{:gpu}, sc::NamedTuple) = ExactScope(MyGPUDevice(sc.worker, sc.gpu))
# Generate an `ExactScope` for `MyGPUDevice` on worker 2, device 3
-Dagger.scope(gpu=3, worker=2)
sourceDagger.constrain
— Functionconstraint(x::AbstractScope, y::AbstractScope) -> ::AbstractScope
Constructs a scope that is the intersection of scopes x
and y
.
sourceLazy Task Functions
Dagger.domain
— Functiondomain(x::T)
Returns metadata about x
. This metadata will be in the domain
field of a Chunk object when an object of type T
is created as the result of evaluating a Thunk.
sourceDagger.compute
— Functioncompute(ctx::Context, d::Thunk; options=nothing) -> Chunk
Compute a Thunk - creates the DAG, assigns ranks to nodes for tie breaking and runs the scheduler with the specified options. Returns a Chunk which references the result.
sourceDagger.dependents
— Functiondependents(node::Thunk) -> Dict{Union{Thunk,Chunk}, Set{Thunk}}
Find the set of direct dependents for each task.
sourceDagger.noffspring
— Functionnoffspring(dpents::Dict{Union{Thunk,Chunk}, Set{Thunk}}) -> Dict{Thunk, Int}
Recursively find the number of tasks dependent on each task in the DAG. Takes a Dict as returned by dependents
.
sourceDagger.order
— Functionorder(node::Thunk, ndeps) -> Dict{Thunk,Int}
Given a root node of the DAG, calculates a total order for tie-breaking.
- Root node gets score 1,
- rest of the nodes are explored in DFS fashion but chunks of each node are explored in order of
noffspring
, i.e. total number of tasks depending on the result of the said node.
Args:
- node: root node
- ndeps: result of
noffspring
sourceDagger.treereduce
— FunctionTree reduce
sourceProcessor Functions
Dagger.execute!
— Functionexecute!(proc::Processor, f, args...; kwargs...) -> Any
Executes the function f
with arguments args
and keyword arguments kwargs
on processor proc
. This function can be overloaded by Processor
subtypes to allow executing function calls differently than normal Julia.
sourceDagger.iscompatible
— Functioniscompatible(proc::Processor, opts, f, Targs...) -> Bool
Indicates whether proc
can execute f
over Targs
given opts
. Processor
subtypes should overload this function to return true
if and only if it is essentially guaranteed that f(::Targs...)
is supported. Additionally, iscompatible_func
and iscompatible_arg
can be overriden to determine compatibility of f
and Targs
individually. The default implementation returns false
.
sourceDagger.default_enabled
— Functiondefault_enabled(proc::Processor) -> Bool
Returns whether processor proc
is enabled by default. The default value is false
, which is an opt-out of the processor from execution when not specifically requested by the user, and true
implies opt-in, which causes the processor to always participate in execution when possible.
sourceDagger.get_processors
— Functionget_processors(proc::Processor) -> Set{<:Processor}
Returns the set of processors contained in proc
, if any. Processor
subtypes should overload this function if they can contain sub-processors. The default method will return a Set
containing proc
itself.
sourceDagger.get_parent
— Functionget_parent(proc::Processor) -> Processor
Returns the parent processor for proc
. The ultimate parent processor is an OSProc
. Processor
subtypes should overload this to return their most direct parent.
sourceDagger.move
— Functionmove(from_proc::Processor, to_proc::Processor, x)
Moves and/or converts x
such that it's available and suitable for usage on the to_proc
processor. This function can be overloaded by Processor
subtypes to transport arguments and convert them to an appropriate form before being used for exection. Subtypes of Processor
wishing to implement efficient data movement should provide implementations where x::Chunk
.
sourceDagger.get_tls
— Functionget_tls()
Gets all Dagger TLS variable as a NamedTuple
.
sourceDagger.set_tls!
— Functionset_tls!(tls)
Sets all Dagger TLS variables from the NamedTuple
tls
.
sourceContext Functions
Dagger.addprocs!
— Functionaddprocs!(ctx::Context, xs)
Add new workers xs
to ctx
.
Workers will typically be assigned new tasks in the next scheduling iteration if scheduling is ongoing.
Workers can be either Processor
s or the underlying process IDs as Integer
s.
sourceDagger.rmprocs!
— Functionrmprocs!(ctx::Context, xs)
Remove the specified workers xs
from ctx
.
Workers will typically finish all their assigned tasks if scheduling is ongoing but will not be assigned new tasks after removal.
Workers can be either Processor
s or the underlying process IDs as Integer
s.
sourceThunk Execution Environment Functions
These functions are used within the function called by a Thunk
.
Dagger.in_thunk
— Functionin_thunk()
Returns true
if currently in a Thunk
process, else false
.
sourceDagger.thunk_processor
— Functionthunk_processor()
Get the current processor executing the current thunk.
sourceDynamic Scheduler Control Functions
These functions query and control the scheduler remotely.
Dagger.Sch.sch_handle
— FunctionGets the scheduler handle for the currently-executing thunk.
sourceDagger.Sch.add_thunk!
— FunctionAdds a new Thunk to the DAG.
sourceBase.fetch
— FunctionBase.fetch(c::DArray)
If a DArray
tree has a Thunk
in it, make the whole thing a big thunk.
sourceWaits on a thunk to complete, and fetches its result.
sourceBase.wait
— FunctionWaits on a thunk to complete.
sourceDagger.Sch.exec!
— FunctionExecutes an arbitrary function within the scheduler, returning the result.
sourceDagger.Sch.halt!
— FunctionCommands the scheduler to halt execution immediately.
sourceDagger.Sch.get_dag_ids
— FunctionReturns all Thunks IDs as a Dict, mapping a Thunk to its downstream dependents.
sourceSettings
This document was generated with Documenter.jl version 0.27.25 on Thursday 16 November 2023. Using Julia version 1.8.5.
+Dagger.scope(gpu=3, worker=2)
Dagger.constrain
— Functionconstraint(x::AbstractScope, y::AbstractScope) -> ::AbstractScope
Constructs a scope that is the intersection of scopes x
and y
.
Lazy Task Functions
Dagger.domain
— Functiondomain(x::T)
Returns metadata about x
. This metadata will be in the domain
field of a Chunk object when an object of type T
is created as the result of evaluating a Thunk.
Dagger.compute
— Functioncompute(ctx::Context, d::Thunk; options=nothing) -> Chunk
Compute a Thunk - creates the DAG, assigns ranks to nodes for tie breaking and runs the scheduler with the specified options. Returns a Chunk which references the result.
Dagger.dependents
— Functiondependents(node::Thunk) -> Dict{Union{Thunk,Chunk}, Set{Thunk}}
Find the set of direct dependents for each task.
Dagger.noffspring
— Functionnoffspring(dpents::Dict{Union{Thunk,Chunk}, Set{Thunk}}) -> Dict{Thunk, Int}
Recursively find the number of tasks dependent on each task in the DAG. Takes a Dict as returned by dependents
.
Dagger.order
— Functionorder(node::Thunk, ndeps) -> Dict{Thunk,Int}
Given a root node of the DAG, calculates a total order for tie-breaking.
- Root node gets score 1,
- rest of the nodes are explored in DFS fashion but chunks of each node are explored in order of
noffspring
, i.e. total number of tasks depending on the result of the said node.
Args:
- node: root node
- ndeps: result of
noffspring
Dagger.treereduce
— FunctionTree reduce
Processor Functions
Dagger.execute!
— Functionexecute!(proc::Processor, f, args...; kwargs...) -> Any
Executes the function f
with arguments args
and keyword arguments kwargs
on processor proc
. This function can be overloaded by Processor
subtypes to allow executing function calls differently than normal Julia.
Dagger.iscompatible
— Functioniscompatible(proc::Processor, opts, f, Targs...) -> Bool
Indicates whether proc
can execute f
over Targs
given opts
. Processor
subtypes should overload this function to return true
if and only if it is essentially guaranteed that f(::Targs...)
is supported. Additionally, iscompatible_func
and iscompatible_arg
can be overriden to determine compatibility of f
and Targs
individually. The default implementation returns false
.
Dagger.default_enabled
— Functiondefault_enabled(proc::Processor) -> Bool
Returns whether processor proc
is enabled by default. The default value is false
, which is an opt-out of the processor from execution when not specifically requested by the user, and true
implies opt-in, which causes the processor to always participate in execution when possible.
Dagger.get_processors
— Functionget_processors(proc::Processor) -> Set{<:Processor}
Returns the set of processors contained in proc
, if any. Processor
subtypes should overload this function if they can contain sub-processors. The default method will return a Set
containing proc
itself.
Dagger.get_parent
— Functionget_parent(proc::Processor) -> Processor
Returns the parent processor for proc
. The ultimate parent processor is an OSProc
. Processor
subtypes should overload this to return their most direct parent.
Dagger.move
— Functionmove(from_proc::Processor, to_proc::Processor, x)
Moves and/or converts x
such that it's available and suitable for usage on the to_proc
processor. This function can be overloaded by Processor
subtypes to transport arguments and convert them to an appropriate form before being used for exection. Subtypes of Processor
wishing to implement efficient data movement should provide implementations where x::Chunk
.
Dagger.get_tls
— Functionget_tls()
Gets all Dagger TLS variable as a NamedTuple
.
Dagger.set_tls!
— Functionset_tls!(tls)
Sets all Dagger TLS variables from the NamedTuple
tls
.
Context Functions
Dagger.addprocs!
— Functionaddprocs!(ctx::Context, xs)
Add new workers xs
to ctx
.
Workers will typically be assigned new tasks in the next scheduling iteration if scheduling is ongoing.
Workers can be either Processor
s or the underlying process IDs as Integer
s.
Dagger.rmprocs!
— Functionrmprocs!(ctx::Context, xs)
Remove the specified workers xs
from ctx
.
Workers will typically finish all their assigned tasks if scheduling is ongoing but will not be assigned new tasks after removal.
Workers can be either Processor
s or the underlying process IDs as Integer
s.
Thunk Execution Environment Functions
These functions are used within the function called by a Thunk
.
Dagger.in_thunk
— Functionin_thunk()
Returns true
if currently in a Thunk
process, else false
.
Dagger.thunk_processor
— Functionthunk_processor()
Get the current processor executing the current thunk.
Dynamic Scheduler Control Functions
These functions query and control the scheduler remotely.
Dagger.Sch.sch_handle
— FunctionGets the scheduler handle for the currently-executing thunk.
Dagger.Sch.add_thunk!
— FunctionAdds a new Thunk to the DAG.
Base.fetch
— FunctionWaits on a thunk to complete, and fetches its result.
Base.fetch(c::DArray)
If a DArray
tree has a Thunk
in it, make the whole thing a big thunk.
Base.wait
— FunctionWaits on a thunk to complete.
Dagger.Sch.exec!
— FunctionExecutes an arbitrary function within the scheduler, returning the result.
Dagger.Sch.halt!
— FunctionCommands the scheduler to halt execution immediately.
Dagger.Sch.get_dag_ids
— FunctionReturns all Thunks IDs as a Dict, mapping a Thunk to its downstream dependents.