CMS 3D CMS Logo

ProcessAcceleratorCUDA.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 
3 import os
4 
5 from HeterogeneousCore.Common.PlatformStatus import PlatformStatus
6 
7 class ProcessAcceleratorCUDA(cms.ProcessAccelerator):
8  def __init__(self):
9  super(ProcessAcceleratorCUDA, self).__init__()
10  self._label = "gpu-nvidia"
11 
12  def labels(self):
13  return [ self._label ]
14 
15  def enabledLabels(self):
16  # Check if CUDA is available, and if the system has at least one usable device.
17  # These should be checked on each worker node, because it depends both
18  # on the architecture and on the actual hardware present in the machine.
19  status = PlatformStatus(os.waitstatus_to_exitcode(os.system("cudaIsEnabled")))
20  return self.labels() if status == PlatformStatus.Success else []
21 
22  def apply(self, process, accelerators):
23 
24  if self._label in accelerators:
25  # Ensure that the CUDAService is loaded
26  if not hasattr(process, "CUDAService"):
27  from HeterogeneousCore.CUDAServices.CUDAService_cfi import CUDAService
28  process.add_(CUDAService)
29 
30  # Propagate the CUDAService messages through the MessageLogger
31  if not hasattr(process.MessageLogger, "CUDAService"):
32  process.MessageLogger.CUDAService = cms.untracked.PSet()
33 
34  else:
35  # Make sure the CUDAService is not loaded
36  if hasattr(process, "CUDAService"):
37  del process.CUDAService
38 
39  # Drop the CUDAService messages from the MessageLogger
40  if hasattr(process.MessageLogger, "CUDAService"):
41  del process.MessageLogger.CUDAService
42 
43 
44 # Ensure this module is kept in the configuration when dumping it
45 cms.specialImportRegistry.registerSpecialImportForType(ProcessAcceleratorCUDA, "from HeterogeneousCore.CUDACore.ProcessAcceleratorCUDA import ProcessAcceleratorCUDA")