我有带 GPU 的firefly rk 3288 板,所以我想测试 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;
}
输出 :
平台数 1:错误 = 0
clGetPlatformIDs 返回错误 = 0
平台信息 0:供应商 = ARM 名称 = ARM 平台版本 = OpenCL 1.1 错误 = 0
clGetDeviceIDs GPU 错误 -6
设备类型 ffffffdf:
MAX_WORK_ITEM_DIMENSIONS = 0,MAX_WORK_GROUP_SIZE = 0
device_id FOR Platform = 0 供应商 = ARM,设备名称 = ARM 平台,
设备版本 = OpenCL 1.1,驱动版本 = �*��
CL_DEVICE_PROFILING_TIMER_RESOLUTION = 0
最大计算单位 = 0
最大时钟频率 = 0
现在不明白为什么它的回报-6 (CL_OUT_OF_HOST_MEMORY)
?
为什么它无法在主机上分配 OpenCL 实现所需的资源或我错过的地方?