ATLAS Offline Software
Loading...
Searching...
No Matches
AthHIPCompsConfig.py
Go to the documentation of this file.
1# Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
2
3# Framework import(s).
4from AthenaConfiguration.ComponentFactory import CompFactory
5from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
6
7# Local import(s).
8from AthHIPComps.HIPConfigFlags import HIPStream
9
10
11def HostMemoryResourceToolCfg(flags, **kwargs):
12 '''Default HIP host memory resource tool to use
13
14 It makes sure that appropriate caching would be used, as allocating pinned
15 host memory is relatively slow.
16 '''
17
18 # Create an accumulator to hold the configuration.
19 result = ComponentAccumulator()
20
21 # Create the components that would collaborate to provide thread-safe
22 # caching to the "bare" memory resource.
23 tool = CompFactory.AthHIP.HostMemoryResourceTool(**kwargs)
24 if flags.Device.Memory.Monitor:
25 monitorTool = CompFactory.AthDevice.MonitoredMemoryResourceTool(
26 'HIPHostMemoryResourceMonitorTool',
27 MRTool=tool)
28 tool = monitorTool
29 pass
30 if flags.Device.Memory.Debug:
31 debugTool = CompFactory.AthDevice.DebugMemoryResourceTool(
32 'HIPHostMemoryResourceDebugTool',
33 MRTool=tool)
34 tool = debugTool
35 pass
36 if flags.Device.Memory.Cache:
37 cacheSvc = CompFactory.AthDevice.BinaryPageMemoryResourceSvc(
38 'HIPHostCachedMemoryResourceSvc',
39 MRTool=tool)
40 result.addService(cacheSvc)
41 cacheTool = CompFactory.AthDevice.MemoryResourceSvcAdaptorTool(
42 'HIPHostCachedMemoryResourceTool',
43 MRSvc=cacheSvc)
44 tool = cacheTool
45 if flags.Device.Memory.Debug:
46 debugTool = CompFactory.AthDevice.DebugMemoryResourceTool(
47 'HIPHostCachedMemoryResourceDebugTool',
48 MRTool=tool)
49 tool = debugTool
50 pass
51 pass
52 if flags.Device.Memory.Monitor and flags.Device.Memory.Cache:
53 monitorTool = CompFactory.AthDevice.MonitoredMemoryResourceTool(
54 'HIPHostCachedMemoryResourceMonitorTool',
55 MRTool=tool)
56 tool = monitorTool
57 pass
58 result.setPrivateTools(tool)
59
60 # Return the CA.
61 return result
62
63
64def DeviceMemoryResourceToolCfg(flags, **kwargs):
65 '''Default HIP device memory resource tool to use
66
67 It makes sure that appropriate caching would be used, as allocating device
68 memory is relatively slow.
69 '''
70
71 # Create an accumulator to hold the configuration.
72 result = ComponentAccumulator()
73
74 # Create the components that would collaborate to provide thread-safe
75 # caching to the "bare" memory resource.
76 tool = CompFactory.AthHIP.DeviceMemoryResourceTool(**kwargs)
77 if flags.Device.Memory.Monitor:
78 monitorTool = CompFactory.AthDevice.MonitoredMemoryResourceTool(
79 'HIPDeviceMemoryResourceMonitorTool',
80 MRTool=tool)
81 tool = monitorTool
82 pass
83 if flags.Device.Memory.Debug:
84 debugTool = CompFactory.AthDevice.DebugMemoryResourceTool(
85 'HIPDeviceMemoryResourceDebugTool',
86 MRTool=tool)
87 tool = debugTool
88 pass
89 if flags.Device.Memory.Cache:
90 cacheSvc = CompFactory.AthDevice.BinaryPageMemoryResourceSvc(
91 'HIPDeviceCachedMemoryResourceSvc',
92 MRTool=tool)
93 result.addService(cacheSvc)
94 cacheTool = CompFactory.AthDevice.MemoryResourceSvcAdaptorTool(
95 'HIPDeviceCachedMemoryResourceTool',
96 MRSvc=cacheSvc)
97 tool = cacheTool
98 if flags.Device.Memory.Debug:
99 debugTool = CompFactory.AthDevice.DebugMemoryResourceTool(
100 'HIPDeviceCachedMemoryResourceDebugTool',
101 MRTool=tool)
102 tool = debugTool
103 pass
104 pass
105 if flags.Device.Memory.Monitor and flags.Device.Memory.Cache:
106 monitorTool = CompFactory.AthDevice.MonitoredMemoryResourceTool(
107 'HIPDeviceCachedMemoryResourceMonitorTool',
108 MRTool=tool)
109 tool = monitorTool
110 pass
111 result.setPrivateTools(tool)
112
113 # Return the CA.
114 return result
115
116
117def ManagedMemoryResourceToolCfg(flags, **kwargs):
118 '''Default HIP managed memory resource tool to use
119
120 It makes sure that appropriate caching would be used, as allocating managed
121 memory is relatively slow.
122 '''
123
124 # Create an accumulator to hold the configuration.
125 result = ComponentAccumulator()
126
127 # Create the components that would collaborate to provide thread-safe
128 # caching to the "bare" memory resource.
129 tool = CompFactory.AthHIP.ManagedMemoryResourceTool(**kwargs)
130 if flags.Device.Memory.Monitor:
131 monitorTool = CompFactory.AthDevice.MonitoredMemoryResourceTool(
132 'HIPManagedMemoryResourceMonitorTool',
133 MRTool=tool)
134 tool = monitorTool
135 pass
136 if flags.Device.Memory.Debug:
137 debugTool = CompFactory.AthDevice.DebugMemoryResourceTool(
138 'HIPManagedMemoryResourceDebugTool',
139 MRTool=tool)
140 tool = debugTool
141 pass
142 if flags.Device.Memory.Cache:
143 cacheSvc = CompFactory.AthDevice.BinaryPageMemoryResourceSvc(
144 'HIPManagedCachedMemoryResourceSvc',
145 MRTool=tool)
146 result.addService(cacheSvc)
147 cacheTool = CompFactory.AthDevice.MemoryResourceSvcAdaptorTool(
148 'HIPManagedCachedMemoryResourceTool',
149 MRSvc=cacheSvc)
150 tool = cacheTool
151 if flags.Device.Memory.Debug:
152 debugTool = CompFactory.AthDevice.DebugMemoryResourceTool(
153 'HIPManagedCachedMemoryResourceDebugTool',
154 MRTool=tool)
155 tool = debugTool
156 pass
157 pass
158 if flags.Device.Memory.Monitor and flags.Device.Memory.Cache:
159 monitorTool = CompFactory.AthDevice.MonitoredMemoryResourceTool(
160 'HIPManagedCachedMemoryResourceMonitorTool',
161 MRTool=tool)
162 tool = monitorTool
163 pass
164 result.setPrivateTools(tool)
165
166 # Return the CA.
167 return result
168
169
170def MemoryResourcesToolCfg(flags, **kwargs):
171 '''Default tool providing the IMemoryResourcesTool interface for HIP
172 '''
173
174 # Create an accumulator to hold the configuration.
175 result = ComponentAccumulator()
176
177 # Create the main tool that would provide the
178 # AthDevice::IMemoryResourcesTool interface.
179 tool = CompFactory.AthDevice.MemoryResourcesAdaptorTool(**kwargs)
180
181 # Set up the main tool according to the received flags.
182 if flags.Device.Memory.Shared:
183 tool.MainMRTool = result.getPrimaryAndMerge(
185 else:
186 tool.MainMRTool = result.getPrimaryAndMerge(
188 tool.HostMRTool = result.getPrimaryAndMerge(
190 pass
191
192 # Return the adaptor tool as the main component of the CA.
193 result.setPrivateTools(tool)
194 return result
195
196
197def SingleStreamToolCfg(flags, **kwargs):
198 '''Tool providing a single HIP stream for all components in the entire job
199 '''
200
201 # Create an accumulator to hold the configuration.
202 result = ComponentAccumulator()
203
204 # Create the stream service and add it to the accumulator.
205 streamSvc = CompFactory.AthHIP.SingleStreamSvc(**kwargs)
206 result.addService(streamSvc)
207
208 # Create an adaptor tool on top of the service, and set that as the main
209 # component of the CA.
210 streamTool = CompFactory.AthHIP.StreamSvcAdaptorTool(
211 'HIPSingleStreamTool', StreamSvc=streamSvc)
212 result.setPrivateTools(streamTool)
213
214 # Return the CA.
215 return result
216
217
218def PerEventStreamToolCfg(flags, **kwargs):
219 '''Tool providing one HIP stream per event/slot
220 '''
221
222 # Create an accumulator to hold the configuration.
223 result = ComponentAccumulator()
224
225 # Create the stream service and add it to the accumulator.
226 streamSvc = CompFactory.AthHIP.PerEventStreamSvc(**kwargs)
227 result.addService(streamSvc)
228
229 # Create an adaptor tool on top of the service, and set that as the main
230 # component of the CA.
231 streamTool = CompFactory.AthHIP.StreamSvcAdaptorTool(
232 'HIPPerEventStreamTool', StreamSvc=streamSvc)
233 result.setPrivateTools(streamTool)
234
235 # Return the CA.
236 return result
237
238
239def PerComponentStreamToolCfg(flags, **kwargs):
240 '''Tool providing one HIP stream per component (algorithm/tool/service)
241 '''
242
243 # Create an accumulator to hold the configuration.
244 result = ComponentAccumulator()
245
246 # Create an tool that implements this behaviour.
247 streamTool = CompFactory.AthHIP.PerComponentStreamTool(**kwargs)
248 result.setPrivateTools(streamTool)
249
250 # Return the CA.
251 return result
252
253
255 '''Tool providing one HIP stream per component and event/slot
256 '''
257
258 # Create an accumulator to hold the configuration.
259 result = ComponentAccumulator()
260
261 # Create an tool that implements this behaviour.
262 streamTool = CompFactory.AthHIP.PerEventAndComponentStreamTool(**kwargs)
263 result.setPrivateTools(streamTool)
264
265 # Return the CA.
266 return result
267
268
269def StreamToolCfg(flags, **kwargs):
270 '''Default HIP stream provider tool to use
271 '''
272
273 # Create the default stream tool, depending on the job's configuration.
274 if flags.HIP.Stream == HIPStream.Single:
275 return SingleStreamToolCfg(flags, **kwargs)
276 elif flags.HIP.Stream == HIPStream.PerEvent:
277 return PerEventStreamToolCfg(flags, **kwargs)
278 elif flags.HIP.Stream == HIPStream.PerComponent:
279 return PerComponentStreamToolCfg(flags, **kwargs)
280 elif flags.HIP.Stream == HIPStream.PerEventAndComponent:
281 return PerEventAndComponentStreamToolCfg(flags, **kwargs)
282 else:
283 raise ValueError(f"Invalid HIP stream strategy: {flags.HIP.Stream}")
284 pass
285 pass
286
287
288def SyncCopyToolCfg(flags, **kwargs):
289 '''Synchronous copy object provider tool
290 '''
291
292 # Create an accumulator to hold the configuration.
293 result = ComponentAccumulator()
294
295 # Create the tool in a simple way.
296 result.setPrivateTools(CompFactory.AthHIP.CopyTool(**kwargs))
297
298 # Return the CA.
299 return result
300
301
302def AsyncCopyToolCfg(flags, **kwargs):
303 '''Asynchronous copy object provider tool
304 '''
305
306 # Create an accumulator to hold the configuration.
307 result = ComponentAccumulator()
308
309 # Create the tool. Attaching a stream tool to it.
310 copyTool = CompFactory.AthHIP.AsyncCopyTool(**kwargs)
311 streamTool = StreamToolCfg(flags, **kwargs)
312 copyTool.StreamTool = streamTool.getPrimary()
313 result.merge(streamTool)
314 result.setPrivateTools(copyTool)
315
316 # Return the CA.
317 return result
318
319
320def CopyToolCfg(flags, **kwargs):
321 '''Default tool providing the ICopyTool interface for HIP
322 '''
323
324 # Set up the device copy tool according to the received flags.
325 if flags.Device.Copy.Async:
326 return AsyncCopyToolCfg(flags, **kwargs)
327 else:
328 return SyncCopyToolCfg(flags, **kwargs)
329 pass
330
331
332def CopiesToolCfg(flags, **kwargs):
333 '''Default tool providing the ICopiesTool interface for HIP
334 '''
335
336 # Create an accumulator to hold the configuration.
337 result = ComponentAccumulator()
338
339 # Create the main tool that would provide the AthDevice::ICopiesTool
340 # interface.
341 tool = CompFactory.AthDevice.CopiesAdaptorTool(**kwargs)
342
343 # Set up the "host" copy tool. Which is always the same in our current code.
344 from AthDeviceComps.AthDeviceCompsConfig import HostCopyToolCfg
345 tool.HostCopyTool = \
346 result.popToolsAndMerge(HostCopyToolCfg(flags, **kwargs))
347
348 # Set up the device copy tool according to the received flags.
349 if flags.Device.Copy.Async:
350 tool.DeviceCopyTool = \
351 result.popToolsAndMerge(AsyncCopyToolCfg(flags, **kwargs))
352 else:
353 tool.DeviceCopyTool = \
354 result.popToolsAndMerge(SyncCopyToolCfg(flags, **kwargs))
355 pass
356
357 # Return the adaptor tool as the main component of the CA.
358 result.setPrivateTools(tool)
359
360 # Return the CA.
361 return result
PerEventAndComponentStreamToolCfg(flags, **kwargs)
ManagedMemoryResourceToolCfg(flags, **kwargs)
MemoryResourcesToolCfg(flags, **kwargs)
AsyncCopyToolCfg(flags, **kwargs)
CopyToolCfg(flags, **kwargs)
SyncCopyToolCfg(flags, **kwargs)
CopiesToolCfg(flags, **kwargs)
HostMemoryResourceToolCfg(flags, **kwargs)
PerComponentStreamToolCfg(flags, **kwargs)
DeviceMemoryResourceToolCfg(flags, **kwargs)
StreamToolCfg(flags, **kwargs)
PerEventStreamToolCfg(flags, **kwargs)
SingleStreamToolCfg(flags, **kwargs)