def dnn_gradweight(img, topgrad, kerns_shp, border_mode='valid', subsample=(1, 1), conv_mode='conv'):
 ctx_name = infer_context_name(img, topgrad)
 img = as_gpuarray_variable(img, ctx_name)
 topgrad = as_gpuarray_variable(topgrad, ctx_name)
 img = gpu_contiguous(img)
 topgrad = gpu_contiguous(topgrad)
 kerns_shp = as_tensor_variable(kerns_shp)
 desc = gpu_dnn_conv_desc(border_mode=border_mode, subsample=subsample, conv_mode=conv_mode)(kerns_shp)
 out = gpu_alloc_empty(ctx_name, dtype=img.dtype)(*kerns_shp)
 return gpu_dnn_conv_gradW()(img, topgrad, out, desc)

def dnn_gradweight ( img , topgrad , kerns_shp , border_mode = 'valid' , subsample = ( 1 , 1 ) , conv_mode = 'conv' ) : ctx_name = infer_context_name ( img , topgrad ) img = as_gpuarray_variable ( img , ctx_name ) topgrad = as_gpuarray_variable ( topgrad , ctx_name ) img = gpu_contiguous ( img ) topgrad = gpu_contiguous ( topgrad ) kerns_shp = as_tensor_variable ( kerns_shp ) desc = gpu_dnn_conv_desc ( border_mode = border_mode , subsample = subsample , conv_mode = conv_mode ) ( kerns_shp ) out = gpu_alloc_empty ( ctx_name , dtype = img . dtype ) ( * kerns_shp ) return gpu_dnn_conv_gradW ( ) ( img , topgrad , out , desc )
gpu convolution gradient with respect to weight using cudnn from nvidia .