C_and_CPP 板


LINE

※ 引述《johnjohnlin ()》之銘言: : 上面有推文說這篇做 GPU 黑箱測試的方法 : 可以測試出 cache 大小、way 數等等的資訊 (Figure 1) : https://mc.stanford.edu/cgi-bin/images/6/65/SC08_Volkov_GPU.pdf : 因為這篇有點久之前看的了,有點印象模糊 : 重新讀了一遍,想說自己來回一下好了 感謝回覆, 這篇paper也是非常有幫助 心得網址: https://tinyurl.com/yxrczcyv 原本以為在 4K 時最慢只是因為J大提到的 Collision Miss,但我又做了一些實驗,當我把 array size 降為 16K 時,發現速度仍然是在 4K 時最慢,這時我們只會去存取 4個 element, 照理來說 Set 0 是放的下的,那為什麼還會最慢呢? Google了很久才找到答案,這與Intel CPU 針對 data hazard 設計的機制有關。 先複習一下 Data Hazard 是什麼,從下圖的例子可以看到 add r1,r2,r3 之後緊接著 sub r4,r1,r3 指令,這代表第二條 sub 指令會用前面的 r1 計算完 add 後的值,但因 為 pipeline 設計,在 sub 指令進入execute階段時,這時 r1還未 writeback,所以會 導致結果錯誤。 為了解決這個問題,CPU會有 Forwarding 的機制,也就是圖中看到的紅線,如果將 add 算完後的值提早在 execute階段之後就能傳入給 sub ,這樣一來就不用等到 writeback 了。 圖片來源: https://webdocs.cs.ualberta.ca/~amaral/courses/429/webslides/Topic3-Pipelining/sld033.htm Forwarding to avoid data hazard 課本裡面的例子講到的都是對於 Register的 forwarding ,但實際上應用 x64 架構可以 直接存取 memory,例如 add BYTE PTR [rdi+rcx], 10 ,這時必須得要算出實際上的位 置 (rdi+rcx),才知道跟前面的指令是不是會有 hazard產生。 而 Intel CPU的設計剛好紀錄這個位置的 memory order buffer 只能存 address 的 LSB 12 Bits,剛好就是 4KB,所以,在存取 array[4096] 時,Intel CPU 會以為我們在 存取 array[0],會試著把他forward給下一次的 add,而要直到 array[4096] 的位置被 完全 decode 之後,CPU才發現原來之前的 forwarding 是錯的,得要重新 load 一次 array[4096],此時會產生 5 cycles 的 delay。 因此,在 4K 時一直不斷產生了 5 Cycles 的 delay ,但與 L2 Cache Fetch 的時間比 起來還是較少的 (CPU : L2 Cache = 1:14),所以導致些微上升。 全文: https://software.intel.com/en-us/forums/intel-vtune-amplifier/topic/606846 When an earlier (in program order) load issued after a later (in program order) store, a potential WAR (write-after-read) hazard exists. To detect such hazards, the memory order buffer (MOB) compares the low-order 12 bits of the load and store in every potential WAR hazard. If they match, the load is reissued, penalizing performance. However, as only 12 bits are compared, a WAR hazard may be detected falsely on loads and stores whose addresses are separated by a multiple of 4096 (2^12). This metric estimates the performance penalty of handling such falsely aliasing loads and stores. This occurs when a load is issued after a store and their memory addresses are offset by (4K). When this is processed in the pipeline, the issue of the load will match the previous store (the full address is not used at this point), so pipeline will try to forward the results of the store and avoid doing the load (this is store forwarding). Later on when the address of the load is fully resolved, it will not match the store, and so the load will have to be re-issued from a later point in the pipe. This has a 5-cycle penalty in the normal case, but could be worse in certain situations, like with un-aligned loads that span 2 cache lines. --



※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.171.25.61 (臺灣)
※ 文章網址: https://webptt.com/m.aspx?n=bbs/C_and_CPP/M.1566630443.A.346.html ※ 編輯: hsnuer1171 (1.171.25.61 臺灣), 08/24/2019 15:10:19
1F:推 johnjohnlin: 沒想到還有這種這麼細的陷阱 XD 08/24 16:34
2F:→ hsnuer1171: 真的xD 太多設計在裡面 08/24 16:37
3F:推 sarafciel: 推 每次看計結的東西都覺得跟玩海龜湯沒兩樣XD 08/26 08:47
4F:→ sarafciel: 哪天有個能像debugger一樣step by step看CPU細部運作的 08/26 08:51
5F:→ sarafciel: 工具就好了......雖然有生之年可能看不到(目死 08/26 08:54
6F:→ a58524andy: RISCV成功推廣之後說不定會有(? 08/26 09:41
7F:→ a58524andy: 其他proprietary的感覺不太可能會出 08/26 09:41
8F:→ cc1plus: 我看過 Cavium MIPS64 有可以看 step by step CPU cycle 08/27 10:51
9F:→ cc1plus: 的工具, 不過一般人應該拿不到 08/27 10:52
10F:推 Ryspon: 推實驗~ 不過你的文章裡 Step = 64 應該是”每 1 次”存 08/29 03:18
11F:→ Ryspon: 取就會有一次 cache line miss 吧? 08/29 03:18
12F:→ hsnuer1171: 對!! 感謝 我修正一下 08/29 12:28







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:Gossiping站內搜尋

TOP