在Opencl CLGetDeviceID中,返回错误CL_OUT_OF_HOST_内存

在Opencl CLGetDeviceID中,返回错误CL_OUT_OF_HOST_内存,c,linux,arm,opencl,mali,C,Linux,Arm,Opencl,Mali,我有GPU,所以我想测试openCL C代码,编写非常基本的代码,可以读取平台信息,如下所示: #include <stdio.h> #include <stdlib.h> #include <CL/cl.h> #define LOGI printf int main() { cl_uint i_plat; cl_int err; // Discover the number of platforms: cl_u

我有GPU,所以我想测试openCL C代码,编写非常基本的代码,可以读取平台信息,如下所示:

#include <stdio.h>    
#include <stdlib.h>
#include <CL/cl.h>
#define LOGI  printf

int main() {

    cl_uint i_plat;
    cl_int err;

    // Discover the number of platforms:
    cl_uint nplatforms;
    err = clGetPlatformIDs(0, NULL, &nplatforms);

    LOGI("\n Number of Platform %d: error = %d ", nplatforms, err );

    //check_error(err, "clGetPlatformIds");
    cl_device_id device_id = NULL;
    cl_uint ret_num_devices;
    // Now ask OpenCL for the platform IDs:
    cl_platform_id* platforms = (cl_platform_id*)malloc(sizeof(cl_platform_id)* nplatforms);


    if(platforms == NULL){
        printf("\n Fail to allocate memory for platforms");
    }


    err = clGetPlatformIDs(nplatforms, platforms, NULL);
    LOGI("\n clGetPlatformIDs return error = %d ", err );

    //check_error(err, "clGetPlatformIds");

    // Ask OpenCL about each platform to understand the problem:
    char name[128];
    char vendor[128];
    char version[128];
    char driver[128];
    cl_uint val = 0;
    size_t val1 = 0;
    size_t val2 = 0;
    size_t prof_tmr_res = 0;
    cl_uint MaxComputeUnit = 0;
    cl_uint MaxClockFrequency = 0;

    cl_device_type deviceType;

    cl_device_exec_capabilities exec_capabilities;

    //LOGI(ANDROID_LOG_INFO,"POOJA","AKVEDIAHE");

    for (i_plat = 0; i_plat < nplatforms; i_plat++) {
        err |= clGetPlatformInfo(platforms[i_plat], CL_PLATFORM_VENDOR, 128, vendor, NULL);
        err |= clGetPlatformInfo(platforms[i_plat], CL_PLATFORM_NAME, 128, name, NULL);
        err |= clGetPlatformInfo(platforms[i_plat], CL_PLATFORM_VERSION, 128, version, NULL);
        //check_error(err, "clGetPlatformInfo");

        LOGI("\n Platform Info %d: Vendor = %s Name = %s Version = %s  Error = %d", i_plat, vendor, name, version,err);

        /*device info*/
        //err = clGetDeviceIDs(platforms[i_plat], CL_DEVICE_TYPE_GPU, 1, &device_id, &ret_num_devices);
        err = clGetDeviceIDs(platforms[i_plat], CL_DEVICE_TYPE_GPU, 1, &device_id, NULL);

        LOGI("\n clGetDeviceIDs GPU  Error %d ",err );

        err |= clGetDeviceInfo(device_id, CL_DEVICE_TYPE,sizeof(cl_int), &deviceType, NULL);
        err |= clGetDeviceInfo(device_id, CL_DEVICE_VENDOR, 128, vendor, NULL);
        err |= clGetDeviceInfo(device_id, CL_DEVICE_NAME, 128, name, NULL);
        err |= clGetDeviceInfo(device_id, CL_DEVICE_VERSION, 128, version, NULL);
        err |= clGetDeviceInfo(device_id, CL_DRIVER_VERSION, 128, driver, NULL);
        err |= clGetDeviceInfo(device_id, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, sizeof(cl_uint), &val, NULL);
        err |= clGetDeviceInfo(device_id, CL_DEVICE_PROFILING_TIMER_RESOLUTION, sizeof(size_t), &prof_tmr_res, NULL);
        err |= clGetDeviceInfo(device_id, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(cl_uint), &MaxComputeUnit, NULL);
        err |= clGetDeviceInfo(device_id, CL_DEVICE_MAX_CLOCK_FREQUENCY, sizeof(cl_uint), &MaxClockFrequency, NULL);
        err |= clGetDeviceInfo(device_id, CL_DEVICE_EXECUTION_CAPABILITIES,sizeof(cl_int), &exec_capabilities, NULL);

        LOGI("\n Device Type %08x:",deviceType );
        for(int i =0; i < val ; i++){
            err = clGetDeviceInfo(device_id, CL_DEVICE_MAX_WORK_ITEM_SIZES, sizeof(size_t), &val1, NULL);
            LOGI("\n MAX_WORK_ITEM_SIZES[%d] = %d,", i,val1 );
        }
        err = clGetDeviceInfo(device_id, CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(size_t), &val2, NULL);

        LOGI("\n MAX_WORK_ITEM_DIMENSIONS = %d , MAX_WORK_GROUP_SIZE = %d ", val,val2 );
        LOGI("\n device_id FOR Platform = %d vender = %s, device name = %s, device version = %s, driver version = %s", i_plat, vendor, name, version, driver);
        LOGI("\n CL_DEVICE_PROFILING_TIMER_RESOLUTION = %d",prof_tmr_res );
        LOGI("\n Max Compute Unit = %d",MaxComputeUnit );
        LOGI("\n Max Clock Frequency = %d",MaxClockFrequency );
        LOGI("\n Device exec capabilities = %08x",exec_capabilities );
    }
    return 0;
 }
#包括
#包括
#包括
#定义logiprintf
int main(){
cl_uint i_平台;
cl_int err;
//了解平台的数量:
cl_uint nplatforms;
err=clGetPlatformIDs(0、NULL和nplatforms);
登录(“\n平台%d的数量:错误=%d”,nplatforms,err);
//检查_错误(err,“clGetPlatformIds”);
cl\U设备\U id设备\U id=NULL;
氯离子交换装置;
//现在向OpenCL询问平台ID:
cl_平台id*平台=(cl_平台id*)malloc(sizeof(cl_平台id)*nplatforms);
如果(平台==NULL){
printf(“\n无法为平台分配内存”);
}
err=clGetPlatformIDs(nplatforms,platforms,NULL);
LOGI(“\n clGetPlatformIDs返回错误=%d”,err);
//检查_错误(err,“clGetPlatformIds”);
//询问OpenCL关于每个平台的信息以了解问题:
字符名[128];
字符供应商[128];
字符版本[128];
字符驱动程序[128];
cl_uint val=0;
尺寸值1=0;
尺寸值2=0;
大小为0;
cl_uint MaxComputeUnit=0;
cl_uint MaxClockFrequency=0;
cl_设备类型设备类型;
cl_设备执行功能执行功能;
//LOGI(安卓系统日志信息、“POOJA”、“AKVEDIAHE”);
对于(i_plat=0;i_plat
输出:

平台1的数量:错误=0

clGetPlatformIDs返回错误=0

平台信息0:供应商=ARM名称=ARM平台版本=OpenCL 1.1 错误=0

CLGetDeviceID GPU错误-6

设备类型FFFFFF DF:

最大工作项目尺寸=0,最大工作组尺寸=0

平台的设备id=0供应商=ARM,设备名称=ARM平台

设备版本=OpenCL 1.1,驱动程序版本=�*��

CL\U设备\U配置文件\U计时器\U分辨率=0

最大计算单位=0

最大时钟频率=0

现在不明白它为什么返回
-6(主机内存不足)


为什么它无法在主机上分配OpenCL实现所需的资源,或者我缺少的资源?

我在RK3288(Android、Viewsonic VSD242)上的应用程序中使用OpenCL,我对以下代码没有问题。 我希望这段代码能帮助别人

cl_context OPENCL_CONTEXT;
cl_command_queue OPENCL_COMMAND_QUEUE;
cl_kernel* OPENCL_KERNELS;
cl_device_id OPENCL_DEVICE_ID;
cl_program OPENCL_PROGRAM;
cl_uint OPENCL_NUM_KERNELS;


void init_openCL() {

  size_t kernel_code_size;
  cl_int ret;
  cl_uint ret_num_platforms;
  cl_platform_id platform_id = NULL;
  cl_uint ret_num_devices;
  char buildLog[1024];
  int i;

  ret = clGetPlatformIDs(1, &platform_id, &ret_num_platforms);
  print_opencl_result("clGetPlatformIDs", ret);
  LOGD("--->available number of platforms = %d", ret_num_platforms);
  ret = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU, 1, &OPENCL_DEVICE_ID, &ret_num_devices);
  print_opencl_result("clGetDeviceIDs", ret);
  LOGD("--->available number of devices = %d", ret_num_devices);
  OPENCL_CONTEXT = clCreateContext(NULL, 1, &OPENCL_DEVICE_ID, NULL, NULL, &ret);
  print_opencl_result("clCreateContext", ret);
  //OPENCL_COMMAND_QUEUE = clCreateCommandQueue(OPENCL_CONTEXT, OPENCL_DEVICE_ID, 0, &ret);
  OPENCL_COMMAND_QUEUE = clCreateCommandQueue(OPENCL_CONTEXT, OPENCL_DEVICE_ID, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE, &ret);
  print_opencl_result("clCreateCommandQueue", ret);


  // load kernel code from the assets directory
  const char* source = (const char*)loadResourceFromAssets("my_kernels.cl");
  kernel_code_size = sizeof(source);


  OPENCL_PROGRAM = clCreateProgramWithSource(OPENCL_CONTEXT, 1, &source, NULL, &ret);
  print_opencl_result("clCreateProgramWithSource", ret);
  ret = clBuildProgram(OPENCL_PROGRAM, 1, &OPENCL_DEVICE_ID, "", NULL, NULL);
  print_opencl_result("clBuildProgram", ret);

  ret = clGetProgramBuildInfo(OPENCL_PROGRAM, OPENCL_DEVICE_ID, CL_PROGRAM_BUILD_LOG, 1024, buildLog, NULL);
  print_opencl_result("clGetProgramBuildInfo", ret);
  LOGD("%s", buildLog);

  ret = clCreateKernelsInProgram(OPENCL_PROGRAM, 0, NULL, &OPENCL_NUM_KERNELS);
  OPENCL_KERNELS = (cl_kernel*)malloc(OPENCL_NUM_KERNELS * sizeof(cl_kernel));
  ret = clCreateKernelsInProgram(OPENCL_PROGRAM, OPENCL_NUM_KERNELS, OPENCL_KERNELS, NULL);
  print_opencl_result("clCreateKernelsInProgram", ret);

}



void close_openCL() {
  int i;

  clFinish(OPENCL_COMMAND_QUEUE);
  clReleaseContext(OPENCL_CONTEXT);
  clReleaseCommandQueue(OPENCL_COMMAND_QUEUE);

  for (i = 0; i < OPENCL_NUM_KERNELS; i++) {
    clReleaseKernel(OPENCL_KERNELS[i]);
  }
  clReleaseProgram(OPENCL_PROGRAM);
  free(OPENCL_KERNELS);
}


void print_opencl_result(const char *name, int ret) {
  if (ret == CL_SUCCESS) {
      print_logD("--->%s = success", name);
  } else if (ret == CL_DEVICE_NOT_FOUND) {
      print_logE("--->%s = CL_DEVICE_NOT_FOUND", name);
  } else if (ret == CL_DEVICE_NOT_AVAILABLE) {
      print_logE("--->%s = CL_DEVICE_NOT_AVAILABLE", name);
  } else if (ret == CL_COMPILER_NOT_AVAILABLE) {
      print_logE("--->%s = CL_COMPILER_NOT_AVAILABLE", name);
  } else if (ret == CL_MEM_OBJECT_ALLOCATION_FAILURE) {
      print_logE("--->%s = CL_MEM_OBJECT_ALLOCATION_FAILURE", name);
  } else if (ret == CL_OUT_OF_RESOURCES) {
      print_logE("--->%s = CL_OUT_OF_RESOURCES", name);
  } else if (ret == CL_OUT_OF_HOST_MEMORY) {
      print_logE("--->%s = CL_OUT_OF_HOST_MEMORY", name);
  } else if (ret == CL_PROFILING_INFO_NOT_AVAILABLE) {
      print_logE("--->%s = CL_PROFILING_INFO_NOT_AVAILABLE", name);
  } else if (ret == CL_MEM_COPY_OVERLAP) {
      print_logE("--->%s = CL_MEM_COPY_OVERLAP", name);
  } else if (ret == CL_IMAGE_FORMAT_MISMATCH) {
      print_logE("--->%s = CL_IMAGE_FORMAT_MISMATCH", name);
  } else if (ret == CL_IMAGE_FORMAT_NOT_SUPPORTED) {
      print_logE("--->%s = CL_IMAGE_FORMAT_NOT_SUPPORTED", name);
  } else if (ret == CL_BUILD_PROGRAM_FAILURE) {
      print_logE("--->%s = CL_BUILD_PROGRAM_FAILURE", name);
  } else if (ret == CL_MAP_FAILURE) {
      print_logE("--->%s = CL_MAP_FAILURE", name);
  } else if (ret == CL_MISALIGNED_SUB_BUFFER_OFFSET) {
      print_logE("--->%s = CL_MISALIGNED_SUB_BUFFER_OFFSET", name);
  } else if (ret == CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST) {
      print_logE("--->%s = CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST", name);
  } else if (ret == CL_INVALID_VALUE) {
      print_logE("--->%s = CL_INVALID_VALUE", name);
  } else if (ret == CL_INVALID_DEVICE_TYPE) {
      print_logE("--->%s = CL_INVALID_DEVICE_TYPE", name);
  } else if (ret == CL_INVALID_PLATFORM) {
      print_logE("--->%s = CL_INVALID_PLATFORM", name);
  } else if (ret == CL_INVALID_DEVICE) {
      print_logE("--->%s = CL_INVALID_DEVICE", name);
  } else if (ret == CL_INVALID_CONTEXT) {
      print_logE("--->%s = CL_INVALID_CONTEXT", name);
  } else if (ret == CL_INVALID_QUEUE_PROPERTIES) {
      print_logE("--->%s = CL_INVALID_QUEUE_PROPERTIES", name);
  } else if (ret == CL_INVALID_COMMAND_QUEUE) {
      print_logE("--->%s = CL_INVALID_COMMAND_QUEUE", name);
  } else if (ret == CL_INVALID_HOST_PTR) {
      print_logE("--->%s = CL_INVALID_HOST_PTR", name);
  } else if (ret == CL_INVALID_MEM_OBJECT) {
      print_logE("--->%s = CL_INVALID_MEM_OBJECT", name);
  } else if (ret == CL_INVALID_IMAGE_FORMAT_DESCRIPTOR) {
      print_logE("--->%s = CL_INVALID_IMAGE_FORMAT_DESCRIPTOR", name);
  } else if (ret == CL_INVALID_IMAGE_SIZE) {
      print_logE("--->%s = CL_INVALID_IMAGE_SIZE", name);
  } else if (ret == CL_INVALID_SAMPLER) {
      print_logE("--->%s = CL_INVALID_SAMPLER", name);
  } else if (ret == CL_INVALID_BINARY) {
      print_logE("--->%s = CL_INVALID_BINARY", name);
  } else if (ret == CL_INVALID_BUILD_OPTIONS) {
      print_logE("--->%s = CL_INVALID_BUILD_OPTIONS", name);
  } else if (ret == CL_INVALID_PROGRAM) {
      print_logE("--->%s = CL_INVALID_PROGRAM", name);
  } else if (ret == CL_INVALID_PROGRAM_EXECUTABLE) {
      print_logE("--->%s = CL_INVALID_PROGRAM_EXECUTABLE", name);
  } else if (ret == CL_INVALID_KERNEL_NAME) {
      print_logE("--->%s = CL_INVALID_KERNEL_NAME", name);
  } else if (ret == CL_INVALID_KERNEL_DEFINITION) {
      print_logE("--->%s = CL_INVALID_KERNEL_DEFINITION", name);
  } else if (ret == CL_INVALID_KERNEL) {
      print_logE("--->%s = CL_INVALID_KERNEL", name);
  } else if (ret == CL_INVALID_ARG_INDEX) {
      print_logE("--->%s = CL_INVALID_ARG_INDEX", name);
  } else if (ret == CL_INVALID_ARG_VALUE) {
      print_logE("--->%s = CL_INVALID_ARG_VALUE", name);
  } else if (ret == CL_INVALID_ARG_SIZE) {
      print_logE("--->%s = CL_INVALID_ARG_SIZE", name);
  } else if (ret == CL_INVALID_KERNEL_ARGS) {
      print_logE("--->%s = CL_INVALID_KERNEL_ARGS", name);
  } else if (ret == CL_INVALID_WORK_DIMENSION) {
      print_logE("--->%s = CL_INVALID_WORK_DIMENSION", name);
  } else if (ret == CL_INVALID_WORK_GROUP_SIZE) {
      print_logE("--->%s = CL_INVALID_WORK_GROUP_SIZE", name);
  } else if (ret == CL_INVALID_WORK_ITEM_SIZE) {
      print_logE("--->%s = CL_INVALID_WORK_ITEM_SIZE", name);
  } else if (ret == CL_INVALID_GLOBAL_OFFSET) {
      print_logE("--->%s = CL_INVALID_GLOBAL_OFFSET", name);
  } else if (ret == CL_INVALID_EVENT_WAIT_LIST) {
      print_logE("--->%s = CL_INVALID_EVENT_WAIT_LIST", name);
  } else if (ret == CL_INVALID_EVENT) {
      print_logE("--->%s = CL_INVALID_EVENT", name);
  } else if (ret == CL_INVALID_OPERATION) {
      print_logE("--->%s = CL_INVALID_OPERATION", name);
  } else if (ret == CL_INVALID_GL_OBJECT) {
      print_logE("--->%s = CL_INVALID_GL_OBJECT", name);
  } else if (ret == CL_INVALID_BUFFER_SIZE) {
      print_logE("--->%s = CL_INVALID_BUFFER_SIZE", name);
  } else if (ret == CL_INVALID_MIP_LEVEL) {
      print_logE("--->%s = CL_INVALID_MIP_LEVEL", name);
  } else if (ret == CL_INVALID_GLOBAL_WORK_SIZE) {
      print_logE("--->%s = CL_INVALID_GLOBAL_WORK_SIZE", name);
  } else if (ret == CL_INVALID_PROPERTY) {
      print_logE("--->%s = CL_INVALID_PROPERTY", name);
  } else {
      print_logE("--->%s is failed", name);
  }
}
cl\u上下文OPENCL\u上下文;
cl_命令队列OPENCL_命令队列;
cl_内核*OPENCL_内核;
cl_设备id OPENCL_设备id;
cl_计划OPENCL_计划;
cl_uint OPENCL_NUM_内核;
void init_openCL(){
大小\u t内核\u代码\u大小;
cl_int ret;
cl_uint ret_num_平台;
cl_平台_id平台_id=NULL;
氯离子交换装置;
char buildLog[1024];
int i;
ret=clGetPlatformIDs(1,&platform\u id,&ret\u num\u platforms);
打印opencl结果(“clGetPlatformIDs”,ret);
LOGD(“-->可用平台数量=%d”,ret_num_平台);
ret=CLGetDeviceID(平台id、CL设备类型、GPU、1和OPENCL设备id以及ret设备数量);
打印opencl结果(“CLGetDeviceID”,ret);
LOGD(“-->可用设备数量=%d”,ret_num_设备);
OPENCL_CONTEXT=clCreateContext(NULL、1和OPENCL_设备ID、NULL、NULL和ret);
打印opencl结果(“clCreateContext”,ret);
//OPENCL_命令_队列=clCreateCommandQueue(