2015-09-11 74 views
4

我可以訪問安裝了兩個Nvidia Tesla卡的運行Debian 7的系統。我想用OpenCL做一些基準測試。但是,OpenCL無法找到任何兼容的平臺。爲了與OpenCL一起工作,我需要額外的庫還是特殊的驅動程序?Nvidia Tesla上的OpenCL:找不到平臺

下面是示例代碼示出了沒有平臺發現:我以前編譯代碼

#include <stdio.h> 
#include <stdlib.h> 
#ifdef __APPLE__ 
#include <OpenCL/opencl.h> 
#else 
#include <CL/cl.h> 
#endif 

int main() { 

    int i, j; 
    char* info; 
    size_t infoSize; 
    cl_uint platformCount; 
    cl_platform_id *platforms; 
    const char* attributeNames[5] = { "Name", "Vendor", 
     "Version", "Profile", "Extensions" }; 
    const cl_platform_info attributeTypes[5] = { CL_PLATFORM_NAME, CL_PLATFORM_VENDOR, 
     CL_PLATFORM_VERSION, CL_PLATFORM_PROFILE, CL_PLATFORM_EXTENSIONS }; 
    const int attributeCount = sizeof(attributeNames)/sizeof(char*); 

    // get platform count 
    clGetPlatformIDs(5, NULL, &platformCount); 

    // get all platforms 
    platforms = (cl_platform_id*) malloc(sizeof(cl_platform_id) * platformCount); 
    clGetPlatformIDs(platformCount, platforms, NULL); 

    printf("Platform count: %d\n",platformCount); 

    // for each platform print all attributes 
    for (i = 0; i < platformCount; i++) { 

     printf("n %d. Platform n", i+1); 

     for (j = 0; j < attributeCount; j++) { 

      // get platform attribute value size 
      clGetPlatformInfo(platforms[i], attributeTypes[j], 0, NULL, &infoSize); 
      info = (char*) malloc(infoSize); 

      // get platform attribute value 
      clGetPlatformInfo(platforms[i], attributeTypes[j], infoSize, info, NULL); 

      printf(" %d.%d %-11s: %sn", i+1, j+1, attributeNames[j], info); 
      free(info); 

     } 

     printf("n"); 

    } 

    free(platforms); 
    return 0; 

} 

和命令:

gcc platforms.c -lOpenCL 

如果我運行的代碼,輸出是:

Platform count: 0 
+0

當您調用clGetPlatformIDs時,它會告訴您已安裝了多少個平臺。例如,可能有一個用於AMD,一個用於NVIDIA,另一個用於英特爾。 然後在每個平臺中調用clGetDeviceIDs,這將返回該平臺內的設備數量。在您的NVIDIA平臺上,您可以找到您的K20,在您的英特爾平臺中,您可以找到您的至強CPU和Xeon Phi協處理器。 – LPs

+2

您是否安裝了專有的NVIDIA驅動程序?是否有'/ etc/OpenCL/vendors/nvidia.icd',並且它包含的庫​​名稱(通常是'libnvidia-opencl.so')是否存在? – jprice

+0

文件'/ etc/OpenCL/vendors/nvidia.icd'確實存在,它的內容是'libnvidia-opencl.so.1',它也存在。 –

回答

2

您可能正面臨典型的ICD 32/64位問題。 64位和32位的ICD完全隔離,您無法使用32位ICD運行64位應用程序,反之亦然。

當ICD是找不到的,或者說ICD架構平臺,clGetPlatformIDs回報-1001錯誤代碼:

Returned by clGetPlatformIDs when no platforms are found 

    CL_PLATFORM_NOT_FOUND_KHR   -1001 

的nVIDIA只安裝平臺庫下載,通常爲64位版本,將32位OpenCL應用程序留在範圍之外。 ICD仍將加載,但不返回任何平臺。

在「其他模式」(32/64位)中編譯你的應用程序,它會工作。

+0

我剛剛證實CUDA安裝在64位版本中。 OpenCL程序也以64位模式編譯。仍然沒有檢測到平臺。 –