@@ -15,16 +15,16 @@ considered valid.
1515
1616Let's take the example of a webcam handle generated by VideoIO.jl. This handle
1717is a C pointer, and thus has process scope. We can open the handle on a given
18- process, and set the scope of the resulting data to a ` ProcessScope() ` , which
19- defaults to the current Julia process :
18+ process, and set the scope of the resulting data to be locked to the current
19+ process with ` Dagger.scope ` to construct a ` ProcessScope ` :
2020
2121``` julia
22- using VideoIO
22+ using VideoIO, Distributed
2323
2424function get_handle ()
2525 handle = VideoIO. opencamera ()
2626 proc = Dagger. thunk_processor ()
27- scope = ProcessScope ()
27+ scope = Dagger . scope (worker = myid ()) # constructs a `ProcessScope`
2828 return Dagger. tochunk (handle, proc, scope)
2929end
3030
@@ -41,7 +41,7 @@ cam_frame = Dagger.@spawn read(cam_handle)
4141
4242The ` cam_frame ` task is executed within any processor on the same process that
4343the ` cam_handle ` task was executed on. Of course, the resulting camera frame is
44- * not* scoped to anywhere specific (denoted as ` AnyScope() ` ), and thus
44+ * not* scoped to anywhere specific (denoted as ` AnyScope ` ), and thus
4545computations on it may execute anywhere.
4646
4747You may also encounter situations where you want to use a callable struct (such
@@ -53,13 +53,15 @@ using Flux
5353m = Chain (... )
5454# If `m` is only safe to transfer to and execute on this process,
5555# we can set a `ProcessScope` on it:
56- result = Dagger. @spawn scope= ProcessScope ( ) m (rand (8 ,8 ))
56+ result = Dagger. @spawn scope= Dagger . scope (worker = myid () ) m (rand (8 ,8 ))
5757```
5858
5959Setting a scope on the function treats it as a regular piece of data (like the
6060arguments to the function), so it participates in the scoping rules described
6161in the following sections all the same.
6262
63+ [ ` Dagger.scope ` ] ( @ref )
64+
6365Now, let's try out some other kinds of scopes, starting with ` NodeScope ` . This
6466scope encompasses the server that one or more Julia processes may be running
6567on. Say we want to use memory mapping (mmap) to more efficiently send arrays
@@ -75,6 +77,7 @@ function generate()
7577 arr = Mmap. mmap (path, Matrix{Int}, (64 ,64 ))
7678 fill! (arr, 1 )
7779 Mmap. sync! (arr)
80+ # Note: Dagger.scope() does not yet support node scopes
7881 Dagger. tochunk (path, Dagger. thunk_processor (), NodeScope ())
7982end
8083
@@ -87,14 +90,14 @@ a = Dagger.@spawn generate()
8790@assert fetch (Dagger. @spawn consume (a)) == 64 * 64
8891```
8992
90- Whatever server ` a ` executed on, ` b ` will also execute on!
93+ Whatever server ` a ` executed on, ` b ` will also execute on it !
9194
9295Finally, we come to the "lowest" scope on the scope hierarchy, the
9396` ExactScope ` . This scope specifies one exact processor as the bounding scope,
94- and is typically useful in certain limited cases. We won't provide an example
95- here, because you don 't usually need to ever use this scope, but if you already
96- understand the ` NodeScope ` and ` ProcessScope ` , the ` ExactScope ` should be easy
97- to figure out.
97+ and is typically useful in certain limited cases (such as data existing only on
98+ a specific GPU). We won 't provide an example here, because you don't usually
99+ need to ever use this scope, but if you already understand the ` NodeScope ` and
100+ ` ProcessScope ` , the ` ExactScope ` should be easy to figure out.
98101
99102## Union Scopes
100103
0 commit comments