Пример #1
0
def life_eval(actions, stride, hw_spec, df_order=None):
    #function to query chip_estimator and get energy+latency feedback

    #actions: tiling factors for a specific loop-order
    #stride: the stride number for this CONV layer operation
    #hw_spec: hw specs for evaluation
    #df_order: loop-order for evaluation
    #           !!!!if not provided PLS provide it in chip_estimator
    #           !!!!legacy functionality, so always try to provide specific loop-order here
    try:
        #input isolation
        input_actions = dict(actions)
        if df_order:
            input_df_order = list(df_order)
        else:
            input_df_order = None
        ene_results = simnas.sample_energy(input_actions,
                                           stride,
                                           hw_spec,
                                           input_df_order=input_df_order)
        penalty = -(ene_results[0] * 1e-8 * ene_results[1] * 100)
        #print(ene_results[0],ene_results[1])
    #if design hw constraint exceeded,
    #if exceeded return extremely large penalty
    except Exception as e:
        if 'resource' in str(e):
            pass
        else:
            print('error:', e)
            print(actions)
            print(df_order)
        penalty = -9e12  #very strong penalty to over budget
    return penalty
Пример #2
0
def life_eval(actions,stride,hw_spec,mode,group_num=1,df_order=None):
    #function to query chip_estimator and get energy+latency feedback

    #actions: tiling factors for a specific loop-order
    #stride: the stride number for this CONV layer operation
    #hw_spec: hw specs for evaluation
    #df_order: loop-order for evaluation 
    #           !!!!if not provided PLS provide it in chip_estimator
    #           !!!!legacy functionality, so always try to provide specific loop-order here
    try:
        if mode!=2 and group_num!=1:
            print('You did not choose group convolution, please set group num to 1')
            raise
        #input isolation
        input_actions=dict(actions)
        if df_order:
            input_df_order=list(df_order)
        else:
            input_df_order=None
        ene_results=simnas.sample_energy(input_actions,stride,hw_spec,mode,input_df_order=input_df_order)
        penalty=(ene_results[0]*1e-8*group_num,ene_results[1]*100*group_num)
        buffer_not_exceed=True
        #print(ene_results[0],ene_results[1])
    #if design hw constraint exceeded, 
    #if exceeded return extremely large penalty
    except Exception as e:
        if 'resource' in str(e):
            pass
        else:
            print('error:',e)
            print(actions)
            print(df_order)         
        penalty=(9e12,9e12)                                  #very strong penalty to over budget
        buffer_not_exceed=False
    return penalty, buffer_not_exceed
Пример #3
0
def ene_lat_qury(dnn, layer_num):
    #hw settup
    hw_spec={\
    'gb_vol':16*1024*1024, \
    'rf_vol':512*8, \
    'num_pe':824, \
    'num_rf':824
   }

   # hw_spec={ \
   # 'gb_vol':108*1024*8, \
   # 'rf_vol':512*8, \
   # 'num_pe':168, \
   # 'num_rf':168
   # }

    df_order=[['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'batch_gb', 'ch_out_gb', 'ch_in_gb', 'col_out_gb', 'ref_gb_we', 'row_kernel_gb', 'ref_gb_in', 'row_out_gb', 'ref_gb_out', 'col_kernel_gb', 'col_kernel_dram', 'ch_out_dram', 'ch_in_dram', 'col_out_dram', 'batch_dram', 'row_out_dram', 'row_kernel_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'col_out_gb', 'ref_gb_in', 'row_out_gb', 'row_kernel_gb', 'ref_gb_we', 'ch_out_gb', 'ref_gb_out', 'ch_in_gb', 'col_kernel_gb', 'batch_gb', 'row_out_dram', 'col_kernel_dram', 'ch_in_dram', 'col_out_dram', 'row_kernel_dram', 'ch_out_dram', 'batch_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'ch_out_gb', 'col_kernel_gb', 'col_out_gb', 'row_out_gb', 'ref_gb_out', 'batch_gb', 'ref_gb_we', 'ref_gb_in', 'row_kernel_gb', 'ch_in_gb', 'ch_out_dram', 'col_out_dram', 'col_kernel_dram', 'ch_in_dram', 'row_kernel_dram', 'row_out_dram', 'batch_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'row_kernel_gb', 'ref_gb_we', 'ch_in_gb', 'ref_gb_out', 'col_kernel_gb', 'row_out_gb', 'batch_gb', 'ch_out_gb', 'col_out_gb', 'ref_gb_in', 'row_out_dram', 'ch_in_dram', 'row_kernel_dram', 'col_out_dram', 'ch_out_dram', 'batch_dram', 'col_kernel_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'ref_gb_in', 'row_kernel_gb', 'col_out_gb', 'row_out_gb', 'ch_in_gb', 'ref_gb_we', 'batch_gb', 'col_kernel_gb', 'ref_gb_out', 'ch_out_gb', 'ch_in_dram', 'col_kernel_dram', 'col_out_dram', 'ch_out_dram', 'row_out_dram', 'batch_dram', 'row_kernel_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'col_kernel_gb', 'row_kernel_gb', 'batch_gb', 'ch_in_gb', 'ref_gb_we', 'row_out_gb', 'ref_gb_out', 'ch_out_gb', 'ref_gb_in', 'col_out_gb', 'col_kernel_dram', 'ch_out_dram', 'batch_dram', 'row_kernel_dram', 'row_out_dram', 'ch_in_dram', 'col_out_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'row_kernel_gb', 'col_kernel_gb', 'col_out_gb', 'ch_out_gb', 'ref_gb_out', 'ref_gb_in', 'row_out_gb', 'batch_gb', 'ch_in_gb', 'ref_gb_we', 'row_kernel_dram', 'col_out_dram', 'row_out_dram', 'ch_in_dram', 'ch_out_dram', 'col_kernel_dram', 'batch_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'col_out_gb', 'batch_gb', 'row_out_gb', 'ch_out_gb', 'col_kernel_gb', 'row_kernel_gb', 'ref_gb_in', 'ref_gb_out', 'ch_in_gb', 'ref_gb_we', 'ch_in_dram', 'row_out_dram', 'col_out_dram', 'ch_out_dram', 'batch_dram', 'col_kernel_dram', 'row_kernel_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'row_kernel_gb', 'ch_out_gb', 'ref_gb_out', 'col_out_gb', 'row_out_gb', 'ch_in_gb', 'ref_gb_in', 'batch_gb', 'col_kernel_gb', 'ref_gb_we', 'row_kernel_dram', 'ch_in_dram', 'col_kernel_dram', 'row_out_dram', 'ch_out_dram', 'col_out_dram', 'batch_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'ch_out_gb', 'ref_gb_in', 'ref_gb_out', 'row_kernel_gb', 'row_out_gb', 'ref_gb_we', 'col_kernel_gb', 'col_out_gb', 'batch_gb', 'ch_in_gb', 'row_out_dram', 'col_kernel_dram', 'row_kernel_dram', 'batch_dram', 'col_out_dram', 'ch_in_dram', 'ch_out_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'row_kernel_gb', 'row_out_gb', 'ch_in_gb', 'ref_gb_we', 'ref_gb_out', 'ref_gb_in', 'batch_gb', 'col_out_gb', 'col_kernel_gb', 'ch_out_gb', 'ch_in_dram', 'row_kernel_dram', 'row_out_dram', 'col_kernel_dram', 'col_out_dram', 'batch_dram', 'ch_out_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'col_kernel_gb', 'col_out_gb', 'row_out_gb', 'ref_gb_in', 'batch_gb', 'ch_in_gb', 'row_kernel_gb', 'ch_out_gb', 'ref_gb_out', 'ref_gb_we', 'batch_dram', 'row_out_dram', 'ch_out_dram', 'col_out_dram', 'row_kernel_dram', 'col_kernel_dram', 'ch_in_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'col_kernel_gb', 'ref_gb_in', 'row_kernel_gb', 'col_out_gb', 'batch_gb', 'row_out_gb', 'ch_in_gb', 'ch_out_gb', 'ref_gb_we', 'ref_gb_out', 'ch_out_dram', 'col_kernel_dram', 'row_kernel_dram', 'row_out_dram', 'col_out_dram', 'batch_dram', 'ch_in_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'row_kernel_gb', 'col_out_gb', 'row_out_gb', 'ref_gb_out', 'batch_gb', 'ref_gb_in', 'ch_out_gb', 'col_kernel_gb', 'ch_in_gb', 'ref_gb_we', 'row_kernel_dram', 'batch_dram', 'col_out_dram', 'ch_in_dram', 'col_kernel_dram', 'ch_out_dram', 'row_out_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'col_kernel_gb', 'col_out_gb', 'ref_gb_out', 'row_out_gb', 'ch_out_gb', 'row_kernel_gb', 'ref_gb_we', 'ref_gb_in', 'batch_gb', 'ch_in_gb', 'ch_in_dram', 'col_out_dram', 'col_kernel_dram', 'batch_dram', 'ch_out_dram', 'row_out_dram', 'row_kernel_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'ref_gb_in', 'ch_out_gb', 'row_out_gb', 'col_out_gb', 'row_kernel_gb', 'ch_in_gb', 'batch_gb', 'ref_gb_we', 'ref_gb_out', 'col_kernel_gb', 'col_out_dram', 'ch_in_dram', 'batch_dram', 'row_kernel_dram', 'ch_out_dram', 'row_out_dram', 'col_kernel_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'row_kernel_gb', 'ref_gb_in', 'ch_out_gb', 'col_out_gb', 'row_out_gb', 'ref_gb_we', 'ch_in_gb', 'batch_gb', 'col_kernel_gb', 'ref_gb_out', 'col_kernel_dram', 'ch_in_dram', 'col_out_dram', 'row_out_dram', 'ch_out_dram', 'row_kernel_dram', 'batch_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'ch_out_gb', 'ch_in_gb', 'row_out_gb', 'col_out_gb', 'ref_gb_we', 'ref_gb_out', 'ref_gb_in', 'row_kernel_gb', 'batch_gb', 'col_kernel_gb', 'ch_in_dram', 'batch_dram', 'row_kernel_dram', 'col_kernel_dram', 'ch_out_dram', 'col_out_dram', 'row_out_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'ref_gb_we', 'row_out_gb', 'ref_gb_in', 'ch_out_gb', 'col_kernel_gb', 'batch_gb', 'ref_gb_out', 'ch_in_gb', 'col_out_gb', 'row_kernel_gb', 'col_out_dram', 'row_kernel_dram', 'batch_dram', 'col_kernel_dram', 'row_out_dram', 'ch_in_dram', 'ch_out_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'row_kernel_gb', 'col_kernel_gb', 'row_out_gb', 'ref_gb_in', 'ch_in_gb', 'batch_gb', 'ch_out_gb', 'ref_gb_out', 'col_out_gb', 'ref_gb_we', 'ch_out_dram', 'row_out_dram', 'batch_dram', 'row_kernel_dram', 'ch_in_dram', 'col_out_dram', 'col_kernel_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'ch_in_gb', 'col_out_gb', 'batch_gb', 'ref_gb_in', 'row_kernel_gb', 'col_kernel_gb', 'row_out_gb', 'ref_gb_out', 'ref_gb_we', 'ch_out_gb', 'col_kernel_dram', 'ch_out_dram', 'batch_dram', 'ch_in_dram', 'row_out_dram', 'row_kernel_dram', 'col_out_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'col_kernel_gb', 'row_kernel_gb', 'row_out_gb', 'col_out_gb', 'ch_out_gb', 'ch_in_gb', 'batch_gb', 'ref_gb_we', 'ref_gb_in', 'ref_gb_out', 'row_out_dram', 'batch_dram', 'row_kernel_dram', 'ch_in_dram', 'ch_out_dram', 'col_kernel_dram', 'col_out_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'row_out_gb', 'ch_out_gb', 'ref_gb_we', 'col_kernel_gb', 'ch_in_gb', 'ref_gb_out', 'ref_gb_in', 'batch_gb', 'row_kernel_gb', 'col_out_gb', 'col_kernel_dram', 'ch_out_dram', 'row_out_dram', 'row_kernel_dram', 'col_out_dram', 'batch_dram', 'ch_in_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'ch_in_gb', 'col_kernel_gb', 'col_out_gb', 'row_kernel_gb', 'ref_gb_we', 'ch_out_gb', 'ref_gb_out', 'batch_gb', 'row_out_gb', 'ref_gb_in', 'row_kernel_dram', 'col_out_dram', 'row_out_dram', 'batch_dram', 'col_kernel_dram', 'ch_out_dram', 'ch_in_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'row_kernel_gb', 'col_kernel_gb', 'row_out_gb', 'col_out_gb', 'batch_gb', 'ref_gb_in', 'ref_gb_out', 'ch_in_gb', 'ch_out_gb', 'ref_gb_we', 'row_kernel_dram', 'col_kernel_dram', 'batch_dram', 'row_out_dram', 'ch_in_dram', 'col_out_dram', 'ch_out_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'row_kernel_gb', 'ch_out_gb', 'col_out_gb', 'ch_in_gb', 'row_out_gb', 'batch_gb', 'col_kernel_gb', 'ref_gb_we', 'ref_gb_out', 'ref_gb_in', 'col_out_dram', 'batch_dram', 'row_kernel_dram', 'col_kernel_dram', 'row_out_dram', 'ch_out_dram', 'ch_in_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'col_out_gb', 'row_kernel_gb', 'ref_gb_in', 'ch_in_gb', 'ref_gb_out', 'row_out_gb', 'batch_gb', 'ref_gb_we', 'ch_out_gb', 'col_kernel_gb', 'row_kernel_dram', 'ch_out_dram', 'batch_dram', 'ch_in_dram', 'row_out_dram', 'col_kernel_dram', 'col_out_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'batch_gb', 'ref_gb_in', 'ch_in_gb', 'col_kernel_gb', 'row_out_gb', 'ref_gb_out', 'ch_out_gb', 'row_kernel_gb', 'col_out_gb', 'ref_gb_we', 'row_out_dram', 'col_kernel_dram', 'ch_in_dram', 'row_kernel_dram', 'col_out_dram', 'batch_dram', 'ch_out_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'batch_gb', 'ch_in_gb', 'ref_gb_out', 'row_out_gb', 'ch_out_gb', 'row_kernel_gb', 'ref_gb_we', 'ref_gb_in', 'col_kernel_gb', 'col_out_gb', 'ch_out_dram', 'col_out_dram', 'col_kernel_dram', 'batch_dram', 'row_out_dram', 'row_kernel_dram', 'ch_in_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'ch_out_gb', 'col_kernel_gb', 'row_out_gb', 'ref_gb_out', 'ref_gb_in', 'ref_gb_we', 'batch_gb', 'col_out_gb', 'row_kernel_gb', 'ch_in_gb', 'col_out_dram', 'row_kernel_dram', 'col_kernel_dram', 'batch_dram', 'ch_in_dram', 'row_out_dram', 'ch_out_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'batch_gb', 'row_out_gb', 'ch_in_gb', 'col_out_gb', 'ref_gb_out', 'ch_out_gb', 'col_kernel_gb', 'row_kernel_gb', 'ref_gb_in', 'ref_gb_we', 'batch_dram', 'col_kernel_dram', 'ch_in_dram', 'row_out_dram', 'ch_out_dram', 'row_kernel_dram', 'col_out_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'ch_out_gb', 'row_out_gb', 'ref_gb_out', 'ref_gb_in', 'col_kernel_gb', 'row_kernel_gb', 'ch_in_gb', 'batch_gb', 'ref_gb_we', 'col_out_gb', 'ch_out_dram', 'row_kernel_dram', 'row_out_dram', 'col_kernel_dram', 'col_out_dram', 'ch_in_dram', 'batch_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'row_kernel_gb', 'ch_out_gb', 'row_out_gb', 'col_kernel_gb', 'ref_gb_we', 'ref_gb_in', 'col_out_gb', 'ch_in_gb', 'ref_gb_out', 'batch_gb', 'ch_out_dram', 'ch_in_dram', 'col_kernel_dram', 'row_kernel_dram', 'col_out_dram', 'batch_dram', 'row_out_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'ref_gb_in', 'row_out_gb', 'ref_gb_we', 'row_kernel_gb', 'col_kernel_gb', 'ch_out_gb', 'col_out_gb', 'ref_gb_out', 'batch_gb', 'ch_in_gb', 'batch_dram', 'ch_in_dram', 'col_kernel_dram', 'ch_out_dram', 'row_kernel_dram', 'col_out_dram', 'row_out_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'batch_gb', 'ref_gb_in', 'row_kernel_gb', 'ref_gb_out', 'ch_in_gb', 'ref_gb_we', 'col_out_gb', 'ch_out_gb', 'col_kernel_gb', 'row_out_gb', 'row_out_dram', 'row_kernel_dram', 'batch_dram', 'ch_out_dram', 'ch_in_dram', 'col_kernel_dram', 'col_out_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'ch_in_gb', 'ref_gb_out', 'row_out_gb', 'ch_out_gb', 'ref_gb_we', 'ref_gb_in', 'batch_gb', 'col_kernel_gb', 'col_out_gb', 'row_kernel_gb', 'col_kernel_dram', 'row_out_dram', 'col_out_dram', 'ch_in_dram', 'ch_out_dram', 'batch_dram', 'row_kernel_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'col_kernel_gb', 'ch_in_gb', 'ch_out_gb', 'ref_gb_in', 'batch_gb', 'row_out_gb', 'row_kernel_gb', 'ref_gb_out', 'col_out_gb', 'ref_gb_we', 'row_kernel_dram', 'col_kernel_dram', 'ch_in_dram', 'row_out_dram', 'col_out_dram', 'ch_out_dram', 'batch_dram'], ['col_kernel_noc', 'ch_in_noc', 'col_out_noc', 'ch_out_noc', 'ch_in_gb', 'ref_gb_we', 'row_out_gb', 'ch_out_gb', 'ref_gb_out', 'row_kernel_gb', 'col_out_gb', 'col_kernel_gb', 'ref_gb_in', 'batch_gb', 'row_out_dram', 'col_out_dram', 'col_kernel_dram', 'row_kernel_dram', 'batch_dram', 'ch_in_dram', 'ch_out_dram']]
    (tiling_pool,alloc_slots)=fpga_tiling_generator(dnn,hw_spec['gb_vol'],hw_spec['num_pe'])
    score,best_dict=random_life([df_order[layer_num]],tiling_pool,[dnn[0][0]],hw_spec,alloc_slots,1,return_best_dict=True)
    ene_results=simnas.sample_energy(best_dict[0],dnn[0][0],hw_spec,df_order[layer_num])
    return ene_results[0], ene_results[1]