def use(device, force=False, default_to_move_computation_to_gpu=True, move_shared_float32_to_gpu=True, enable_cuda=True, test_driver=True):
 global cuda_enabled, cuda_initialization_error_message
 _logger.warn('The cuda backend is deprecated and will be removed in the next release.  Please switch to the gpuarray backend. You can get more information about how to switch at this URL:\n https://github.com/Theano/Theano/wiki/Converting-to-the-new-gpu-back-end%28gpuarray%29\n')
 if (force and (not cuda_available) and device.startswith('gpu')):
  if (not nvcc_compiler.is_nvcc_available()):
   raise EnvironmentError(("You forced the use of gpu device '%s', but nvcc was not found. Set it in your PATH environment variable or set the Theano flags 'cuda.root' to its directory" % device))
  else:
   raise EnvironmentError(('You forced the use of gpu device %s, but CUDA initialization failed with error:\n%s' % (device, cuda_initialization_error_message)))
 elif (not nvcc_compiler.is_nvcc_available()):
  _logger.error('nvcc compiler not found on $PATH. Check your nvcc installation and try again.')
  return
 elif (not cuda_available):
  error_addendum = ''
  try:
   if cuda_initialization_error_message:
    error_addendum = (' (error: %s)' % cuda_initialization_error_message)
  except NameError:
   pass
  _logger.warning('CUDA is installed, but device %s is not available %s', device, error_addendum)
  return
 if (device == 'gpu'):
  pass
 elif device.startswith('gpu'):
  device = int(device[3:])
 elif (device == 'cpu'):
  device = (-1)
 else:
  raise ValueError('Invalid device identifier', device)
 if (use.device_number is None):
  if ((device != 'gpu') and (device < 0)):
   return
  msg = ('Theano flag device=gpu* (old gpu back-end) only support floatX=float32. You have floatX=%s. Use the new gpu back-end with device=cuda* for that value of floatX.' % config.floatX)
  if (config.floatX == 'float16'):
   raise RuntimeError(msg)
  elif (config.floatX == 'float64'):
   warnings.warn(msg)
  pycuda_init_dev = False
  if config.pycuda.init:
   import theano.misc.pycuda_init
   pycuda_init_dev = theano.misc.pycuda_init.pycuda_available
  try:
   if pycuda_init_dev:
    use.device_number = active_device_number()
    gpu_init(use.device_number, config.lib.cnmem)
   elif (device != 'gpu'):
    assert isinstance(device, int)
    gpu_init(device, config.lib.cnmem)
    use.device_number = device
    active_device = active_device_number()
    assert (active_device == device), (active_device, device)
   else:
    if (not hasattr(cuda_ndarray.cuda_ndarray, 'select_a_gpu')):
     raise Exception('Delete your Theano cache. The automatic recompilation did not work.')
    cuda_ndarray.cuda_ndarray.select_a_gpu()
    use.device_number = active_device_number()
    gpu_init(use.device_number, config.lib.cnmem)
   if test_driver:
    import theano.sandbox.cuda.tests.test_driver
    theano.sandbox.cuda.tests.test_driver.test_nvidia_driver1()
   if (device_properties(use.device_number)['warpSize'] != 32):
    raise ValueError("Your GPU has a warpSize != 32. Currently we have code that depends on this. Email the Theano mailing list to tell us about this new GPU as we don't know any with this property")
   if config.print_active_device:
    if config.lib.cnmem:
     if (config.lib.cnmem > 1):
      cnmem_enabled = ('enabled with initial size: %d MB' % config.lib.cnmem)
     else:
      cnmem = (min(config.lib.cnmem, 0.95) * 100)
      cnmem_enabled = ('enabled with initial size: %.1f%% of memory' % cnmem)
    else:
     cnmem_enabled = 'disabled'
    cudnn_version = 'not available'
    warn = None
    try:
     if dnn_available():
      (hdr_v, runtime_v) = dnn_version()
      cudnn_version = runtime_v
      if (cudnn_version >= 5200):
       warn = 'Your cuDNN version is more recent than the one Theano officially supports. If you see any problems, try updating Theano or downgrading cuDNN to version 5.1.'
    except Exception:
     cudnn_version = dnn_available.msg
    print(('Using gpu device %d: %s (CNMeM is %s, cuDNN %s)' % (active_device_number(), active_device_name(), cnmem_enabled, cudnn_version)), file=sys.stderr)
    if warn:
     warnings.warn(warn)
   if (device_properties(use.device_number)['regsPerBlock'] < 16384):
    _logger.warning('You are probably using an old GPU, that Theano does not support. This means GPU code will most likely be slow AND may crash when we try to use features that your GPU does not support.')
  except (EnvironmentError, ValueError, RuntimeError) as e:
   _logger.error('ERROR: Not using GPU. Initialisation of device %s failed:\n%s', str(device), e)
   cuda_enabled = False
   if force:
    e.args += ('You asked to force this device and it failed. No fallback to the cpu or other gpu device.',)
    raise
 elif ((use.device_number != device) and (device != 'gpu')):
  _logger.warning('Ignoring call to use(%s), GPU number %i is already in use.', str(device), use.device_number)
 if move_shared_float32_to_gpu:
  handle_shared_float32(True)
 if enable_cuda:
  cuda_enabled = True
 if default_to_move_computation_to_gpu:
  optdb.add_tags('gpu_opt', 'fast_compile', 'fast_run')
  optdb.add_tags('gpu_after_fusion', 'fast_run')
  optdb.add_tags('gpu_scanOp_make_inplace', 'fast_run')
 if force:
  try:
   cuda_ndarray.cuda_ndarray.CudaNdarray.zeros((5, 5))
  except (Exception, NameError) as e:
   e.args += ('ERROR: GPU forced but failed. ',)
   raise

def use ( device , force = False , default_to_move_computation_to_gpu = True , move_shared_float32_to_gpu = True , enable_cuda = True , test_driver = True ) : global cuda_enabled , cuda_initialization_error_message _logger . warn ( 'The cuda backend is deprecated and will be removed in the next release.  Please switch to the gpuarray backend. You can get more information about how to switch at this URL:\n https://github.com/Theano/Theano/wiki/Converting-to-the-new-gpu-back-end%28gpuarray%29\n' ) if ( force and ( not cuda_available ) and device . startswith ( 'gpu' ) ) : if ( not nvcc_compiler . is_nvcc_available ( ) ) : raise EnvironmentError ( ( "You forced the use of gpu device '%s', but nvcc was not found. Set it in your PATH environment variable or set the Theano flags 'cuda.root' to its directory" % device ) ) else : raise EnvironmentError ( ( 'You forced the use of gpu device %s, but CUDA initialization failed with error:\n%s' % ( device , cuda_initialization_error_message ) ) ) elif ( not nvcc_compiler . is_nvcc_available ( ) ) : _logger . error ( 'nvcc compiler not found on $PATH. Check your nvcc installation and try again.' ) return elif ( not cuda_available ) : error_addendum = '' try : if cuda_initialization_error_message : error_addendum = ( ' (error: %s)' % cuda_initialization_error_message ) except NameError : pass _logger . warning ( 'CUDA is installed, but device %s is not available %s' , device , error_addendum ) return if ( device == 'gpu' ) : pass elif device . startswith ( 'gpu' ) : device = int ( device [ 3 : ] ) elif ( device == 'cpu' ) : device = ( - 1 ) else : raise ValueError ( 'Invalid device identifier' , device ) if ( use . device_number is None ) : if ( ( device != 'gpu' ) and ( device < 0 ) ) : return msg = ( 'Theano flag device=gpu* (old gpu back-end) only support floatX=float32. You have floatX=%s. Use the new gpu back-end with device=cuda* for that value of floatX.' % config . floatX ) if ( config . floatX == 'float16' ) : raise RuntimeError ( msg ) elif ( config . floatX == 'float64' ) : warnings . warn ( msg ) pycuda_init_dev = False if config . pycuda . init : import theano . misc . pycuda_init pycuda_init_dev = theano . misc . pycuda_init . pycuda_available try : if pycuda_init_dev : use . device_number = active_device_number ( ) gpu_init ( use . device_number , config . lib . cnmem ) elif ( device != 'gpu' ) : assert isinstance ( device , int ) gpu_init ( device , config . lib . cnmem ) use . device_number = device active_device = active_device_number ( ) assert ( active_device == device ) , ( active_device , device ) else : if ( not hasattr ( cuda_ndarray . cuda_ndarray , 'select_a_gpu' ) ) : raise Exception ( 'Delete your Theano cache. The automatic recompilation did not work.' ) cuda_ndarray . cuda_ndarray . select_a_gpu ( ) use . device_number = active_device_number ( ) gpu_init ( use . device_number , config . lib . cnmem ) if test_driver : import theano . sandbox . cuda . tests . test_driver theano . sandbox . cuda . tests . test_driver . test_nvidia_driver1 ( ) if ( device_properties ( use . device_number ) [ 'warpSize' ] != 32 ) : raise ValueError ( "Your GPU has a warpSize != 32. Currently we have code that depends on this. Email the Theano mailing list to tell us about this new GPU as we don't know any with this property" ) if config . print_active_device : if config . lib . cnmem : if ( config . lib . cnmem > 1 ) : cnmem_enabled = ( 'enabled with initial size: %d MB' % config . lib . cnmem ) else : cnmem = ( min ( config . lib . cnmem , 0.95 ) * 100 ) cnmem_enabled = ( 'enabled with initial size: %.1f%% of memory' % cnmem ) else : cnmem_enabled = 'disabled' cudnn_version = 'not available' warn = None try : if dnn_available ( ) : ( hdr_v , runtime_v ) = dnn_version ( ) cudnn_version = runtime_v if ( cudnn_version >= 5200 ) : warn = 'Your cuDNN version is more recent than the one Theano officially supports. If you see any problems, try updating Theano or downgrading cuDNN to version 5.1.' except Exception : cudnn_version = dnn_available . msg print ( ( 'Using gpu device %d: %s (CNMeM is %s, cuDNN %s)' % ( active_device_number ( ) , active_device_name ( ) , cnmem_enabled , cudnn_version ) ) , file = sys . stderr ) if warn : warnings . warn ( warn ) if ( device_properties ( use . device_number ) [ 'regsPerBlock' ] < 16384 ) : _logger . warning ( 'You are probably using an old GPU, that Theano does not support. This means GPU code will most likely be slow AND may crash when we try to use features that your GPU does not support.' ) except ( EnvironmentError , ValueError , RuntimeError ) as e : _logger . error ( 'ERROR: Not using GPU. Initialisation of device %s failed:\n%s' , str ( device ) , e ) cuda_enabled = False if force : e . args += ( 'You asked to force this device and it failed. No fallback to the cpu or other gpu device.' , ) raise elif ( ( use . device_number != device ) and ( device != 'gpu' ) ) : _logger . warning ( 'Ignoring call to use(%s), GPU number %i is already in use.' , str ( device ) , use . device_number ) if move_shared_float32_to_gpu : handle_shared_float32 ( True ) if enable_cuda : cuda_enabled = True if default_to_move_computation_to_gpu : optdb . add_tags ( 'gpu_opt' , 'fast_compile' , 'fast_run' ) optdb . add_tags ( 'gpu_after_fusion' , 'fast_run' ) optdb . add_tags ( 'gpu_scanOp_make_inplace' , 'fast_run' ) if force : try : cuda_ndarray . cuda_ndarray . CudaNdarray . zeros ( ( 5 , 5 ) ) except ( Exception , NameError ) as e : e . args += ( 'ERROR: GPU forced but failed. ' , ) raise
set the matplotlib backend to one of the known backends .