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