def main(argv): if len(argv) > 1: raise app.UsageError("Unrecognized command line flags.") #################################################################################################################### # Setup # Get flag values embeddings = task_utils.ReadEmbeddingFileFromFlags() input_data = FLAGS.input_data out = FLAGS.out if not os.path.exists(out): os.makedirs(out) device = FLAGS.device assert device in [ "all", "Cypress", "Tahiti", "Fermi", "Kepler", ], "Choose device among: all, Cypress, Tahiti, Fermi, Kepler" dense_layer_size = FLAGS.dense_layer print_summary = FLAGS.print_summary num_epochs = FLAGS.num_epochs batch_size = FLAGS.batch_size # Unpack data archive if necessary. if not os.path.exists(os.path.join(input_data, "kernels_ir")): dataset = bazelutil.DataArchive( "phd/deeplearning/ncc/published_results/task_threadcoarsening.zip") dataset.ExtractAll(pathlib.Path(input_data)) with vocabulary.VocabularyZipFile(FLAGS.vocabulary_zip_path) as vocab: task_utils.CreateSeqDirFromIr(os.path.join(input_data, "kernels_ir"), vocab) #################################################################################################################### # Reference values # Values copied from papers and github magni_pl_sp_vals = [1.21, 1.01, 0.86, 0.94] magni_sp_mean = 1.005 deeptune_pl_sp_vals = [1.10, 1.05, 1.10, 0.99] deeptune_sp_mean = 1.06 deeptuneTL_pl_sp_vals = [1.17, 1.23, 1.14, 0.93] deeptuneTL_sp_mean = 1.1175 #################################################################################################################### # Train model # Evaluate NCC_threadcoarsening print("\nEvaluating NCC_threadcoarsening ...") ncc_threadcoarsening = evaluate( NCC_threadcoarsening(), device, input_data, out, embeddings, dense_layer_size, print_summary, num_epochs, batch_size, ) #################################################################################################################### # Print results print( "\n", ncc_threadcoarsening.groupby("Platform")["Platform", "Speedup", "Oracle"].mean(), ) d = np.array([ncc_threadcoarsening[["Speedup", "Oracle"]].mean()]).T print( "\n", pd.DataFrame(d, columns=["DeepTuneInst2Vec"], index=["Speedup", "Oracle"]), ) # Model comparison: speedups print("\nModel comparison: speedups") d = list() d.append(np.append(magni_pl_sp_vals, magni_sp_mean)) d.append(np.append(deeptune_pl_sp_vals, deeptune_sp_mean)) d.append(np.append(deeptuneTL_pl_sp_vals, deeptuneTL_sp_mean)) d.append( np.append( ncc_threadcoarsening.groupby(["Platform" ])["Speedup"].mean().values, ncc_threadcoarsening["Speedup"].mean(), )) if FLAGS.device == "all": d = np.array(d).T.reshape(5, 4) devs = [ "AMD Radeon HD 5900", "AMD Tahiti 7970", "NVIDIA GTX 480", "NVIDIA Tesla K20c", "Average", ] else: d = np.array(d).T.reshape(1, 4) devs = [_FLAG_TO_DEVICE_NAME[FLAGS.device]] print( "\n", pd.DataFrame( d, columns=[ "Magni et al.", "DeepTune", "DeepTuneTL", "DeepTuneInst2Vec" ], index=devs, ), )
def main(argv): if len(argv) > 1: raise app.UsageError("Unrecognized command line flags.") #################################################################################################################### # Setup # Get flag values embeddings = task_utils.ReadEmbeddingFileFromFlags() folder_results = FLAGS.out assert ( len(folder_results) > 0 ), "Please specify a path to the results folder using --folder_results" folder_data = FLAGS.input_data dense_layer_size = FLAGS.dense_layer print_summary = FLAGS.print_summary num_epochs = FLAGS.num_epochs batch_size = FLAGS.batch_size train_samples = FLAGS.train_samples pathlib.Path(folder_data).mkdir(parents=True, exist_ok=True) # Acquire data if not os.path.exists(folder_data + "_train"): # Download data task_utils.download_and_unzip( "https://polybox.ethz.ch/index.php/s/JOBjrfmAjOeWCyl/download", "classifyapp_training_data", folder_data, ) with vocabulary.VocabularyZipFile(FLAGS.vocabulary_zip_path) as vocab: task_utils.CreateSeqDirFromIr(folder_data + "_train", vocab) assert os.path.exists(folder_data + "_val"), ("Folder not found: " + folder_data + "_val") task_utils.CreateSeqDirFromIr(folder_data + "_val", vocab) assert os.path.exists(folder_data + "_test"), ("Folder not found: " + folder_data + "_test") task_utils.CreateSeqDirFromIr(folder_data + "_test", vocab) # Create directories if they do not exist if not os.path.exists(folder_results): os.makedirs(folder_results) if not os.path.exists(os.path.join(folder_results, "models")): os.makedirs(os.path.join(folder_results, "models")) if not os.path.exists(os.path.join(folder_results, "predictions")): os.makedirs(os.path.join(folder_results, "predictions")) #################################################################################################################### # Train model # Evaluate Classifyapp print("\nEvaluating ClassifyappInst2Vec ...") classifyapp_accuracy = evaluate( NCC_classifyapp(), embeddings, folder_data, train_samples, folder_results, dense_layer_size, print_summary, num_epochs, batch_size, ) #################################################################################################################### # Print results print( "\nTest accuracy:", sum(classifyapp_accuracy) * 100 / len(classifyapp_accuracy), "%", )
def test_CreateSeqDirFromIr_creates_directory( llvm_ir_dir: str, vocab: vocabulary.VocabularyZipFile): """Test that sequence directory is returned.""" sequence_folder = pathlib.Path( task_utils.CreateSeqDirFromIr(llvm_ir_dir, vocab)) assert sequence_folder.is_dir()
def test_CreateSeqDirFromIr_creates_csv_file( llvm_ir_dir: str, vocab: vocabulary.VocabularyZipFile): """Test that CSV file is created.""" sequence_folder = pathlib.Path( task_utils.CreateSeqDirFromIr(llvm_ir_dir, vocab)) assert (sequence_folder / "program_seq.csv").is_file()
def main(argv): if len(argv) > 1: raise app.UsageError("Unrecognized command line flags.") # Don't truncate output when printing pandas tables. pd.set_option("display.max_columns", None) pd.set_option("display.max_rows", None) # Setup # Get flag values embeddings = task_utils.ReadEmbeddingFileFromFlags() out = FLAGS.out if not os.path.exists(out): os.makedirs(out) device = FLAGS.device assert device in [ "all", "amd", "nvidia", ], "Choose device among: all, amd, nvidia" dense_layer_size = FLAGS.dense_layer print_summary = FLAGS.print_summary num_epochs = FLAGS.num_epochs batch_size = FLAGS.batch_size input_data = FLAGS.input_data # Unpack data archive if necessary. if not os.path.exists(os.path.join(input_data, "kernels_ir")): dataset = bazelutil.DataArchive( "phd/deeplearning/ncc/published_results/task_devmap.zip") dataset.ExtractAll(pathlib.Path(input_data)) with vocabulary.VocabularyZipFile(FLAGS.vocabulary_zip_path) as vocab: task_utils.CreateSeqDirFromIr(os.path.join(input_data, "kernels_ir"), vocab) # Reference values copied from: # https://github.com/ChrisCummins/paper-end2end-dl/blob/master/code/Case%20Study%20A.ipynb static_pred_vals = [58.823529, 56.911765] static_pred_mean = 57.867647 static_sp_vals = [1.0, 1.0] static_sp_mean = 1.0 grewe_pred_vals = [73.382353, 72.941176] grewe_pred_mean = 73.161765 grewe_sp_vals = [2.905822, 1.264801] grewe_sp_mean = 2.085312 deeptune_pred_vals = [83.676471, 80.294118] deeptune_pred_mean = 81.985294 deeptune_sp_vals = [3.335612, 1.412222] deeptune_sp_mean = 2.373917 # Train model app.Log(1, "Evaluating ncc model") ncc_devmap = evaluate( NCC_devmap(), device, input_data, out, embeddings, dense_layer_size, print_summary, num_epochs, batch_size, ) # Print results print("--- Prediction results") print( ncc_devmap.groupby(["Platform", "Benchmark Suite"])["Platform", "Correct?", "Speedup"].mean()) print("--- Prediction results (summarized)") print( ncc_devmap.groupby(["Platform"])["Platform", "Correct?", "Speedup"].mean()) # Model comparison: prediction accuracy print("--- Model comparison: prediction accuracy") d = list() d.append(np.append(static_pred_vals, static_pred_mean)) d.append(np.append(grewe_pred_vals, grewe_pred_mean)) d.append(np.append(deeptune_pred_vals, deeptune_pred_mean)) d.append( np.append( ncc_devmap.groupby(["Platform"])["Correct?"].mean().values * 100, ncc_devmap["Correct?"].mean() * 100, )) d = np.array(d).T.reshape(3, 4) print( pd.DataFrame( d, columns=[ "Static mapping", "Grewe et al.", "DeepTune", "DeepTuneInst2Vec", ], index=["AMD Tahiti 7970", "NVIDIA GTX 970", "Average"], )) # Model comparison: speedups print("--- Model comparison: speedups") d = list() d.append(np.append(static_sp_vals, static_sp_mean)) d.append(np.append(grewe_sp_vals, grewe_sp_mean)) d.append(np.append(deeptune_sp_vals, deeptune_sp_mean)) d.append( np.append( ncc_devmap.groupby(["Platform"])["Speedup"].mean().values, ncc_devmap["Speedup"].mean(), )) d = np.array(d).T.reshape(3, 4) print( pd.DataFrame( d, columns=[ "Static mapping", "Grewe et al.", "DeepTune", "DeepTuneInst2Vec", ], index=["AMD Tahiti 7970", "NVIDIA GTX 970", "Average"], )) app.Log(1, "done")