<s> from __future__ import absolute_import , print_function , division <EOL> import sys <EOL> import logging <EOL> import sys <EOL> import warnings <EOL> import theano <EOL> from theano import config <EOL> from theano . compile import optdb <EOL> from theano . tensor . basic import register_transfer <EOL> _logger_name = '<STR_LIT>' <EOL> _logger = logging . getLogger ( _logger_name ) <EOL> error = _logger . error <EOL> info = _logger . info <EOL> pygpu_activated = False <EOL> try : <EOL> import pygpu <EOL> import pygpu . gpuarray <EOL> except ImportError : <EOL> pygpu = None <EOL> from . type import ( GpuArrayType , GpuArrayVariable , GpuArrayConstant , <EOL> GpuArraySharedVariable , gpuarray_shared_constructor , <EOL> reg_context , get_context , ContextNotDefined ) <EOL> from . basic_ops import as_gpuarray_variable <EOL> from . import dnn , opt , nerv , extra_ops <EOL> def transfer ( x , target ) : <EOL> try : <EOL> get_context ( target ) <EOL> return as_gpuarray_variable ( x , target ) <EOL> except ContextNotDefined : <EOL> pass <EOL> register_transfer ( transfer ) <EOL> def init_dev ( dev , name = None ) : <EOL> v = pygpu . gpuarray . api_version ( ) <EOL> if v [ <NUM_LIT:0> ] != - <NUM_LIT> : <EOL> raise RuntimeError ( "<STR_LIT>" , v [ <NUM_LIT:0> ] , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if v [ <NUM_LIT:1> ] < <NUM_LIT:0> : <EOL> raise RuntimeError ( "<STR_LIT>" , v [ <NUM_LIT:1> ] , <EOL> "<STR_LIT>" ) <EOL> global pygpu_activated <EOL> if dev not in init_dev . devmap : <EOL> ctx = pygpu . init ( dev ) <EOL> init_dev . devmap [ dev ] = ctx <EOL> if config . gpuarray . preallocate != <NUM_LIT:0> : <EOL> if config . gpuarray . preallocate < <NUM_LIT:1> : <EOL> gmem = min ( config . gpuarray . preallocate , <NUM_LIT> ) * ctx . total_gmem <EOL> else : <EOL> gmem = config . gpuarray . preallocate * ( <NUM_LIT> * <NUM_LIT> ) <EOL> pygpu . empty ( ( gmem , ) , dtype = '<STR_LIT>' , context = ctx ) <EOL> context = init_dev . devmap [ dev ] <EOL> reg_context ( name , context ) <EOL> pygpu_activated = True <EOL> if config . print_active_device : <EOL> warn = None <EOL> cudnn_version = "<STR_LIT>" <EOL> if dev . startswith ( '<STR_LIT>' ) : <EOL> cudnn_version = "<STR_LIT>" <EOL> try : <EOL> cudnn_version = dnn . version ( ) <EOL> if cudnn_version > <NUM_LIT> : <EOL> warn = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> cudnn_version = "<STR_LIT>" % cudnn_version <EOL> except Exception : <EOL> cudnn_version = dnn . dnn_present . msg <EOL> print ( "<STR_LIT>" % ( <EOL> name , dev , context . devname , cudnn_version ) , <EOL> file = sys . stderr ) <EOL> if warn : <EOL> warnings . warn ( warn ) <EOL> init_dev . devmap = { } <EOL> if pygpu : <EOL> try : <EOL> if ( config . device . startswith ( '<STR_LIT>' ) or <EOL> config . device . startswith ( '<STR_LIT>' ) ) : <EOL> init_dev ( config . device ) <EOL> import theano . compile <EOL> theano . compile . shared_constructor ( gpuarray_shared_constructor ) <EOL> optdb . add_tags ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> optdb . add_tags ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> elif ( config . init_gpu_device . startswith ( '<STR_LIT>' ) or <EOL> config . init_gpu_device . startswith ( '<STR_LIT>' ) ) : <EOL> if config . device != '<STR_LIT>' : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if config . contexts != '<STR_LIT>' : <EOL> print ( "<STR_LIT>" ) <EOL> init_dev ( config . init_gpu_device ) <EOL> if config . contexts != '<STR_LIT>' : <EOL> for n , d in ( c . split ( '<STR_LIT>' ) for c in config . contexts . split ( '<STR_LIT:;>' ) ) : <EOL> init_dev ( d . strip ( ) , n . strip ( ) ) <EOL> import theano . compile <EOL> theano . compile . shared_constructor ( gpuarray_shared_constructor ) <EOL> optdb . add_tags ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> optdb . add_tags ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> from . basic_ops import ( GpuAlloc , GpuAllocEmpty , GpuContiguous , GpuEye , <EOL> GpuFromHost , GpuJoin , GpuReshape , GpuSplit , <EOL> HostFromGpu ) <EOL> from . basic_ops import host_from_gpu , GpuFromHost <EOL> from . elemwise import GpuElemwise <EOL> from . subtensor import ( GpuSubtensor , GpuIncSubtensor , <EOL> GpuAdvancedIncSubtensor1 ) <EOL> except Exception : <EOL> error ( "<STR_LIT>" , exc_info = True ) <EOL> else : <EOL> if ( config . init_gpu_device . startswith ( '<STR_LIT>' ) or <EOL> config . init_gpu_device . startswith ( '<STR_LIT>' ) or <EOL> config . device . startswith ( '<STR_LIT>' ) or <EOL> config . device . startswith ( '<STR_LIT>' ) or <EOL> config . contexts != '<STR_LIT>' ) : <EOL> error ( "<STR_LIT>" , exc_info = True ) </s>
