免費詳解 / 中山 / 硬體 / 104

104 中山資工所考古題解答|硬體逐題詳解

104 中山資工所硬體考古題的逐題詳解,共 7 題,免費公開。

逐題詳解

114%

The following table shows the percentage of MIPS instructions executed by category for average of SPEC2000 integer programs and SPEC2000 floating point programs.

Instruction classMIPS examplesAverage CPIFrequency
IntegerFloating point
Arithmeticadd, sub, addi1.0 clock cycles24%48%
Data transferlw, sw, lb, sb, lui1.4 clock cycles36%39%
Logicaland, or, nor, andi, ori1.0 clock cycles18%5%
Conditional branchbeq, bne, slt, slti1.7 clock cycles18%6%
Jumpj, jr, jal1.2 clock cycles4%2%

1.1 (4%) Using the average instruction mix information for the program SPEC2000fp, find the percentage of all memory accesses (both data and instruction) that are for reads. Assume that two-thirds of data transfers are loads.

1.2 (4%) Compute the effective CPI for MIPS. Average the instruction frequencies for SPEC2000int and SPEC2000fp to obtain the instruction mix.

1.3 (6%) Consider an architecture that is similar to MIPS except that it supports update addressing for data transfer instructions. If we run SPEC2000int using this architecture, some percentage of the data transfer instructions will be able to make use of the new instructions, and for each instruction changed, one arithmetic instruction can be eliminated. If 25% of the data transfer instructions can be changed, which will be faster for SPEC2000int, the modified MIPS architecture or the unmodified architecture? How much faster? (Assume that both architectures have CPI values as given in the above table and that the modified architecture has its cycle time increased by 20% in order to accommodate the new instructions.)

1.1 以每條指令為單位:instruction fetch 1 次(read);data transfer 0.39 次,其中 load \(\tfrac23\cdot0.39=0.26\)(read)、store \(0.13\)(write)

memory access 共 \(1+0.39=1.39\),read \(1+0.26=1.26\)

\(1.26/1.39\approx90.6\%\)

1.2 平均 mix:arithmetic 36%、data transfer 37.5%、logical 11.5%、branch 12%、jump 3%

\(\text{CPI}=0.36(1.0)+0.375(1.4)+0.115(1.0)+0.12(1.7)+0.03(1.2)=0.36+0.525+0.115+0.204+0.036\)

1.24

1.3 SPEC2000int,以 100 條指令為基準

原架構 cycles:\(24(1.0)+36(1.4)+18(1.0)+18(1.7)+4(1.2)=24+50.4+18+30.6+4.8=127.8\)

25% 的 data transfer 可改:\(36\times0.25=9\) 條,各省 1 條 arithmetic → arithmetic \(24\to15\),總指令 91 條

新架構 cycles:\(15(1.0)+36(1.4)+18(1.0)+18(1.7)+4(1.2)=118.8\)

設原 cycle time 為 \(T\):原 \(=127.8T\);新 \(=118.8\times1.2T=142.56T\)

\(142.56/127.8\approx1.116\)

原本(未修改)的 MIPS 較快,快約 1.12 倍(新架構慢約 12%)

212%

Consider two different implementations, I1 and I2, of the same instruction set. There are three classes of instructions (A, B, and C) in the instruction set. I1 has a clock rate of 4 GHz, and I2 has a clock rate of 2 GHz. The following table shows the average number of cycles for each instruction class on I1 and I2.

ClassCPI on I1CPI on I2C1 UsageC2 UsageC3 Usage
A2140%40%50%
B3240%20%25%
C5220%40%25%

The table also contains a summary of average proportion of instruction classes generated by three different compilers. C1 is a compiler produced by the makers of I1, C2 is produced by the makers of I2, and C3 is a third-party product. Assume that each compiler uses the same number of instructions for a given program but that the instruction mix is as described in the table.

2.1 (6%) Using C1 on both I1 and I2, how much faster can the makers of I1 claim I1 is compared to I2?

2.2 (6%) Which computer and compiler would you purchase if all other criteria are identical, including cost?

每條指令時間 \(=\text{CPI}/\text{clock}\)

2.1 I1:\(0.4\cdot2+0.4\cdot3+0.2\cdot5=3.0\),\(3.0/4\text{ GHz}=0.75\) ns

I2:\(0.4\cdot1+0.4\cdot2+0.2\cdot2=1.6\),\(1.6/2\text{ GHz}=0.80\) ns

\(0.80/0.75\approx1.07\) → I1 比 I2 快約 7%

2.2 六種組合都算

CPI每條指令時間
I1+C13.00.75 ns
I1+C2(\(0.8+0.6+2.0\))3.40.85 ns
I1+C3(\(1.0+0.75+1.25\))3.00.75 ns
I2+C11.60.80 ns
I2+C2(\(0.4+0.4+0.8\))1.60.80 ns
I2+C3(\(0.5+0.5+0.5\))1.50.75 ns

I1+C1、I1+C3、I2+C3 並列最快(0.75 ns/指令)

C3 在兩台機器上都達到 0.75 ns,是唯一在兩台上都最快的 compiler;成本等其他條件相同,買 C3 配 I1 或 I2 皆可。

310%

You are going to enhance a computer, and there are two possible improvements: either make multiply instructions run four times faster than before, or make memory access instructions run two times faster than before. You repeatedly run a program that takes 100 seconds to execute. Of this time, 20% is used for multiplication, 50% for memory access instructions, and 30% for other tasks.

3.1 (4%) What will the speedup be if both improvements are made?

3.2 (6%) You are going to change the program described in Problem 3 so that the percentages are not 20%, 50%, and 30% anymore. Assuming that none of the new percentages is 0, what sort of program would result in a tie with regard to speedup (i.e., the same speedup) between the two individual improvements? Provide both a formula and some examples.

3.1 \(T_{new}=\dfrac{20}{4}+\dfrac{50}{2}+30=5+25+30=60\) s

\(100/60\approx1.67\)

3.2 multiply 佔 \(m\)、memory 佔 \(k\)、其他 \(1-m-k\)(皆 \(\gt0\))

\(S_m=\dfrac{1}{(1-m)+m/4}=\dfrac{1}{1-\frac34m}\),\(S_k=\dfrac{1}{(1-k)+k/2}=\dfrac{1}{1-\frac12k}\)

相等 → \(\tfrac34m=\tfrac12k\)

\(k=1.5\,m\) (memory 的時間比例是 multiply 的 1.5 倍)

multiplymemory其他兩者各自 speedup
10%15%75%1.081
20%30%50%1.176
30%45%25%1.290

原題 20%/50%/30% 不滿足 \(k=1.5m\),兩種改善 speedup 不同(1.176 與 1.333)。

416%

Figure 1 gives the datapath of a pipelined processor with forwarding and hazard detection (IF/ID、ID/EX、EX/MEM、MEM/WB pipeline registers; hazard detection unit using ID/EX.MemRead; forwarding unit comparing ID/EX.RegisterRs, ID/EX.RegisterRt with EX/MEM and MEM/WB destination registers).

4.1 (3%) We have a program of 1000 instructions in the format of "lw, add, lw, add, ..." The add instruction depends (and only depends) on the lw instruction right before it. The lw instruction also depends (and only depends) on the add instruction right before it. If the program is executed on the pipelined datapath of Figure 1, what would be the actual CPI?

4.2 (3%) What would be the actual CPI for the program in Problem 4.1 without forwarding?

4.3 (4%) Consider executing the following code on the pipelined datapath of Figure 1. How many cycles will it take to execute this code?

lw   $4, 100($2)
sub  $6, $4, $3
add  $2, $3, $6
add  $7, $5, $2

4.4 (6%) With regard to the code in Problem 4.3, explain what the forwarding unit is doing during the sixth cycle of execution. If any comparisons are being made, mention them.

4.1 lw 後緊接用到 lw 結果的 add:load-use,forwarding 也要 stall 1 拍

add 後緊接的 lw 用 add 的結果當 base:EX/MEM 往前送,不用 stall

500 個 add 各 1 個 stall:\(\text{cycles}\approx1000+500=1500\)(含填 pipeline 的 4 拍為 1504)

CPI \(\approx1.5\)

4.2 沒有 forwarding:結果要等 WB 才寫回,register 前半 cycle 寫、後半 cycle 讀,相鄰相依要 stall 2 拍

每條指令都依賴前一條,999 對:\(\text{cycles}\approx1000+999\times2\approx3000\)

CPI \(\approx3.0\)

4.3 sub 用到 lw 剛載入的 $4:load-use,stall 1 拍;第三、四條各用前一條的 ALU 結果,靠 forwarding 不用 stall

cycle123456789
lw $4IFIDEXMEMWB
sub $6IFIDIDEXMEMWB
add $2IFIFIDEXMEMWB
add $7IFIDEXMEMWB

9 個 cycle

4.4 第 6 個 cycle:sub 在 MEM、add $2 在 EX、add $7 在 ID,MEM/WB 裡是 stall 留下的 bubble(RegWrite=0)

forwarding unit 為 EX 階段的 add $2,$3,$6 比對 ID/EX.Rs(=$3)、ID/EX.Rt(=$6)與兩個後級的 destination:

比對結果
EX/MEM.Rd(=$6,RegWrite=1)= ID/EX.Rs($3)?否
EX/MEM.Rd(=$6)= ID/EX.Rt($6)?是
MEM/WB(bubble,RegWrite=0)與 Rs、Rt 比對不成立

ForwardB = 10:第二個 ALU 運算元取 EX/MEM 中 sub 的結果($6);ForwardA = 00:第一個運算元用 register file 的值

516%

We have a program core consisting of several conditional branches. The program core will be executed thousands of times. Below are the outcomes of each branch for one execution of the program core (T for taken, N for not taken).

Branch 1: T-T-T-T, Branch 2: N-N-N-N-N, Branch 3: T-N-T-N-T-N, Branch 4: T-T-T-N-T

Assume the behavior of each branch remains the same for each program core execution. For dynamic schemes, assume each branch has its own prediction buffer and each buffer initialized to the same state before each execution. List the predictions and calculate the prediction accuracy for the following branch prediction schemes:

5.1 (5%) Always-taken

5.2 (5%) 1-bit predictor (initialized to predict taken)

5.3 (6%) 2-bit predictor as shown in Figure 2 (initialized to weakly predict taken)

Predict takenPredict taken(weakly)Predict not takenPredict not taken Not takenTakenNot takenTakenTakenNot taken

2-bit predictor 狀態:S1 左上(predict taken)、S2 右上(weakly taken)、S3 右下(predict not taken,Not taken 自環)、S4 左下(predict not taken)

S1:T→S1,N→S2 S2:T→S1,N→S3 S3:N→S3,T→S4 S4:T→S1,N→S3

5.1 Always-taken:預測全是 T

Branch實際預測對
1T T T TT T T T4/4
2N N N N NT T T T T0/5
3T N T N T NT T T T T T3/6
4T T T N TT T T T T4/5

\(11/20=55\%\)

5.2 1-bit(初始預測 T,預測=上一次結果)

Branch實際預測對
1T T T TT T T T4/4
2N N N N NT N N N N4/5
3T N T N T NT T N T N T1/6
4T T T N TT T T T N3/5

\(12/20=60\%\)

5.3 2-bit,初始 S2(weakly taken)

Branch狀態變化實際預測對
1S2→S1→S1→S1→S1T T T TT T T T4/4
2S2→S3→S3→S3→S3→S3N N N N NT N N N N4/5
3S2→S1→S2→S1→S2→S1→S2T N T N T NT T T T T T3/6
4S2→S1→S1→S1→S2→S1T T T N TT T T T T4/5

\(15/20=75\%\)

Branch 3 在 S1、S2 間來回,一直預測 taken,3 次 taken 全中、3 次 not taken 全錯。

612%

The average memory access time (AMAT) is possibly useful as a figure of merit for different cache systems.

6.1 (3%) Find the AMAT for a processor with a 2 ns clock, a miss penalty of 20 clock cycles, a miss rate of 0.06 misses per instruction, and a cache access time (including hit detection) of 1 clock cycle. Assume that the read and write miss penalties are the same and ignore other write stalls.

6.2 (3%) Suppose we can improve the miss rate to 0.04 misses per reference by doubling the cache size. This causes the cache access time to increase to 1.2 clock cycles. Using the AMAT as a metric, determine if this is a good trade-off.

6.3 (6%) If the cache access time determines the processor's clock cycle time, which is often the case, AMAT may not correctly indicate whether one cache organization is better than another. If the processor's clock cycle time must be changed to match that of a cache, is this a good trade-off? Assume the processors are identical except for the clock rate and the number of cache miss cycles; assume 1.5 references per instruction and a CPI without cache misses of 2. The miss penalty is 20 cycles for both processors.

6.1 \(\text{AMAT}=\text{hit time}+\text{miss rate}\times\text{miss penalty}=1+0.06\times20=2.2\) cycles

\(2.2\times2\text{ ns}=4.4\) ns

6.2 \(\text{AMAT}=1.2+0.04\times20=2.0\) cycles \(=4.0\) ns

4.0 ns \(\lt\) 4.4 ns:以 AMAT 看是好的取捨

6.3 第二台的 miss 次數/指令 \(=0.04\times1.5=0.06\),與第一台(0.06/指令)相同

\(\text{CPI}=2+0.06\times20=3.2\)(兩台都是 3.2)

第二台 cache 要 1.2 個舊 cycle,clock 拉長到 \(1.2\times2=2.4\) ns

處理器CPIclock每條指令時間
原本的 cache3.22.0 ns6.40 ns
加倍的 cache3.22.4 ns7.68 ns

\(7.68/6.40=1.2\):原本的處理器較快,不是好的取捨

若把 6.1 的 0.06 也當成每次 reference 的 miss rate,則原本 \(2+1.5\times0.06\times20=3.8\),時間 7.6 ns,仍比 7.68 ns 短,結論相同。AMAT 把 hit time 與 miss penalty 都以各機器自己的 cycle 計,clock 不同時不能直接比較。

720%

Consider three processors with different cache configurations: Cache 1: Direct-mapped with two-word blocks; Cache 2: Direct-mapped with four-word blocks; Cache 3: Two-way set associative with four-word blocks. The following miss rate measurements have been made: Cache 1: Instruction miss rate is 3.75%; data miss rate is 5%. Cache 2: Instruction miss rate is 2%; data miss rate is 4%. Cache 3: Instruction miss rate is 2%; data miss rate is 3%.

For these processors, one-half of the instructions contain a data reference. Assume that the cache miss penalty is 6 + Block size in words. The CPI for this workload was measured on a processor with Cache 1 and was found to be 2.0.

7.1 (6%) Assuming a cache of 16K blocks and a 32-bit address, find the total number of sets and the total number of tag bits for Cache 1, Cache 2, and Cache 3.

7.2 (6%) Determine which processor spends the most cycles on cache misses.

7.3 (8%) The cycle times for the processors in Problem 7.2 are 400 ps for the first and second processors and 300 ps for the third processor. Determine which processor is the fastest and which is the slowest.

7.1 16K \(=2^{14}\) 個 block

setsbyte offsetindextag/blocktotal tag bits
Cache 1(DM,2 words=8 B)16K314\(32-14-3=15\)\(15\times16384=245{,}760\)
Cache 2(DM,4 words=16 B)16K414\(32-14-4=14\)\(14\times16384=229{,}376\)
Cache 3(2-way,4 words)8K413\(32-13-4=15\)\(15\times16384=245{,}760\)

7.2 每條指令:1 次 instruction access + 0.5 次 data access;miss penalty:Cache 1 為 \(6+2=8\),Cache 2、3 為 \(6+4=10\)

miss/指令penaltymiss cycles/指令
Cache 1\(0.0375+0.5\cdot0.05=0.0625\)80.500
Cache 2\(0.02+0.5\cdot0.04=0.04\)100.400
Cache 3\(0.02+0.5\cdot0.03=0.035\)100.350

Cache 1 的處理器花在 miss 的 cycle 最多

7.3 Cache 1 的 CPI 2.0 含 0.5 miss cycles → 不含 miss 的基底 CPI \(=1.5\)

CPIcycle time每條指令時間
處理器 1\(1.5+0.5=2.0\)400 ps800 ps
處理器 2\(1.5+0.4=1.9\)400 ps760 ps
處理器 3\(1.5+0.35=1.85\)300 ps555 ps

處理器 3 最快,處理器 1 最慢

109–115 的詳解也是這樣寫的。

國立中山大學 109–115 的詳解收錄在付費版;106–115 全年度完整詳解共 236 頁,逐題推導。

購買 · NT$ 850 看中山其他免費詳解

其他年度與考科

同一年的其他科

同一科的其他年度

聯絡我們

題目有錯、詳解看不懂,都歡迎來信

想許願補哪一份、對購買有疑問也可以,收到後會盡快回覆。

william.chou.123123@gmail.com