clgetplatforminfo分割故障

clGetPlatformInfo Segmentation Fault

本文关键字:故障 分割 clgetplatforminfo      更新时间:2023-10-16

我有一个使用opencl的简单main.cpp文件。(请参阅最后(我在Windows 10 Linux子系统(Ubuntu 14(下使用Bash,以使我更容易(我认为(,因此我不必在Windows上使用Mingw或其他内容。

无论如何,我使用以下内容编译了该简单的main.cpp文件:

g++ -o main main.cpp -I "/mnt/c/Program Files (x86)/AMD APP SDK/3.0/include" -L "/mnt/c/Program Files (x86)/AMD APP SDK/3.0/lib/x86_64" -lOpenCL

我尝试运行程序时会出现细分故障。它发生在第33行(错误= clgetPlatformids(

main.cpp

#include <stdio.h>
#include <stdlib.h>
#ifdef APPLE
#include <OpenCL/cl.h>
#else
#include <CL/cl.h>
#endif
void displayPlatformInfo(cl_platform_id id, cl_platform_info param_name, const char* paramNameAsStr)
{
  cl_int error = 0;
  size_t paramSize = 0;
  error = clGetPlatformInfo( id, param_name, 0, NULL, &paramSize);
  char* moreInfo = (char*)alloca(sizeof(char)*paramSize);
  error = clGetPlatformInfo( id, param_name, paramSize, moreInfo, NULL);
  if (error != CL_SUCCESS) {
    perror("Unable to find any OpenCL Plaform Information");
    return;
  }
  printf("%s: %sn", paramNameAsStr, moreInfo);
}
int main() {
  cl_platform_id* platforms;
  cl_uint numOfPlatforms;
  cl_int error;
  error = clGetPlatformIDs(0, NULL, &numOfPlatforms);
  if (error <0 ) {
    perror("Unable to find any openCL Platforms");
    exit(1);
  }
  printf("Number of OpenCL platform found: %dn",numOfPlatforms);
  platforms = (cl_platform_id*) alloca(sizeof(cl_platform_id)* numOfPlatforms);
  for (cl_uint i = 0; i < numOfPlatforms; ++i) {
    displayPlatformInfo( platforms[i], CL_PLATFORM_PROFILE,   "CL_PLATFORM_PROFILE");
    displayPlatformInfo( platforms[i], CL_PLATFORM_VERSION,   "CL_PLATFORM_VERSION");
    displayPlatformInfo( platforms[i], CL_PLATFORM_NAME,      "CL_PLATFORM_NAME");
    displayPlatformInfo( platforms[i], CL_PLATFORM_VENDOR,    "CL_PLATFORM_VENDOR");
    displayPlatformInfo( platforms[i], CL_PLATFORM_EXTENSIONS,"CL_PLATFORM_EXTENSIONS");
  }
  return 0;
}

为平台放一个值。

值大于找到的平台数量。

示例:

numOfPlatforms = 10;