If I execute a kernel that uses a small piece of constant memory, then write to that constant memory while the kernel is running, does the kernel immediately see the change, or is the contents of the constant memory “cached” upon kernel launch – or does the OpenCL driver unconditionally delay the constant memory update until the kernel is done running?
If the first or third options occur, then how can I execute the same kernel with different constant memory data simultaneously? Do I need to create multiple kernel/constant buffer objects and work with that? Note I can’t precalculate anything as kernel launches are a result of external signals that can occur at any time and rate. I could also create kernel objects on the fly, but that seems like an ugly solution.
It’s a fundamental concept in OpenCL that commands that are ‘Enqueued’ into the same command queue are executed in order. This includes
WriteBufferand similar commands. This means if you doThen regardless of them being blocking or non-blocking, the write will only effect the second set of kernels.
If you’re updating via a mapped pointer then it should be unmapped before any kernels run. Running kernels which access a buffer that is currently mapped is undefined (Spec 1.1 – Section 5.4.2.1).
As
EnqueueMapBufferandEnqueUnmapMemObjectare also placed on the command queue, as long as you unmap the ordering of updates is still guaranteed.Does that answer your question, or are you updating your buffer in another way?
Yes, multiple buffer objects.