<s> import os <EOL> import warnings <EOL> import theano <EOL> import theano . sandbox . cuda <EOL> from theano import config <EOL> def set_gpu_from_theano ( ) : <EOL> """<STR_LIT>""" <EOL> if config . device . startswith ( "<STR_LIT>" ) and len ( config . device ) > <NUM_LIT:3> : <EOL> os . environ [ "<STR_LIT>" ] = theano . config . device [ <NUM_LIT:3> : ] <EOL> elif ( config . init_gpu_device . startswith ( "<STR_LIT>" ) and <EOL> len ( config . init_gpu_device ) > <NUM_LIT:3> ) : <EOL> os . environ [ "<STR_LIT>" ] = theano . config . init_gpu_device [ <NUM_LIT:3> : ] <EOL> set_gpu_from_theano ( ) <EOL> pycuda_available = False <EOL> if ( not hasattr ( theano . sandbox , '<STR_LIT>' ) or <EOL> theano . sandbox . cuda . use . device_number is None ) : <EOL> try : <EOL> import pycuda <EOL> import pycuda . autoinit <EOL> pycuda_available = True <EOL> except ImportError : <EOL> warnings . warn ( "<STR_LIT>" ) <EOL> except pycuda . _driver . LogicError : <EOL> if theano . config . force_device : <EOL> raise <EOL> else : <EOL> if "<STR_LIT>" in os . environ : <EOL> del os . environ [ "<STR_LIT>" ] <EOL> import pycuda . autoinit <EOL> pycuda_available = True <EOL> else : <EOL> try : <EOL> import pycuda . driver <EOL> pycuda_available = True <EOL> except ImportError : <EOL> pass <EOL> if pycuda_available : <EOL> if hasattr ( pycuda . driver . Context , "<STR_LIT>" ) : <EOL> pycuda . driver . Context . attach ( ) <EOL> import atexit <EOL> atexit . register ( pycuda . driver . Context . pop ) <EOL> else : <EOL> warnings . warn ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) </s>
