KhronosGroup / KhronosGroup/OpenCL-Docs

Unspecified behaviour when multiple buffer read mappings at the same offset have the same pointer and different sizes

Open
#165 1 comment 0 reactions 1 assignee Claimed by @kpet View on GitHub
Dominant language
Python
Stars
420
Forks
131
Avg merge
5d 13h
Merged PRs (30d)
11

Description

Consider the following snippet of code:

```
size_t total_size = 32 * 1024;
size_t offset = 1024;
size_t map_size1 = 1024;
size_t map_size2 = 2048;
cl_mem buffer = clCreateBuffer(context, CL_MEM_READ_WRITE, total_size, NULL, NULL);

void *ptr1 = clEnqueueMapBuffer(queue, buffer, CL_BLOCKING, CL_MAP_READ, offset, map_size1, 0, NULL, NULL, NULL);

void *ptr2 = clEnqueueMapBuffer(queue, buffer, CL_BLOCKING, CL_MAP_READ, offset, map_size2, 0, NULL, NULL, NULL);

clEnqueueUnmapMemObject(queue, buffer, ptr1, 0, NULL, NULL);
clFinish(queue);
```

Assuming that `ptr1 == ptr2` which is likely to happen in many implementations when the offsets are the same:

- Which mapping is removed by the `clEnqueueUnmapMemObject` call? Or: what mapped memory is valid to access after `clFinish`?
- Are we requiring that implementations return different pointers?

See section 5.5.3 in the API spec.

I suggest we require implementations to remove the smallest existing mapping for a given pointer when there is ambiguity.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.