114 年 國立成功大學人工智慧科技碩士學位學程《計算機組織與系統(計算機組織及作業系統)》

📄 試題原卷 免費註冊後即可對照原始考卷 PDF免費註冊

第 1 題15 分

Consider a memory hierarchy consisting of two-tier memory subsystems A and B. The access latencies averaged per unit data item for A and B are LAL_A and LBL_B, respectively. Additionally, denote respectively the storage capacities for A and B as SAS_A and SBS_B. Moreover, assume the costs per bit for A and B are CAC_A and CBC_B, respectively. Note that CA>CBC_A > C_B. Consider the design that a processor reads (or writes) A if A can deliver requested data items. Otherwise, the processor reads (or writes) B, and supplies A with the missed data items so that the processor can then fetch data from A. If we intend to come up with a cost-effective design in minimizing average memory access latency, please identify true (denoted by o) or false (×) for the following questions.
(a) [5%] LA>LBL_A > L_B
(b) [5%] SACA>SBCBS_A C_A > S_B C_B
(c) [5%] None is true

登入後即可作答並保存紀錄。

這一題的完整詳解

核心觀念

這題考的是「記憶體階層」的設計原則:

  • 越靠近處理器的記憶體 A,應具有較低的存取延遲,但每 bit 成本較高、容量較小。
  • 較低層的記憶體 B,通常延遲較高,但每 bit 成本較低、容量較大。
  • A 未命中時,才到 B 取資料,並將資料填回 A。

設 A 的命中率為 hh。若每次存取都先查詢 A,則平均存取延遲可表示為

Lavg=hLA+(1−h)(LA+LB)=LA+(1−h)LB.L_{\text{avg}} = hL_A+(1-h)(L_A+L_B) = L_A+(1-h)L_B.

因此,A 必須比 B 快,才能降低整體平均存取延遲,即

LA<LB.L_A<L_B.

成本方面,兩層記憶體的總成本分別為

CostA=SACA,CostB=SBCB.\text{Cost}_A=S_A C_A,\qquad \text{Cost}_B=S_B C_B.

其中 CA>CBC_A>C_B 只代表 A 的「每 bit 成本」較高,不能單獨推論總成本 SACAS_A C_A 一定大於 SBCBS_B C_B。容量大小也會影響總成本。

選項分析

(a) LA>LBL_A>L_B

錯誤,判定為 ×。

A 是優先被查詢的上層記憶體。若 LA>LBL_A>L_B,即使 A 命中,存取時間也比直接存取 B 更久;若 A 未命中,還要額外付出 A 的查詢時間,再存取 B。

因此,A 應滿足

LA<LB,L_A<L_B,

而不是 LA>LBL_A>L_B。


(b) SACA>SBCBS_A C_A>S_B C_B

錯誤,判定為 ×。

題目只給定

🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 2 題15 分

Recall that a random variable X follows the exponential distribution of the probability density function f(x)=λe−λxf(x) = \lambda e^{-\lambda x}, where λ\lambda is a given parameter. Assume that processes in a computer system have their execution time following the exponential distribution. Let two processes A and B have lifetimes represented by the random variables XAX_A and XBX_B with parameters λA\lambda_A and λB\lambda_B, respectively. Here, λA=100<λB=200\lambda_A = 100 < \lambda_B = 200. Both processes activate their execution at time 0. The computer system hosts a single processor. Please identify true (0) or false (×) for the followings.
(a) [5%] Pr(XA≥101∣XA≥100)=Pr(XB≥111∣XB≥110)Pr(X_A \ge 101 | X_A \ge 100) = Pr(X_B \ge 111 | X_B \ge 110)
(b) [5%] If we employ the shortest job scheduling, then A shall be scheduled first and then B.
(c) [5%] For any scheduling policy, the total expected time to finish both tasks is 300.

登入後即可作答並保存紀錄。

這一題的完整詳解

核心觀念

指數分布的機率密度函數為

fX(x)=λe−λx,x≥0f_X(x)=\lambda e^{-\lambda x},\qquad x\ge 0

其存活函數為

P(X≥t)=∫t∞λe−λx dx=e−λt.P(X\ge t)=\int_t^\infty \lambda e^{-\lambda x}\,dx=e^{-\lambda t}.

此外,指數分布具有無記憶性:

P(X≥s+t∣X≥s)=P(X≥s+t)P(X≥s)=e−λt.P(X\ge s+t\mid X\ge s) =\frac{P(X\ge s+t)}{P(X\ge s)} =e^{-\lambda t}.

平均執行時間為

E[X]=1λ.E[X]=\frac{1}{\lambda}.

因此,λ\lambda 越大,平均執行時間越短。本題中

E[XA]=1100,E[XB]=1200.E[X_A]=\frac{1}{100},\qquad E[X_B]=\frac{1}{200}.

所以 B 的期望執行時間較短。


選項分析

(a)

對 A 而言:

P(XA≥101∣XA≥100)=P(XA≥101)P(XA≥100)=e−100(101)e−100(100)=e−100.\begin{aligned} P(X_A\ge 101\mid X_A\ge 100) &=\frac{P(X_A\ge 101)}{P(X_A\ge 100)}\\ &=\frac{e^{-100(101)}}{e^{-100(100)}}\\ &=e^{-100}. \end{aligned}

對 B 而言:

P(XB≥111∣XB≥110)=P(XB≥111)P(XB≥110)=e−200(111)e−200(110)=e−200.\begin{aligned} P(X_B\ge 111\mid X_B\ge 110) &=\frac{P(X_B\ge 111)}{P(X_B\ge 110)}\\ &=\frac{e^{-200(111)}}{e^{-200(110)}}\\ &=e^{-200}. \end{aligned}

由於

e−100≠e−200,e^{-100}\ne e^{-200},

兩者不相等。因此本選項錯誤。

答案:×


🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 3 題20 分

Consider a disk file F that stores a set of key-value pairs. "y = READ(x)" API is provided to return the value y for a designated key x if the key-value pair (x, y) is available in F. "WRITE(x, y)" API is to write the provided (x,y) into F if (x, y) is absent; otherwise, WRITE(x, y) updates the key x with the value y. Here, READ(·) and WRITE(·) are independent processes (or threads). Please identify true (0) or false (×) for the potential designs, as follows, that optimize the read and write operations (in terms of access latency) over the file F. Assume S be the set of key-value pairs stored in F.
(a) [5%] Partition S into a number of disjoint blocks {s}\{s\}, i.e., S=∪{s}S = \cup\{s\}. Each block s∈Ss \in S serves as a fetching unit between the memory and disk subsystems. Given (x,y)∈s(x, y) \in s, we allocate a memory block mm to store ss copied from the disk. Then, retrieve (x,y)(x, y) from mm and deliver the result for READ(). For efficiency, the keys in mm shall be organized in a balanced search tree, for example.
(b) [5%] For WRITE(), update (x,y)(x, y) in mm. When mm is replaced, mm shall be written back to F and the original s∈Fs \in F may be overwritten.
(c) [5%] We shall additionally create a local file index I in the file system for locating (x,y)(x, y) in S. That is, I helps rapidly identify which of s∈Ss \in S storing (x,y)(x, y). I shall be replicated in the memory (denoted by I∗I^*) to minimize the number of IO operations performed over the disk subsystem. I∗I^* is updated for newly arrivals (x,y)(x, y) due to WRITE(). Consequently, I∗I^* and I may be inconsistent.
(d) [5%] Possibly, multiple WRITE() operations address the identical key x. These WRITE() operations may be concurrently invoked by distinct clients. One potential implementation is that each WRITE(·) successfully acquires the locks for accessing both mm and I∗I^* before the WRITE() can proceed to update the value of x. Once the value is committed, both locks are released. With such an implementation, it is NOT possible to introduce deadlock due to various WRITE() operations.

登入後即可作答並保存紀錄。

這一題的完整詳解

核心觀念

本題綜合考查四個觀念:

  1. 磁碟區塊與記憶體緩衝區:磁碟通常以區塊 ss 為傳輸單位,讀取時將整個區塊載入記憶體區塊 mm,可減少磁碟 I/O。
  2. 寫回式快取(write-back cache):先修改記憶體中的資料,區塊被替換時再寫回磁碟。
  3. 檔案索引的一致性:記憶體索引 I∗I^* 與磁碟索引 II 必須維持可恢復的一致狀態。
  4. 鎖與死結(deadlock):同時持有多把鎖時,必須遵守固定的鎖定順序,才能避免循環等待。

設磁碟檔案被分割為區塊 s1,s2,…,sns_1,s_2,\ldots,s_n,則可寫成:

S=s1⊎s2⊎⋯⊎snS=s_1 \uplus s_2 \uplus \cdots \uplus s_n

其中 ⊎\uplus 表示各區塊彼此不重疊。若目標區塊已在記憶體中,則為 cache hit,不需磁碟 I/O;若不在記憶體中,則需先讀入整個區塊。


選項分析

(a)正確(0)

將 SS 分割成多個互斥區塊,並以區塊作為記憶體與磁碟之間的傳輸單位,是檔案系統與資料庫常用的設計。

當 (x,y)∈si(x,y)\in s_i 時,先將 sis_i 載入記憶體區塊 mm,再於 mm 中搜尋 (x,y)(x,y)。若 mm 已經在記憶體中,便可直接完成讀取;若尚未載入,則只需進行一次區塊讀取。

若區塊內的索引採用平衡搜尋樹,則搜尋時間約為:

O(log⁡∣si∣)O(\log |s_i|)

相較於逐一掃描區塊內所有鍵值對的 O(∣si∣)O(|s_i|),可降低 CPU 搜尋成本。因此,此設計能同時利用:

  • 記憶體快取降低磁碟 I/O;
  • 平衡搜尋樹降低區塊內搜尋時間。

須注意,平衡搜尋樹只能快速搜尋「已載入的區塊」;要找出目標區塊 sis_i,仍需檔案索引或其他區塊定位機制,但這不影響本選項作為緩衝設計的正確性。


(b)正確(0)

此設計採用的是寫回式快取。

執行 WRITE(x,y) 時,先在記憶體區塊 mm 中修改資料,並將 mm 標記為 dirty。當 mm 被替換時,才將修改後的整個區塊寫回磁碟,覆寫原本的 sis_i。

若同一區塊在被替換前被修改 kk 次:

  • write-through 可能需要進行 kk 次磁碟寫入;
  • write-back 只需在替換時寫回一次。

因此,寫回式快取能合併多次修改,降低寫入延遲。

此設計成立的條件包括:

  • 所有 READ() 與 WRITE() 都透過同一套快取管理;
  • dirty 區塊被替換前確實寫回磁碟;
  • 區塊仍被執行緒使用時不可直接替換,通常需使用 pin 或 reference count;
  • 若要求斷電後資料仍可恢復,還需搭配日誌或其他持久化機制。
🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 4 題30 分

Please indicate whether the following statements are Correct or Incorrect and provide your explanations to justify your answers.
(a) [5%] In the design of a microprocessor, the instruction set architecture of the processor completely hides all physical implementation details.
(b) [5%] For a given problem, the speedup achieved by a multicore processor is a critical factor in assessing the processor design. A multicore system exhibits strong scaling when the speedup is achieved without increasing the problem size, S, where the memory size utilized by each processor core is S.
(c) [5%] In the design of a multi-level processor cache, it is critical to balance between miss rate and miss penalty. The design of the first-level caches focuses on miss rate reduction, so larger cache blocks are desired to reduce the miss rate. The design of the second-level caches puts emphasis on miss penalty improvement to avoid higher memory access latencies.
(d) [5%] In the design of a pipelined processor, it is important to allow instructions to take fewer clock cycles in order to increase overall pipeline performance. A common practice is to make ALU instructions take fewer cycles to improve the processor throughput.
(e) [5%] In the design of arithmetic logic units, the speed of addition depends highly on the number of bits involved. As the number of bits increases, more 1-bit adders are required to calculate the sum of each bit and it leads to longer delays to obtain the sum for all bits involved.
(f) [5%] For the PC-relative addressing in RISC-V processors, the SB-format branches have a 12-bit address immediate and the UJ-format jumps have a 20-bit address immediate. These formats mean that a RISC-V program can branch within ±2^10 words of the current instruction and jump within ±2^18 words of the current instruction, if the PC is used as the register to be added to the address.

登入後即可作答並保存紀錄。

這一題的完整詳解

(a) 錯誤。ISA 只抽象指令語意、寄存器與記憶體模型,仍會透露字長、端序、對齊規則等架構資訊;微架構細節(流水線、快取層級、實體佈局)不會完全被隱蔽。

(b) 錯誤。強伸縮 (strong scaling) 指在固定總問題規模下隨核心數增加而加速;不涉及每核心使用與問題大小相同的記憶體量,題述的記憶體需求 S 與強伸縮定義不符。

(c) 錯誤。L1 快取追求低存取延遲與高頻寬,通常採用較小的快取塊以減少 miss penalty;L2 快取則以較大容量降低 miss rate,且其存取延遲仍高於 L1,故設計焦點與題述相反。

🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

第 5 題20 分

Please answer the following questions related to memory locality of matrix multiplication. The following C code having elements within the same row are stored contiguously. The nested loops perform the operations on the floating-point arrays, N and M. Each array element is a 32-bit floating-point number.
for (x=0; x<8; x++)
for (y=0; y<8000; y++)
N[x][y] = M[x][0] + N[x][y];
(a) [5%] Which variables demonstrate temporal locality in their references?
(b) [5%] Which variables demonstrate spatial locality in their references?
(c) [5%] If the cache size is unlimited, how many cache blocks, each with 4 words, are required to store all the referenced matrix elements?
(d) [5%] Assume that the data in the two arrays, N and M, are streaming over Internet (similar to a video streaming application) with predictable data accessing patterns. What technique can be used to bring up adjacent cache blocks into a buffer within the processor core to reduce the data accessing time? Note that when the data is found in the buffer, it is considered as a hit and moved into the cache for the next block. Please provide a detailed explanation of how this technique works.

登入後即可作答並保存紀錄。

這一題的完整詳解

核心觀念

本題考查快取的兩種區域性:

  • 時間區域性(temporal locality):某資料剛被存取後,很快再次被存取。
  • 空間區域性(spatial locality):某資料被存取後,附近位址的資料很快也會被存取。
  • C 語言的二維陣列採**列優先(row-major order)**儲存,因此同一列中,yy 增加 11 代表下一個連續元素。
  • 每個浮點數為 3232 位元,即 11 word;每個 cache block 有 44 words,即 1616 bytes。

陣列元素的線性位置可表示為:

offset⁡(A[x][y])=x×8000+y\operatorname{offset}(A[x][y])=x\times 8000+y

關鍵程式碼為:

for (x = 0; x < 8; x++)
    for (y = 0; y < 8000; y++)
        N[x][y] = M[x][0] + N[x][y];

(a) 時間區域性

對固定的 xx 而言,內層迴圈中 yy 從 00 跑到 79997999,因此:

M[x][0]M[x][0]

在同一列的 80008000 次迭代中都被重複讀取。第一次載入後,後續存取通常都能在 cache 中命中,因此 M[x][0]M[x][0] 展現明顯的時間區域性。

此外,原始程式中每次迭代的 N[x][y]N[x][y] 會先被讀取,再立即寫回同一元素,因此從完整的記憶體參考序列來看,N[x][y]N[x][y] 也具有極短距離的時間重用。不過,以迴圈層級的主要分類而言,M[x][0]M[x][0] 是本題要辨識的典型時間區域性。


(b) 空間區域性

N[x][y]N[x][y] 的存取順序為:

N[x][0],N[x][1],N[x][2],…,N[x][7999]N[x][0],N[x][1],N[x][2],\ldots,N[x][7999]

同一列的元素連續儲存,因此每次 yy 增加 11,位址前進 11 word,具有明顯的空間區域性。

例如一個 4-word cache block 可以同時包含:

N[x][0]∼N[x][3]N[x][0]\sim N[x][3]

處理完這四個元素後,下一個 block 會包含:

N[x][4]∼N[x][7]N[x][4]\sim N[x][7]

由於每列有 80008000 個元素,且 80008000 是 44 的倍數,從一列結尾接到下一列開頭時,仍可視為連續的 cache block 串流。

M[x][0]M[x][0] 在固定 xx 時是同一元素重複存取,並非空間區域性。當 xx 改變時,相鄰兩次存取相隔 80008000 words:

8000 words=2000 cache blocks8000\ \text{words}=2000\ \text{cache blocks}

因此也不具相鄰位址的空間區域性。


(c) 所需 cache block 數量

以下採用標準假設:陣列起始位址與 4-word cache block 對齊,且 NN 與 MM 為彼此獨立的陣列。

對 NN 而言,所有元素都會被參考:

8×8000=64000 words8\times 8000=64000\ \text{words}

每個 block 有 44 words,因此需要:

640004=16000 blocks\frac{64000}{4}=16000\ \text{blocks}

對 MM 而言,實際被參考的元素只有:

M[0][0],M[1][0],…,M[7][0]M[0][0],M[1][0],\ldots,M[7][0]
🔒

後續完整解題步驟與【答案】

免費註冊,享三天全站完整詳解閱覽。

免費註冊

其他考古題

114 年成功大學的其他科目

成功大學《計算機組織與系統》其他年度