#NEWLINE# def summary_nodes( self , file = sys . stderr , N = None ) : #NEWLINE# #INDENT# if self . apply_time : #NEWLINE# #INDENT# local_time = sum ( self . apply_time . values ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# local_time = 0 #NEWLINE# #UNINDENT# if ( local_time == 0 ) : #NEWLINE# #INDENT# print ( 'ProfileMode.summary_nodes: total time 0 (did you forget to enable counters?)' , file = file ) #NEWLINE# return #NEWLINE# #UNINDENT# print ( 'Apply' , file = file ) #NEWLINE# print ( '------' , file = file ) #NEWLINE# hs = [ ] #NEWLINE# es = [ ] #NEWLINE# hs += [ '<% time>' ] #NEWLINE# es += [ '  %4.1f%% ' ] #NEWLINE# hs += [ '<sum %>' ] #NEWLINE# es += [ ' %5.1f%% ' ] #NEWLINE# hs += [ '<apply time>' ] #NEWLINE# es += [ '   %7.3fs ' ] #NEWLINE# hs += [ '<time per call>' ] #NEWLINE# es += [ '     %8.2es ' ] #NEWLINE# hs += [ '<#call>' ] #NEWLINE# es += [ ' %4d  ' ] #NEWLINE# hs += [ '<id>' ] #NEWLINE# es += [ '%3d' ] #NEWLINE# es += [ '%s' , '%s' ] #NEWLINE# if self . variable_shape : #NEWLINE# #INDENT# hs += [ '<Mflops>' , '<Gflops/s>' ] #NEWLINE# #UNINDENT# upto_length = ( numpy . sum ( [ len ( x ) for x in hs ] ) + len ( hs ) ) #NEWLINE# maxlen = max ( ( self . line_width - upto_length ) , 0 ) #NEWLINE# hs += [ '<Apply name>' ] #NEWLINE# es += [ '%s' ] #NEWLINE# header_str = ' ' . join ( hs ) #NEWLINE# format_str = ' ' . join ( es ) #NEWLINE# print ( header_str , file = file ) #NEWLINE# topos = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# atimes = [ ] #NEWLINE# for ( a , t ) in iteritems ( self . apply_time ) : #NEWLINE# #INDENT# if ( a . fgraph not in topos ) : #NEWLINE# #INDENT# topo = a . fgraph . toposort ( ) #NEWLINE# topos [ a . fgraph ] = topo #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# topo = topos [ a . fgraph ] #NEWLINE# #UNINDENT# atimes . append ( ( ( ( t * 100 ) / local_time ) , t , a , topo . index ( a ) , self . apply_callcount [ a ] ) ) #NEWLINE# #UNINDENT# del topos #NEWLINE# atimes . sort ( reverse = True , key = ( lambda t : ( t [ 1 ] , t [ 3 ] ) ) ) #NEWLINE# tot = 0 #NEWLINE# for ( f , t , a , nd_id , nb_call ) in atimes [ : N ] : #NEWLINE# #INDENT# tot += t #NEWLINE# ftot = ( ( tot * 100 ) / local_time ) #NEWLINE# if ( nb_call == 0 ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( not self . variable_shape ) : #NEWLINE# #INDENT# flops = '' #NEWLINE# flops_s = '' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if hasattr ( a . op , 'flops' ) : #NEWLINE# #INDENT# fl = a . op . flops ( [ self . variable_shape [ var ] for var in a . inputs ] , [ self . variable_shape [ var ] for var in a . outputs ] ) #NEWLINE# flops = ( '%8.1f' % ( ( fl / 1024.0 ) / 1024 ) ) #NEWLINE# flops_s = ( '%10.1f' % ( ( ( ( fl / 1024.0 ) / 1024 ) / 1024 ) / t ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# flops = '        ' #NEWLINE# flops_s = '          ' #NEWLINE# #UNINDENT# #UNINDENT# print ( ( format_str % ( f , ftot , t , ( t / nb_call ) , nb_call , nd_id , flops , flops_s , str ( a ) [ : maxlen ] ) ) , file = file ) #NEWLINE# if ( not config . profile_memory ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# for ( idx , var ) in enumerate ( a . inputs ) : #NEWLINE# #INDENT# sh = self . variable_shape . get ( var , 'no shape' ) #NEWLINE# st = self . variable_strides . get ( var , 'no strides' ) #NEWLINE# dtype = getattr ( var , 'dtype' , 'no dtype' ) #NEWLINE# print ( ( '    input %d: dtype=%s, shape=%s, strides=%s ' % ( idx , dtype , sh , st ) ) , file = file ) #NEWLINE# #UNINDENT# for ( idx , var ) in enumerate ( a . outputs ) : #NEWLINE# #INDENT# sh = self . variable_shape . get ( flops , 'no shape' ) #NEWLINE# st = self . variable_strides . get ( var , 'no strides' ) #NEWLINE# dtype = getattr ( var , 'dtype' , 'no dtype' ) #NEWLINE# print ( ( '    output %d: dtype=%s, shape=%s, strides=%s ' % ( idx , dtype , sh , st ) ) , file = file ) #NEWLINE# #UNINDENT# #UNINDENT# print ( ( '   ... (remaining %i Apply instances account for %.2f%%(%.2fs) of the runtime)' % ( max ( 0 , ( len ( atimes ) - N ) ) , sum ( ( f for ( f , t , a , nd_id , nb_call ) in atimes [ N : ] ) ) , sum ( ( t for ( f , t , a , nd_id , nb_call ) in atimes [ N : ] ) ) ) ) , file = file ) #NEWLINE# print ( '' , file = file )