@@ -13,7 +13,7 @@ make it easy to transfer data to/from other types of `Processor` at runtime.
13
13
abstract type Processor end
14
14
15
15
const PROCESSOR_CALLBACKS = Dict {Symbol,Any} ()
16
- const OSPROC_PROCESSOR_CACHE = Dict {Int,Vector {Processor}} ()
16
+ const OSPROC_PROCESSOR_CACHE = Dict {Int,Set {Processor}} ()
17
17
18
18
add_processor_callback! (func, name:: String ) =
19
19
add_processor_callback! (func, Symbol (name))
@@ -56,18 +56,39 @@ iscompatible_arg(proc::Processor, opts, x) = false
56
56
"""
57
57
default_enabled(proc::Processor) -> Bool
58
58
59
- Returns whether processor `proc` is enabled by default (opt-out). `Processor` subtypes can override this function to make themselves opt-in (default returns `false`).
59
+ Returns whether processor `proc` is enabled by default. The default value is
60
+ `false`, which is an opt-out of the processor from execution when not
61
+ specifically requested by the user, and `true` implies opt-in, which causes the
62
+ processor to always participate in execution when possible.
60
63
"""
61
64
default_enabled (proc:: Processor ) = false
62
65
63
66
"""
64
- get_processors(proc::Processor) -> Vector{T} where T <:Processor
67
+ get_processors(proc::Processor) -> Set{ <:Processor}
65
68
66
- Returns the full list of processors contained in `proc`, if any. `Processor`
67
- subtypes should overload this function if they can contain sub-processors. The
68
- default method will return a `Vector` containing `proc` itself.
69
+ Returns the set of processors contained in `proc`, if any. `Processor` subtypes
70
+ should overload this function if they can contain sub-processors. The default
71
+ method will return a `Vector` containing `proc` itself.
69
72
"""
70
- get_processors (proc:: Processor ) = Processor[proc]
73
+ get_processors (proc:: Processor ) = Set {Processor} (proc)
74
+
75
+ """
76
+ get_storage_resources(proc::Processor) -> Set{<:StorageResource}
77
+
78
+ Returns the full set of storage resources accessible to `proc`, if any.
79
+ `Processor` subtypes should overload this function if they have direct access
80
+ to any storage resources. The default method will return an empty set.
81
+ """
82
+ get_storage_resources (proc:: Processor ) = Set {StorageResource} ()
83
+
84
+ """
85
+ get_storage_devices(proc::Processor) -> Set{<:StorageDevice}
86
+
87
+ Returns the full set of storage devices accessible to `proc`, if any.
88
+ `Processor` subtypes should overload this function if they have direct access
89
+ to any storage devices. The default method will return an empty set.
90
+ """
91
+ get_storage_devices (proc:: Processor ) = Set {StorageDevice} ()
71
92
72
93
"""
73
94
get_parent(proc::Processor) -> Processor
@@ -91,6 +112,7 @@ data movement should provide implementations where `x::Chunk`.
91
112
"""
92
113
move (from_proc:: Processor , to_proc:: Processor , x) = x
93
114
115
+ #=
94
116
"""
95
117
capacity(proc::Processor=OSProc()) -> Int
96
118
@@ -99,6 +121,7 @@ Returns the total processing capacity of `proc`.
99
121
capacity(proc=OSProc()) = length(get_processors(proc))
100
122
capacity(proc, ::Type{T}) where T =
101
123
length(filter(x->x isa T, get_processors(proc)))
124
+ =#
102
125
103
126
"""
104
127
OSProc <: Processor
@@ -111,37 +134,34 @@ struct OSProc <: Processor
111
134
pid:: Int
112
135
function OSProc (pid:: Int = myid ())
113
136
get! (OSPROC_PROCESSOR_CACHE, pid) do
114
- remotecall_fetch (get_processor_hierarchy , pid)
137
+ remotecall_fetch (detect_hierarchy , pid, :processor )
115
138
end
116
- get! (OSPROC_STORAGE_CACHE, pid) do
117
- remotecall_fetch (get_storage_hierarchy, pid)
139
+ get! (OSPROC_STORAGE_RESOURCE_CACHE, pid) do
140
+ remotecall_fetch (detect_hierarchy, pid, :storage_resource )
141
+ end
142
+ get! (OSPROC_STORAGE_DEVICE_CACHE, pid) do
143
+ remotecall_fetch (detect_hierarchy, pid, :storage_device )
118
144
end
119
145
new (pid)
120
146
end
121
147
end
122
148
get_parent (proc:: OSProc ) = proc
123
- children (proc:: OSProc ) = get (OSPROC_PROCESSOR_CACHE, proc. pid, Processor[])
124
- function get_processor_hierarchy ()
125
- children = Processor[]
126
- for name in keys (PROCESSOR_CALLBACKS)
127
- cb = PROCESSOR_CALLBACKS[name]
128
- try
129
- child = Base. invokelatest (cb)
130
- if (child isa Tuple) || (child isa Vector)
131
- append! (children, child)
132
- elseif child != = nothing
133
- push! (children, child)
134
- end
135
- catch err
136
- @error " Error in processor callback: $name " exception= (err,catch_backtrace ())
137
- end
149
+ get_processors (proc:: OSProc ) = get (OSPROC_PROCESSOR_CACHE, proc. pid, Set {Processor} ())
150
+ get_storage_resources (proc:: OSProc ) = get (OSPROC_STORAGE_RESOURCE_CACHE, proc. pid, Set {StorageResource} ())
151
+ get_storage_devices (proc:: OSProc ) = get (OSPROC_STORAGE_DEVICE_CACHE, proc. pid, Set {StorageDevice} ())
152
+ children (proc:: OSProc ) = get_processors (proc)
153
+ function detect_hierarchy (kind:: Symbol )
154
+ cb_dict, children = if kind == :processor
155
+ PROCESSOR_CALLBACKS, Set {Processor} ()
156
+ elseif kind == :storage_resource
157
+ STORAGE_RESOURCE_CALLBACKS, Set {StorageResource} ()
158
+ elseif kind == :storage_device
159
+ STORAGE_DEVICE_CALLBACKS, Set {StorageDevice} ()
160
+ else
161
+ throw (ArgumentError (" Invalid hierarchy kind: $kind " ))
138
162
end
139
- children
140
- end
141
- function get_storage_hierarchy ()
142
- children = Processor[]
143
- for name in keys (STORAGE_CALLBACKS)
144
- cb = STORAGE_CALLBACKS[name]
163
+ for name in keys (cb_dict)
164
+ cb = cb_dict[name]
145
165
try
146
166
child = Base. invokelatest (cb)
147
167
if (child isa Tuple) || (child isa Vector)
@@ -150,7 +170,7 @@ function get_storage_hierarchy()
150
170
push! (children, child)
151
171
end
152
172
catch err
153
- @error " Error in storage callback: $name " exception= (err,catch_backtrace ())
173
+ @error " Error in $( String (kind)) callback: $name " exception= (err,catch_backtrace ())
154
174
end
155
175
end
156
176
children
@@ -164,8 +184,6 @@ iscompatible_arg(proc::OSProc, opts, args...) =
164
184
any (child->
165
185
all (arg-> iscompatible_arg (child, opts, arg), args),
166
186
children (proc))
167
- get_processors (proc:: OSProc ) =
168
- vcat ((get_processors (child) for child in children (proc)). .. )
169
187
170
188
"""
171
189
ThreadProc <: Processor
229
247
end
230
248
get_parent (proc:: ThreadProc ) = OSProc (proc. owner)
231
249
default_enabled (proc:: ThreadProc ) = true
250
+ storage_resource (proc:: ThreadProc ) = CPURAMStorage (proc. owner)
232
251
233
252
# TODO : ThreadGroupProc?
234
253
@@ -340,7 +359,8 @@ get_tls() = (
340
359
sch_uid= task_local_storage (:_dagger_sch_uid ),
341
360
sch_handle= task_local_storage (:_dagger_sch_handle ),
342
361
processor= thunk_processor (),
343
- utilization= task_local_storage (:_dagger_utilization ),
362
+ time_utilization= task_local_storage (:_dagger_time_utilization ),
363
+ alloc_utilization= task_local_storage (:_dagger_alloc_utilization ),
344
364
)
345
365
346
366
"""
@@ -352,5 +372,6 @@ function set_tls!(tls)
352
372
task_local_storage (:_dagger_sch_uid , tls. sch_uid)
353
373
task_local_storage (:_dagger_sch_handle , tls. sch_handle)
354
374
task_local_storage (:_dagger_processor , tls. processor)
355
- task_local_storage (:_dagger_utilization , tls. utilization)
375
+ task_local_storage (:_dagger_time_utilization , tls. time_utilization)
376
+ task_local_storage (:_dagger_alloc_utilization , tls. alloc_utilization)
356
377
end
0 commit comments