我有接受下列參數內核:一種在OpenCl內核中抵消索引的方法?
1)全局ID是1040
2)本地ID是16
下面是不我使用的內核,但我用它來說明了我想要實施的內容;基本上A和B的數組輸入是1040 * 10長。
__kernel void vector_add(__global const int *A, __global const int *B, __global int *C, int Offset, int constant) {
// Index of the current element to be processed
int i = get_global_id(0);
// Do the operation
C[i + Offset*constant] = A[i + Offset*constant] + B[i + Offset*constant];
}
雖然常數是一個常數,我想偏移量是一個「數組」,包含值0,1,...,9。我已經嘗試將這些值作爲數組傳遞,但我不認爲有可能以這種方式使用數組來抵消(程序崩潰)。我想寫些什麼示例如下:
__kernel void vector_add(__global const int *A, __global const int *B, __global int *C, __constant const int *Offset, int constant) {
// Index of the current element to be processed
int i = get_global_id(0);
for (int k = 0; k < 10; k++) {
// Do the operation
C[i + Offset[k]*constant] = A[i + Offset[k]*constant] + B[i + Offset[k]*constant];
}
}
請注意:擴大全球ID是不是一種選擇,因爲在我的內核,它需要保持固定。因此:無論如何要實現這一目標?
編輯:我添加了一個我想要實現的例子。目前,它不能像這樣工作。這合法嗎?我
如果數組元素爲零,它不應該崩潰,如果崩潰的時候沒有,那麼他們超出緩衝區的邊界 –
@huseyintugrulbuyukisik我編輯我的問題,也許它更清晰。我發佈的第二個內核不工作...如果你告訴我這是合法的,那麼我的主機代碼 – user1816546