Does CL_MAP_WRITE_INVALIDATE_REGION permit overlapping kernel execution on the same buffer?
0 reputation · 16 May 2025, 21:17 UTC
I am designing a host-side pipeline that maps an OpenCL buffer for writing while previously enqueued kernels may still be running. The specification describes CL_MAP_WRITE_INVALIDATE_REGION as a hint that the entire mapped region will be overwritten, so the implementation may discard prior contents instead of fetching them.
What I cannot pin down is the interaction with concurrent device-side access. The flag seems aimed at avoiding a read-back of stale data, but I cannot find explicit language stating whether a kernel reading or writing an overlapping region during the map is legal, forbidden, or simply undefined. If some vendors treat the flag as a promise of exclusive access and skip coherence work while others preserve consistency, the same code could silently corrupt data on one platform and work on another.
Assume OpenCL 1.2 or later, where this flag exists, and a standard in-order command queue.
My questions:
- Does the OpenCL specification define any ordering or exclusivity guarantee between
clEnqueueMapBufferwithCL_MAP_WRITE_INVALIDATE_REGIONand concurrently executing kernels that touch the same buffer? - Is blocking map behavior (with
CL_TRUE) sufficient to make this safe, or must kernel completion be enforced with events orclFinishregardless? - Is there a portable way to detect whether an implementation skips coherence for this flag, short of empirical corruption testing?