2013-04-10 88 views
0

我有下面的例程,應該根據索引中找到的索引將元素從src矩陣複製到dst矩陣。索引計算正確,但dst未更新。我錯過了什麼?兩個緩衝區的索引副本

__kernel void 
src_indexed_copy(__global real *dst, __global const real *src, 
    __global const int *index, int src_offset) 
{ 
     int id = get_global_id(ROW_DIM); 
     int src_idx = src_offset + index[id]; 
     dst[id] = src[src_idx]; 
} 

全局工作空間具有與索引數組中索引一樣多的工作項。

線性代碼會是這個樣子:

for (k = 0; k < n; k++) { 
     dst[k] = src[m * column + index[k]]; 
} 

哪個副本從列列的矩陣SRC所有的索引元素。

這是我正在讀的緩衝回(問評論):

rc = clEnqueueReadBuffer(ompctx->clctx.queue, c, 
     CL_TRUE, 0, i * sizeof(real), &tmp[0], 
     0, NULL, NULL); 
if (rc != CL_SUCCESS) { 
    log_error("omp", "[%d] readbuf() failed", rc); 
    goto err; 
} 
log_info("omp", "c"); 
for (k = 0; k < i; k++) { 
    log_info("omp", "%6.8f", tmp[k]); 
} 
+0

您如何知道索引是否正確計算?嘗試dst [id] = id來驗證您的主機代碼。 – 2013-04-10 15:41:59

+0

我printf'ed它,我也做了dst [id] = 515和dst [id] = id。而且dst看起來還是一樣。而printf'ing我看到索引計算正確。 – 2013-04-10 15:44:03

+0

然後,您可能無法正確讀取dst。你好嗎? – 2013-04-10 15:47:54

回答

1

一定出事的主機代碼。請驗證:

  • 所有的OpenCL API調用的返回值,
  • 緩衝創建標誌,(你需要寫訪問目標緩存),
  • 內核參數對應的內核代碼。
+0

事實上,這是一個浮動與主機代碼的雙重問題。 – 2013-04-11 15:24:44