CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SwitchProducerCUDA.py
Go to the documentation of this file.
1 import FWCore.ParameterSet.Config as cms
2 
3 _cuda_enabled_cached = None
4 
6  global _cuda_enabled_cached
7  if _cuda_enabled_cached is None:
8  import os
9  _cuda_enabled_cached = (os.system("cudaIsEnabled") == 0)
10  return (_cuda_enabled_cached, 2)
11 
12 class SwitchProducerCUDA(cms.SwitchProducer):
13  def __init__(self, **kargs):
14  super(SwitchProducerCUDA,self).__init__(
15  dict(cpu = cms.SwitchProducer.getCpu(),
16  cuda = _switch_cuda),
17  **kargs
18  )
19 cms.specialImportRegistry.registerSpecialImportForType(SwitchProducerCUDA, "from HeterogeneousCore.CUDACore.SwitchProducerCUDA import SwitchProducerCUDA")
20 
21 if __name__ == "__main__":
22  import unittest
23 
24  class TestSwitchProducerCUDA(unittest.TestCase):
25  def testPickle(self):
26  import pickle
27  sp = SwitchProducerCUDA(cpu = cms.EDProducer("Foo"), cuda = cms.EDProducer("Bar"))
28  pkl = pickle.dumps(sp)
29  unpkl = pickle.loads(pkl)
30  self.assertEqual(unpkl.cpu.type_(), "Foo")
31  self.assertEqual(unpkl.cuda.type_(), "Bar")
32 
33  unittest.main()
34