clGetPlatformInfo分段错误

问题描述 投票:0回答:1

我有一个使用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行(error = 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: %s\n", 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: %d\n",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;
}
c++ opencl
1个回答
0
投票

为平台设置一个值。

值大于找到的平台数。

例:

numOfPlatforms = 10;
© www.soinside.com 2019 - 2024. All rights reserved.