0
$\begingroup$

In the book - Computer Organization and Design: The Hardware/Software Interface [RISC-V Edition] by Patterson and Hennessy, CPI is defined like this:

The term clock cycles per instruction, which is the average number of clock cycles each instruction takes to execute, is often abbreviated as CPI. Since different instructions may take different amounts of time depending on what they do, CPI is an average of all the instructions executed in the program. CPI provides one way of comparing two different implementations of the identical instruction set architecture, since the number of instructions executed for a program will, of course, be the same.


I am solving question 1.7 from the Exercises section of chapter 1:

1.7 Compilers can have a profound impact on the performance of an application. Assume that for a program, compiler A results in a dynamic instruction count of 1.0E9($I_A)$ and has an execution time of 1.1 s($T_A$), while compiler B results in a dynamic instruction count of 1.2E9($I_B)$ and an execution time of 1.5 s($T_B$).

a. Find the average CPI(both $CPI_A$ and $CPI_B$) for each program given that the processor has a clock cycle time of 1 ns.

b. Assume the compiled programs run on two different processors. If the execution times on the two processors are the same, how much faster is the clock of the processor($P_A$) running compiler A’s code versus the clock of the processor($P_B$) running compiler B’s code?

c. A new compiler C is developed that uses only 6.0E8 instructions($I_C$) and has an average CPI($CPI_C$) of 1.1. What is the speedup of using this new compiler versus using compiler A or B on the original processor?

Attempted Solution:

a.

Using the formula $T = I * CPI * CC$

where $CC = $ clock cycle time, I calculated part a of the question

$CPI_A = \frac{T_A}{I_A * CC_A} = 1.1$

Similarly, $CPI_B = 1.25$

b.

Given, execution times on two different processors are same

Again using the formula, I calculated

$\frac{T_A}{T_B} = \frac{I_A * CPI_A * CC_A}{I_B * CPI_B * CC_B}$

My task is to find $\frac{CC_A}{CC_B}$, which I am unable to, since I don't know the value of $CPI_A$ and $CPI_B$.

c.

Again, using the formula, I calculated

$\frac{T_A}{T_C} = \frac{I_A * CPI_A * CC_A}{I_C * CPI_C * CC_C}$

My task is to find $\frac{T_A}{T_C}$, which I am unable to, since I don't know the value of $CPI_A$. Here I know that, $CC_A = CC_C$, since the processor remains same.

In part b and part c of the solution, will the value of $CPI$ be same as that calculated in part a. If so, please explain why? What are the metrics on which $CPI$ depends. Does it not change with processor, or execution time, or any other metric?

$\endgroup$
6
  • $\begingroup$ One hen lays five eggs in twelve days. Another hen lays eight eggs in twenty days. Now we define DPE (days per egg) as the ratio of days divided by eggs laid. Wait a second... All the questions you are asking are also valid for DPEs. So what does your question have to do with computer science? $\endgroup$
    – gnasher729
    Feb 1, 2021 at 23:31
  • 1
    $\begingroup$ Suppose on one processor a program with instruction count of 40 takes 80 clock cycles to run and on another processor the same program runs in 40 clock cycles. The CPI on former machine is 2 and the latter machine is 1. So CPI changes with processors. Also, note that the program in question was compiled on a machine and its execution time was calculated for that machine. In part a of the question, we calculated $CPI_A$ and $CPI_B$ for the same machine. Now, in part b of the question the compiled programs run on two different processors, so $CPI$ could be different, and its not given. $\endgroup$ Feb 2, 2021 at 5:38
  • $\begingroup$ So my hens have a clock that I can change to whistle 5 times a day, or six times a day, or ten times a day. And we count how many eggs laid in how many clock whistles. How is your problem related to computer science again? $\endgroup$
    – gnasher729
    Feb 2, 2021 at 22:58
  • 1
    $\begingroup$ Please elaborate the analogy you have given. $\endgroup$ Feb 4, 2021 at 16:34
  • 2
    $\begingroup$ The point is, you're essentially looking at cross-multiplication, which is middle-school mathematics. (Why the authors would include those exercise in a, preumably, university-level textbook, I don't know.) $\endgroup$
    – Raphael
    Feb 7, 2021 at 23:49

1 Answer 1

1
$\begingroup$

In part a same processor is assumed, and 2 compilers are used. In part b, 2 processors with different clock frequency is used, since the execution times for both processors are equal but the CPIs and dynamic instruction counts are unequal. The CPI for both processors is the same as the CPI from part a because the same compilers were used and the same compiled program is run. So the dynamic instruction count and CPI is the same from part a.

$\frac{f_A}{f_B}=\frac{CC_B}{CC_A}=\frac{T_B}{CPI_B*I_B}*\frac{CPI_A*I_A}{T_A}$.

Since $T_A=T_B$, we get

$\frac{f_A}{f_B}=\frac{CPI_A*I_A}{CPI_B*I_B} = \frac{1.1*1*10^9}{1.25*1.2*10^9} =0.7333 $

or $\frac{f_B}{f_A} = 1.37$

For part c, use CPIs obtained in part a.

Speedup

$\frac{T_A}{T_C}=1.67$

$\frac{T_B}{T_C}=2.27$

CPI depends on the processor's hardware architecture, processor clock frequency, compiler and the number of instructions.

$\endgroup$
7
  • $\begingroup$ I am not convinced by the line - The CPI for both processors is the same as the CPI from part a because the same compilers were used and the same compiled program is run.- in the answer. Will that always be the true, independent of other factors? $\endgroup$ Feb 8, 2021 at 16:15
  • $\begingroup$ @HasloVardos, here the CPI is the same and only the clock frequency is varying. The question is in the initial chapters, it is assumed that the same micro-architecture is used, since it is not mentioned that a different micro-architecture is used. CPI, as I have mentioned at the end of my answer, depends on hardware architecture, program under consideration, compiler and clock frequency. $\endgroup$ Feb 8, 2021 at 16:27
  • $\begingroup$ CPI can vary with pipelining, for example. $\endgroup$ Feb 8, 2021 at 16:31
  • $\begingroup$ I am not saying that I refuse to believe you, but Is it written somewhere(that I missed) that such an assumption has been made? In Section 1.6 on Performance on page 39 there is a table where it states that Algorithm, Programming language, compiler, and Instruction set architecture affect CPI. Since they have included ISA, micro-architecture should be implied. $\endgroup$ Feb 8, 2021 at 17:02
  • $\begingroup$ @HasloVardos, 2 processors can have the same ISA and different micro-architectures. Can you expect to solve the question assuming different CPIs? $\endgroup$ Feb 8, 2021 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.