RK3288 OpenCL 打印platform 和device 信息

ε祈祈猫儿з 提交于 2020-01-18 04:44:12

准备工作:

1)下载头文件:https://github.com/KhronosGroup/OpenCL-Headers/tree/master/CL

2)从RK3288 android 系统路径 /system/vendor/lib/egl 中到处库文件 libGLES_mali.so

1.打印platform 信息;

2.打印device 信息;

3.打印总是工作项目;

void print_openCL_platform_device() {

    int i, j;
    char info[1024];
    cl_int err;
    cl_uint nPlatform;
    cl_platform_id *listPlatform;
    cl_uint nDevice;
    cl_device_id *listDevice;

    cl_uint nMaxComputeUnits = 0;
    cl_uint nMaxWorkItemDims = 0;
    size_t *nMaxWorkItemSizes = NULL;
    size_t nMaxGlobalWorkSize = 1;
    size_t nMaxWorkGroupSize = 0;

    err = clGetPlatformIDs(0, NULL, &nPlatform);
    if(err < 0) {
        perror("Couldn't find any platforms.");
        exit(1);
    }
    listPlatform = (cl_platform_id*)malloc(nPlatform * sizeof(cl_platform_id));
    clGetPlatformIDs(nPlatform, listPlatform, NULL);

    for (i = 0; i < nPlatform; i++) {

        //返回平台名称
        clGetPlatformInfo(listPlatform[i], CL_PLATFORM_NAME, 1024, info, NULL);
        LOGD("###########################################################");
        LOGD("\n\tPlatfom[%d]:", i);
        LOGD("\n\tName\t\t%s", info);
        //查看opencl 版本
        clGetPlatformInfo(listPlatform[i], CL_PLATFORM_VERSION, 1024, info, NULL);
        LOGD("\n\tVersion\t\t%s", info);
        //返回和平台相关的厂商
        clGetPlatformInfo(listPlatform[i], CL_PLATFORM_VENDOR, 1024, info, NULL);
        LOGD("\n\tVendor\t\t%s", info);
        //确认系统是否支持完整的opencl版本还是嵌入式版本
        clGetPlatformInfo(listPlatform[i], CL_PLATFORM_PROFILE, 1024, info, NULL);
        LOGD("\n\tProfile\t\t%s", info);
        //查看平台支持的浮点精度扩展
        clGetPlatformInfo(listPlatform[i], CL_PLATFORM_EXTENSIONS, 1024, info, NULL);
        LOGD("\n\tExtension\t%s", info);
        LOGD("###########################################################");
        err = clGetDeviceIDs(listPlatform[i], CL_DEVICE_TYPE_ALL, 0, NULL, &nDevice);
        if(err < 0) {
            perror("Couldn't find any devices");
            exit(1);
        }
        listDevice = (cl_device_id*)malloc(nDevice * sizeof(cl_device_id));
        clGetDeviceIDs(listPlatform[i], CL_DEVICE_TYPE_ALL, nDevice, listDevice, NULL);

        for (j = 0; j < nDevice; j++) {
            LOGD("\n");
            clGetDeviceInfo(listDevice[j], CL_DEVICE_NAME, 1024, info, NULL);
            LOGD("###########################################################");
            LOGD("\n\tDevice[%d]:", j);
            LOGD("\n\tName\t\t%s", info);
            clGetDeviceInfo(listDevice[j], CL_DEVICE_VERSION, 1024, info, NULL);
            LOGD("\n\tVersion\t\t%s", info);
            clGetDeviceInfo(listDevice[j], CL_DEVICE_TYPE, 1024, info, NULL);
            switch (info[0]) {
                case CL_DEVICE_TYPE_DEFAULT:strcpy(info, "DEFAULT"); break;
                case CL_DEVICE_TYPE_CPU:strcpy(info, "CPU"); break;
                case CL_DEVICE_TYPE_GPU:strcpy(info, "GPU"); break;
                case CL_DEVICE_TYPE_ACCELERATOR:strcpy(info, "ACCELERATOR"); break;
                //case CL_DEVICE_TYPE_CUSTOM:strcpy_s(info, "CUSTOM"); break;
                //case CL_DEVICE_TYPE_ALL:strcpy(info, "ALL"); break;
            }
            LOGD("\n\tType\t\t%s", info);
            clGetDeviceInfo(listDevice[j], CL_DEVICE_VENDOR, 1024, info, NULL);
            LOGD("\n\tVdendor\t\t%s", info);
            clGetDeviceInfo(listDevice[j], CL_DEVICE_PROFILE, 1024, info, NULL);
            LOGD("\n\tProfile\t\t%s", info);
            LOGD("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
            err = clGetDeviceInfo(listDevice[j],CL_DEVICE_MAX_COMPUTE_UNITS,sizeof(cl_uint),&nMaxComputeUnits,NULL);
            if(err==CL_SUCCESS){
                LOGD("\n\tnMaxComputeUnits=%d\n",nMaxComputeUnits);
            }
            err = clGetDeviceInfo(listDevice[j],CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS,sizeof(cl_uint),&nMaxWorkItemDims,NULL);
            if(err==CL_SUCCESS){
                LOGD("\n\tnMaxWorkItemDims=%d\n",nMaxWorkItemDims);
                nMaxWorkItemSizes = (size_t*)malloc(sizeof(size_t)*nMaxWorkItemDims);
                err = clGetDeviceInfo(listDevice[j],CL_DEVICE_MAX_WORK_ITEM_SIZES,sizeof(size_t)*nMaxWorkItemDims,nMaxWorkItemSizes,NULL);
                if(err==CL_SUCCESS){
                    for(i=0;i<nMaxWorkItemDims;i++){
                        nMaxGlobalWorkSize = nMaxGlobalWorkSize * nMaxWorkItemSizes[i];
                        LOGD("\n\tnMaxWorkItemSizes[%d]=%d\n",i,nMaxWorkItemSizes[i]);
                    }
                    LOGD("\n\tnMaxGlobalWorkSize=%d\n",nMaxGlobalWorkSize);
                }
                free(nMaxWorkItemSizes);
            }
            err = clGetDeviceInfo(listDevice[j],CL_DEVICE_MAX_WORK_GROUP_SIZE,sizeof(size_t),&nMaxWorkGroupSize,NULL);
            if(err==CL_SUCCESS){
                LOGD("\n\tnMaxWorkGroupSize=%d\n",nMaxWorkGroupSize);
            }
            LOGD("###########################################################");
        }
        LOGD("\n\n");
        free(listDevice);
    }
    free(listPlatform);
}

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!