2015-09-06 14 views
0

我一直在努力使OpenCL在我的筆記本電腦中工作。我遵循this鏈接。我有一個NVIDIA GT525M顯卡和Windows 8.1。 我遵循的步驟如下:運行OpenCL程序時發生clGetPlatformID錯誤。

安裝最新的NVIDIA驅動程序。

安裝Visual Studio 2013社區版。

添加鏈接器和編譯器的路徑。

,然後我試圖運行下面的代碼在該頁面給出:

#include <stdio.h> 
#include <CL/cl.h> 

int main(void) 
{ 
    cl_int err; 
    cl_uint* numPlatforms=NULL; 

    err = clGetPlatformIDs(0, NULL,numPlatforms); 
    if (CL_SUCCESS == err) 
     printf("\nDetected OpenCL platforms: %d", numPlatforms); 
    else 
     printf("\nError calling clGetPlatformIDs. Error code: %d", err); 
    getchar(); 
    return 0; 
} 

代碼成功生成,但結果我得到的是:

Error calling clGetPlatformIDs. Error code: -30 

我得到零數的平臺。 我一直在尋找一個解決方案,但無法找到一個互聯網。請幫忙。

+1

你怎麼能指望'clGetPlatformIDs(0,NULL,NULL)'工作?請閱讀該功能的文檔,這是非常清楚的。你想要的是聲明'cl_uint numPlatforms = 0;'然後'clGetPlatformIDs(0,NULL,&numPlatforms)'。 –

+0

@AnastasiyaAsadullayeva抱歉在這裏問愚蠢的問題。但文件不是很清楚。 (或者我太愚蠢,無法理解),謝謝你,這工作。 – PPGoodMan

+0

好的,我會編輯答案。 –

回答

2

此:

cl_uint* numPlatforms=NULL; 
err = clGetPlatformIDs(0, NULL,numPlatforms); 

等效於此:

err = clGetPlatformIDs(0, NULL, NULL); 

這是沒有意義的。按照documentation

如果函數成功執行,則返回CL_SUCCESS。否則,如果num_entries等於零且平臺不爲NULL,或者如果num_platforms和platforms均爲NULL,則返回CL_INVALID_VALUE。

CL_INVALID_VALUE是你得到的-30,出於上述原因。

你真正想要的是以下幾點:

cl_uint numPlatforms = 0; 
err = clGetPlatformIDs(0, NULL, &numPlatforms);