4from AthenaConfiguration.ComponentFactory
import CompFactory
5from AthenaConfiguration.ComponentAccumulator
import ComponentAccumulator
8from AthCUDAServices.CUDAConfigFlags
import CUDAStream
12 acc = ComponentAccumulator()
13 svc = CompFactory.getComp(
"AthCUDA::GPUSystemInfoSvc")(
"GPUSystemInfoSvc")
19 '''Default CUDA host memory resource tool to use
21 It makes sure that appropriate caching would be used, as allocating pinned
22 host memory is relatively slow.
26 result = ComponentAccumulator()
30 tool = CompFactory.AthCUDA.HostMemoryResourceTool(**kwargs)
31 if flags.Device.Memory.Debug:
32 debugTool = CompFactory.AthDevice.DebugMemoryResourceTool(
33 'CUDAHostMemoryResourceDebugTool',
37 if flags.Device.Memory.Cache:
38 cacheSvc = CompFactory.AthDevice.BinaryPageMemoryResourceSvc(
39 'CUDAHostCachedMemoryResourceSvc',
41 result.addService(cacheSvc)
42 cacheTool = CompFactory.AthDevice.MemoryResourceSvcAdaptorTool(
43 'CUDAHostCachedMemoryResourceTool',
46 if flags.Device.Memory.Debug:
47 debugTool = CompFactory.AthDevice.DebugMemoryResourceTool(
48 'CUDAHostCachedMemoryResourceDebugTool',
53 result.setPrivateTools(tool)
60 '''Default CUDA device memory resource tool to use
62 It makes sure that appropriate caching would be used, as allocating device
63 memory is relatively slow.
67 result = ComponentAccumulator()
71 tool = CompFactory.AthCUDA.DeviceMemoryResourceTool(**kwargs)
72 if flags.Device.Memory.Debug:
73 debugTool = CompFactory.AthDevice.DebugMemoryResourceTool(
74 'CUDADeviceMemoryResourceDebugTool',
78 if flags.Device.Memory.Cache:
79 cacheSvc = CompFactory.AthDevice.BinaryPageMemoryResourceSvc(
80 'CUDADeviceCachedMemoryResourceSvc',
82 result.addService(cacheSvc)
83 cacheTool = CompFactory.AthDevice.MemoryResourceSvcAdaptorTool(
84 'CUDADeviceCachedMemoryResourceTool',
87 if flags.Device.Memory.Debug:
88 debugTool = CompFactory.AthDevice.DebugMemoryResourceTool(
89 'CUDADeviceCachedMemoryResourceDebugTool',
94 result.setPrivateTools(tool)
101 '''Default CUDA managed memory resource tool to use
103 It makes sure that appropriate caching would be used, as allocating managed
104 memory is relatively slow.
108 result = ComponentAccumulator()
112 tool = CompFactory.AthCUDA.ManagedMemoryResourceTool(**kwargs)
113 if flags.Device.Memory.Debug:
114 debugTool = CompFactory.AthDevice.DebugMemoryResourceTool(
115 'CUDAManagedMemoryResourceDebugTool',
119 if flags.Device.Memory.Cache:
120 cacheSvc = CompFactory.AthDevice.BinaryPageMemoryResourceSvc(
121 'CUDAManagedCachedMemoryResourceSvc',
123 result.addService(cacheSvc)
124 cacheTool = CompFactory.AthDevice.MemoryResourceSvcAdaptorTool(
125 'CUDAManagedCachedMemoryResourceTool',
128 if flags.Device.Memory.Debug:
129 debugTool = CompFactory.AthDevice.DebugMemoryResourceTool(
130 'CUDAManagedCachedMemoryResourceDebugTool',
135 result.setPrivateTools(tool)
142 '''Default tool providing the IMemoryResourcesTool interface for CUDA
146 result = ComponentAccumulator()
150 tool = CompFactory.AthDevice.MemoryResourcesAdaptorTool(**kwargs)
153 if flags.Device.Memory.Shared:
155 tool.MainMRTool = mainMRTool.getPrimary()
156 result.merge(mainMRTool)
159 tool.MainMRTool = mainMRTool.getPrimary()
160 result.merge(mainMRTool)
163 tool.HostMRTool = hostMRTool.getPrimary()
164 result.merge(hostMRTool)
168 result.setPrivateTools(tool)
173 '''Tool providing a single CUDA stream for all components in the entire job
177 result = ComponentAccumulator()
180 streamSvc = CompFactory.AthCUDA.SingleStreamSvc(**kwargs)
181 result.addService(streamSvc)
185 streamTool = CompFactory.AthCUDA.StreamSvcAdaptorTool(
186 'CUDASingleStreamTool', StreamSvc=streamSvc)
187 result.setPrivateTools(streamTool)
194 '''Tool providing one CUDA stream per event/slot
198 result = ComponentAccumulator()
201 streamSvc = CompFactory.AthCUDA.PerEventStreamSvc(**kwargs)
202 result.addService(streamSvc)
206 streamTool = CompFactory.AthCUDA.StreamSvcAdaptorTool(
207 'CUDAPerEventStreamTool', StreamSvc=streamSvc)
208 result.setPrivateTools(streamTool)
215 '''Tool providing one CUDA stream per component (algorithm/tool/service)
219 result = ComponentAccumulator()
222 streamTool = CompFactory.AthCUDA.PerComponentStreamTool(**kwargs)
223 result.setPrivateTools(streamTool)
230 '''Tool providing one CUDA stream per component and event/slot
234 result = ComponentAccumulator()
237 streamTool = CompFactory.AthCUDA.PerEventAndComponentStreamTool(**kwargs)
238 result.setPrivateTools(streamTool)
245 '''Default CUDA stream provider tool to use
249 result = ComponentAccumulator()
252 if flags.CUDA.Stream == CUDAStream.Single:
254 result.setPrivateTools(cfg.getPrimary())
256 elif flags.CUDA.Stream == CUDAStream.PerEvent:
258 result.setPrivateTools(cfg.getPrimary())
260 elif flags.CUDA.Stream == CUDAStream.PerComponent:
262 result.setPrivateTools(cfg.getPrimary())
264 elif flags.CUDA.Stream == CUDAStream.PerEventAndComponent:
266 result.setPrivateTools(cfg.getPrimary())
269 raise ValueError(f
"Invalid CUDA stream strategy: {flags.CUDA.Stream}")
277 '''Synchronous copy object provider tool
281 result = ComponentAccumulator()
284 result.setPrivateTools(CompFactory.AthCUDA.CopyTool(**kwargs))
291 '''Asynchronous copy object provider tool
295 result = ComponentAccumulator()
298 copyTool = CompFactory.AthCUDA.AsyncCopyTool(**kwargs)
300 copyTool.StreamTool = streamTool.getPrimary()
301 result.merge(streamTool)
302 result.setPrivateTools(copyTool)
309 '''Default tool providing the ICopyTool interface for CUDA
313 result = ComponentAccumulator()
316 if flags.Device.Copy.Async:
317 result.setPrivateTools(result.popToolsAndMerge(
320 result.setPrivateTools(result.popToolsAndMerge(
329 '''Default tool providing the ICopiesTool interface for CUDA
333 result = ComponentAccumulator()
337 tool = CompFactory.AthDevice.CopiesAdaptorTool(**kwargs)
340 from AthDeviceComps.AthDeviceCompsConfig
import HostCopyToolCfg
341 tool.HostCopyTool = \
342 result.popToolsAndMerge(HostCopyToolCfg(flags, **kwargs))
345 if flags.Device.Copy.Async:
346 tool.DeviceCopyTool = \
349 tool.DeviceCopyTool = \
354 result.setPrivateTools(tool)
SingleStreamToolCfg(flags, **kwargs)
DeviceMemoryResourceToolCfg(flags, **kwargs)
PerComponentStreamToolCfg(flags, **kwargs)
PerEventStreamToolCfg(flags, **kwargs)
PerEventAndComponentStreamToolCfg(flags, **kwargs)
StreamToolCfg(flags, **kwargs)
GPUSystemInfoSvcCfg(flags)
AsyncCopyToolCfg(flags, **kwargs)
MemoryResourcesToolCfg(flags, **kwargs)
ManagedMemoryResourceToolCfg(flags, **kwargs)
SyncCopyToolCfg(flags, **kwargs)
CopyToolCfg(flags, **kwargs)
CopiesToolCfg(flags, **kwargs)
HostMemoryResourceToolCfg(flags, **kwargs)