#NEWLINE# def c_code( self , node , name , inputs , outputs , sub ) : #NEWLINE# #INDENT# ins = inputs #NEWLINE# ( outs , ) = outputs #NEWLINE# if ( self . tensor_format == 'b01c' ) : #NEWLINE# #INDENT# tensor_format = 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# tensor_format = 0 #NEWLINE# #UNINDENT# if ( self . mode == 'instance' ) : #NEWLINE# #INDENT# mode = 1 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# mode = 0 #NEWLINE# #UNINDENT# if ( self . algo == 'fast' ) : #NEWLINE# #INDENT# algo = 'CUDNN_SOFTMAX_FAST' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( self . algo == 'log' ) : #NEWLINE# #INDENT# algo = 'CUDNN_SOFTMAX_LOG' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# algo = 'CUDNN_SOFTMAX_ACCURATE' #NEWLINE# #UNINDENT# #UNINDENT# result = ( '\ncudnnStatus_t err%(name)s;\ncudnnTensorFormat_t format%(name)s = CUDNN_TENSOR_NCHW;\nif (%(tensor_format)d == 1)\n  format%(name)s = CUDNN_TENSOR_NHWC;\n\ncudnnSoftmaxAlgorithm_t algo%(name)s = %(algo)s;\n\ncudnnSoftmaxMode_t mode%(name)s = CUDNN_SOFTMAX_MODE_CHANNEL;\nif (%(mode)d == 1)\n  mode%(name)s = CUDNN_SOFTMAX_MODE_INSTANCE;\n' % dict ( name = name , tensor_format = tensor_format , mode = self , algo = algo ) ) #NEWLINE# for ( input_idx , input_name ) in enumerate ( self . softmax_inputs ) : #NEWLINE# #INDENT# result += c_set_tensor4d ( ins [ input_idx ] , ( ( input_name + '_' ) + name ) , ( 'err' + name ) , sub [ 'fail' ] ) #NEWLINE# #UNINDENT# subs = dict ( ins = ins [ ( - 1 ) ] , outs = outs , fail = sub [ 'fail' ] , name = name ) #NEWLINE# for ( idx , softmax_input ) in enumerate ( self . softmax_inputs ) : #NEWLINE# #INDENT# subs [ ( 'name%d' % idx ) ] = softmax_input #NEWLINE# subs [ ( 'ins%d' % idx ) ] = inputs [ idx ] #NEWLINE# #UNINDENT# result += ( '\nif (CudaNdarray_prep_output(&%(outs)s, 4, CudaNdarray_HOST_DIMS(%(ins)s)) != 0)\n{\n  %(fail)s\n}\n' % subs ) #NEWLINE# result += c_set_tensor4d ( outs , ( 'softmax_output_' + name ) , ( 'err' + name ) , sub [ 'fail' ] ) #NEWLINE# result += ( self . method ( ) % subs ) #NEWLINE# return result