You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/datadeps.md
+60Lines changed: 60 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -221,6 +221,66 @@ function Dagger.move!(dep_mod::Any, from_space::Dagger.MemorySpace, to_space::Da
221
221
end
222
222
```
223
223
224
+
## Custom Schedulers
225
+
226
+
The `spawn_datadeps` function accepts an optional `scheduler` keyword argument that controls how tasks are assigned to processors. By default, `spawn_datadeps` uses `RoundRobinScheduler()`, which cycles through available processors in a round-robin fashion.
227
+
228
+
### Built-in Schedulers
229
+
230
+
-**`RoundRobinScheduler()`** (default): Assigns tasks to processors in round-robin order. This is a simple and effective scheduler for most use cases.
231
+
-**`NaiveScheduler()`**: Uses the main Dagger scheduler's cost estimation to select processors. (Currently experimental)
232
+
-**`UltraScheduler()`**: An advanced scheduler that tracks task completion times and tries to minimize overall execution time. (Currently experimental)
233
+
234
+
### Using a Different Scheduler
235
+
236
+
You can pass a scheduler to `spawn_datadeps` like so:
237
+
238
+
```julia
239
+
Dagger.spawn_datadeps(; scheduler=Dagger.RoundRobinScheduler()) do
240
+
Dagger.@spawn my_task!(InOut(A))
241
+
Dagger.@spawn another_task!(In(B))
242
+
end
243
+
```
244
+
245
+
### Writing Your Own Scheduler
246
+
247
+
You can implement a custom scheduler by:
248
+
1. Defining a struct that subtypes `Dagger.DataDepsScheduler`
249
+
2. Implementing the `Dagger.datadeps_schedule_task` method for your scheduler
250
+
251
+
The scheduler's job is to select which processor should execute a given task. Here's a simple example that randomly selects a processor:
throw(SchedulingException("No processors available for task $(task.uid) with scope $(task_scope)"))
263
+
end
264
+
# Simply pick a random processor from the compatible ones
265
+
return rand(compatible_procs)
266
+
end
267
+
268
+
# Use it
269
+
Dagger.spawn_datadeps(; scheduler=RandomScheduler()) do
270
+
Dagger.@spawn my_task!(InOut(A))
271
+
end
272
+
```
273
+
274
+
The `datadeps_schedule_task` function receives:
275
+
-`state`: Internal datadeps state (typically not needed for simple schedulers)
276
+
-`all_procs`: Vector of all available processors
277
+
-`all_scope`: The combined scope of all processors
278
+
-`task_scope`: The scope constraint for this specific task
279
+
-`spec`: The task specification
280
+
-`task`: The DTask being scheduled
281
+
282
+
The function must return a processor from `all_procs` that is compatible with `task_scope`.
283
+
224
284
## Chunk and DTask slicing with `view`
225
285
226
286
The `view` function allows you to efficiently create a "view" of a `Chunk` or `DTask` that contains an array. This enables operations on specific parts of your distributed data using standard Julia array slicing, without needing to materialize the entire array.
0 commit comments