113 年 國立中山大學資訊工程學系碩士班甲組《計算機結構》
第 1 題8 分
(8% total) When parallelizing an application, the ideal speedup is speeding up by the number of processors. This is limited by two things: percentage of the application that can be parallelized and the cost of communication. If 80% of the application is parallelizable, answer the following questions.
1.1 (4%) What is the speedup with 8 processors, ignoring the cost of communication?
1.2 (4%) What is the speedup with 8 processors if, for every time the number of processors is doubled, the communication overhead is increased by 0.5% of the original execution time?
登入後即可作答並保存紀錄。
核心觀念
本題的核心考點為平行計算架構中的阿姆達爾定律(Amdahl's Law)以及通訊開銷(Communication Overhead)對平行加速效能的影響。
-
阿姆達爾定律(Amdahl's Law):
定義加速比(Speedup)為單一處理器之執行時間()與 個處理器平行執行時間()的比值:
若程式中可平行化比例為 ,不可平行化(循序執行)比例為 ,在忽略通訊與同步開銷的情況下:
-
納入通訊開銷之平行執行時間:
當考量通訊額外開銷()時,總平行執行時間變為:
加速比則修正為:
解題方法
令單一處理器的原始執行時間為基準 。
已知可平行化比例 ,循序比例 ,處理器個數 。
1.1 計算忽略通訊成本時的加速比()
-
計算平行執行時間 :
-
計算加速比:
1.2 計算加入通訊開銷時的加速比()
-
計算處理器數量倍增次數:
處理器數量從 增長至 ,每次加倍為一個增量週期:
倍增次數為 次。 -
計算總通訊開銷 :
題目定義「每倍增一次處理器數量,通訊開銷增加原始執行時間的 」:
第 2 題8 分
(8% total) Assume a hypothetical GPU with the following characteristics:
■ Clock rate 2.0 GHz
■ Contains 16 SIMD processors, each containing 16 single-precision floating-point units
■ Has 600 GB/sec off-chip memory bandwidth
2.1 (4%) Without considering memory bandwidth, what is the peak single-precision floating-point throughput for this GPU in GFLOPS/sec, assuming that all memory latencies can be hidden?
2.2 (4%) Is this throughput sustainable given the memory bandwidth limitation? Please explain your reasons clearly.
登入後即可作答並保存紀錄。
核心觀念
本題考查兩個概念:
-
GPU 的峰值浮點吞吐量
計算所有可同時工作的浮點單元數,再乘上時脈頻率。 -
記憶體頻寬限制與算術強度(Arithmetic Intensity)
算術強度定義為:GPU 的實際效能受下式限制:
即使記憶體延遲能完全隱藏,有限的記憶體頻寬仍可能限制吞吐量。
解題方法
2.1 峰值單精度浮點吞吐量
GPU 中的單精度浮點單元總數為:
時脈頻率為:
在每個浮點單元每個 clock 完成 1 次浮點運算的假設下:
因此:
2.2 記憶體頻寬是否足以維持此吞吐量
要維持 ,所需的最低算術強度為:
因此:
- 若 ,記憶體頻寬足以支撐計算單元達到 。
- 若 ,效能會受記憶體頻寬限制,無法達到峰值。
題目未提供實際程式的資料搬移量,因此嚴格而言缺少算術強度,無法對所有程式給出唯一的「是」或「否」。依考題常見的無資料重用、每次浮點運算都需要搬移一個新的單精度值之假設:
單精度數值占 bytes,因此:
此時記憶體頻寬所能支撐的最高計算吞吐量為:
小於計算單元的峰值 ,所以在此假設下無法維持峰值吞吐量。
等價地說,若要維持 ,即使每個 FLOP 只需搬移一個 -byte 單精度值,也需要:
第 3 題18 分
(18% total) Assume that individual stages of the datapath have the following latencies, and instructions executed by the processor are broken down as the following percentages:
IF
ID
EX
MEM
WB
250 ps
150 ps
350 ps
300 ps
200 ps
alu
45%
beq
lw
SW
10%
25%
20%
3.1 (4%) What is the clock cycle time in a non-pipelined and pipelined processor, respectively?
3.2 (4%) What is the individual total latency of the following two instructions: lw, beq in a non-pipelined and pipelined processor?
3.3 (6%) Assuming there are no stalls or hazards, what is the total execution time of the following four instructions: lw, sw, add, beq in a non-pipelined and pipelined processor, respectively?
3.4 (4%) Assuming there are no stalls or hazards, what is the utilization of the data memory and the write-register port of the "Register" unit?
登入後即可作答並保存紀錄。
3.1 時脈週期時間 (Clock Cycle Time)
-
非流水線處理器 (Non-pipelined / Single-cycle):
時脈週期時間由執行時間最長的指令(即經過全部 5 個階段的lw指令)決定:
-
流水線處理器 (Pipelined):
時脈週期時間由延遲最長的單一階段(EX 階段)決定:
【答案】非流水線處理器為 ;流水線處理器為 。
3.2 個別指令總延遲 (Individual Total Latency)
-
非流水線處理器:
單一時脈週期架構下,時脈週期固定為 ,故每筆指令執行時間皆佔據一個完整時脈週期 (若按硬體實際經過的階段延遲,lw為 ,beq為 )。 -
流水線處理器:
所有指令在流水線中皆須通過 5 個 pipeline 階段,總延遲為:
因此lw與beq的總延遲皆為 。
【答案】
- 非流水線處理器:
lw為 ;beq為 (硬體路徑延遲為 )。 - 流水線處理器:
lw為 ;beq為 。
3.3 四筆指令總執行時間 (Total Execution Time)
- 非流水線處理器:
執行 4 筆指令需要 4 個時脈週期:
第 4 題15 分
(15% total) The importance of having a good branch predictor depends on how often conditional branches are executed. Together with branch predictor accuracy, this will determine how much time is spent stalling due to mispredicted branches. Assume that the breakdown of dynamic instructions into various instruction categories is as follows:
R-Type
40%
BEQ
20%
JMP
5%
LW
25%
SW
10%
Also, assume the following branch predictor accuracies:
Always-Taken
40%
Always-Not-Taken
60%
2-Bit
80%
4.1 (5%) Assume no stall cycle is required when branch prediction is correct. Stall cycles due to mispredicted branches increase the CPI. What is the extra CPI due to mispredicted branches with the always-taken predictor? Assume that branch outcomes are determined in the EX stage of a basic 5-stage pipelined processor, that there are no data hazards, and that no delay slots are used.
4.2 (5%) Repeat 4.1 for the 2-bit predictor.
4.3 (5%) With the always-taken predictor, what speedup would be achieved if we could convert half of the branch instructions in a way that replaces a branch instruction with an ALU instruction? Assume that correctly and incorrectly predicted instructions have the same chance of being replaced.
登入後即可作答並保存紀錄。
觀念與前提設定
- 條件分歧指令(BEQ)比例:
- 分支預測錯誤懲罰(Penalty):在傳統 5 階段 Pipeline(IF, ID, EX, MEM, WB)中,若分支結果於 EX 階段(第 3 階段)確定,預測錯誤時需 Flush 已進入 IF 與 ID 階段的 2 個指令,懲罰時間為 個 Clock Cycles。
- 基礎 CPI:無任何 Hazard 下之理想 CPI 為 。
4.1
使用 Always-Taken 預測器,正確率為 ,預測錯誤率(Misprediction Rate)為 。
預測錯誤導致的額外 CPI(Extra CPI)計算如下:
【答案】
4.2
使用 2-Bit 預測器,正確率為 ,預測錯誤率為 。
額外 CPI 計算如下:
【答案】
4.3
將半數條件分歧指令替換為普通 ALU 指令:
- 原系統總 CPI:
第 5 題15 分
- (15% total) Caches are important to providing a high-performance memory hierarchy to processors.
Below is a list of 32-bit memory address references, given as word addresses.
3, 180, 43, 2, 191, 88, 190, 14, 181, 44, 186, 253
5.1 (9%) For each of these references, identify the binary address, the tag, and the index given a direct-mapped cache with two-word blocks and a total size of 8 blocks. Also list if each reference is a hit or a miss, assuming the cache is initially empty.
| Word Address | Binary Address | Tag | Index | Hit/Miss |
|---|---|---|---|---|
| 3 | 0000 0011 | 0 | 3 | Miss |
| 180 | ||||
| 43 | ||||
| 2 | ||||
| 191 | ||||
| ... | ||||
| 181 | ||||
| 44 | ||||
| 186 | ||||
| 253 |
5.2 (6%) How many total bits are required for a direct-mapped cache with 32 KiB of data, 8-word blocks, and 32-bit address?
登入後即可作答並保存紀錄。
5.1 快取記憶體存取追蹤分析
1. 快取結構與位址分割
依題意,快取組織為 Direct-Mapped Cache:
- 區塊大小 (Block Size):,因此每個區塊需要 作為 Block Offset(區塊內字組偏移量)。
- 區塊總數 (Number of Blocks):,因此快取索引需要 作為 Index(範圍 )。
- 位址表示與欄位切割:
題目給定為 Word Address,參照題目表格範例使用 8-bit 二進位表示(因為給定數列最大值 ):- Block Offset (最低 1 位元):
- Index (中間 3 位元):
- Tag (高位元):(若以 32-bit word address 表示則為高 28 位元)。
註(題目表格範例之印刷勘誤):
題目表格第一列範例給出 Word Address 3 之 、、。此處 Index 印為 3 顯係印刷筆誤(誤套用 1-word block 下 之結果)。在題幹指定的 2-word block 下,Word 3 與 Word 2 同屬 Block Address ,映射至 。以下依題意標準規格(2-word block, 8 blocks)進行完整推導,文末亦附上若出題者依範例筆誤計算之對照。
2. 各筆位址存取追蹤過程(初始快取為空)
- Word Address = 3 ():
- Offset: ,Index: (),Tag: ()
- 狀態:Miss(將 Block 1 載入 Tag 0,包含 Word 2 與 3)
- Word Address = 180 ():
- Offset: ,Index: (),Tag: ()
- 狀態:Miss(將 Block 2 載入 Tag 11,包含 Word 180 與 181)
- Word Address = 43 ():
- Offset: ,Index: (),Tag: ()
- 狀態:Miss(將 Block 5 載入 Tag 2,包含 Word 42 與 43)
- Word Address = 2 ():
- Offset: ,Index: (),Tag: ()
- 狀態:Hit(Block 1 內已有 Tag 0)
- Word Address = 191 ():
- Offset: ,Index: (),Tag: ()
- 狀態:Miss(將 Block 7 載入 Tag 11,包含 Word 190 與 191)
- Word Address = 88 ():
- Offset: ,Index: (),Tag: ()
- 狀態:Miss(將 Block 4 載入 Tag 5,包含 Word 88 與 89)
- Word Address = 190 ():
- Offset: ,Index: (),Tag: ()
- 狀態:Hit(Block 7 內已有 Tag 11)
- Word Address = 14 ():
- Offset: ,Index: (),Tag: ()
- 狀態:Miss(替換 Block 7,改存 Tag 0,包含 Word 14 與 15)
- Word Address = 181 ():
- Offset: ,Index: (),Tag: ()
- 狀態:Hit(Block 2 內已有 Tag 11)
- Word Address = 44 ():
- Offset: ,Index: (),Tag: ()
- 狀態:Miss(將 Block 6 載入 Tag 2,包含 Word 44 與 45)
- Word Address = 186 ():
- Offset: ,Index: (),Tag: ()
- 狀態:Miss(替換 Block 5,改存 Tag 11,包含 Word 186 與 187)
- Word Address = 253 ():
- Offset: ,Index: (),Tag: ()
- 狀態:Miss(替換 Block 6,改存 Tag 15,包含 Word 252 與 253)
3. 彙總結果表
| Word Address | Binary Address | Tag (Decimal / Binary) | Index (Decimal / Binary) | Hit / Miss |
|---|---|---|---|---|
| 3 | 0000 0011 | 0 (0000) | 1 (001) | Miss |
| 180 | 1011 0100 | 11 (1011) | 2 (010) | Miss |
| 43 | 0010 1011 | 2 (0010) | 5 (101) | Miss |
第 6 題16 分
(16% total) Assume that the CPI with a perfect cache is 2.0, the clock cycle time is 1.0 ns, there are 1.5 memory references per instruction, the size of both caches is 64 KB, and both have a block size of 64 bytes. One cache is direct mapped and the other is two-way set associative. Since the speed of the CPU is tied directly to the speed of a cache hit, assume the CPU clock cycle time must be stretched 1.3 times to accommodate the selection multiplexor of the set-associative cache. To the first approximation, the cache miss penalty is 80 ns for either cache organization. Assume the hit time is 1 clock cycle, the miss rate of a direct-mapped 64 KB cache is 1.5%, and the miss rate for a two-way set-associative cache of the same size is 1.1%.
6.1 (8%) Calculate the average memory access time for these two different cache organizations.
6.2 (8%) Calculate the CPU performance in terms of CPU time.
登入後即可作答並保存紀錄。
核心觀念
本題比較兩種快取組織的兩項指標:
-
平均記憶體存取時間:
-
CPU 執行時間:
完美快取下的 已包含正常快取命中的執行成本,因此只需額外加入快取未命中的停滯時間。
快取總區塊數為:
直接映射快取有 條快取線;二路組合相聯快取有 個集合,每集合含 條快取線。題目已直接給出兩者的 miss rate,因此不必再由位址存取序列推導 miss rate。
6.1 平均記憶體存取時間
直接映射快取
原始時脈週期為:
命中時間為一個時脈週期:
因此:
二路組合相聯快取
由於選擇多工器使 CPU 時脈週期延長為原本的 倍:
命中時間為:
因此:
二路組合相聯快取的 AMAT 為 ,略低於直接映射快取的 。
6.2 CPU 執行時間
設程式共有 條指令。每條指令平均有 次記憶體參考,因此每條指令的 miss 次數為:
每條指令的額外 miss 停滯時間為:
直接映射快取
每條指令的 miss 次數:
每條指令的 miss 停滯時間:
完美快取下,每條指令的基本執行時間為:
所以每條指令的平均 CPU 時間為:
等效 CPI 為:
因此:
二路組合相聯快取
每條指令的 miss 次數:
每條指令的 miss 停滯時間:
第 7 題20 分
(20% total) Consider the virtual memory system.
7.1 (8%) The following list provides parameters of a virtual memory system.
| Virtual Address (bits) | Physical DRAM Installed | Page Size | PTE Size (byte) |
|---|---|---|---|
| 42 | 16 GiB | 4 KiB | 4 |
For a single-level page table, how many page table entries (PTEs) are needed? How much physical memory is needed for storing the page table?
7.2 (12%) The following data constitutes a stream of virtual address as seen on a system. Assume 4 KiB pages, a 4-entry fully associative TLB, and true LRU replacement. If pages must be brought in from disk, increment the next largest page number.
TLB
| Valid | Tag | Physical Page Number |
|---|---|---|
| 1 | 11 | 12 |
| 1 | 7 | 4 |
| 1 | 3 | 6 |
| 0 | 4 | 9 |
Page table
| Valid | Physical Page or in Disk |
|---|---|
| 1 | 5 |
| 0 | Disk |
| 0 | Disk |
| 1 | 6 |
| 1 | 9 |
| 1 | 11 |
| 0 | Disk |
| 1 | 4 |
| 0 | Disk |
| 0 | Disk |
| 1 | 3 |
| 1 | 12 |
Given the following address stream: 4669, 13916, ..., and the initial TLB and page table states provided above, show the final state of the system. Also list for each reference if it is a hit in the TLB, a hit in the page table, or a page fault.
| Address | Virtual Page | TLB H/M | Valid | TLB<br>Tag | Physical Page Number |
|---|---|---|---|---|---|
| 4669 | |||||
| 13916 | |||||
登入後即可作答並保存紀錄。
7.1 單層頁表大小計算
1. 虛擬頁號(VPN)與頁內位移(Offset)位元數
- 頁面大小(Page Size):
因此頁內位移(Offset)需要 12 bits。 - 虛擬位址(Virtual Address):共 42 bits。
- 虛擬頁號(VPN)位元數:
2. 單層頁表所需 PTE 數量
在單層頁表(Single-Level Page Table)架構下,虛擬位址空間中的每一個虛擬頁皆對應一個頁表項(Page Table Entry, PTE):
3. 儲存頁表所需實體記憶體容量
每個 PTE 大小為 4 bytes:
因此,儲存該單層頁表共需 4 GiB 的實體記憶體空間。
7.2 記憶體存取模擬與系統狀態更新
系統參數與初始狀態
- 頁面大小:。
- TLB 架構:4-entry 全相聯(Fully Associative),採真實 LRU(True LRU)替換策略。
- 頁面替換規則:若從磁碟換入頁面,配置下一個最大的實體頁號(Increment the next largest page number)。
- 初始狀態中,頁表中最大的實體頁號為 12(VPN 11 對應到實體頁 12),因此首次從磁碟換入時分配的實體頁號為 。
位址存取逐步分析
Reference 1: Virtual Address = 4669
- 計算 VPN 與 Offset:
- 查詢 TLB:
初始 TLB 內有效的 Tag 為 ,不包含 Tag 1。
- 查詢 Page Table:
查詢 VPN 1 的頁表項,其狀態為Valid = 0, in Disk。
- 處理 Page Fault:
從磁碟將頁面載入實體記憶體,配置下一個最大實體頁號:
- 更新 Page Table:VPN 1 設為
Valid = 1, Physical Page = 13。
- 更新 Page Table:VPN 1 設為
- 更新 TLB:
TLB 原有一筆無效項目(Entry 3,Valid = 0),直接將新映射填入該空項:
依 LRU 策略,VPN 1 成為最近存取項(MRU)。
Reference 2: Virtual Address = 13916
- 計算 VPN 與 Offset:
- 查詢 TLB:
比對 TLB 各項,Entry 2 具備Valid = 1且Tag = 3,比對成功。
- 轉換位址:
直接自 TLB 取得對應之實體頁號 。