def test_dnn_tag():
 x = T.tensor4()
 old = theano.config.on_opt_error
 theano.config.on_opt_error = 'raise'
 sio = StringIO()
 handler = logging.StreamHandler(sio)
 logging.getLogger('theano.compile.tests.test_dnn').addHandler(handler)
 logging.getLogger('theano').removeHandler(theano.logging_default_handler)
 raised = False
 try:
  f = theano.function([x], pool_2d(x, ws=(2, 2), ignore_border=True), mode=mode_with_gpu.including('cudnn'))
 except (AssertionError, RuntimeError):
  assert (not dnn.dnn_available(test_ctx_name))
  raised = True
 finally:
  theano.config.on_opt_error = old
  logging.getLogger('theano.compile.tests.test_dnn').removeHandler(handler)
  logging.getLogger('theano').addHandler(theano.logging_default_handler)
 if (not raised):
  assert dnn.dnn_available(test_ctx_name)
  assert any([isinstance(n.op, dnn.GpuDnnPool) for n in f.maker.fgraph.toposort()])

def test_dnn_tag ( ) : x = T . tensor4 ( ) old = theano . config . on_opt_error theano . config . on_opt_error = 'raise' sio = StringIO ( ) handler = logging . StreamHandler ( sio ) logging . getLogger ( 'theano.compile.tests.test_dnn' ) . addHandler ( handler ) logging . getLogger ( 'theano' ) . removeHandler ( theano . logging_default_handler ) raised = False try : f = theano . function ( [ x ] , pool_2d ( x , ws = ( 2 , 2 ) , ignore_border = True ) , mode = mode_with_gpu . including ( 'cudnn' ) ) except ( AssertionError , RuntimeError ) : assert ( not dnn . dnn_available ( test_ctx_name ) ) raised = True finally : theano . config . on_opt_error = old logging . getLogger ( 'theano.compile.tests.test_dnn' ) . removeHandler ( handler ) logging . getLogger ( 'theano' ) . addHandler ( theano . logging_default_handler ) if ( not raised ) : assert dnn . dnn_available ( test_ctx_name ) assert any ( [ isinstance ( n . op , dnn . GpuDnnPool ) for n in f . maker . fgraph . toposort ( ) ] )
test that if cudnn isnt avail we crash and that if it is avail .