HandsOnOpenCL / Lecture-Slides

Lecture Slide Issue Tracking
Other
245 stars 44 forks source link

Slide 55: "C++ interface: The vadd host program", Buffer default explanation correct? #1

Closed simonmcs closed 11 years ago

simonmcs commented 11 years ago

On slide 55, "C++ interface: The vadd host program", we explain the following three lines:

d_a = Buffer(begin(h_a), end(h_a), true); d_b = Buffer(begin(h_b), end(h_b), true); d_c = Buffer(begin(h_c), end(h_c));

Thusly:

Note: These “trues” stipulate that we want to copy an array on the host (i.e. from a host pointer) into the OpenCL buffer. Without this true parameter the buffer is not copied from the host, and created as uninitialized on the device. True means READ ONLY from the device’s point of view.

This needs cleaning up as we update the C++ API.

tomdeakin commented 11 years ago

I don't have the slides in front of me right now to remind myself of what I put, but the constructor has definition: Buffer(startIterator, endIterator, bool readOnly, bool useHostPtr)

If the last boolean useHostPtr is specified as true then no copy occurs. Otherwise, and in the default it is false, there is a copy enqueued of the host data to the device.

The first Boolean toggles read only or read-write and doesn't affect whether a copy occurs or not.

Therefore the three constructors above all initilise device memory with a copy of the host arrays.

The Buffer constructor can also have a specified context as the first argument.

If the context has multiple devices, this constructor copies to the first one. This is OK as the OpenCL runtime will copy the data to the right devices when the kernels need it.

The slide in question needs to make all this clear.

simonmcs commented 11 years ago

My code above is taken straight from the slides - it only lists one boolean. So in this case, which parameter is it, readOnly or useHostPtr? We should put an explanation of this into the slides.

tomdeakin commented 11 years ago

That true is for readOnly as it's the first one. The arguments are in a fixed order. Any arguments missing on the right hand side of the list take default values but you have to write them out in order. I.e you must specify true or false for readOnly in order to specify the non default for hostPtr.

tomdeakin commented 11 years ago

Just looked at the slide for this. I will delete the box explaining this call as it's now incorrect. I will update the slide to explain this properly too.