我有在試圖弄清楚什麼是在下面的內核問題很難循環:UINT陣列和OpenCL中
__kernel void test(global unsigned char *word, int len) {
uint chunks[16];
// Init the array with zeros
for (int i = 0;i<16; i++) {
printf("%d\n",i);
chunks[i] = 0;
}
// padding
for (uint i = 0;i<len;i+=4) {
chunks[i/4] = 0;
for(uint j = 0;j<4 && i+j < len;j++) {
uint c = word[i+j]<<(8*(3-j));
chunks[i/4] |= c;
}
}
// bit-wise print of the first element of the array, just as a test
for (int j = 0;j<32;j++) {
printf("%d ",(chunks[0]>>(31-j))&1);
}
}
內核是爲了做一個簡單的填充,存儲4 char
s在uint
中。目前這僅僅是一個測試,所以我只創建一個工作組,而內核實際上只執行一次。
問題是,該程序收到SIGABRT
(真的不明白的時候)。
試圖追蹤問題我注意到,如果我註釋掉「init」部分,留下填充和按位打印,代碼似乎正常工作,並且相反,如果我評論填充,它的工作原理將離開初始化和打印。
此外,我不斷收到一個SIGABRT
如果我刪除填充和與整個陣列的逐位打印取代chunks
的第一個元素的逐位打印
for (int i = 0;i<16; i++) {
for (int j = 0;j<32;j++) {
printf("%d ",(chunks[i]>>(31-j))&1);
}
printf("\n");
}
的代碼工作正常,如果我使用CPU而不是GPU啓動它(在下面的主機代碼中直接使用CL_DEVICE_TYPE_CPU
)。
我擔心我在做什麼在概念上是錯誤的,但是在specs或搜索網絡時沒有找到任何有用的提示。
我使用的是MacOS 10.8.5。這裏是我的主代碼:
int main(int argc, const char * argv[]) {
char name[128];
dispatch_queue_t queue = gcl_create_dispatch_queue(CL_DEVICE_TYPE_GPU, NULL);
if (queue == NULL) {
queue = gcl_create_dispatch_queue(CL_DEVICE_TYPE_CPU, NULL);
}
// print name of the device
cl_device_id gpu = gcl_get_device_id_with_dispatch_queue(queue);
clGetDeviceInfo(gpu, CL_DEVICE_NAME, 128, name, NULL);
printf("Created a dispatch queue using the %s\n", name);
unsigned char *word = (unsigned char*) malloc(7*sizeof(unsigned char));
sprintf(word, "string");
void* word_mem = gcl_malloc(7 * sizeof(char), word,
CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR);
dispatch_sync(queue, ^{
cl_ndrange range = {
1,
{0, 0, 0},
{1, 0, 0},
{0, 0, 0}
};
test_kernel(&range,(unsigned char*)word_mem, 6);
});
gcl_free(word_mem);
free(word);
dispatch_release(queue);
return 0;
}
好,我的GPU的確是AMD(AMD的Radeon HD 6750M)。而且,如果我不能使用'printf',我會期待在這種情況下出現錯誤,正如我所說的那樣,這個程序似乎有效。 – Saphrosit
Ups,對不起。我剛剛在AMD FirePro S9150上試用了你的內核,它使用OpenCL C++編寫的主機端代碼完美工作。我不知道MacOS的GCL。你能否嘗試將你的GCL代碼改爲OpenCL代碼,以便丟棄問題出在主機端? –
我稍後再試一次。如果是這種情況,聽起來很奇怪,因爲我的主機代碼非常模仿蘋果在他們的文檔中提供的「OpenCL hello world」。我會告訴你! – Saphrosit