Esempio n. 1
0
 def __init__(self,
              NetStruct,
              SimConfig_path,
              model_power=None,
              model_latency=None,
              multiple=None,
              TCG_mapping=None):
     self.NetStruct = NetStruct
     self.SimConfig_path = SimConfig_path
     modelL_config = cp.ConfigParser()
     modelL_config.read(self.SimConfig_path, encoding='UTF-8')
     NoC_Compute = int(
         modelL_config.get('Algorithm Configuration', 'NoC_enable'))
     if multiple is None:
         multiple = [1] * len(self.NetStruct)
     if TCG_mapping is None:
         TCG_mapping = TCG(NetStruct, SimConfig_path, multiple)
     self.graph = TCG_mapping
     self.total_layer_num = self.graph.layer_num
     if model_latency is None:
         self.model_latency = Model_latency(NetStruct, SimConfig_path,
                                            multiple, TCG_mapping)
         self.model_latency.calculate_model_latency(mode=2)
     else:
         self.model_latency = model_latency
     if model_power is None:
         self.model_power = Model_inference_power(NetStruct, SimConfig_path,
                                                  multiple, TCG_mapping)
     else:
         self.model_power = model_power
     self.arch_energy = self.total_layer_num * [0]
     self.arch_xbar_energy = self.total_layer_num * [0]
     self.arch_ADC_energy = self.total_layer_num * [0]
     self.arch_DAC_energy = self.total_layer_num * [0]
     self.arch_digital_energy = self.total_layer_num * [0]
     self.arch_adder_energy = self.total_layer_num * [0]
     self.arch_shiftreg_energy = self.total_layer_num * [0]
     self.arch_iReg_energy = self.total_layer_num * [0]
     self.arch_oReg_energy = self.total_layer_num * [0]
     self.arch_input_demux_energy = self.total_layer_num * [0]
     self.arch_output_mux_energy = self.total_layer_num * [0]
     self.arch_jointmodule_energy = self.total_layer_num * [0]
     self.arch_buf_energy = self.total_layer_num * [0]
     self.arch_buf_r_energy = self.total_layer_num * [0]
     self.arch_buf_w_energy = self.total_layer_num * [0]
     self.arch_pooling_energy = self.total_layer_num * [0]
     self.arch_total_energy = 0
     self.arch_total_xbar_energy = 0
     self.arch_total_ADC_energy = 0
     self.arch_total_DAC_energy = 0
     self.arch_total_digital_energy = 0
     self.arch_total_adder_energy = 0
     self.arch_total_shiftreg_energy = 0
     self.arch_total_iReg_energy = 0
     self.arch_total_input_demux_energy = 0
     self.arch_total_jointmodule_energy = 0
     self.arch_total_buf_energy = 0
     self.arch_total_buf_r_energy = 0
     self.arch_total_buf_w_energy = 0
     self.arch_total_output_mux_energy = 0
     self.arch_total_pooling_energy = 0
     if NoC_Compute == 1:
         path = os.getcwd() + '/Final_Results/'
         data = pd.read_csv(path + 'Energy.csv')
         self.arch_Noc_energy = float(data.columns[0].split(' ')[-2]) * 1e-3
     else:
         self.arch_Noc_energy = 0
     # print("**********************************")
     # print(self.arch_Noc_energy)
     self.calculate_model_energy()
Esempio n. 2
0
            # print("		NoC part area:", self.arch_Noc_area, "um^2")
        if layer_information:
            for i in range(self.total_layer_num):
                print("Layer", i, ":")
                layer_dict = self.NetStruct[i][0][0]
                if layer_dict['type'] == 'element_sum':
                    print(
                        "     Hardware area (global accumulator):",
                        self.global_add.adder_area *
                        self.graph.global_adder_num + self.global_buf.buf_area,
                        "um^2")
                else:
                    print("     Hardware area:", self.arch_area[i], "um^2")


if __name__ == '__main__':
    test_SimConfig_path = os.path.join(
        os.path.dirname(os.path.dirname(os.getcwd())), "SimConfig.ini")
    test_weights_file_path = os.path.join(
        os.path.dirname(os.path.dirname(os.getcwd())), "vgg8_params.pth")

    __TestInterface = TrainTestInterface('vgg8_128_9',
                                         'MNSIM.Interface.cifar10',
                                         test_SimConfig_path,
                                         test_weights_file_path)
    structure_file = __TestInterface.get_structure()
    __TCG_mapping = TCG(structure_file, test_SimConfig_path)
    __area = Model_area(NetStruct=structure_file,
                        SimConfig_path=test_SimConfig_path,
                        TCG_mapping=__TCG_mapping)
    __area.model_area_output(1, 1)
Esempio n. 3
0
def main():
    # home_path = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
    # print("home path", home_path)
    # if __name__=='__main__':
    #     home_path = os.path.dirname(os.path.dirname(os.getcwd()))
    #     print(1)
    # else:
    home_path = os.getcwd()
    # print(home_path)
    SimConfig_path = os.path.join(home_path, "SimConfig.ini")
    weights_file_path = os.path.join(home_path, "vgg16_params.pth")
    # print(SimConfig_path)
    parser = argparse.ArgumentParser(description='MNSIM example')
    parser.add_argument(
        "-AutoDelete",
        "--file_auto_delete",
        default=True,
        help="Whether delete the unnecessary files automatically")
    # parser.add_argument("-NoC", "--NoC_computation", default=False,
    #                     help="Whether call booksim to compute the NoC part")
    parser.add_argument(
        "-HWdes",
        "--hardware_description",
        default=SimConfig_path,
        help=
        "Hardware description file location & name, default:/MNSIM_Python/SimConfig.ini"
    )
    parser.add_argument(
        "-Weights",
        "--weights",
        default=weights_file_path,
        help=
        "NN model weights file location & name, default:/MNSIM_Python/vgg8_params.pth"
    )
    parser.add_argument(
        "-NN",
        "--NN",
        default='vgg16',
        help="NN model description (name), default: vgg8_128_9")
    parser.add_argument("-DisHW",
                        "--disable_hardware_modeling",
                        action='store_true',
                        default=False,
                        help="Disable hardware modeling, default: false")
    parser.add_argument("-DisAccu",
                        "--disable_accuracy_simulation",
                        action='store_true',
                        default=False,
                        help="Disable accuracy simulation, default: false")
    parser.add_argument("-SAF",
                        "--enable_SAF",
                        action='store_true',
                        default=False,
                        help="Enable simulate SAF, default: false")
    parser.add_argument("-Var",
                        "--enable_variation",
                        action='store_true',
                        default=False,
                        help="Enable simulate variation, default: false")
    parser.add_argument(
        "-FixRange",
        "--enable_fixed_Qrange",
        action='store_true',
        default=False,
        help="Enable fixed quantization range (max value), default: false")
    parser.add_argument(
        "-DisPipe",
        "--disable_inner_pipeline",
        action='store_true',
        default=False,
        help="Disable inner layer pipeline in latency modeling, default: false"
    )
    parser.add_argument(
        "-D",
        "--device",
        default=0,
        help="Determine hardware device for simulation, default: CPU")
    parser.add_argument(
        "-DisModOut",
        "--disable_module_output",
        action='store_true',
        default=False,
        help="Disable module simulation results output, default: false")
    parser.add_argument(
        "-DisLayOut",
        "--disable_layer_output",
        action='store_true',
        default=False,
        help="Disable layer-wise simulation results output, default: false")
    args = parser.parse_args()
    if args.file_auto_delete:
        print("use the root mode by 'sudo -s'")
        Data_clean()
    else:
        print(
            "You should make sure that the files are removed which may cause confusions"
        )
    print("Hardware description file location:", args.hardware_description)
    print("Software model file location:", args.weights)
    print("Whether perform hardware simulation:",
          not (args.disable_hardware_modeling))
    print("Whether perform accuracy simulation:",
          not (args.disable_accuracy_simulation))
    print("Whether consider SAFs:", args.enable_SAF)
    print("Whether consider variations:", args.enable_variation)
    if args.enable_fixed_Qrange:
        print("Quantization range: fixed range (depends on the maximum value)")
    else:
        print(
            "Quantization range: dynamic range (depends on the data distribution)"
        )
    # __TestInterface = TrainTestInterface(args.NN, 'MNSIM.Interface.cifar10', args.hardware_description,
    #                                      args.weights, args.device)
    __TestInterface = TrainTestInterface(
        network_module=args.NN,
        dataset_module='MNSIM.Interface.cifar10',
        SimConfig_path=args.hardware_description,
        device=args.device)
    structure_file = __TestInterface.get_structure()
    weight = __TestInterface.get_net_bits()
    # print(structure_file)
    # print(__TestInterface.origin_evaluate(method = 'FIX_TRAIN', adc_action = 'SCALE'))
    # print(__TestInterface.set_net_bits_evaluate(weight, adc_action = 'SCALE'))
    TCG_mapping = TCG(structure_file, args.hardware_description)
    #print(TCG_mapping.max_inbuf_size)
    #print(TCG_mapping.max_outbuf_size)
    if not (args.disable_hardware_modeling):
        __latency = Model_latency(NetStruct=structure_file,
                                  SimConfig_path=args.hardware_description,
                                  TCG_mapping=TCG_mapping)
        if not (args.disable_inner_pipeline):
            __latency.calculate_model_latency(mode=1)
            # __latency.calculate_model_latency_nopipe()
        else:
            __latency.calculate_model_latency_nopipe()
        print(
            "========================Latency Results================================="
        )
        __latency.model_latency_output(not (args.disable_module_output),
                                       not (args.disable_layer_output))

        __area = Model_area(NetStruct=structure_file,
                            SimConfig_path=args.hardware_description,
                            TCG_mapping=TCG_mapping)
        print(
            "========================Area Results================================="
        )
        __area.model_area_output(not (args.disable_module_output),
                                 not (args.disable_layer_output))
        __power = Model_inference_power(
            NetStruct=structure_file,
            SimConfig_path=args.hardware_description,
            TCG_mapping=TCG_mapping)
        print(
            "========================Power Results================================="
        )
        __power.model_power_output(not (args.disable_module_output),
                                   not (args.disable_layer_output))
        __energy = Model_energy(NetStruct=structure_file,
                                SimConfig_path=args.hardware_description,
                                TCG_mapping=TCG_mapping,
                                model_latency=__latency,
                                model_power=__power)
        print(
            "========================Energy Results================================="
        )
        __energy.model_energy_output(not (args.disable_module_output),
                                     not (args.disable_layer_output))

    if (args.disable_accuracy_simulation):
        print("======================================")
        print("Accuracy simulation will take a few minutes on GPU")
        weight = __TestInterface.get_net_bits()
        weight_2 = weight_update(args.hardware_description,
                                 weight,
                                 is_Variation=args.enable_variation,
                                 is_SAF=args.enable_SAF)
        if not (args.enable_fixed_Qrange):
            print(
                "Original accuracy:",
                __TestInterface.origin_evaluate(method='FIX_TRAIN',
                                                adc_action='SCALE'))
            print(
                "PIM-based computing accuracy:",
                __TestInterface.set_net_bits_evaluate(weight_2,
                                                      adc_action='SCALE'))
        else:
            print(
                "Original accuracy:",
                __TestInterface.origin_evaluate(method='FIX_TRAIN',
                                                adc_action='FIX'))
            print(
                "PIM-based computing accuracy:",
                __TestInterface.set_net_bits_evaluate(weight_2,
                                                      adc_action='FIX'))