# # Convert raw output of the Caffe 'time' command # to the CK timing format. # # Developers: # - Grigori Fursin, cTuning foundation / dividiti, 2016 # - Anton Lokhmotov, dividiti, 2016-2017 # import json import os import re import sys def ck_postprocess(i): ck=i['ck_kernel'] rt=i['run_time'] deps=i['deps'] d={} env=i.get('env',{}) # Load both stderr and stdout. Concatenate into one list. # NB: This assumes that Caffe iterates only once (--iterations=1). # Otherwise, looping over the log would be required. rf1=rt['run_cmd_out1'] rf2=rt['run_cmd_out2'] lst=[] if os.path.isfile(rf1): r=ck.load_text_file({'text_file':rf1,'split_to_list':'yes'}) if r['return']>0: return r lst+=r['lst'] if os.path.isfile(rf2): r=ck.load_text_file({'text_file':rf2,'split_to_list':'yes'}) if r['return']>0: return r lst+=r['lst'] d['per_layer_info']=[] layer_index = 0 # The new prototxt format includes data layer but for compatibility # with stale branches (notably, with NVIDIA's fp16) we converted # the AlexNet, GoogleNet and SqueezeNet 1.1 models to the old # prototxt format. For compatibility with experimental data obtained # before this conversion (e.g. on the GTX 1080), we can emulate the # presence of the data layer. It shouldn't be needed for new experiments. emulate_data_layer = False if emulate_data_layer: for direction in ['forward','backward']: data_layer_info = {} data_layer_info['direction'] = direction data_layer_info['index'] = layer_index data_layer_info['label'] = "00: data" data_layer_info['time_ms'] = 0.0 data_layer_info['time_s'] = 0.0 data_layer_info['timestamp'] = "0101 00:00:00.000000" d['per_layer_info'].append(data_layer_info) layer_index = 1 d['REAL_ENV_CK_CAFFE_BATCH_SIZE']=env.get('CK_CAFFE_BATCH_SIZE','') d['REAL_ENV_CK_CAFFE_ITERATIONS']=env.get('CK_CAFFE_ITERATIONS','') d['REAL_ENV_CK_CAFFE_MODEL']=env.get('CK_CAFFE_MODEL','') for line in lst: # Update for Android (minor hack) line=line.replace('..\\caffe','caffe') line=line.replace('../caffe','caffe') # Match layer info. layer_regex = \ 'I(?P\d{4}(\s+)\d{2}:\d{2}:\d{2}\.\d{6})' + \ '(\s+)(?P\d+)(\s+)' + \ 'caffe(\w*)\.cpp:\d{3,4}](\s+)' + \ '(?P