2 Replies Latest reply on Feb 2, 2010 3:36 PM by _Big_Mac_

    Memory access flags not enforced

    _Big_Mac_
      Can write to read_only

      Page 8 of the slides from http://gpgpu.org/wp/wp-content/uploads/2009/09/C1-OpenCL-API.pdf says

      "MEM_READ_ONLY, MEM_WRITE_ONLY flags are 
      important."

      Not really, it seems. You can set WRITE_ONLY to an input buffer and READ_ONLY to an output buffer and the app will work flawlessly.

      This is not inconsistent with the specs, which say such operations are "undefined", so they might as well work without signaling any warnings or errors. Actually, the runtime is free to ignore access flags completely and it does so. But why stress the importance of those flags then? Is it something left for future implementation?

      By the way, NVIDIA's implementation does the same thing.

        • Memory access flags not enforced
          MicahVillmow
          _Big_Mac_,
          undefined does not mean that it can't work, just that it is not guaranteed to work. As far as the runtime is concerned, if you mark a buffer as read_only, and then use that same buffer on two devices and write to it on one of the devices, it won't synchronize the buffer on the other device. So, your results are now undefined.
            • Memory access flags not enforced
              _Big_Mac_

              This makes sense, thank you.

              Don't you think it would be smart to have writing to read_only and vice versa produce an error of some sort? It's better to receive an error than to hunt a potentially very subtle bug at runtime ("Why doesn't this get synchronized?" or even "Why am I getting random results?").

              Granted it's neither required by the specs nor actually possible with the current error codes (CL_INVALID_KERNEL_ARGS comes to mind but its occurrence is strictly defined "if the kernel argument values have not been specified" while here they are specified only wrong). It would be handy though, like const correctness in normal code it could spare some gray hairs.