Good Predictions Are Worth a Few Comparisons Carine Pivoteau with Nicolas Auger and Cyril Nicaud LIGM - Universit´ e Paris-Est-Marne-la-Vall´ ee March 2016 Carine Pivoteau Good predictions are worth... 1/11
A case study Find both the min. and the max. of an array of size n . Naive Algorithm: 5 1 4 3 6 0 2 8 7 9 min = 5 max = 5 Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Naive Algorithm: 5 1 4 3 6 0 2 8 7 9 1 < min ? 1 > max ? min = 5 max = 5 Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Naive Algorithm: 5 1 4 3 6 0 2 8 7 9 1 < min ? 1 > max ? min = 1 max = 5 Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Naive Algorithm: 5 1 4 3 6 0 2 8 7 9 4 < min ? 4 > max ? min = 1 max = 5 Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Naive Algorithm: 5 1 4 3 6 0 2 8 7 9 3 < min ? 3 > max ? min = 1 max = 5 Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Naive Algorithm: 5 1 4 3 6 0 2 8 7 9 6 < min ? 6 > max ? min = 1 max = 5 Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Naive Algorithm: 5 1 4 3 6 0 2 8 7 9 6 < min ? 6 > max ? min = 1 max = 6 Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Naive Algorithm: 5 1 4 3 6 0 2 8 7 9 0 < min ? 0 > max ? min = 1 max = 6 Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Naive Algorithm: 5 1 4 3 6 0 2 8 7 9 0 < min ? 0 > max ? min = 0 max = 6 Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Naive Algorithm: 5 1 4 3 6 0 2 8 7 9 2 < min ? 2 > max ? min = 0 max = 6 Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Naive Algorithm: 5 1 4 3 6 0 2 8 7 9 8 < min ? 8 > max ? min = 0 max = 6 Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Naive Algorithm: 5 1 4 3 6 0 2 8 7 9 8 < min ? 8 > max ? min = 0 max = 8 Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Naive Algorithm: 5 1 4 3 6 0 2 8 7 9 7 < min ? 7 > max ? min = 0 max = 8 Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Naive Algorithm: 5 1 4 3 6 0 2 8 7 9 9 < min ? 9 > max ? min = 0 max = 8 Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Naive Algorithm: 5 1 4 3 6 0 2 8 7 9 9 < min ? 9 > max ? min = 0 max = 9 Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Naive Algorithm: 2 n comparisons 5 1 4 3 6 0 2 8 7 9 9 < min ? 9 > max ? min = 0 max = 9 Can we do better? Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Optimized Algorithm: 5 1 4 3 6 0 2 8 7 9 min = 5 max = 5 Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Optimized Algorithm: 5 1 4 3 6 0 2 8 7 9 5 < 1 ? 1 < min ? min = 5 5 > max ? max = 5 Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Optimized Algorithm: 5 1 4 3 6 0 2 8 7 9 5 < 1 ? 1 < min ? min = 1 5 > max ? max = 5 Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Optimized Algorithm: 5 1 4 3 6 0 2 8 7 9 4 < 3 ? 3 < min ? min = 1 4 > max ? max = 5 Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Optimized Algorithm: 5 1 4 3 6 0 2 8 7 9 6 < 0 ? 0 < min ? min = 1 6 > max ? max = 5 Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Optimized Algorithm: 5 1 4 3 6 0 2 8 7 9 6 < 0 ? 0 < min ? min = 0 6 > max ? max = 6 Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Optimized Algorithm: 5 1 4 3 6 0 2 8 7 9 2 < 8 ? 2 < min ? min = 0 8 > max ? max = 6 Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Optimized Algorithm: 5 1 4 3 6 0 2 8 7 9 2 < 8 ? 2 < min ? min = 0 8 > max ? max = 8 Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Optimized Algorithm: 5 1 4 3 6 0 2 8 7 9 7 < 9 ? 7 < min ? min = 0 9 > max ? max = 8 Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Optimized Algorithm: 5 1 4 3 6 0 2 8 7 9 7 < 9 ? 7 < min ? min = 0 9 > max ? max = 9 Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Optimized Algorithm: 3 n/ 2 comparisons (optimal) 5 1 4 3 6 0 2 8 7 9 7 < 9 ? 7 < min ? min = 0 9 > max ? max = 9 Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Optimized Algorithm: 3 n/ 2 comparisons (optimal) Naive Algorithm: 2 n comparisons Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . Optimized Algorithm: 3 n/ 2 comparisons (optimal) Naive Algorithm: 2 n comparisons In practice, on uniform random data? Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . in C, using gcc -O0 , random integers Carine Pivoteau Good predictions are worth... 2/11
A case study Find both the min. and the max. of an array of size n . in C, using gcc -O0 , random integers Carine Pivoteau Good predictions are worth... 2/11
Some background (mostly from Hennessy and Patterson [HP11]) ◮ Most modern processors are pipelined ◮ Instructions are parallelized Branch predictors are used to avoid stalls on branches! Conditional instructions (such as the “if” statement) yield branches in the execution of a program The branch predictor will guess which branch will be taken (T) or not (NT). A misprediction can be quite expensive ! Different schemes: static, dynamic, local, global,. . . Carine Pivoteau Good predictions are worth... 3/11
Some background (mostly from Hennessy and Patterson [HP11]) ◮ Most modern processors are pipelined ◮ Instructions are parallelized Branch predictors are used to avoid stalls on branches! 1-bit predictor: NT T T NT T NT Carine Pivoteau Good predictions are worth... 3/11
Some background (mostly from Hennessy and Patterson [HP11]) ◮ Most modern processors are pipelined ◮ Instructions are parallelized Branch predictors are used to avoid stalls on branches! 2-bit predictor: NT T T T T S. NT NT T S. T NT NT NT Carine Pivoteau Good predictions are worth... 3/11
Some background (mostly from Hennessy and Patterson [HP11]) ◮ Most modern processors are pipelined ◮ Instructions are parallelized Branch predictors are used to avoid stalls on branches! Global (or mixed) predictor: ← − ¸ − → 0000...00 0000...01 ... 1111...11 Carine Pivoteau Good predictions are worth... 3/11
Some background (mostly from Hennessy and Patterson [HP11]) ◮ Most modern processors are pipelined ◮ Instructions are parallelized Branch predictors are used to avoid stalls on branches! Conditional instructions (such as the “if” statement) yield branches in the execution of a program The branch predictor will guess which branch will be taken (T) or not (NT). A misprediction can be quite expensive ! Different schemes: static, dynamic, local, global,. . . Min and max search is very sensitive to branch prediction... Carine Pivoteau Good predictions are worth... 3/11
Recommend
More recommend