Ahmad Siavosh
Ahmad Siavosh

Reputation: 676

Memory Object Assignation to Context Mechanism In OpenCL

I'd like to know what exactly happens when we assign a memory object to a context in OpenCL.

I'd be thankful if you help me understand this issue :-)

Upvotes: 0

Views: 37

Answers (1)

Dithermaster
Dithermaster

Reputation: 6343

Generally and typically the copy happens when the runtime handles the clEnqueueWriteBuffer / clEnqueueReadBuffer commands.

However, if you created the memory object using certain combinations of flags, the runtime can choose to copy the memory sooner than that (like right after creation) or later (like on-demand before running a kernel or even on-demand as it needs it). Vendor documentation often indicates if they take special advantage of any of these flags.

A couple of the "interesting" variations:

  • Shared memory (Intel Ingrated Graphics GPUs, AMD APUs, and CPU drivers): You can allocate a buffer and never copy it to the device because the device can access host memory.
  • On-demand paging: Some discrete GPUs can copy buffer memory over PCIe as it is read or written by a kernel.

Those are both "advanced" usage of OpenCL buffers. You should probably start with "regular" buffers and work your way up if they don't do what you need.

This post describes the extra flags fairly well.

Upvotes: 1

Related Questions