def run(self, net): print(test_dir) instrndir = compiler_path + net #tracedir = os.path.join(os.path.join(test_dir, 'traces'), net.split('/')[-1]) tracedir = trace_path + net print("Inst directory: ", instrndir) print("Trace directory: ", tracedir) if cfg.authenticated: f = Factory() puma_cypher_hash = f.auth(cfg.cypher_hash) if not puma_cypher_hash.authenticateModel(instrndir): print("Model not authenticated") sys.exit(1) if not puma_cypher_hash.authenticateInput(instrndir): print("Input not authenticated") sys.exit(1) if cfg.encrypted: f = Factory() puma_crypto = f.crypto(cfg.cypher_name) puma_crypto.decrypt(instrndir) assert ( os.path.exists(instrndir) == 1 ), 'Instructions for net missing: generate intuctions (in folder hierarchy) hierarchy' '''if not os.path.exists(instrndir): os.makedirs(instrndir) for i in range (cfg.num_tile): temp_tiledir = instrndir + '/tile' + str(i) os.makedirs(temp_tiledir)''' if not os.path.exists(tracedir): os.makedirs(tracedir) for i in range(cfg.num_tile): temp_tiledir = tracedir + '/tile' + str(i) if not os.path.exists(temp_tiledir): os.makedirs(temp_tiledir) self.instrnpath = instrndir + '/' self.tracepath = tracedir + '/' # Instantiate the node under test # A physical node consists of several logical nodes equal to the actual node size node_dut = node.node() # Initialize the node with instrn & trace paths # instrnpath provides instrns for tile & resident imas # tracepath is where all tile & ima traces will be stored node_dut.node_init(self.instrnpath, self.tracepath) # Read the input data (input.t7) into the input tile's edram inp_filename = os.path.join(str(self.instrnpath), 'input.npy') inp_tileId = 0 assert (os.path.exists(inp_filename) ), 'Input Error: Provide input before running the DPE' assert (os.path.exists(instrndir + '/' + 'tile0') ), 'Input Error: Provide input before running the DPE' inp = np.load(inp_filename, allow_pickle=True).item() print('length of input data:', len(inp['data'])) for i in range(len(inp['data'])): data = float2fixed(inp['data'][i], cfg.int_bits, cfg.frac_bits) node_dut.tile_list[inp_tileId].edram_controller.mem.memfile[ i] = data node_dut.tile_list[inp_tileId].edram_controller.counter[i] = int( inp['counter'][i]) node_dut.tile_list[inp_tileId].edram_controller.valid[i] = int( inp['valid'][i]) #program the X-bars with weights using the dnn_wt_p.dnn_wt() API dnn_wt_p.dnn_wt().prog_dnn_wt(self.instrnpath, node_dut) # Run all the tiles cycle = 0 start = time.time() while (not node_dut.node_halt and cycle < cfg.cycles_max): node_dut.node_run(cycle) cycle = cycle + 1 end = time.time() print('simulation time: ' + str(end - start) + 'secs') # For DEBUG only - dump the contents of all tiles # NOTE: Output and input tiles are dummy tiles to enable self-contained simulation if (cfg.debug): node_dump(node_dut, self.tracepath) if (cfg.xbar_record): record_xbar(node_dut) # Dump the contents of output tile (DNN output) to output file (output.txt) output_file = self.tracepath + 'output.txt' fid = open(output_file, 'w') tile_id = cfg.num_tile - 1 mem_dump(fid, node_dut.tile_list[tile_id].edram_controller.mem.memfile, 'EDRAM') fid.close() print('Output Tile dump finished') # Dump the harwdare access traces (For now - later upgrade to actual energy numbers) hwtrace_file = self.tracepath + 'harwdare_stats.txt' fid = open(hwtrace_file, 'w') metric_dict = get_hw_stats(fid, node_dut, cycle) fid.close() print('Success: Hardware results compiled!!')
#**************************************************************************************** # Designed by - Guilherme Maurer # Miguel Xavier # Plinio Silveira # Yago Liborio # Pontifical Catholic University of Rio Grande do Sul # # GenerateMAC - A script that calls functions to generate MAC for Model and Input # #**************************************************************************************** from Factory import Factory import sys if __name__ == "__main__": cypher_hash = sys.argv[1] path = sys.argv[2] f = Factory() puma_cypher_hash = f.auth(cypher_hash) puma_cypher_hash.generateMACModel(path) puma_cypher_hash.generateMACInput(path)