def set_gpu_from_theano():
 if (config.device.startswith('gpu') and (len(config.device) > 3)):
  os.environ['CUDA_DEVICE'] = theano.config.device[3:]
 elif (config.init_gpu_device.startswith('gpu') and (len(config.init_gpu_device) > 3)):
  os.environ['CUDA_DEVICE'] = theano.config.init_gpu_device[3:]

def set_gpu_from_theano ( ) : if ( config . device . startswith ( 'gpu' ) and ( len ( config . device ) > 3 ) ) : os . environ [ 'CUDA_DEVICE' ] = theano . config . device [ 3 : ] elif ( config . init_gpu_device . startswith ( 'gpu' ) and ( len ( config . init_gpu_device ) > 3 ) ) : os . environ [ 'CUDA_DEVICE' ] = theano . config . init_gpu_device [ 3 : ]
this set the gpu used by pycuda to the same as the one used by theano .