計算機組織與結構›Ch3 效能評估(Performance)第 8 題/共 35 題
8. Arithmetic Intensity、Cache Residency
#CC-03-008中Arithmetic IntensityCache Residency
題組題幹(本題:Q3,共 5 小題)點擊展開
如下所示,函式 compute_distance 遍歷一串2D點並計算每一對點之間的距離。注意每個點是用single precision浮點數表示。請回答下列問題。
void compute_distance(float x[], float y[], int N, float distance[]) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
float x_dist = x[i] - x[j];
float y_dist = y[i] - y[j];
distance[j + i * N] = sqrt(x_dist*x_dist + y_dist*y_dist);
}
}
}
(Q3,2分)接續前一題,假設我們把處理器做得夠大,可以容納全部的2D點,使得在函式被呼叫前,所有的x[]與y[]都已經在cache裡。在這個情況下,這個函式的arithmetic intensity是多少?
📄 台大112
▤完整推導請見《WH 資工筆記 · 計算機組織與結構》Ch3 效能評估(Performance)