Skip to content

Commit 2542c42

Browse files
ExpandingManjpsamaroo
authored andcommitted
Toward better docs
Ignore built docs Add simple example to README
1 parent df202f1 commit 2542c42

File tree

12 files changed

+336
-57
lines changed

12 files changed

+336
-57
lines changed

.github/workflows/Documentation.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- uses: actions/checkout@v2
1515
- uses: julia-actions/setup-julia@latest
1616
with:
17-
version: '1.4'
17+
version: '1.6'
1818
- name: Install dependencies
1919
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
2020
- name: Build and deploy

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ Manifest.toml
77
*.jld
88
*.jls
99
*.dot
10+
docs/build

README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
[build-img]: https://badge.buildkite.com/d8f020afb67a5920709c2b0a29111cf596f3f052099b5b656f.svg?branch=master
1212
[build-url]: https://buildkite.com/julialang/dagger-dot-jl
1313

14-
At the core of Dagger.jl is a scheduler heavily inspired by [Dask](https://docs.dask.org/en/latest/). It can run computations represented as [directed-acyclic-graphs](https://en.wikipedia.org/wiki/Directed_acyclic_graph) (DAGs) efficiently on many Julia worker processes.
14+
At the core of Dagger.jl is a scheduler heavily inspired by [Dask](https://docs.dask.org/en/latest/). It can run computations represented as [directed-acyclic-graphs](https://en.wikipedia.org/wiki/Directed_acyclic_graph) (DAGs) efficiently on many Julia worker processes and threads, as well as GPUs via [DaggerGPU.jl](https://github.com/JuliaGPU/DaggerGPU.jl).
1515

1616

1717
## Installation
@@ -24,10 +24,17 @@ julia> ] add Dagger
2424

2525
## Usage
2626

27-
Once installed, the `Dagger` package can by used by typing
27+
Once installed, the `Dagger` package can by used like so
2828

2929
```julia
30+
using Distributed; addprocs() # get us some workers
3031
using Dagger
32+
33+
# do some stuff in parallel!
34+
a = Dagger.@spawn 1+3
35+
b = Dagger.@spawn rand(a, 4)
36+
c = Dagger.@spawn sum(b)+a
37+
fetch(c) # some number!
3138
```
3239

3340
## Acknowledgements

docs/make.jl

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ makedocs(;
1919
"Logging and Graphing" => "logging.md",
2020
"Benchmarking" => "benchmarking.md",
2121
"Scheduler Internals" => "scheduler-internals.md",
22+
"API" => [
23+
"Types" => "api/types.md",
24+
"Functions and Macros" => "api/functions.md",
25+
]
2226
]
2327
)
2428

docs/src/api/functions.md

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
```@meta
2+
CurrentModule = Dagger
3+
```
4+
5+
# Functions
6+
```@index
7+
Pages = ["functions.md"]
8+
```
9+
10+
## General
11+
```@docs
12+
delayed
13+
spawn
14+
tochunk
15+
domain
16+
compute
17+
dependents
18+
noffspring
19+
order
20+
treereduce
21+
```
22+
23+
## Processors
24+
```@docs
25+
execute!
26+
iscompatible
27+
default_enabled
28+
get_processors
29+
get_parent
30+
move
31+
capacity
32+
get_tls
33+
set_tls!
34+
```
35+
36+
## Context
37+
```@docs
38+
addprocs!
39+
rmprocs!
40+
```
41+
42+
## Logging
43+
```@docs
44+
get_logs!
45+
```
46+
47+
## Thunk Execution Environment
48+
49+
These functions are used within the function called by a `Thunk`.
50+
51+
```@docs
52+
in_thunk
53+
thunk_processor
54+
```
55+
56+
### Dynamic Scheduler Control
57+
58+
These functions query and control the scheduler remotely.
59+
60+
```@docs
61+
Sch.sch_handle
62+
Sch.add_thunk!
63+
Base.fetch
64+
Base.wait
65+
Sch.exec!
66+
Sch.halt!
67+
Sch.get_dag_ids
68+
```
69+
70+
## Arrays
71+
```@docs
72+
alignfirst
73+
view
74+
```
75+
76+
## File IO
77+
78+
!!! warning
79+
These APIs are currently untested and may be removed or modified.
80+
81+
```@docs
82+
save
83+
load
84+
```
85+
86+
# Macros
87+
```@docs
88+
@par
89+
@spawn
90+
```

docs/src/api/types.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
```@meta
2+
CurrentModule = Dagger
3+
```
4+
5+
# Types
6+
```@index
7+
Pages = ["types.md"]
8+
```
9+
10+
## General
11+
```@docs
12+
Thunk
13+
EagerThunk
14+
Chunk
15+
UnitDomain
16+
```
17+
18+
## Processors
19+
```@docs
20+
Processor
21+
OSProc
22+
ThreadProc
23+
```
24+
25+
## Context
26+
```@docs
27+
Context
28+
```
29+
30+
## Logging
31+
```@docs
32+
NoOpLog
33+
LocalEventLog
34+
```
35+
36+
## Scheduling
37+
```@docs
38+
Sch.SchedulerOptions
39+
Sch.ThunkOptions
40+
Sch.MaxUtilization
41+
Sch.DynamicThunkException
42+
```
43+
44+
## Arrays
45+
```@docs
46+
DArray
47+
Blocks
48+
ArrayDomain
49+
```
50+
51+
## File IO
52+
53+
!!! warning
54+
These APIs are currently untested and may be removed or modified.
55+
56+
```@docs
57+
FileReader
58+
```

src/array/darray.jl

+29-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import Serialization: serialize, deserialize
44

55
###### Array Domains ######
66

7+
"""
8+
ArrayDomain{N}
9+
10+
An `N`-dimensional domain over an array.
11+
"""
712
struct ArrayDomain{N}
813
indexes::NTuple{N, Any}
914
end
@@ -176,7 +181,9 @@ function Base.isequal(x::ArrayOp, y::ArrayOp)
176181
end
177182

178183
"""
179-
`view` of a `DArray` chunk returns a `DArray` of thunks
184+
view(c::DArray, d)
185+
186+
A `view` of a `DArray` chunk returns a `DArray` of `Thunk`s.
180187
"""
181188
function Base.view(c::DArray, d)
182189
subchunks, subdomains = lookup_parts(chunks(c), domainchunks(c), d)
@@ -234,8 +241,10 @@ end
234241

235242

236243
"""
237-
A DArray object may contain a thunk in it, in which case
238-
we first turn it into a Thunk object and then compute it.
244+
compute(ctx::Context, x::DArray; persist=true, options=nothing)
245+
246+
A `DArray` object may contain a thunk in it, in which case
247+
we first turn it into a `Thunk` and then compute it.
239248
"""
240249
function compute(ctx::Context, x::DArray; persist=true, options=nothing)
241250
thunk = thunkize(ctx, x, persist=persist)
@@ -247,7 +256,9 @@ function compute(ctx::Context, x::DArray; persist=true, options=nothing)
247256
end
248257

249258
"""
250-
If a DArray tree has a Thunk in it, make the whole thing a big thunk
259+
thunkize(ctx::Context, c::DArray; persist=true)
260+
261+
If a `DArray` tree has a `Thunk` in it, make the whole thing a big thunk.
251262
"""
252263
function thunkize(ctx::Context, c::DArray; persist=true)
253264
if any(istask, chunks(c))
@@ -271,14 +282,18 @@ end
271282
global _stage_cache = WeakKeyDict{Context, Dict}()
272283

273284
"""
285+
cached_stage(ctx::Context, x)
286+
274287
A memoized version of stage. It is important that the
275-
tasks generated for the same DArray have the same
288+
tasks generated for the same `DArray` have the same
276289
identity, for example:
277290
278-
A = rand(Blocks(100,100), Float64, 1000, 1000)
279-
compute(A+A')
291+
```julia
292+
A = rand(Blocks(100,100), Float64, 1000, 1000)
293+
compute(A+A')
294+
```
280295
281-
must not result in computation of A twice.
296+
must not result in computation of `A` twice.
282297
"""
283298
function cached_stage(ctx::Context, x)
284299
cache = if !haskey(_stage_cache, ctx)
@@ -308,6 +323,12 @@ size(x::Distribute) = size(domain(x.data))
308323

309324
export BlockPartition, Blocks
310325

326+
"""
327+
Blocks(xs...)
328+
329+
Indicates the size of an array operation, specified as `xs`, whose length
330+
indicates the number of dimensions in the resulting array.
331+
"""
311332
struct Blocks{N}
312333
blocksize::NTuple{N, Int}
313334
end

src/chunks.jl

+18-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ the result of evaluating a Thunk.
1616
function domain end
1717

1818
"""
19+
UnitDomain
20+
1921
Default domain -- has no information about the value
2022
"""
2123
struct UnitDomain end
@@ -29,9 +31,22 @@ domain(x::Any) = UnitDomain()
2931
###### Chunk ######
3032

3133
"""
32-
A reference to a piece of data located on a remote worker. `Chunk`s are typically created with `Dagger.tochunk(data)`, and the data can then be accessed from any worker with `collect(::Chunk)`. `Chunk`s are serialization-safe, and use distributed refcounting (provided by `MemPool.DRef`) to ensure that the data referenced by a `Chunk` won't be GC'd, as long as a reference exists on some worker.
33-
34-
Each `Chunk` is associated with a given `Dagger.Processor`, which is (in a sense) the processor that "owns" or contains the data. Calling `collect(::Chunk)` will perform data movement and conversions defined by that processor to safely serialize the data to the calling worker.
34+
Chunk
35+
36+
A reference to a piece of data located on a remote worker. `Chunk`s are
37+
typically created with `Dagger.tochunk(data)`, and the data can then be
38+
accessed from any worker with `collect(::Chunk)`. `Chunk`s are
39+
serialization-safe, and use distributed refcounting (provided by
40+
`MemPool.DRef`) to ensure that the data referenced by a `Chunk` won't be GC'd,
41+
as long as a reference exists on some worker.
42+
43+
Each `Chunk` is associated with a given `Dagger.Processor`, which is (in a
44+
sense) the processor that "owns" or contains the data. Calling
45+
`collect(::Chunk)` will perform data movement and conversions defined by that
46+
processor to safely serialize the data to the calling worker.
47+
48+
## Constructors
49+
See [`tochunk`](@ref).
3550
"""
3651
mutable struct Chunk{T, H, P<:Processor}
3752
chunktype::Type{T}

src/file-io.jl

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
export save, load
22
using SparseArrays
33

4+
"""
5+
FileReader
6+
7+
Used as a `Chunk` handle for reading a file, starting at a given offset.
8+
"""
49
mutable struct FileReader{T}
510
file::AbstractString
611
chunktype::Type{T}
@@ -40,7 +45,9 @@ function save(ctx, chunk::Union{Chunk, Thunk}, file_path::AbstractString)
4045
end
4146

4247
"""
43-
special case distmem writing - write to disk on the process with the chunk.
48+
save(ctx, chunk, file_path)
49+
50+
Special case distmem writing - write to disk on the process with the chunk.
4451
"""
4552
function save(ctx, chunk::Chunk{X,DRef}, file_path::AbstractString) where X
4653
pid = chunk.handle.where

0 commit comments

Comments
 (0)