Skip to content

Commit 10e1307

Browse files
authored
Merge pull request #493 from JamesWrigley/options-docs
Add options docstrings to the docs
2 parents ff0d02e + 7f65603 commit 10e1307

File tree

5 files changed

+80
-67
lines changed

5 files changed

+80
-67
lines changed

Diff for: docs/src/api-dagger/types.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ EagerThunk
1414
```
1515

1616
## Task Options Types
17-
```
17+
```@docs
1818
Options
1919
Sch.ThunkOptions
2020
Sch.SchedulerOptions
2121
```
2222

2323
## Data Management Types
24-
```
24+
```@docs
2525
Chunk
2626
Shard
2727
```

Diff for: docs/src/scheduler-internals.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ execution (called "firing"). Once all tasks are either waiting or running, the
6969
scheduler may sleep until actions need to be performed
7070

7171
When fired tasks have completed executing, an entry will exist in the inbound
72-
queue signaling the task's result and other metadata. At this point, the most
72+
queue signalling the task's result and other metadata. At this point, the most
7373
recently-queued task is removed from the queue, "finished", and placed in the
7474
"finished" state. Finishing usually unlocks downstream tasks from the waiting
7575
state and allows them to transition to the ready state.
@@ -117,7 +117,7 @@ outdated, or when its estimates about the task's behavior are inaccurate. To
117117
minimize the possibility of workload imbalance, the worker schedulers'
118118
processors will attempt to steal tasks from each other when they are
119119
under-occupied. Tasks will only be stolen if the task's [scope](scopes.md) is
120-
compatibl with the processor attempting the steal, so tasks with wider scopes
120+
compatible with the processor attempting the steal, so tasks with wider scopes
121121
have better balancing potential.
122122

123123
## Core: Finishing

Diff for: docs/src/task-spawning.md

+21-15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
```@meta
2+
CurrentModule = Dagger
3+
```
4+
15
# Task Spawning
26

37
The main entrypoint to Dagger is `@spawn`:
@@ -8,8 +12,8 @@ or `spawn` if it's more convenient:
812

913
`Dagger.spawn(f, Dagger.Options(options), args...; kwargs...)`
1014

11-
When called, it creates an `EagerThunk` (also known as a "thunk" or "task")
12-
object representing a call to function `f` with the arguments `args` and
15+
When called, it creates an [`EagerThunk`](@ref) (also known as a "thunk" or
16+
"task") object representing a call to function `f` with the arguments `args` and
1317
keyword arguments `kwargs`. If it is called with other thunks as args/kwargs,
1418
such as in `Dagger.@spawn f(Dagger.@spawn g())`, then, in this example, the
1519
function `f` gets passed the results of executing `g()`, once that result is
@@ -18,21 +22,23 @@ waits on `g()` to complete before executing.
1822

1923
An important observation to make is that, for each argument to
2024
`@spawn`/`spawn`, if the argument is the result of another `@spawn`/`spawn`
21-
call (thus it's an `EagerThunk`), the argument will be computed first, and then
25+
call (thus it's an [`EagerThunk`](@ref)), the argument will be computed first, and then
2226
its result will be passed into the function receiving the argument. If the
23-
argument is *not* an `EagerThunk` (instead, some other type of Julia object),
27+
argument is *not* an [`EagerThunk`](@ref) (instead, some other type of Julia object),
2428
it'll be passed as-is to the function `f` (with some exceptions).
2529

2630
## Options
2731

28-
The `Options` struct in the second argument position is optional; if provided,
29-
it is passed to the scheduler to control its behavior. `Options` contains a
30-
`NamedTuple` of option key-value pairs, which can be any of:
31-
- Any field in `Dagger.Sch.ThunkOptions` (see [Scheduler and Thunk options](@ref))
32-
- `meta::Bool` -- Pass the input `Chunk` objects themselves to `f` and not the value contained in them
32+
The [`Options`](@ref Dagger.Options) struct in the second argument position is
33+
optional; if provided, it is passed to the scheduler to control its
34+
behavior. [`Options`](@ref Dagger.Options) contains a `NamedTuple` of option
35+
key-value pairs, which can be any of:
36+
- Any field in [`Sch.ThunkOptions`](@ref) (see [Scheduler and Thunk options](@ref))
37+
- `meta::Bool` -- Pass the input [`Chunk`](@ref) objects themselves to `f` and
38+
not the value contained in them.
3339

3440
There are also some extra optionss that can be passed, although they're considered advanced options to be used only by developers or library authors:
35-
- `get_result::Bool` -- return the actual result to the scheduler instead of `Chunk` objects. Used when `f` explicitly constructs a Chunk or when return value is small (e.g. in case of reduce)
41+
- `get_result::Bool` -- return the actual result to the scheduler instead of [`Chunk`](@ref) objects. Used when `f` explicitly constructs a [`Chunk`](@ref) or when return value is small (e.g. in case of reduce)
3642
- `persist::Bool` -- the result of this Thunk should not be released after it becomes unused in the DAG
3743
- `cache::Bool` -- cache the result of this Thunk such that if the thunk is evaluated again, one can just reuse the cached value. If it’s been removed from cache, recompute the value.
3844

@@ -68,9 +74,9 @@ The final result (from `fetch(s)`) is the obvious consequence of the operation:
6874
### Eager Execution
6975

7076
Dagger's `@spawn` macro works similarly to `@async` and `Threads.@spawn`: when
71-
called, it wraps the function call specified by the user in an `EagerThunk`
72-
object, and immediately places it onto a running scheduler, to be executed once
73-
its dependencies are fulfilled.
77+
called, it wraps the function call specified by the user in an
78+
[`EagerThunk`](@ref) object, and immediately places it onto a running scheduler,
79+
to be executed once its dependencies are fulfilled.
7480

7581
```julia
7682
x = rand(400,400)
@@ -181,8 +187,8 @@ Note that, as a legacy API, usage of the lazy API is generally discouraged for m
181187
While Dagger generally "just works", sometimes one needs to exert some more
182188
fine-grained control over how the scheduler allocates work. There are two
183189
parallel mechanisms to achieve this: Scheduler options (from
184-
`Dagger.Sch.SchedulerOptions`) and Thunk options (from
185-
`Dagger.Sch.ThunkOptions`). These two options structs contain many shared
190+
[`Sch.SchedulerOptions`](@ref)) and Thunk options (from
191+
[`Sch.ThunkOptions`](@ref)). These two options structs contain many shared
186192
options, with the difference being that Scheduler options operate
187193
globally across an entire DAG, and Thunk options operate on a thunk-by-thunk
188194
basis.

Diff for: src/eager_thunk.jl

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ function Base.fetch(t::ThunkFuture; proc=OSProc(), raw=false)
2323
end
2424
Base.put!(t::ThunkFuture, x; error=false) = put!(t.future, (error, x))
2525

26+
"""
27+
Options(::NamedTuple)
28+
Options(; kwargs...)
29+
30+
Options for thunks and the scheduler. See [Task Spawning](@ref) for more
31+
information.
32+
"""
2633
struct Options
2734
options::NamedTuple
2835
end

Diff for: src/sch/Sch.jl

+48-48
Original file line numberDiff line numberDiff line change
@@ -153,23 +153,23 @@ Stores DAG-global options to be passed to the Dagger.Sch scheduler.
153153
154154
# Arguments
155155
- `single::Int=0`: (Deprecated) Force all work onto worker with specified id.
156-
`0` disables this option.
156+
`0` disables this option.
157157
- `proclist=nothing`: (Deprecated) Force scheduler to use one or more
158-
processors that are instances/subtypes of a contained type. Alternatively, a
159-
function can be supplied, and the function will be called with a processor as
160-
the sole argument and should return a `Bool` result to indicate whether or not
161-
to use the given processor. `nothing` enables all default processors.
158+
processors that are instances/subtypes of a contained type. Alternatively, a
159+
function can be supplied, and the function will be called with a processor as
160+
the sole argument and should return a `Bool` result to indicate whether or not
161+
to use the given processor. `nothing` enables all default processors.
162162
- `allow_errors::Bool=true`: Allow thunks to error without affecting
163-
non-dependent thunks.
163+
non-dependent thunks.
164164
- `checkpoint=nothing`: If not `nothing`, uses the provided function to save
165-
the final result of the current scheduler invocation to persistent storage, for
166-
later retrieval by `restore`.
165+
the final result of the current scheduler invocation to persistent storage, for
166+
later retrieval by `restore`.
167167
- `restore=nothing`: If not `nothing`, uses the provided function to return the
168-
(cached) final result of the current scheduler invocation, were it to execute.
169-
If this returns a `Chunk`, all thunks will be skipped, and the `Chunk` will be
170-
returned. If `nothing` is returned, restoring is skipped, and the scheduler
171-
will execute as usual. If this function throws an error, restoring will be
172-
skipped, and the error will be displayed.
168+
(cached) final result of the current scheduler invocation, were it to execute.
169+
If this returns a `Chunk`, all thunks will be skipped, and the `Chunk` will be
170+
returned. If `nothing` is returned, restoring is skipped, and the scheduler
171+
will execute as usual. If this function throws an error, restoring will be
172+
skipped, and the error will be displayed.
173173
"""
174174
Base.@kwdef struct SchedulerOptions
175175
single::Union{Int,Nothing} = nothing
@@ -186,52 +186,52 @@ Stores Thunk-local options to be passed to the Dagger.Sch scheduler.
186186
187187
# Arguments
188188
- `single::Int=0`: (Deprecated) Force thunk onto worker with specified id. `0`
189-
disables this option.
189+
disables this option.
190190
- `proclist=nothing`: (Deprecated) Force thunk to use one or more processors
191-
that are instances/subtypes of a contained type. Alternatively, a function can
192-
be supplied, and the function will be called with a processor as the sole
193-
argument and should return a `Bool` result to indicate whether or not to use
194-
the given processor. `nothing` enables all default processors.
191+
that are instances/subtypes of a contained type. Alternatively, a function can
192+
be supplied, and the function will be called with a processor as the sole
193+
argument and should return a `Bool` result to indicate whether or not to use
194+
the given processor. `nothing` enables all default processors.
195195
- `time_util::Dict{Type,Any}`: Indicates the maximum expected time utilization
196-
for this thunk. Each keypair maps a processor type to the utilization, where
197-
the value can be a real (approximately the number of nanoseconds taken), or
198-
`MaxUtilization()` (utilizes all processors of this type). By default, the
199-
scheduler assumes that this thunk only uses one processor.
196+
for this thunk. Each keypair maps a processor type to the utilization, where
197+
the value can be a real (approximately the number of nanoseconds taken), or
198+
`MaxUtilization()` (utilizes all processors of this type). By default, the
199+
scheduler assumes that this thunk only uses one processor.
200200
- `alloc_util::Dict{Type,UInt64}`: Indicates the maximum expected memory
201-
utilization for this thunk. Each keypair maps a processor type to the
202-
utilization, where the value is an integer representing approximately the
203-
maximum number of bytes allocated at any one time.
201+
utilization for this thunk. Each keypair maps a processor type to the
202+
utilization, where the value is an integer representing approximately the
203+
maximum number of bytes allocated at any one time.
204204
- `occupancy::Dict{Type,Real}`: Indicates the maximum expected processor
205-
occupancy for this thunk. Each keypair maps a processor type to the
206-
utilization, where the value can be a real between 0 and 1 (the occupancy
207-
ratio, where 1 is full occupancy). By default, the scheduler assumes that this
208-
thunk has full occupancy.
205+
occupancy for this thunk. Each keypair maps a processor type to the
206+
utilization, where the value can be a real between 0 and 1 (the occupancy
207+
ratio, where 1 is full occupancy). By default, the scheduler assumes that this
208+
thunk has full occupancy.
209209
- `allow_errors::Bool=true`: Allow this thunk to error without affecting
210-
non-dependent thunks.
210+
non-dependent thunks.
211211
- `checkpoint=nothing`: If not `nothing`, uses the provided function to save
212-
the result of the thunk to persistent storage, for later retrieval by
213-
`restore`.
212+
the result of the thunk to persistent storage, for later retrieval by
213+
`restore`.
214214
- `restore=nothing`: If not `nothing`, uses the provided function to return the
215-
(cached) result of this thunk, were it to execute. If this returns a `Chunk`,
216-
this thunk will be skipped, and its result will be set to the `Chunk`. If
217-
`nothing` is returned, restoring is skipped, and the thunk will execute as
218-
usual. If this function throws an error, restoring will be skipped, and the
219-
error will be displayed.
215+
(cached) result of this thunk, were it to execute. If this returns a `Chunk`,
216+
this thunk will be skipped, and its result will be set to the `Chunk`. If
217+
`nothing` is returned, restoring is skipped, and the thunk will execute as
218+
usual. If this function throws an error, restoring will be skipped, and the
219+
error will be displayed.
220220
- `storage::Union{Chunk,Nothing}=nothing`: If not `nothing`, references a
221-
`MemPool.StorageDevice` which will be passed to `MemPool.poolset` internally
222-
when constructing `Chunk`s (such as when constructing the return value). The
223-
device must support `MemPool.CPURAMResource`. When `nothing`, uses
224-
`MemPool.GLOBAL_DEVICE[]`.
221+
`MemPool.StorageDevice` which will be passed to `MemPool.poolset` internally
222+
when constructing `Chunk`s (such as when constructing the return value). The
223+
device must support `MemPool.CPURAMResource`. When `nothing`, uses
224+
`MemPool.GLOBAL_DEVICE[]`.
225225
- `storage_root_tag::Any=nothing`: If not `nothing`,
226-
specifies the MemPool storage leaf tag to associate with the thunk's result.
227-
This tag can be used by MemPool's storage devices to manipulate their behavior,
228-
such as the file name used to store data on disk."
226+
specifies the MemPool storage leaf tag to associate with the thunk's result.
227+
This tag can be used by MemPool's storage devices to manipulate their behavior,
228+
such as the file name used to store data on disk."
229229
- `storage_leaf_tag::MemPool.Tag,Nothing}=nothing`: If not `nothing`,
230-
specifies the MemPool storage leaf tag to associate with the thunk's result.
231-
This tag can be used by MemPool's storage devices to manipulate their behavior,
232-
such as the file name used to store data on disk."
230+
specifies the MemPool storage leaf tag to associate with the thunk's result.
231+
This tag can be used by MemPool's storage devices to manipulate their behavior,
232+
such as the file name used to store data on disk."
233233
- `storage_retain::Bool=false`: The value of `retain` to pass to
234-
`MemPool.poolset` when constructing the result `Chunk`.
234+
`MemPool.poolset` when constructing the result `Chunk`.
235235
"""
236236
Base.@kwdef struct ThunkOptions
237237
single::Union{Int,Nothing} = nothing

0 commit comments

Comments
 (0)