hey, I am new to OPENCL. bumped into an issue when we try to leverage the GPU for some math operations (basically matrix multiplication).
following is my sample code,
char *allocptr = malloc(WIDTH*HEIGHT*2); cl_mem buffer = clImportMemoryARM(context,CL_MEM_READ_WRITE, NULL,allocp$ if (error ==CL_SUCCESS) { printf("sucess\n"); } else { printf("error %d\n.",error); }
the code can be compiled without any issue, however it through out error -6 at run time. Can anyone shed some lights here?
the CLINFO is pasted below as well.
firefly@firefly:~$ sudo clinfo -a Platform #0 Name: ARM Platform Vendor: ARM Version: OpenCL 1.2 v1.r14p0-01rel0-git(966ed26).f44c85cb3d2ceb87e8be88e7592755c3 Profile: FULL_PROFILE Extensions: cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store cl_khr_3d_image_writes cl_khr_fp64 cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_fp16 cl_khr_gl_sharing cl_khr_icd cl_khr_egl_event cl_khr_egl_image cl_khr_image2d_from_buffer cl_arm_core_id cl_arm_printf cl_arm_thread_limit_hint cl_arm_non_uniform_work_group_size cl_arm_import_memory Device #0 Name: Mali-T860 Type: GPU Vendor: ARM Vendor ID: 140517376 Profile: FULL_PROFILE Available: Yes Version: OpenCL 1.2 v1.r14p0-01rel0-git(966ed26).f44c85cb3d2ceb87e8be88e7592755c3 Driver version: 1.2 Compiler available: Yes Address space size: 64 Little endian: Yes Error correction support: No Address alignment (bits): 1024 Smallest alignment (bytes): 128 Resolution of timer (ns): 1000 Max clock frequency (MHz): 200 Max compute units: 4 Max constant args: 8 Max constant buffer size: 64 kB Max mem alloc size: 489 MB 942 kB Max parameter size: 1024 Command-queue supported props: Out of order execution Profiling Execution capabilities: OpenCL kernels Global memory size: 1 GB 935 MB 696 kB Global memory cache size: 256 kB Global memory line cache size: 64 Local memory size: 32 kB Local memory type: Global Global memory cache type: Read write Max work group size: 256 Max work item dimensions: 3 Max work item sizes: (256, 256, 256) Image support: Yes Max 2D image height: 65536 Max 2D image width: 65536 Max 3D image depth: 65536 Max 3D image height: 65536 Max 3D image width: 65536 Max read image args: 128 Max write image args: 8 Max samplers: 16 Preferred vector width char: 16 Preferred vector width short: 8 Preferred vector width int: 4 Preferred vector width long: 2 Preferred vector width float: 4 Preferred vector width double: 2 Half precision float capability: Denorms Inf and NaNs Round to nearest even rounding mode Round to zero rounding mode Round to +ve and -ve infinity rounding modes IEEE754-2008 fused multiply-add Single precision float capability: Denorms Inf and NaNs Round to nearest even rounding mode Round to zero rounding mode Round to +ve and -ve infinity rounding modes IEEE754-2008 fused multiply-add Double precision float capability: Denorms Inf and NaNs Round to nearest even rounding mode Round to zero rounding mode Round to +ve and -ve infinity rounding modes IEEE754-2008 fused multiply-add Extensions: cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store cl_khr_3d_image_writes cl_khr_fp64 cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_fp16 cl_khr_gl_sharing cl_khr_icd cl_khr_egl_event cl_khr_egl_image cl_khr_image2d_from_buffer cl_arm_core_id cl_arm_printf cl_arm_thread_limit_hint cl_arm_non_uniform_work_group_size cl_arm_import_memory
1) I'm afraid your driver doesn't support the feature. In R14, the feature was still under an experimental build flag that your platform provider chose not to enable. There's nothing we can do to help. You can try to contact the platform provider to get an updated driver or one with experimental features turned on. Sorry.
2) Thanks for posting the code. Before I comment on the code, I should point out that writing efficient matrix multiplication kernels is no simple task. I encourage you to have a look at our Compute Library (https://github.com/ARM-software/ComputeLibrary) and see if that provides what you need directly.
Having said that, here are a couple of comments on your code:
- clEnqueueWriteBuffer will always perform a copy. You may want to consider using clEnqueueMapBuffer and write data directly using the mapped pointer if possible. The same comment applies to the final read, you may be able to use a map operation and avoid one copy.
- Most of your operations are blocking. This means that you'll pay the cost of dispatch and synchronisation multiple times. Try making all commands non-blocking apart from the final clEnqueue{Read,Map}Buffer. You can use queue profiling on copy or map commands as well.Generally speaking, you want to give as big a batch of commands as possible to the OpenCL driver.
Let me know how you get on :).
Kevin - thanks for your valuable input. will try to optimize the code as you recommend. let me get back to you once I have some update.