einpoklum
einpoklum

Reputation: 131385

Is clCreateBuffer not device-specific?

The clCreateBuffer function takes a context identifier but no device identifier; and a clContext may have multiple devices.

Does that mean that OpenCL buffers are not device-specific? Or can contexts only contain devices which share a single physical memory space? Or perhaps I'm just missing something?

Upvotes: 2

Views: 259

Answers (1)

DarkZeros
DarkZeros

Reputation: 8410

Buffers are not device specific, only context specific. And therefore, they can be used in all the devices that are part of the CL context. This makes it possible to run OpenCL kernels where each kernel runs in a different GPU.

If your question is: "Ok, but where does the memory actually reside?" The answer is, "it is not clear".

It can reside in the Host, Device, or multiple devices. It will eventually reside in the device that needs it for the kernel execution. The CL API ensures consistency, but does not ensure the buffer will be located in a given position. The API will asynchronously copy the buffer to another device if it thinks that it is going to be needed there in the future.

You can however manually tell the API to move a buffer to a device with: clEnqueueMigrateMemObject() But the API is free to move it again if needed by another kernel.

Upvotes: 4

Related Questions