# # Collective Knowledge (ccprof workflow) # # See CK LICENSE.txt for licensing details # See CK COPYRIGHT.txt for copyright details # # Developer: # cfg={} # Will be updated by CK (meta description of this module) work={} # Will be updated by CK (temporal data) ck=None # Will be updated by CK (initialized CK kernel) # Local settings import os ############################################################################## # Initialize module def init(i): """ Input: {} Output: { return - return code = 0, if successful > 0, if error (error) - error text if return > 0 } """ return {'return':0} ############################################################################## # run workflow def run_cache_stat(i): """ Input: { } Output: { return - return code = 0, if successful > 0, if error (error) - error text if return > 0 } """ prog_uoa=i.get('data_uoa','') # This allows you to run "ck run_cache_stat ccprof:{NAME OF CK PROGRAM}" # where data_uoa=={NAME OF CK PROGRAM} if prog_uoa=='': prog_uoa='tinydnn-representative-pad' # Set env for HPC ToolKit libmonitor ck.out('*********************************************************************') ck.out('Preparing environment for HPC ToolKit libmonitor ...') ck.out('') r=ck.access({'action':'set', 'module_uoa':cfg['module_deps']['env'], 'tags':'lib,hpctoolkit-libmonitor', 'out':'con'}) if r['return']>0: return r #Print output to check API #ck.debug_out(r) monitor_bat=r['bat'] # Compile TinyDNN representative pad ck.out('*********************************************************************') ck.out('Compiling TinyDNN representative pad (-g -O3) ...') ck.out('') r=ck.access({'action':'compile', 'module_uoa':cfg['module_deps']['program'], 'data_uoa':prog_uoa, 'flags':'-g -O3', 'out':'con'}) if r['return']>0: return r #Print output to check API #ck.debug_out(r) characteristics=r.get('characteristics',{}) success=characteristics.get('compilation_success_bool',False) if not success: return {'return':1, 'error':'compilation failed'} path=r.get('tmp_dir','') misc=r.get('misc',{}) target_exe=misc.get('target_exe','') full_path_to_bin=os.path.join(path,target_exe) # Run program r=ck.access({'action':'run', 'module_uoa':cfg['module_deps']['program'], 'data_uoa':prog_uoa, 'extra_env':monitor_bat, 'pre_run_cmd':'OMP_NUM_THREADS=1 sudo ${CK_ENV_LIB_PAPI_SRC}/libpfm4/perf_examples/task -e L1-DCACHE-LOADS -e L1-DCACHE-LOAD-MISSES -e LLC_MISSES -e LLC_REFERENCES', 'out':'con'}) if r['return']>0: return r #Print output to check API #ck.debug_out(r) characteristics=r.get('characteristics',{}) success=characteristics.get('run_success_bool',False) if not success: return {'return':1, 'error':'execution failed'} # Postprocess HPCToolkit stats os.chdir(path) r=ck.access({'action':'run', 'module_uoa':cfg['module_deps']['script'], 'data_uoa':'postprocess-hpctoolkit', 'code':'process', 'func':'parse_output'}) if r['return']>0: return r d=r['dict'] ck.out('') ck.out('Cache stats:') ck.out('') for k in sorted(d): ck.out(' * '+k+' : '+d[k]) return {'return':0}