#NEWLINE# def dnn_conv3d( img , kerns , border_mode = 'valid' , subsample = ( 1 , 1 , 1 ) , conv_mode = 'conv' , direction_hint = None , workmem = None , algo = 'none' , precision = None ) : #NEWLINE# #INDENT# "\n    GPU convolution using cuDNN from NVIDIA.\n\n    The memory layout to use is 'bct01', that is 'batch', 'channel',\n    'first dim', 'second dim', 'third dim' in that order.\n\n    :param img: images to do the convolution over\n    :param kerns: convolution filters\n    :param border_mode: One of 'valid', 'full', 'half'; additionally, the\n        padding size can be directly specified by an integer or a triplet of\n        integers (as a tuple), specifying the amount of zero padding added to\n        _both_ the top and bottom (first entry) and left and right (second\n        entry) and front and back (third entry) sides of the volume.\n    :param subsample: perform subsampling of the output (default: (1, 1, 1))\n    :param conv_mode: perform convolution (kernels flipped) or\n        cross-correlation. One of 'conv', 'cross'. (default: 'conv')\n    :param direction_hint: Used by graph optimizers to change algorithm choice.\n        By default, GpuDnnConv will be used to carry out the convolution.\n        If border_mode is 'valid', subsample is (1,1,1) and direction_hint is\n        'bprop weights', it will use GpuDnnConvGradW.\n        This parameter is used internally by graph optimizers and may be\n        removed at any time without a deprecation period. You have been warned.\n    :param workmem: *deprecated*, use param algo instead\n    :param algo: convolution implementation to use. Only 'none' is implemented\n        for the conv3d. Default is the value of\n        :attr:`config.dnn.conv.algo_fwd`.\n    :param precision : dtype in which the computation of the convolution\n        should be done. Possible values are 'as_input', 'float16', 'float32'\n        and 'float64'. Default is the value of\n        :attr:`config.dnn.conv.precision`.\n\n    :warning: The cuDNN library only works with GPU that have a compute\n      capability of 3.0 or higer.  This means that older GPU will not\n      work with this Op.\n    :warning: dnn_conv3d only works with cuDNN library 3.0\n\n    " #NEWLINE# if ( border_mode == ( 0 , 0 ) ) : #NEWLINE# #INDENT# border_mode = 'valid' #NEWLINE# #UNINDENT# if ( shape2 is None ) : #NEWLINE# #INDENT# precision = theano . config . dnn . conv . precision #NEWLINE# #UNINDENT# if ( precision == 'as_input' ) : #NEWLINE# #INDENT# precision = theano . scalar . upcast ( img . dtype , kerns . dtype ) #NEWLINE# #UNINDENT# if ( workmem is not None ) : #NEWLINE# #INDENT# warnings . warn ( "dnn_conv3d: parameter 'workmem' is deprecated. Use 'algo' instead." , stacklevel = 3 ) #NEWLINE# assert ( algo is None ) #NEWLINE# algo = workmem #NEWLINE# #UNINDENT# assert ( direction_hint in [ None , 'bprop weights' , 'forward' ] ) #NEWLINE# fgraph = ( getattr ( img , 'fgraph' , None ) or getattr ( kerns , 'fgraph' , None ) ) #NEWLINE# if ( ( border_mode == 'valid' ) and ( subsample == ( 1 , 1 , 1 ) ) and ( direction_hint == 'bprop weights' ) ) : #NEWLINE# #INDENT# img = gpu_contiguous ( img . dimshuffle ( 1 , 0 , 2 , 3 , 4 ) ) #NEWLINE# if ( conv_mode == 'conv' ) : #NEWLINE# #INDENT# kerns = kerns [ : , : , : : ( - 1 ) , : : ( - 1 ) , : : ( - 1 ) ] #NEWLINE# #UNINDENT# kerns = gpu_contiguous ( kerns . dimshuffle ( 1 , 0 , 2 , 3 , 4 ) ) #NEWLINE# shape2 = ( ( shape_i ( img , 2 , fgraph ) - shape_i ( kerns , 2 , fgraph ) ) + 1 ) #NEWLINE# shape3 = ( ( shape_i ( img , 3 , fgraph ) - shape_i ( kerns , 3 , fgraph ) ) + 1 ) #NEWLINE# shape4 = ( ( shape_i ( img , 4 , fgraph ) - shape_i ( kerns , 4 , fgraph ) ) + 1 ) #NEWLINE# out = gpu_alloc_empty ( shape_i ( kerns , 1 , fgraph ) , shape_i ( img , 1 , fgraph ) , shape2 , shape3 , shape4 ) #NEWLINE# desc = GpuDnnConvDesc ( border_mode = 'valid' , subsample = ( 1 , 1 , 1 ) , conv_mode = 'cross' , precision = precision ) ( img . shape , out . shape ) #NEWLINE# conv = GpuDnnConv3dGradW ( ) ( img , kerns , out , desc ) #NEWLINE# return as_cuda_ndarray_variable ( conv . dimshuffle ( 1 , 0 , 2 , 3 , 4 ) ) #NEWLINE# #UNINDENT# img = gpu_contiguous ( img ) #NEWLINE# kerns = gpu_contiguous ( kerns ) #NEWLINE# desc = GpuDnnConvDesc ( border_mode = border_mode , subsample = subsample , conv_mode = conv_mode , precision = precision ) ( img . shape , kerns . shape ) #NEWLINE# desc_op = desc . owner . op #NEWLINE# out_shp = GpuDnnConv3d . get_out_shape ( img . shape , kerns . shape , desc_op . border_mode , desc_op . subsample ) #NEWLINE# out = gpu_alloc_empty ( * out_shp ) #NEWLINE# return GpuDnnConv3d ( algo = algo ) ( img , kerns , out , desc )