openclmali

ARM Mali - How to share the read only memory object between CPU and GPU at the same time?


I am using ARM Mali T604 GPU. I've created a memory object using ALLOC_HOST_PTR. I would like to know if the following procedure is valid? Can I access(reading only) the memory object in GPU and mapped (as read only) same memory object in CPU simultaneously?

Step 1: unmap memory object (previously mapped as CL_MAP_READ_WRITE)

Step 2: map the memory object back using CL_MAP_READ (argument to the clEnqueueMapBuffer())

Step 3: read and process the data by CPU and GPU at the same time (but I'll not do any write operations on this memory object)

Step 4: unmap memory object

Step 5: map the memory object using CL_MAP_READ_WRITE to host.

In other words, my objective at the end of the day is to have a memory object which is readable by CPU and GPU at the same time. Is this possible in Mali OpenCL platform?


Solution

  • It is not only possible in Mali GPU, is possible in any version of the OpenCL spec and platforms/devices, your approach is correct, and is compatible with OpenCL 1.0.

    However you should know that there is a memory duplicity (the host is accessing a local copy generated trough the map operation, not the real GPU data), and therefore you are not saving memory by saving the array in OpenCL buffer format, if that was your intention.

    As an example: If you write from a kernel to that memory while it is being mapped, the CPU will still read the old data, until you unmap/map again for reading.