I have firefly rk 3288 board with GPU and so I want test openCL C code , Written very basic code which can read platform info as follow:
#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;
}
Output :
Number of Platform 1: error = 0
clGetPlatformIDs return error = 0
Platform Info 0: Vendor = ARM Name = ARM Platform Version = OpenCL 1.1 Error = 0
clGetDeviceIDs GPU Error -6
Device Type ffffffdf:
MAX_WORK_ITEM_DIMENSIONS = 0 , MAX_WORK_GROUP_SIZE = 0
device_id FOR Platform = 0 vender = ARM, device name = ARM Platform,
device version = OpenCL 1.1 , driver version = �*��
CL_DEVICE_PROFILING_TIMER_RESOLUTION = 0
Max Compute Unit = 0
Max Clock Frequency = 0
Now not understanding Why it's returns -6 (CL_OUT_OF_HOST_MEMORY)
?
Why it's failing to allocate resources required by the OpenCL implementation on the host or where I missing ?