[英]Why is this printf function fixing my OpenCL kernel?
我正在寫一個 kernel ,它使用 Hillis-Steele 掃描模式計算累積直方圖。 它似乎無法正常工作 - 輸出數字太高且順序錯誤。
不過在調試期間,我添加了一個簡單的 printf() function ,它只打印出每個運行的工作項的全局大小:
kernel void cumulative(global const int *hist, global int *c_hist) {
int id = get_global_id(0);
int size = get_global_size(0);
printf("%d\n", size); //MAKES THE CUMULATIVE HISTOGRAM CORRECT
for (int step = 1; step < size; step *= 2) {
c_hist[id] = hist[id];
if (id >= step) c_hist[id] += hist[id - step];
barrier(CLK_GLOBAL_MEM_FENCE);
global int* tmp = hist; hist = c_hist; c_hist = tmp;
}
}
有人能告訴我這里發生了什么嗎? 是否有任何東西可以修復此代碼,而不是一遍又一遍地打印 1024 到控制台?
將 OpenCL 2 與 RTX 2060 一起使用 - 如果需要任何其他信息,請告訴我,我會找到的!
當你的代碼:
kernel void cumulative(global const int *hist, global int *c_hist) {
int id = get_global_id(0);
int size = get_global_size(0);
for (int step = 1; step < size; step *= 2) {
c_hist[id] = hist[id];
if (id >= step) c_hist[id] += hist[id - step];
barrier(CLK_GLOBAL_MEM_FENCE);
global int* tmp = hist; hist = c_hist; c_hist = tmp;
}
}
是饋送到這個網站它發現以下問題:
10:17: warning: initializing '__global int *' with an expression of type 'const __global int *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
global int* tmp = hist; hist = c_hist; c_hist = tmp;
^ ~~~~
1 warning generated.
00d8ad302736fae9192e5f1d4027e53e.opt.bc: warning: Assuming the arguments 'hist', 'c_hist' of 'cumulative' on line 1 of to be non-aliased; please consider adding a restrict qualifier to these arguments
6:18: error: possible null pointer access for work item (1, 1) in work group (4, 4)
c_hist[id] = hist[id];
6:16: error: possible null pointer access for work item (5, 1) in work group (4, 4)
c_hist[id] = hist[id];
error: possible read-write race on c_hist[1008]:
Write by work item (0, 0) in work group (0, 0), 6:16:
c_hist[id] = hist[id];
Read by work item (20, 1) in work group (4, 4), possible sources are:
6:18:
c_hist[id] = hist[id];
7:32:
if (id >= step) c_hist[id] += hist[id - step];
7:35:
if (id >= step) c_hist[id] += hist[id - step];
error: possible write-write race on hist[1008]:
Write by work item (0, 0) in work group (0, 0), 6:16:
c_hist[id] = hist[id];
Write by work item (20, 1) in work group (4, 4), possible sources are:
6:16:
c_hist[id] = hist[id];
7:32:
if (id >= step) c_hist[id] += hist[id - step];
error: possible write-read race on hist[128]:
Read by work item (0, 0) in work group (4, 0), 6:18:
c_hist[id] = hist[id];
Write by work item (5, 1) in work group (4, 4), possible sources are:
6:16:
c_hist[id] = hist[id];
7:32:
if (id >= step) c_hist[id] += hist[id - step];
GPUVerify kernel analyser finished with 0 verified, 5 errors
請注意它報告: error: possible write-read race on hist[128]:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.