I am testing the clImportMemoryARM function of opencl.
cl_int error;
cl_uint num_devices;
cl_device_id devices[1];
cl_platform_id platforms[1];
clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_GPU, 1, devices, &num_devices);
cl_context context = clCreateContext( NULL, 1, devices, NULL, NULL, &error );
cl_command_queue queue = clCreateCommandQueue(context, devices[0], 0, NULL);
int Length = 1024;
char *allocptr = (char *)malloc( Length*sizeof(char));
const cl_import_properties_arm importProperties[] =
{
CL_IMPORT_TYPE_ARM,
CL_IMPORT_TYPE_HOST_ARM,
0
};
cl_mem buffer = clImportMemoryARM( context,
CL_MEM_READ_WRITE,
importProperties,
allocptr,
Length*sizeof(char),
&error );
when length is 1024,sometimes clImportMemoryARM
return error -6 which means CL_OUT_OF_HOST_MEMORY
,when I set length = 1024x512x2 which fellows khronos/cl_arm_import_memory.txt no error ever occurred. I want know why.
You asked on Arm Community Forums as well, so putting answer you got there here too, for different audience:
This may happen if the pointer you are trying to import is not aligned to the size of a cache line (i.e. 64 bytes). The specification you linked states:
Though the application is free to provide allocations without any specific alignment on coherent systems, there is a requirement to provide pointers aligned to a cache line on systems where there is no HW-managed coherency between CPU and GPU.
You could align the pointer yourself or use a function such as posix_memalign
.