public void sendResult(uint taskId, BenchmarkStatisticsResult result) { lock (networkStreamLocker) { if (this.simulationSession == null) { Console.WriteLine("Error: Cannot send result. No session is active at the moment. "); return; } ResultPackage resultPackage = new ResultPackage { taskID = taskId, sessionID = this.simulationSession.sessionID, result = result }; try { networkStream.WriteByte((byte)TrasmissionFlags.Result); formatter.Serialize(networkStream, resultPackage); Console.WriteLine("Result sent back to " + clientName); } catch (Exception e) { Console.WriteLine("Attempt to send result back to " + clientName + " failed: " + e.Message); } } }
private void saveResultsToText(string path) { StreamWriter streamWriter; streamWriter = new StreamWriter(path); foreach (KeyValuePair <PredictorInfo, int> predictorAndIndex in simulationResultsDictionary.PredictorsWithIndices) { streamWriter.WriteLine("Simulation with " + predictorAndIndex.Key.description + " : "); streamWriter.WriteLine(); foreach (KeyValuePair <BenchmarkInfo, int> benchmarkAndIndex in simulationResultsDictionary.BenchmarksWithIndices) { streamWriter.WriteLine("Benchmark: " + benchmarkAndIndex.Key.benchmarkName); BenchmarkStatisticsResult result = simulationResultsDictionary.getResult(predictorAndIndex.Value, benchmarkAndIndex.Value); if (result == null) { streamWriter.WriteLine("Simulation on this benchmark was not performed."); streamWriter.WriteLine(); } else { streamWriter.WriteLine("Total Branches: " + result.NumberOfBranches); streamWriter.WriteLine("Correct predictions " + result.NumberOfCorrectPredictions); streamWriter.WriteLine("Incorrect predictions: " + result.NumberOfIncorrectPredictions); streamWriter.WriteLine("Accuracy: " + result.PercentAccuracy); streamWriter.WriteLine(); } } streamWriter.WriteLine("Arithmetic Mean"); streamWriter.WriteLine("Accuracy: " + simulationResultsDictionary.getResultCollectionForPredictor(predictorAndIndex.Key).ArithmeticMean.PercentAccuracy); } streamWriter.Close(); }
public SimulationResultsDictionaryNewValueReceivedEventArgs(int predictorIndex, int benchmarkIndex, BenchmarkStatisticsResult value, BenchmarkStatisticsCollection collection) { this.predictorIndex = predictorIndex; this.benchmarkIndex = benchmarkIndex; this.value = value; this.correspondingCollection = collection; }
public void setResult(PredictorInfo predictor, BenchmarkInfo benchmark, BenchmarkStatisticsResult value) { int predictorIndex; int benchmarkIndex; if (!predictorIndexMap.TryGetValue(predictor, out predictorIndex)) { throw new Exception("Invalid predictor provided."); } if (!benchmarkIndexMap.TryGetValue(benchmark, out benchmarkIndex)) { throw new Exception("Invalid simulator provided."); } if ((value != null) && (resultMatrix[predictorIndex, benchmarkIndex] == null)) { valuesEntered++; observableCollections[predictor].addSorted(value); if (newValueReceived != null) { newValueReceived(this, new SimulationResultsDictionaryNewValueReceivedEventArgs(predictorIndex, benchmarkIndex, value, observableCollections[predictor])); } } else { throw new NotSupportedException(); } resultMatrix[predictorIndex, benchmarkIndex] = value; if ((valuesEntered == numberOfPredictors * numberOfBenchmarks) && (filled != null)) { filled(this, EventArgs.Empty); } }
private void doWork() { try { while (true) { try { if (isPendingClose) { return; } TaskPackage taskPackage = null; lock (taskSource) { if (taskSource.Count > 0) { taskPackage = taskSource.Dequeue(); } } if (taskPackage == null) { waitHandleBetweenTasks.WaitOne(); } else { Console.WriteLine("Simulating " + taskPackage.simulationTask.predictorInfo.predictorTypeFullName + " on " + taskPackage.simulationTask.benchmarkInfo.benchmarkName); BenchmarkStatisticsResult benchmarkStatisticsResult = taskPackage.simulationTask.simulate(ParentConnectionThread.SimulationSession.sessionOptions, Program.applicationOptions); ParentConnectionThread.sendResult(taskPackage.taskID, benchmarkStatisticsResult); ParentConnectionThread.sendTaskRequest(); } } catch (ThreadAbortException) { Thread.ResetAbort(); } } } catch (ThreadAbortException) { Console.WriteLine("The thread abortion process occured at a time when it could not be properly handled."); } }
private void performWork() { try { SimulationInfo currentSimulation; while (true) { // acquire data lock (simulationQueue) { if (simulationQueue.Count > 0) { currentSimulation = simulationQueue.Dequeue(); } else { return; } } // big work BenchmarkStatisticsResult result = currentSimulation.simulate(this.SimulationOptionsCurrentExecution, this.AppOptions); // results lock (simulationResultsDictionary) { simulationResultsDictionary.setResultUsingDispatcher(this.Dispatcher, currentSimulation.predictorInfo, currentSimulation.benchmarkInfo, result); } } } catch (ThreadAbortException) { Thread.ResetAbort(); return; } }
public BenchmarkStatisticsResultReceivedEventArgs(SimulationInfo simulation, BenchmarkStatisticsResult result) { this.simulation = simulation; this.result = result; }
public static BenchmarkStatisticsResult simulate(PredictorInfo predictorInfo, BenchmarkInfo benchmarkInfo, SimulationOptions simulationParameters, ApplicationOptions applicationOptions) { if (simulationParameters == null) { simulationParameters = SimulationOptions.defaultOptions; } string folder = ""; ITraceReader traceReader = null; BenchmarkStatisticsResult currentResult = null; switch (benchmarkInfo.benchmarkType) { case BenchmarkType.Stanford: folder = applicationOptions.TracePathStanford; traceReader = new StanfordReader(); break; case BenchmarkType.SPEC2000: folder = applicationOptions.TracePathSpec2000; traceReader = new Spec2000Reader(); break; case BenchmarkType.CBP2: folder = applicationOptions.TracePathCBP2; traceReader = new CBP2Reader(); break; } // obtain predictor IPredictor predictor = predictorInfo.getPredictor(); if (predictor == null) { return(new BenchmarkStatisticsResult(benchmarkInfo.benchmarkName + " - Could not be performed: The predictor could not be instantiated on the client.")); } // open the trace file if (!traceReader.openTrace(folder, benchmarkInfo.benchmarkName)) { return(new BenchmarkStatisticsResult(benchmarkInfo.benchmarkName + " - Could not be performed: The trace file could not be opened on the client.")); } // create new entry currentResult = new BenchmarkStatisticsResult(benchmarkInfo.benchmarkName); currentResult.NumberOfCorrectPredictions = 0; currentResult.NumberOfIncorrectPredictions = 0; // check if we should skip N branches when counting the performance (to avoid accounting for the predictor warmup) int branchIndex = 0; int numberOfBranchesToSkip = simulationParameters.NumberOfBranchesToSkip; while (true) { // get the next branch IBranch branch = traceReader.getNextBranch(); // null means trace end if (branch == null) { break; } BranchInfo currentJumpInfo = branch.getBranchInfo(); if (!simulationParameters.ConditionalOnly || ((branch.getBranchInfo().branchFlags & BranchInfo.BR_CONDITIONAL) > 0)) { // predict bool prediction = predictor.predictBranch(branch.getBranchInfo()); if (branchIndex >= numberOfBranchesToSkip) { if (branch.taken() == prediction) { currentResult.NumberOfCorrectPredictions++; } else { currentResult.NumberOfIncorrectPredictions++; } } // update the predictor predictor.update(branch); branchIndex++; } } traceReader.closeTrace(); currentResult.NumberOfBranches = currentResult.NumberOfCorrectPredictions + currentResult.NumberOfIncorrectPredictions; currentResult.Accuracy = (double)currentResult.NumberOfCorrectPredictions / currentResult.NumberOfBranches; // free the predictor instance for future reusability predictorInfo.freePredictor(predictor); return(currentResult); }
private void beginInvokeBenchmarkStatisticsCollectionAdd(BenchmarkStatisticsCollection benchmarkStatisticsCollection, BenchmarkStatisticsResult benchmarkStatisticsResult) { this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action( delegate() { benchmarkStatisticsCollection.addSorted(benchmarkStatisticsResult); } )); }