input_num = 1 input_size = [1, H[layer][2]] ################# # 最后评估一下整个系统的DDR读写负荷 print( "\n\nDDR-READ = %d, DDR_WRITE=%d, \nTOTAL-TIME[estimated in 50 MHz]=%f ms" % (DDR_READ, DDR_WRITE, (DDR_READ + DDR_WRITE) / 50e6 * 1e3)) return dict_para, inst_set ######################################### # 测试用 if __name__ == '__main__': #%% 用H表征网络结构,P来表征参数,用D来表征数据 H = gen_cnn.generate_cnn() para_dict, inst_set = generate_npu_inst(H) #print(inst_set) # 将指令保存到c_api文件中 fp = open("./c_api/inst.txt", "w") for i in range(0, len(inst_set)): fp.write("%s\n" % (inst_set[i])) fp.close() # 参数所在的位置是 # 创建一个内存初始化文件 fp = open("./c_api/para.txt", "w") # 首先将参数存储起来 for para in para_dict: # 参数所在的地址
for j in range(W): fp.write("%08X\n" % (int(img[i, j]))) fp.close() #%% 然后要将CRLF转化 subprocess.call(".\c_api\change_crlf.exe %s" % (filename)) #%% 然后是modelsim仿真文件 # 生成待检测样本 image = np.zeros((H, W, 4), dtype=np.float) for i in range(0, 4): image[:, :, i] = np.reshape(x[:, i], (H, W)) image = image / 65536.0 #%% 用H表征网络结构,P来表征参数,用D来表征数据 model = gen_cnn.generate_cnn() conv_out = test_npu_inst.generate_test_file( image, model, "./ver_compare/data_under_test.tb.list") para_dict, inst_set = test_npu_inst.generate_npu_inst(model) # 创建一个内存初始化文件 fp = open("./sim_source/data_under_test.tb.list", "w") fp_a = open("./sim_source/data_under_test_da.tb.list", "w") fp_b = open("./sim_source/data_under_test_db.tb.list", "w") fp_c = open("./sim_source/data_under_test_dc.tb.list", "w") fp_d = open("./sim_source/data_under_test_dd.tb.list", "w") # 首先将参数存储起来 for para in para_dict: # 参数所在的地址 fp.write("@%08X\n" % (para_dict[para])) fp_a.write("@%08X\n" % (para_dict[para])) fp_b.write("@%08X\n" % (para_dict[para]))