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