看板 C_and_CPP 關於我們 聯絡資訊
小弟目前在練習 cuda 程式 發現在多 thread 同時進行寫入下會有 race condition 問題 ex : 計算整個 array 裡面某個值的數量 變的要用另一個相同大小 array 去判斷 這樣下來反而速度是拖慢的 請問有較快的解決方法嗎? 說明一下我程式 : 這個 array 是 1000 x 1000 大小 所以我開了 1000 x 1000 threads 下去判斷 if (idx < 1000 x 1000 && array[idx] == 1) sum++; 就發生~ race condition 問題了~ 一次跑完1000x1000筆判斷 thread 會搶寫入空間 , 導致sum錯誤 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.123.106.104
littleshan: __syncthreads()? 04/21 16:37
※ 編輯: evilned 來自: 140.123.106.104 (04/21 17:19) ※ 編輯: evilned 來自: 140.123.106.104 (04/21 17:19)
littleshan:你這個問題是典型的 reduction 04/21 17:54
littleshan:去找一些講 parallel computing 的教科書應該都會講 04/21 17:56
ironhead:1000x1000? in 1.x, thread id x*y*z must <= 512 ... 04/21 21:08
ironhead:BTW...you need thread sync & share memory 04/21 21:11
littleshan:它的1000x1000應該是指乘上block後的總數 04/21 21:33
evilned:有人有明確一點的說明嗎? 感謝 04/21 22:03
evilned:可能大家有點誤會了 我想問的是CUDA本身有防這種錯誤的機 04/21 22:09
evilned:制嗎?還是遇到了只能自己處理? 04/21 22:10
lgen7604:你想問的該不會是atomicAdd吧 04/21 22:46
xxxx9659:有誰可以告訴我 if(idx >= range || idx+range >= size) 05/23 05:00
xxxx9659:|| 後面的 idx+range >= size 再做什麼 看不懂@@ 05/23 05:02
xxxx9659:推錯篇了 是回覆那篇= = 05/23 05:04