[問題] CUDA shared-memory
開發平台(Platform): (Ex: Win10, Linux, ...)
WIN10
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
VC2017
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
CUDA 9.0
問題(Question):
想透過 shared memory 來加速kernal的效能
利用treadid 平行assign資料 也有用__syncthreads 來同步
但資料還是跟用迴圈跑的不一樣 (結果有錯)
想請問大大們我的使用方式有錯嗎? 還有vc上可以單步執行來看CUDA變數嗎?
餵入的資料(Input):
一維陣列的輸入與輸出指標
預期的正確結果(Expected Output):
USE_SHARED_MEM = 0 與 = 1 data值要一樣
錯誤結果(Wrong Output):
github:
https://github.com/ChiFang/question/blob/master/CUDA_SharedMem.cu
USE_SHARED_MEM = 1 會導致最後結果錯誤,表示data值不一樣 (後面程式完全一模一樣)
程式碼(Code):(請善用置底文網頁, 記得排版)
#define USE_SHARED_MEM 1
__global__ void kernal_test(const int a_RangeUpScale, const int
*a_CostData, int *a_Input)
{
// Get the work index of the current element to be processed
int y = blockIdx.x*blockDim.x + threadIdx.x; //執行緒在陣列中
對應的位置
#if USE_SHARED_MEM == 1
__shared__ int Buff[32];
#else
int Buff[32];
#endif
// Do the operation
for (int x = 1; (x < g_ImgWidth_CUDA); x++)
{
int TmpPos = y*Area + (x-1)*a_RangeUpScale;
#if USE_SHARED_MEM == 1
// Synchronize to make sure the sub-matrices are loaded before starting
the computation
__syncthreads();
if (threadIdx.x < 32)
{
Buff[threadIdx.x] = a_CostSmooth[TmpPos + threadIdx.x];
}
// Synchronize to make sure the sub-matrices are loaded before starting
the computation
__syncthreads();
#else
for (int cnt = 0; cnt < 32 ;cnt++)
{
Buff[cnt] = a_CostSmooth[TmpPos + cnt];
}
#endif
// use Buff to do something
}
}
補充說明(Supplement):
grid size = 8 block size = 135 所以thread id 一定會大於32
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.34.230.27
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1506996728.A.C64.html
→
10/03 10:30,
8年前
, 1F
10/03 10:30, 1F
→
10/03 10:40,
8年前
, 2F
10/03 10:40, 2F
→
10/03 10:44,
8年前
, 3F
10/03 10:44, 3F
→
10/03 11:27,
8年前
, 4F
10/03 11:27, 4F
→
10/03 11:28,
8年前
, 5F
10/03 11:28, 5F
→
10/03 11:32,
8年前
, 6F
10/03 11:32, 6F
推
10/03 12:16,
8年前
, 7F
10/03 12:16, 7F
→
10/03 12:16,
8年前
, 8F
10/03 12:16, 8F
→
10/03 12:37,
8年前
, 9F
10/03 12:37, 9F
→
10/03 13:00,
8年前
, 10F
10/03 13:00, 10F
※ 編輯: hardman1110 (114.34.230.27), 10/03/2017 13:24:40
→
10/03 13:26,
8年前
, 11F
10/03 13:26, 11F
※ 編輯: hardman1110 (114.34.230.27), 10/03/2017 13:31:48
→
10/03 14:00,
8年前
, 12F
10/03 14:00, 12F
→
10/03 14:01,
8年前
, 13F
10/03 14:01, 13F
→
10/03 14:09,
8年前
, 14F
10/03 14:09, 14F
→
10/03 14:19,
8年前
, 15F
10/03 14:19, 15F
→
10/03 14:19,
8年前
, 16F
10/03 14:19, 16F
→
10/03 14:20,
8年前
, 17F
10/03 14:20, 17F
※ 編輯: hardman1110 (114.34.230.27), 10/03/2017 14:21:21
→
10/03 14:22,
8年前
, 18F
10/03 14:22, 18F
→
10/03 14:23,
8年前
, 19F
10/03 14:23, 19F
→
10/03 14:24,
8年前
, 20F
10/03 14:24, 20F
→
10/03 14:25,
8年前
, 21F
10/03 14:25, 21F
→
10/03 14:27,
8年前
, 22F
10/03 14:27, 22F
→
10/03 14:27,
8年前
, 23F
10/03 14:27, 23F
→
10/03 14:28,
8年前
, 24F
10/03 14:28, 24F
→
10/03 14:30,
8年前
, 25F
10/03 14:30, 25F
→
10/03 14:31,
8年前
, 26F
10/03 14:31, 26F
→
10/03 14:32,
8年前
, 27F
10/03 14:32, 27F
→
10/03 14:36,
8年前
, 28F
10/03 14:36, 28F
→
10/03 14:55,
8年前
, 29F
10/03 14:55, 29F
→
10/03 14:56,
8年前
, 30F
10/03 14:56, 30F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章