Welcome    Usage    Browse    Find CID    Search     Log in

cM API Documentation

module.py

Go to the documentation of this file.
00001 #
00002 # Collective Mind
00003 #
00004 # See cM LICENSE.txt for licensing details.
00005 # See cM Copyright.txt for copyright details.
00006 #
00007 # Developer(s): (C) Grigori Fursin, started on 2011.09
00008 #
00009 
00010 # Should always be here
00011 ini={}
00012 cm_kernel=None
00013 
00014 # Local settings
00015 import json
00016 
00017 # ============================================================================
00018 def init(i):
00019     return {'cm_return':0}
00020 
00021 # ============================================================================
00022 def check_features(i):
00023 
00024     # Load features description
00025     ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['cm-module'],
00026         'cm_data_uoa':ini['cfg']['cm_modules']['ctuning.scenario.program.features.milepost'],
00027         'cm_action':'load'}
00028     r=cm_kernel.access(ii)
00029     if r['cm_return']>0: return r
00030 
00031     feat_desc=r['cm_data_obj']['cfg']['milepost_features_description']
00032     feat_norm=r['cm_data_obj']['cfg']['milepost_normalization_feature']
00033 
00034     # List entries with features
00035     ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['ctuning.scenario.program.features.milepost'],
00036         'cm_action':'list'}
00037     r=cm_kernel.access(ii)
00038     if r['cm_return']>0: return r
00039 
00040     nn=0
00041     for q in r['cm_mixed']:
00042         print '****************************************************************************'
00043 
00044         nn+=1
00045 
00046         data=q['cm_data_obj_cfg']
00047         data_uid=q['cm_uid']
00048 
00049         program_uoa=data['points'][0]['pipeline_input']['state']['9f4d948a74b0397a']['input']['program_uoa']
00050 
00051         # Load info about program
00052         ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['code.source'],
00053             'cm_data_uoa':program_uoa,
00054             'cm_action':'load'}
00055         r1=cm_kernel.access(ii)
00056         if r1['cm_return']>0: return r1
00057 
00058         program_cfg=r1['cm_data_obj']['cfg']
00059         program_run_cmds=program_cfg.get('run_cmds',{})
00060 
00061         print str(nn)+')  '+r1['cm_uid']+' - '+r1['cm_display_html']
00062         print r1['cm_path']
00063 
00064         print ''
00065         print 'Program available run command lines:'
00066         print program_run_cmds
00067 
00068         # Get program structure
00069         prog_struct=data['points'][0]['pipeline_output']['state'].get('cb5a5ebdb55441e8',{}).get('output',{}).get('program_structure',{})
00070 
00071         # list functions
00072         print ''
00073         for func in prog_struct:
00074             print ''
00075             print 'Function: ', func
00076 
00077             compiler_passes=prog_struct[func].get('compiler_passes',[])
00078             psp=prog_struct[func].get('program_static_properties',{})
00079 
00080             if len(psp)>0:
00081                psp1=psp[psp.keys()[0]]
00082 
00083                fvfn=0
00084                vfn=psp1.get(feat_norm,'')
00085                if vfn!='': fvfn=float(vfn)
00086 
00087                print 'Total number of instructions: ', fvfn
00088 
00089                if fvfn>0:
00090                   print ''
00091                   print 'Normalized features:'
00092 
00093                   for g in psp1:
00094                       print g, ' = ',
00095                       v1=psp1[g]
00096                       if v1!='':
00097                          fv=float(v1)
00098 
00099                          # Check if already normalized
00100                          n=''
00101                          for k in feat_desc:
00102                              if 'ft'+g in k:
00103                                 n=k['ft'+g].get('normalized','')
00104                                 break
00105 
00106                          if n=='no': fv=fv/fvfn
00107  
00108                          print "%.4f" % fv
00109 
00110     return {'cm_return':0}

Generated on Wed May 28 02:49:01 2014 for Collective Mind Framework by DoxyGen 1.6.1
Concept, design and coordination: Grigori Fursin (C) 1993-2013