Miguel Reynolds

2021-12-23

Compilers can significantly affect how well an application performs. Assume that for a program, compiler A results in a dynamic instruction count of 1.0E9 and has an execution time of 1.1 s, while compiler B results in a dynamic instruction count of 1.2E9 and an execution time of 1.5 s.
a. Find the average CPI for each program given that the processor has a clock cycle time of 1 ns.
b. Assume there are two processors being used to run the compiled programs. If the execution times on the two processors are the same, how much faster is the clock of the processor running compiler A’s code versus the clock of the processor running compiler B’s code?
c. A new compiler is developed that uses only 6.0E8 instructions and has an average CPI of 1.1. What is the speedup of using this new compiler versus using compiler A or B on the original processor?

nghodlokl

Expert

Step 1
a) Remember that
$\text{CPU time}=\text{instructions}×\text{CPU}×\text{cycle time,}$
thus
$\text{CPI}=\frac{\text{COU time}}{\text{instructions}×\text{cycle time}}$
Here cycle time $=1ns={10}^{-9}s$. Additionally, execution time in this context $=\text{CPU time}$. So, for complier A, we have that
${\text{CPI}}_{A}=\frac{{\text{CPU time}}_{A}}{{\text{instructions}}_{A}×\text{cycle time}}=\frac{1.1s}{{10}^{9}×{10}^{-9}s}=1.1$
For compiler B, we have
${\text{CPI}}_{B}=\frac{{\text{CPU time}}_{B}}{{\text{instructions}}_{B}×\text{cycle time}}=\frac{1.5s}{1.2×{10}^{9}×{10}^{-9}s}=1.25$
Step 2
b) Recall that
$\text{execution time}=\text{CPU time}=\frac{\text{instructions}×\text{CPI}}{\text{clock rate}}$
So, since execution times in both cases are the same,
${\text{execution time}}_{1}={\text{execution time}}_{2}$
which yields
$\frac{{\text{instructions}}_{1}×{\text{CPI}}_{1}}{{\text{clock rate}}_{1}}=\frac{{\text{instructions}}_{2}×{\text{CPI}}_{2}}{{\text{clock rate}}_{2}}$
Therefore, after rearranging,
${\text{clock rate}}_{1}=\frac{{\text{instructions}}_{1}×{\text{CPI}}_{1}}{{\text{instructions}}_{2}×{\text{CPI}}_{2}}×{\text{clock rate}}_{2}=\frac{{10}^{9}×1.1}{1.2×{10}^{9}×1.25}×{\text{clock rate}}_{2}$
So,
${\text{clock rate}}_{1}=0.73{\text{clock rate}}_{2}$
So, the clock rate of processor 1 is actually approximately $27\mathrm{%}$ slower than the clock rate of processor 2.
Step 3
c) We use the same formula as in (a):
${\text{CPU time}}_{C}={\text{instructions}}_{C}×{\text{CPI}}_{C}×\text{cycle time}=6×{10}^{8}×1.1×{10}^{-9}s=0.66s$
So,
$\frac{{\text{performance}}_{C}}{{\text{performance}}_{A}}=\frac{{\text{CPU time}}_{A}}{{\text{CPU time}}_{C}}=\frac{1.1s}{0.66s}=1.67$
$\frac{{\text{performance}}_{C}}{{\text{performance}}_{A}}=\frac{{\text{CPU time}}_{A}}{{\text{CPU time}}_{C}}=\frac{1.5s}{0.66s}=2.27$
So, C is faster than A approximately 1.67 times, and faster than B approximately 2.27 times.

Paineow

Expert

Step 1
Given
Cycle Time $=1ns={10}^{-9}$
CPU Time for A $=1.1s$
Instruction count $={10}^{9}$
CPU Time for B $=1.5s$
Instruction Count $=1.2×{10}^{9}$
$\text{CPU Time}=\text{Instructions}×\text{Cycle Time}×\text{CPI}$
So, $\text{CPI}=\frac{\text{CPU Time}}{\text{Instructions}×\text{Cycle Time}}$
CPI for $A=\frac{1.1}{{10}^{9}×{10}^{-9}}$
$\text{CPI}=1.1$
CPI for $B=\frac{1.5}{1.2×{10}^{9}×{10}^{-9}}$
$\text{CPI}=\frac{1.5}{12}$
$\text{CPI}=1.25$
Step 2
Given
$\text{Execution Time on A}=\text{Execution Time on B}$
$\text{CPU Time for A}=1.1s$
$\text{Instruction count}={10}^{9}$
$\text{CPI}=1.1$
CPU Time for $B=1.5s$
Instruction Count $=1.2×{10}^{9}$
$\text{CPI}=1.25$
$\text{Execution Time}=\text{Instructions}×\frac{\text{CPI}}{\text{Clock Rate}}$
$\text{Execution Time A}=\text{Execution Time B}$
${\text{Instruction}}_{A}×\frac{{\text{CPI}}_{A}}{{\text{Clock Rate}}_{A}}={\text{Instruction}}_{B}×\frac{{\text{CPI}}_{B}}{{\text{Clock Rate}}_{B}}$.
Make Clock Rate A the subject of formula
${\text{Clock Rate}}_{A}=\frac{{\text{Instruction}}_{A}×{\text{CPI}}_{A}×{\text{Clock Rate}}_{B}}{{\text{Instruction}}_{B}×{\text{CPI}}_{B}}$
${\text{Clock Rate}}_{A}=\frac{{10}^{9}×1.1×{\text{Clock Rate}}_{B}}{1.2×{10}^{9}×1.25}$
${\text{Clock Rate}}_{A}=0.73{\text{Clock Rate}}_{B}$
So the clock rate of A is $27\mathrm{%}$ slower than clock rate of B
Step 3
For compiler A and C,
$\text{CPU Time}=\text{Instructions}×\text{Cycle Time}\text{CPI}$
$\text{CPU Time of C}=6×{10}^{8}×1.1×{10}^{-9}=0.66s$
Using ratio of CPU time and Compiler performance i,e.
$\text{CPU Time of A}×\text{Performance of A}=\text{CPU Time of C}×\text{Performance of C}$
Given
$\text{CPU Time of A}=1.1$
$\text{CPU Time of C}=0.66$
$1.1×\text{Performance of A}=0.66×\text{Performance of C}$

Do you have a similar question?