#NEWLINE# @ register_opt ( 'cudnn' ) #NEWLINE# @ local_optimizer ( [ GpuElemwise , LogSoftmax ] ) #NEWLINE# def local_log_softmax_dnn( node ) : #NEWLINE# #INDENT# if ( ( not dnn_available ( ) ) or ( version ( ) < ( 3000 , 3000 ) ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# if ( isinstance ( node . op , GpuElemwise ) and isinstance ( node . op . scalar_op , Log ) and node . inputs [ 0 ] . owner and isinstance ( node . inputs [ 0 ] . owner . op , GpuDnnSoftmax ) and ( len ( node . inputs [ 0 ] . owner . out . clients ) == 1 ) ) : #NEWLINE# #INDENT# log_input = out . inputs [ 0 ] #NEWLINE# softmax_node = log_input . owner #NEWLINE# new_softmax_node = GpuDnnSoftmax ( softmax_node . op . tensor_format , 'log' , softmax_node . op . mode ) #NEWLINE# new_log_softmax = new_softmax_node ( softmax_node . inputs [ 0 ] ) #NEWLINE# return [ new_log_softmax ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( isinstance ( node . op , LogSoftmax ) and node . inputs [ 0 ] . owner and isinstance ( node . inputs [ 0 ] . owner . op , HostFromGpu ) ) : #NEWLINE# #INDENT# if ( not dnn_available ( ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# inp = node . inputs [ 0 ] . owner . inputs [ 0 ] #NEWLINE# if ( inp . ndim != 2 ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# inp = inp . dimshuffle ( 0 , 1 , 'x' , 'x' ) #NEWLINE# out = GpuDnnSoftmax ( 'bc01' , 'log' , 'channel' ) ( gpu_contiguous ( inp ) ) #NEWLINE# return [ out . dimshuffle ( 0 , 1 ) ]