# CA HW1
## 1.
| Processor | clock rate (GHz) | CPI | IPS ($10^9$) | instructions ($10^9$) | cycles ($10^9$) |
| - | - | - | - | - | - |
| P1 | 6.0 | 1.5 | 4 | 32 | 48 |
| P2 | 7.5 | 3.0 | 2.5 | 20 | 60 |
| P3 | 3.5 | 1.0 | 3.5 | 28 | 28 |
```javascript
const P = [
{clock_rate: 6.0, CPI: 1.5},
{clock_rate: 7.5, CPI: 3.0},
{clock_rate: 3.5, CPI: 1.0},
];
```
### a.
$$
\text{IPS} = \frac{\text{clock rate}}{\text{CPI}}
$$
```javascript
const IPS = P.map(({clock_rate, CPI}) => clock_rate / CPI);
P.forEach((p, i) => p.IPS = IPS[i]);
```
### b.
$$
\text{instructions} = \text{execution time} \times \text{IPS}
$$
```javascript
const instructions = P.map(({IPS}) => 8 * IPS);
P.forEach((p, i) => p.instructions = instructions[i]);
```
$$
\text{cycles} = \text{instructions} \times \text{CPI}
$$
```javascript
const cycles = P.map(({instructions, CPI}) => instructions * CPI);
P.forEach((p, i) => p.cycles = cycles[i]);
```
### c.
$$
\text{clock rate}
= \frac{\text{instructions} \times \text{CPI}}{\text{execution time}}
$$
Most sensibly, the number of instructions of the program remains constant.
To meet the new requirement, the clock rate must increase **threefold**.
```javascript
const clock_rate_scale = (1 + 0.8) * 1 / (1 - 0.4);
```
## 2.
| Processor | clock rate (GHz) | CPI-A | CPI-B | CPI-C | CPI-D | global CPI | cycles ($10^6$) | execution time (ms) |
| - | - | - | - | - | - | - | - | - |
| P1 | 1.7 | 1 | 3 | 3 | 1 | 2 | 2 | ~1.18 |
| P2 | 2.3 | 2 | 4 | 1 | 1 | 1.9 | 1.9 | ~0.83 |
| dynamic instruction count | CPI-A | CPI-B | CPI-C | CPI-D |
| - | - | - | - | - |
| $10^6$ | 15% | 25% | 25% | 35% |
```javascript
const P = [
{clock_rate: 1.7, CPI: [1, 3, 3, 1]},
{clock_rate: 2.3, CPI: [2, 4, 1, 1]},
];
const proportion = [0.15, 0.25, 0.25, 0.35];
const dynamic_instruction_count = 1; // 10^6
```
### a.
The global CPI of `p` in `P` is the inner-product of `p.CPI` and `proportion`.
```javascript
const global_CPI = P.map(({CPI}) =>
CPI.reduce((s, cpi, i) => s + cpi * proportion[i], 0)
);
P.forEach((p, i) => p.global_CPI = global_CPI[i]);
```
### b.
$$
\text{cycles} = \text{instructions} \times \text{global CPI}
$$
```javascript
const cycles = P.map(({global_CPI}) => dynamic_instruction_count * global_CPI);
P.forEach((p, i) => p.cycles = cycles[i]);
```
### c.
$$
\text{execution time} = \frac{\text{cycles}}{\text{clock rate}}
$$
```javascript
const execution_time = P.map(({clock_rate, cycles}) => cycles / clock_rate);
P.forEach((p, i) => p.execution_time = execution_time[i]);
```
Given these information P2 is faster than P1.
## 3.
| instruction count ($10^9$) | execution time (s) | reference time (s) |
| - | - | - |
| 2389 | 550 | 8750 |
### a.
$$
\text{CPI}
= \frac{\text{execution time}}{\text{instructions} \times \text{clock cycle time}}
= \frac{550}{2389 \times 10^9 \times 0.333 \times 10^{-9}}
\approx 0.69
$$
### b.
$$
\text{SPECratio}
= \frac{\text{reference time}}{\text{execution time}}
= \frac{8750}{550}
\approx 16
$$
### c.
$$
\text{execution time}
= \frac{\text{instructions} \times \text{CPI}}{\text{clock rate}}
$$
Given that clock rate and CPI are fixed, 15% increase in instructions yields 15% increase in execution time.
### d.
$$
\text{execution time}
= \frac{\text{instructions} \times \text{CPI}}{\text{clock rate}}
$$
Given that clock rate is fixed, 10% increase in instructions and 20% increase in CPI yield 32% increase in execution time, as $1.1 \times 1.2 = 1.32$
### e.
$$
\text{SPECratio}
= \frac{\text{reference time}}{\text{execution time}}
$$
32% increase in execution time leads to 24% decrease in SPECratio, as $\dfrac{1}{1.32} \approx 0.76$.