CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY;
const cl_mem_flags host_ptr_flags =
CL_MEM_USE_HOST_PTR | CL_MEM_ALLOC_HOST_PTR | CL_MEM_COPY_HOST_PTR;
+ const cl_mem_flags host_access_flags =
+ CL_MEM_HOST_WRITE_ONLY | CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_NO_ACCESS;
const cl_mem_flags all_mem_flags =
- dev_access_flags | host_ptr_flags;
+ dev_access_flags | host_ptr_flags | host_access_flags;
void
validate_flags(cl_mem_flags flags, cl_mem_flags valid) {
if ((flags & ~valid) ||
- util_bitcount(flags & dev_access_flags) > 1)
+ util_bitcount(flags & dev_access_flags) > 1 ||
+ util_bitcount(flags & host_access_flags) > 1)
throw error(CL_INVALID_VALUE);
if ((flags & CL_MEM_USE_HOST_PTR) &&
const void *op_info, cl_int *r_errcode) try {
auto &parent = obj<root_buffer>(d_mem);
- validate_flags(flags, dev_access_flags);
+ validate_flags(flags, dev_access_flags | host_access_flags);
if (~flags & parent.flags() &
- (dev_access_flags & ~CL_MEM_READ_WRITE))
+ ((dev_access_flags & ~CL_MEM_READ_WRITE) | host_access_flags))
throw error(CL_INVALID_VALUE);
if (op == CL_BUFFER_CREATE_TYPE_REGION) {
}
}
+ ///
+ /// Checks that the host access flags of the memory object are
+ /// within the allowed set \a flags.
+ ///
+ void
+ validate_object_access(const memory_obj &mem, const cl_mem_flags flags) {
+ if (mem.flags() & ~flags &
+ (CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_WRITE_ONLY |
+ CL_MEM_HOST_NO_ACCESS))
+ throw error(CL_INVALID_OPERATION);
+ }
+
///
/// Checks that the mapping flags are correct.
///
void
- validate_flags(const cl_map_flags flags) {
+ validate_map_flags(const memory_obj &mem, const cl_map_flags flags) {
if ((flags & (CL_MAP_WRITE | CL_MAP_READ)) &&
(flags & CL_MAP_WRITE_INVALIDATE_REGION))
throw error(CL_INVALID_VALUE);
+
+ if (flags & CL_MAP_READ)
+ validate_object_access(mem, CL_MEM_HOST_READ_ONLY);
+
+ if (flags & (CL_MAP_WRITE | CL_MAP_WRITE_INVALIDATE_REGION))
+ validate_object_access(mem, CL_MEM_HOST_WRITE_ONLY);
}
///
validate_common(q, deps);
validate_object(q, ptr, {}, obj_pitch, region);
validate_object(q, mem, obj_origin, obj_pitch, region);
+ validate_object_access(mem, CL_MEM_HOST_READ_ONLY);
auto hev = create<hard_event>(
q, CL_COMMAND_READ_BUFFER, deps,
validate_common(q, deps);
validate_object(q, mem, obj_origin, obj_pitch, region);
validate_object(q, ptr, {}, obj_pitch, region);
+ validate_object_access(mem, CL_MEM_HOST_WRITE_ONLY);
auto hev = create<hard_event>(
q, CL_COMMAND_WRITE_BUFFER, deps,
validate_common(q, deps);
validate_object(q, ptr, host_origin, host_pitch, region);
validate_object(q, mem, obj_origin, obj_pitch, region);
+ validate_object_access(mem, CL_MEM_HOST_READ_ONLY);
auto hev = create<hard_event>(
q, CL_COMMAND_READ_BUFFER_RECT, deps,
validate_common(q, deps);
validate_object(q, mem, obj_origin, obj_pitch, region);
validate_object(q, ptr, host_origin, host_pitch, region);
+ validate_object_access(mem, CL_MEM_HOST_WRITE_ONLY);
auto hev = create<hard_event>(
q, CL_COMMAND_WRITE_BUFFER_RECT, deps,
validate_common(q, deps);
validate_object(q, ptr, {}, dst_pitch, region);
validate_object(q, img, src_origin, region);
+ validate_object_access(img, CL_MEM_HOST_READ_ONLY);
auto hev = create<hard_event>(
q, CL_COMMAND_READ_IMAGE, deps,
validate_common(q, deps);
validate_object(q, img, dst_origin, region);
validate_object(q, ptr, {}, src_pitch, region);
+ validate_object_access(img, CL_MEM_HOST_WRITE_ONLY);
auto hev = create<hard_event>(
q, CL_COMMAND_WRITE_IMAGE, deps,
validate_common(q, deps);
validate_object(q, mem, obj_origin, obj_pitch, region);
- validate_flags(flags);
+ validate_map_flags(mem, flags);
void *map = mem.resource(q).add_map(q, flags, blocking, obj_origin, region);
validate_common(q, deps);
validate_object(q, img, origin, region);
- validate_flags(flags);
+ validate_map_flags(img, flags);
void *map = img.resource(q).add_map(q, flags, blocking, origin, region);