1

When creating a buffer in OpenCL, one passes a flags bitfield. One of these possible flags is CL_MEM_READ_WRITE, being the lowest bit in the field (value 1 << 0). Its documentation says that "it is the default".

That means I could pass either 0 or 1 in the lowest bit, with 0 in the next two bits (i.e. not set CL_MEM_WRITE_ONLY nor CL_MEM_READ_ONLY) - and supposedly, the result in both cases is the same - a read-and-write buffer.

Is that really how clCreateBuffer() is supposed to behave? And if it is - why does this flag exist?

2
  • 1
    Seems underspecified. What's also interesting is that in OpenCL 2.2 the specs had the line "If the value specified for flags is 0, the default is used which is CL_​MEM_​READ_​WRITE" in the description of flags parameter, which is missing from 3.0 specs. I opened an issue on Github. Commented May 8 at 0:25
  • @YurkoFlisk: Can you make that an answer? The ability of opening an issue with Khronos is a very useful thing to know about. Commented May 8 at 5:49

1 Answer 1

2

The wording for CL_MEM_READ_WRITE being "the default" in the memory flags table is unclear. I opened an issue on the Github repository for OpenCL specification. According to the reply by Ben Ashbaugh, the intended meaning is that CL_MEM_READ_WRITE is the default behaviour among the group of non-host CL_MEM_* flags:

...

Here's my mental model:

If none of CL_MEM_READ_WRITE, CL_MEM_READ_ONLY, or CL_MEM_WRITE_ONLY are included in the flags, then the memory object is both readable and writeable in a kernel, so it is essentially the same as it would have been if the flags included CL_MEM_READ_WRITE. This is true both when flags is zero and when some other bits are set. ...

Note that while clCreateBuffer and most other functions refer to one table of memory flags (contained within the description of clCreateBuffer and the one you referred to), clSVMAlloc refers to a separate table, which has the same problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.