using namespace clover;
PUBLIC cl_mem
-clCreateBuffer(cl_context ctx, cl_mem_flags flags, size_t size,
- void *host_ptr, cl_int *errcode_ret) try {
- if (!ctx)
- throw error(CL_INVALID_CONTEXT);
+clCreateBuffer(cl_context d_ctx, cl_mem_flags flags, size_t size,
+ void *host_ptr, cl_int *r_errcode) try {
+ auto &ctx = obj(d_ctx);
if (bool(host_ptr) != bool(flags & (CL_MEM_USE_HOST_PTR |
CL_MEM_COPY_HOST_PTR)))
CL_MEM_COPY_HOST_PTR))
throw error(CL_INVALID_VALUE);
- ret_error(errcode_ret, CL_SUCCESS);
- return new root_buffer(obj(ctx), flags, size, host_ptr);
+ ret_error(r_errcode, CL_SUCCESS);
+ return new root_buffer(ctx, flags, size, host_ptr);
} catch (error &e) {
- ret_error(errcode_ret, e);
+ ret_error(r_errcode, e);
return NULL;
}
PUBLIC cl_mem
-clCreateSubBuffer(cl_mem obj, cl_mem_flags flags, cl_buffer_create_type op,
- const void *op_info, cl_int *errcode_ret) try {
- root_buffer *parent = dynamic_cast<root_buffer *>(obj);
-
- if (!parent)
- throw error(CL_INVALID_MEM_OBJECT);
+clCreateSubBuffer(cl_mem d_mem, cl_mem_flags flags,
+ cl_buffer_create_type op,
+ const void *op_info, cl_int *r_errcode) try {
+ auto &parent = obj<root_buffer>(d_mem);
if ((flags & (CL_MEM_USE_HOST_PTR |
CL_MEM_ALLOC_HOST_PTR |
CL_MEM_COPY_HOST_PTR)) ||
- (~flags & parent->flags() & (CL_MEM_READ_ONLY |
- CL_MEM_WRITE_ONLY)))
+ (~flags & parent.flags() & (CL_MEM_READ_ONLY |
+ CL_MEM_WRITE_ONLY)))
throw error(CL_INVALID_VALUE);
if (op == CL_BUFFER_CREATE_TYPE_REGION) {
- const cl_buffer_region *reg = (const cl_buffer_region *)op_info;
+ auto reg = reinterpret_cast<const cl_buffer_region *>(op_info);
if (!reg ||
- reg->origin > parent->size() ||
- reg->origin + reg->size > parent->size())
+ reg->origin > parent.size() ||
+ reg->origin + reg->size > parent.size())
throw error(CL_INVALID_VALUE);
if (!reg->size)
throw error(CL_INVALID_BUFFER_SIZE);
- ret_error(errcode_ret, CL_SUCCESS);
- return new sub_buffer(*parent, flags, reg->origin, reg->size);
+ ret_error(r_errcode, CL_SUCCESS);
+ return new sub_buffer(parent, flags, reg->origin, reg->size);
} else {
throw error(CL_INVALID_VALUE);
}
} catch (error &e) {
- ret_error(errcode_ret, e);
+ ret_error(r_errcode, e);
return NULL;
}
clCreateImage2D(cl_context d_ctx, cl_mem_flags flags,
const cl_image_format *format,
size_t width, size_t height, size_t row_pitch,
- void *host_ptr, cl_int *errcode_ret) try {
+ void *host_ptr, cl_int *r_errcode) try {
auto &ctx = obj(d_ctx);
if (flags & ~(CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY |
if (!supported_formats(ctx, CL_MEM_OBJECT_IMAGE2D).count(*format))
throw error(CL_IMAGE_FORMAT_NOT_SUPPORTED);
- ret_error(errcode_ret, CL_SUCCESS);
+ ret_error(r_errcode, CL_SUCCESS);
return new image2d(ctx, flags, format, width, height,
row_pitch, host_ptr);
} catch (error &e) {
- ret_error(errcode_ret, e);
+ ret_error(r_errcode, e);
return NULL;
}
const cl_image_format *format,
size_t width, size_t height, size_t depth,
size_t row_pitch, size_t slice_pitch,
- void *host_ptr, cl_int *errcode_ret) try {
+ void *host_ptr, cl_int *r_errcode) try {
auto &ctx = obj(d_ctx);
if (flags & ~(CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY |
if (!supported_formats(ctx, CL_MEM_OBJECT_IMAGE3D).count(*format))
throw error(CL_IMAGE_FORMAT_NOT_SUPPORTED);
- ret_error(errcode_ret, CL_SUCCESS);
+ ret_error(r_errcode, CL_SUCCESS);
return new image3d(ctx, flags, format, width, height, depth,
row_pitch, slice_pitch, host_ptr);
} catch (error &e) {
- ret_error(errcode_ret, e);
+ ret_error(r_errcode, e);
return NULL;
}
PUBLIC cl_int
clGetSupportedImageFormats(cl_context d_ctx, cl_mem_flags flags,
cl_mem_object_type type, cl_uint count,
- cl_image_format *buf, cl_uint *count_ret) try {
+ cl_image_format *r_buf, cl_uint *r_count) try {
auto &ctx = obj(d_ctx);
if (flags & ~(CL_MEM_READ_WRITE | CL_MEM_WRITE_ONLY | CL_MEM_READ_ONLY |
CL_MEM_COPY_HOST_PTR))
throw error(CL_INVALID_VALUE);
- if (!count && buf)
+ if (r_buf && !r_count)
throw error(CL_INVALID_VALUE);
auto formats = supported_formats(ctx, type);
- if (buf)
- std::copy_n(formats.begin(), std::min((cl_uint)formats.size(), count),
- buf);
- if (count_ret)
- *count_ret = formats.size();
+ if (r_buf)
+ std::copy_n(formats.begin(),
+ std::min((cl_uint)formats.size(), count),
+ r_buf);
+
+ if (r_count)
+ *r_count = formats.size();
return CL_SUCCESS;
}
PUBLIC cl_int
-clGetMemObjectInfo(cl_mem obj, cl_mem_info param,
+clGetMemObjectInfo(cl_mem d_mem, cl_mem_info param,
size_t size, void *r_buf, size_t *r_size) try {
property_buffer buf { r_buf, size, r_size };
-
- if (!obj)
- return CL_INVALID_MEM_OBJECT;
+ auto &mem = obj(d_mem);
switch (param) {
case CL_MEM_TYPE:
- buf.as_scalar<cl_mem_object_type>() = obj->type();
+ buf.as_scalar<cl_mem_object_type>() = mem.type();
break;
case CL_MEM_FLAGS:
- buf.as_scalar<cl_mem_flags>() = obj->flags();
+ buf.as_scalar<cl_mem_flags>() = mem.flags();
break;
case CL_MEM_SIZE:
- buf.as_scalar<size_t>() = obj->size();
+ buf.as_scalar<size_t>() = mem.size();
break;
case CL_MEM_HOST_PTR:
- buf.as_scalar<void *>() = obj->host_ptr();
+ buf.as_scalar<void *>() = mem.host_ptr();
break;
case CL_MEM_MAP_COUNT:
break;
case CL_MEM_REFERENCE_COUNT:
- buf.as_scalar<cl_uint>() = obj->ref_count();
+ buf.as_scalar<cl_uint>() = mem.ref_count();
break;
case CL_MEM_CONTEXT:
- buf.as_scalar<cl_context>() = &obj->ctx;
+ buf.as_scalar<cl_context>() = desc(mem.ctx);
break;
case CL_MEM_ASSOCIATED_MEMOBJECT: {
- sub_buffer *sub = dynamic_cast<sub_buffer *>(obj);
- buf.as_scalar<cl_mem>() = (sub ? &sub->parent : NULL);
+ sub_buffer *sub = dynamic_cast<sub_buffer *>(&mem);
+ buf.as_scalar<cl_mem>() = (sub ? desc(sub->parent) : NULL);
break;
}
case CL_MEM_OFFSET: {
- sub_buffer *sub = dynamic_cast<sub_buffer *>(obj);
+ sub_buffer *sub = dynamic_cast<sub_buffer *>(&mem);
buf.as_scalar<size_t>() = (sub ? sub->offset() : 0);
break;
}
}
PUBLIC cl_int
-clGetImageInfo(cl_mem obj, cl_image_info param,
+clGetImageInfo(cl_mem d_mem, cl_image_info param,
size_t size, void *r_buf, size_t *r_size) try {
property_buffer buf { r_buf, size, r_size };
- image *img = dynamic_cast<image *>(obj);
-
- if (!img)
- return CL_INVALID_MEM_OBJECT;
+ auto &img = obj<image>(d_mem);
switch (param) {
case CL_IMAGE_FORMAT:
- buf.as_scalar<cl_image_format>() = img->format();
+ buf.as_scalar<cl_image_format>() = img.format();
break;
case CL_IMAGE_ELEMENT_SIZE:
break;
case CL_IMAGE_ROW_PITCH:
- buf.as_scalar<size_t>() = img->row_pitch();
+ buf.as_scalar<size_t>() = img.row_pitch();
break;
case CL_IMAGE_SLICE_PITCH:
- buf.as_scalar<size_t>() = img->slice_pitch();
+ buf.as_scalar<size_t>() = img.slice_pitch();
break;
case CL_IMAGE_WIDTH:
- buf.as_scalar<size_t>() = img->width();
+ buf.as_scalar<size_t>() = img.width();
break;
case CL_IMAGE_HEIGHT:
- buf.as_scalar<size_t>() = img->height();
+ buf.as_scalar<size_t>() = img.height();
break;
case CL_IMAGE_DEPTH:
- buf.as_scalar<size_t>() = img->depth();
+ buf.as_scalar<size_t>() = img.depth();
break;
default:
}
PUBLIC cl_int
-clRetainMemObject(cl_mem obj) {
- if (!obj)
- return CL_INVALID_MEM_OBJECT;
-
- obj->retain();
+clRetainMemObject(cl_mem d_mem) try {
+ obj(d_mem).retain();
return CL_SUCCESS;
+
+} catch (error &e) {
+ return e.get();
}
PUBLIC cl_int
-clReleaseMemObject(cl_mem obj) {
- if (!obj)
- return CL_INVALID_MEM_OBJECT;
-
- if (obj->release())
- delete obj;
+clReleaseMemObject(cl_mem d_mem) try {
+ if (obj(d_mem).release())
+ delete pobj(d_mem);
return CL_SUCCESS;
+
+} catch (error &e) {
+ return e.get();
}
PUBLIC cl_int
-clSetMemObjectDestructorCallback(cl_mem obj,
+clSetMemObjectDestructorCallback(cl_mem d_mem,
void (CL_CALLBACK *pfn_notify)(cl_mem, void *),
- void *user_data) {
- if (!obj)
- return CL_INVALID_MEM_OBJECT;
+ void *user_data) try {
+ auto &mem = obj(d_mem);
if (!pfn_notify)
return CL_INVALID_VALUE;
- obj->destroy_notify([=]{ pfn_notify(obj, user_data); });
+ mem.destroy_notify([=]{ pfn_notify(d_mem, user_data); });
return CL_SUCCESS;
+
+} catch (error &e) {
+ return e.get();
}
/// Common argument checking shared by memory transfer commands.
///
void
- validate_base(command_queue &q, cl_uint num_deps, const cl_event *deps) {
- if (bool(num_deps) != bool(deps) ||
- any_of(is_zero(), range(deps, num_deps)))
- throw error(CL_INVALID_EVENT_WAIT_LIST);
-
- if (any_of([&](const cl_event ev) {
- return &obj(ev).ctx != &q.ctx;
- }, range(deps, num_deps)))
+ validate_common(command_queue &q,
+ std::initializer_list<std::reference_wrapper<memory_obj>> mems,
+ const ref_vector<event> &deps) {
+ if (any_of([&](const event &ev) {
+ return &ev.ctx != &q.ctx;
+ }, deps))
throw error(CL_INVALID_CONTEXT);
- }
- ///
- /// Memory object-specific argument checking shared by most memory
- /// transfer commands.
- ///
- void
- validate_obj(command_queue &q, cl_mem mem) {
- if (!mem)
- throw error(CL_INVALID_MEM_OBJECT);
-
- if (&mem->ctx != &q.ctx)
+ if (any_of([&](const memory_obj &mem) {
+ return &mem.ctx != &q.ctx;
+ }, mems))
throw error(CL_INVALID_CONTEXT);
}
/// \a T. The return value of get() should be implicitly
/// convertible to \a void *.
///
- template<typename T> struct _map;
+ template<typename T>
+ struct _map {
+ static mapping
+ get(command_queue &q, T obj, cl_map_flags flags,
+ size_t offset, size_t size) {
+ return { q, obj->resource(q), flags, true,
+ {{ offset }}, {{ size, 1, 1 }} };
+ }
+ };
- template<> struct _map<void *> {
+ template<>
+ struct _map<void *> {
static void *
- get(cl_command_queue q, void *obj, cl_map_flags flags,
+ get(command_queue &q, void *obj, cl_map_flags flags,
size_t offset, size_t size) {
return (char *)obj + offset;
}
};
- template<> struct _map<const void *> {
+ template<>
+ struct _map<const void *> {
static const void *
- get(cl_command_queue q, const void *obj, cl_map_flags flags,
+ get(command_queue &q, const void *obj, cl_map_flags flags,
size_t offset, size_t size) {
return (const char *)obj + offset;
}
};
- template<> struct _map<memory_obj *> {
- static mapping
- get(cl_command_queue q, memory_obj *mem, cl_map_flags flags,
- size_t offset, size_t size) {<
- return { obj(q), mem->resource(obj(q)), flags, true,
- {{ offset }}, {{ size, 1, 1 }}};
- }
- };
-
///
/// Software copy from \a src_obj to \a dst_obj. They can be
/// either pointers or memory objects.
///
template<typename T, typename S>
std::function<void (event &)>
- soft_copy_op(cl_command_queue q,
+ soft_copy_op(command_queue &q,
T dst_obj, const vector_t &dst_orig, const vector_t &dst_pitch,
S src_obj, const vector_t &src_orig, const vector_t &src_pitch,
const vector_t ®ion) {
- return [=](event &) {
+ return [=, &q](event &) {
auto dst = _map<T>::get(q, dst_obj, CL_MAP_WRITE,
dot(dst_pitch, dst_orig),
dst_pitch[2] * region[2]);
}
PUBLIC cl_int
-clEnqueueReadBuffer(cl_command_queue d_q, cl_mem mem, cl_bool blocking,
+clEnqueueReadBuffer(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking,
size_t offset, size_t size, void *ptr,
cl_uint num_deps, const cl_event *d_deps,
cl_event *rd_ev) try {
auto &q = obj(d_q);
+ auto &mem = obj(d_mem);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
- validate_base(q, num_deps, d_deps);
- validate_obj(q, mem);
+ validate_common(q, { mem }, deps);
- if (!ptr || offset > mem->size() || offset + size > mem->size())
+ if (!ptr || offset > mem.size() || offset + size > mem.size())
throw error(CL_INVALID_VALUE);
hard_event *hev = new hard_event(
q, CL_COMMAND_READ_BUFFER, deps,
- soft_copy_op(d_q,
+ soft_copy_op(q,
ptr, {{ 0 }}, {{ 1 }},
- mem, {{ offset }}, {{ 1 }},
+ &mem, {{ offset }}, {{ 1 }},
{{ size, 1, 1 }}));
ret_object(rd_ev, hev);
}
PUBLIC cl_int
-clEnqueueWriteBuffer(cl_command_queue d_q, cl_mem mem, cl_bool blocking,
+clEnqueueWriteBuffer(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking,
size_t offset, size_t size, const void *ptr,
cl_uint num_deps, const cl_event *d_deps,
cl_event *rd_ev) try {
auto &q = obj(d_q);
+ auto &mem = obj(d_mem);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
- validate_base(q, num_deps, d_deps);
- validate_obj(q, mem);
+ validate_common(q, { mem }, deps);
- if (!ptr || offset > mem->size() || offset + size > mem->size())
+ if (!ptr || offset > mem.size() || offset + size > mem.size())
throw error(CL_INVALID_VALUE);
hard_event *hev = new hard_event(
q, CL_COMMAND_WRITE_BUFFER, deps,
- soft_copy_op(d_q,
- mem, {{ offset }}, {{ 1 }},
+ soft_copy_op(q,
+ &mem, {{ offset }}, {{ 1 }},
ptr, {{ 0 }}, {{ 1 }},
{{ size, 1, 1 }}));
}
PUBLIC cl_int
-clEnqueueReadBufferRect(cl_command_queue d_q, cl_mem mem, cl_bool blocking,
+clEnqueueReadBufferRect(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking,
const size_t *obj_origin,
const size_t *host_origin,
const size_t *region,
cl_uint num_deps, const cl_event *d_deps,
cl_event *rd_ev) try {
auto &q = obj(d_q);
+ auto &mem = obj(d_mem);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
- validate_base(q, num_deps, d_deps);
- validate_obj(q, mem);
+ validate_common(q, { mem }, deps);
if (!ptr)
throw error(CL_INVALID_VALUE);
hard_event *hev = new hard_event(
q, CL_COMMAND_READ_BUFFER_RECT, deps,
- soft_copy_op(d_q,
+ soft_copy_op(q,
ptr, vector(host_origin),
{{ 1, host_row_pitch, host_slice_pitch }},
- mem, vector(obj_origin),
+ &mem, vector(obj_origin),
{{ 1, obj_row_pitch, obj_slice_pitch }},
vector(region)));
}
PUBLIC cl_int
-clEnqueueWriteBufferRect(cl_command_queue d_q, cl_mem mem, cl_bool blocking,
+clEnqueueWriteBufferRect(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking,
const size_t *obj_origin,
const size_t *host_origin,
const size_t *region,
cl_uint num_deps, const cl_event *d_deps,
cl_event *rd_ev) try {
auto &q = obj(d_q);
+ auto &mem = obj(d_mem);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
- validate_base(q, num_deps, d_deps);
- validate_obj(q, mem);
+ validate_common(q, { mem }, deps);
if (!ptr)
throw error(CL_INVALID_VALUE);
hard_event *hev = new hard_event(
q, CL_COMMAND_WRITE_BUFFER_RECT, deps,
- soft_copy_op(d_q,
- mem, vector(obj_origin),
+ soft_copy_op(q,
+ &mem, vector(obj_origin),
{{ 1, obj_row_pitch, obj_slice_pitch }},
ptr, vector(host_origin),
{{ 1, host_row_pitch, host_slice_pitch }},
}
PUBLIC cl_int
-clEnqueueCopyBuffer(cl_command_queue d_q, cl_mem src_mem, cl_mem dst_mem,
+clEnqueueCopyBuffer(cl_command_queue d_q, cl_mem d_src_mem, cl_mem d_dst_mem,
size_t src_offset, size_t dst_offset, size_t size,
cl_uint num_deps, const cl_event *d_deps,
cl_event *rd_ev) try {
auto &q = obj(d_q);
+ auto &src_mem = obj(d_src_mem);
+ auto &dst_mem = obj(d_dst_mem);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
- validate_base(q, num_deps, d_deps);
- validate_obj(q, src_mem);
- validate_obj(q, dst_mem);
+ validate_common(q, { src_mem, dst_mem }, deps);
hard_event *hev = new hard_event(
q, CL_COMMAND_COPY_BUFFER, deps,
- hard_copy_op(q, dst_mem, {{ dst_offset }},
- src_mem, {{ src_offset }},
+ hard_copy_op(q, &dst_mem, {{ dst_offset }},
+ &src_mem, {{ src_offset }},
{{ size, 1, 1 }}));
ret_object(rd_ev, hev);
}
PUBLIC cl_int
-clEnqueueCopyBufferRect(cl_command_queue d_q, cl_mem src_mem,
- cl_mem dst_mem,
+clEnqueueCopyBufferRect(cl_command_queue d_q, cl_mem d_src_mem,
+ cl_mem d_dst_mem,
const size_t *src_origin, const size_t *dst_origin,
const size_t *region,
size_t src_row_pitch, size_t src_slice_pitch,
cl_uint num_deps, const cl_event *d_deps,
cl_event *rd_ev) try {
auto &q = obj(d_q);
+ auto &src_mem = obj(d_src_mem);
+ auto &dst_mem = obj(d_dst_mem);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
- validate_base(q, num_deps, d_deps);
- validate_obj(q, src_mem);
- validate_obj(q, dst_mem);
+ validate_common(q, { src_mem, dst_mem }, deps);
hard_event *hev = new hard_event(
q, CL_COMMAND_COPY_BUFFER_RECT, deps,
- soft_copy_op(d_q,
- dst_mem, vector(dst_origin),
+ soft_copy_op(q,
+ &dst_mem, vector(dst_origin),
{{ 1, dst_row_pitch, dst_slice_pitch }},
- src_mem, vector(src_origin),
+ &src_mem, vector(src_origin),
{{ 1, src_row_pitch, src_slice_pitch }},
vector(region)));
}
PUBLIC cl_int
-clEnqueueReadImage(cl_command_queue d_q, cl_mem mem, cl_bool blocking,
+clEnqueueReadImage(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking,
const size_t *origin, const size_t *region,
size_t row_pitch, size_t slice_pitch, void *ptr,
cl_uint num_deps, const cl_event *d_deps,
cl_event *rd_ev) try {
auto &q = obj(d_q);
+ auto &img = obj<image>(d_mem);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
- image *img = dynamic_cast<image *>(mem);
- validate_base(q, num_deps, d_deps);
- validate_obj(q, img);
+ validate_common(q, { img }, deps);
if (!ptr)
throw error(CL_INVALID_VALUE);
hard_event *hev = new hard_event(
q, CL_COMMAND_READ_IMAGE, deps,
- soft_copy_op(d_q,
+ soft_copy_op(q,
ptr, {},
{{ 1, row_pitch, slice_pitch }},
- mem, vector(origin),
- {{ 1, img->row_pitch(), img->slice_pitch() }},
+ &img, vector(origin),
+ {{ 1, img.row_pitch(), img.slice_pitch() }},
vector(region)));
ret_object(rd_ev, hev);
}
PUBLIC cl_int
-clEnqueueWriteImage(cl_command_queue d_q, cl_mem mem, cl_bool blocking,
+clEnqueueWriteImage(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking,
const size_t *origin, const size_t *region,
size_t row_pitch, size_t slice_pitch, const void *ptr,
cl_uint num_deps, const cl_event *d_deps,
cl_event *rd_ev) try {
auto &q = obj(d_q);
+ auto &img = obj<image>(d_mem);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
- image *img = dynamic_cast<image *>(mem);
- validate_base(q, num_deps, d_deps);
- validate_obj(q, img);
+ validate_common(q, { img }, deps);
if (!ptr)
throw error(CL_INVALID_VALUE);
hard_event *hev = new hard_event(
q, CL_COMMAND_WRITE_IMAGE, deps,
- soft_copy_op(d_q,
- mem, vector(origin),
- {{ 1, img->row_pitch(), img->slice_pitch() }},
+ soft_copy_op(q,
+ &img, vector(origin),
+ {{ 1, img.row_pitch(), img.slice_pitch() }},
ptr, {},
{{ 1, row_pitch, slice_pitch }},
vector(region)));
}
PUBLIC cl_int
-clEnqueueCopyImage(cl_command_queue d_q, cl_mem src_mem, cl_mem dst_mem,
+clEnqueueCopyImage(cl_command_queue d_q, cl_mem d_src_mem, cl_mem d_dst_mem,
const size_t *src_origin, const size_t *dst_origin,
const size_t *region,
cl_uint num_deps, const cl_event *d_deps,
cl_event *rd_ev) try {
auto &q = obj(d_q);
+ auto &src_img = obj<image>(d_src_mem);
+ auto &dst_img = obj<image>(d_dst_mem);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
- image *src_img = dynamic_cast<image *>(src_mem);
- image *dst_img = dynamic_cast<image *>(dst_mem);
- validate_base(q, num_deps, d_deps);
- validate_obj(q, src_img);
- validate_obj(q, dst_img);
+ validate_common(q, { src_img, dst_img }, deps);
hard_event *hev = new hard_event(
q, CL_COMMAND_COPY_IMAGE, deps,
hard_copy_op(q,
- dst_img, vector(dst_origin),
- src_img, vector(src_origin),
+ &dst_img, vector(dst_origin),
+ &src_img, vector(src_origin),
vector(region)));
ret_object(rd_ev, hev);
PUBLIC cl_int
clEnqueueCopyImageToBuffer(cl_command_queue d_q,
- cl_mem src_mem, cl_mem dst_mem,
+ cl_mem d_src_mem, cl_mem d_dst_mem,
const size_t *src_origin, const size_t *region,
size_t dst_offset,
cl_uint num_deps, const cl_event *d_deps,
cl_event *rd_ev) try {
auto &q = obj(d_q);
+ auto &src_img = obj<image>(d_src_mem);
+ auto &dst_mem = obj(d_dst_mem);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
- image *src_img = dynamic_cast<image *>(src_mem);
- validate_base(q, num_deps, d_deps);
- validate_obj(q, src_img);
- validate_obj(q, dst_mem);
+ validate_common(q, { src_img, dst_mem }, deps);
hard_event *hev = new hard_event(
q, CL_COMMAND_COPY_IMAGE_TO_BUFFER, deps,
- soft_copy_op(d_q,
- dst_mem, {{ dst_offset }},
+ soft_copy_op(q,
+ &dst_mem, {{ dst_offset }},
{{ 0, 0, 0 }},
- src_mem, vector(src_origin),
- {{ 1, src_img->row_pitch(), src_img->slice_pitch() }},
+ &src_img, vector(src_origin),
+ {{ 1, src_img.row_pitch(), src_img.slice_pitch() }},
vector(region)));
ret_object(rd_ev, hev);
PUBLIC cl_int
clEnqueueCopyBufferToImage(cl_command_queue d_q,
- cl_mem src_mem, cl_mem dst_mem,
+ cl_mem d_src_mem, cl_mem d_dst_mem,
size_t src_offset,
const size_t *dst_origin, const size_t *region,
cl_uint num_deps, const cl_event *d_deps,
cl_event *rd_ev) try {
auto &q = obj(d_q);
+ auto &src_mem = obj(d_src_mem);
+ auto &dst_img = obj<image>(d_dst_mem);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
- image *dst_img = dynamic_cast<image *>(dst_mem);
- validate_base(q, num_deps, d_deps);
- validate_obj(q, src_mem);
- validate_obj(q, dst_img);
+ validate_common(q, { src_mem, dst_img }, deps);
hard_event *hev = new hard_event(
q, CL_COMMAND_COPY_BUFFER_TO_IMAGE, deps,
- soft_copy_op(d_q,
- dst_mem, vector(dst_origin),
- {{ 1, dst_img->row_pitch(), dst_img->slice_pitch() }},
- src_mem, {{ src_offset }},
+ soft_copy_op(q,
+ &dst_img, vector(dst_origin),
+ {{ 1, dst_img.row_pitch(), dst_img.slice_pitch() }},
+ &src_mem, {{ src_offset }},
{{ 0, 0, 0 }},
vector(region)));
}
PUBLIC void *
-clEnqueueMapBuffer(cl_command_queue d_q, cl_mem mem, cl_bool blocking,
+clEnqueueMapBuffer(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking,
cl_map_flags flags, size_t offset, size_t size,
cl_uint num_deps, const cl_event *d_deps,
cl_event *rd_ev, cl_int *r_errcode) try {
auto &q = obj(d_q);
+ auto &mem = obj(d_mem);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
- validate_base(q, num_deps, d_deps);
- validate_obj(q, mem);
+ validate_common(q, { mem }, deps);
- if (offset > mem->size() || offset + size > mem->size())
+ if (offset > mem.size() || offset + size > mem.size())
throw error(CL_INVALID_VALUE);
- void *map = mem->resource(q).add_map(
+ void *map = mem.resource(q).add_map(
q, flags, blocking, {{ offset }}, {{ size }});
ret_object(rd_ev, new hard_event(q, CL_COMMAND_MAP_BUFFER, deps));
}
PUBLIC void *
-clEnqueueMapImage(cl_command_queue d_q, cl_mem mem, cl_bool blocking,
+clEnqueueMapImage(cl_command_queue d_q, cl_mem d_mem, cl_bool blocking,
cl_map_flags flags,
const size_t *origin, const size_t *region,
size_t *row_pitch, size_t *slice_pitch,
cl_uint num_deps, const cl_event *d_deps,
cl_event *rd_ev, cl_int *r_errcode) try {
auto &q = obj(d_q);
+ auto &img = obj<image>(d_mem);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
- image *img = dynamic_cast<image *>(mem);
- validate_base(q, num_deps, d_deps);
- validate_obj(q, img);
+ validate_common(q, { img }, deps);
- void *map = img->resource(q).add_map(
+ void *map = img.resource(q).add_map(
q, flags, blocking, vector(origin), vector(region));
ret_object(rd_ev, new hard_event(q, CL_COMMAND_MAP_IMAGE, deps));
}
PUBLIC cl_int
-clEnqueueUnmapMemObject(cl_command_queue d_q, cl_mem mem, void *ptr,
+clEnqueueUnmapMemObject(cl_command_queue d_q, cl_mem d_mem, void *ptr,
cl_uint num_deps, const cl_event *d_deps,
cl_event *rd_ev) try {
auto &q = obj(d_q);
+ auto &mem = obj(d_mem);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
- validate_base(q, num_deps, d_deps);
- validate_obj(q, mem);
+ validate_common(q, { mem }, deps);
hard_event *hev = new hard_event(
q, CL_COMMAND_UNMAP_MEM_OBJECT, deps,
[=, &q, &mem](event &) {
- mem->resource(q).del_map(ptr);
+ mem.resource(q).del_map(ptr);
});
ret_object(rd_ev, hev);
#include "core/queue.hpp"
namespace clover {
- typedef struct _cl_mem memory_obj;
-
class resource;
class sub_resource;
-}
-struct _cl_mem : public clover::ref_counter {
-protected:
- _cl_mem(clover::context &ctx, cl_mem_flags flags,
- size_t size, void *host_ptr);
- _cl_mem(const _cl_mem &obj) = delete;
+ class memory_obj : public ref_counter, public _cl_mem {
+ protected:
+ memory_obj(context &ctx, cl_mem_flags flags,
+ size_t size, void *host_ptr);
+ memory_obj(const memory_obj &obj) = delete;
-public:
- virtual ~_cl_mem();
+ public:
+ virtual ~memory_obj();
- virtual cl_mem_object_type type() const = 0;
- virtual clover::resource &resource(clover::command_queue &q) = 0;
+ virtual cl_mem_object_type type() const = 0;
+ virtual clover::resource &resource(command_queue &q) = 0;
- void destroy_notify(std::function<void ()> f);
- cl_mem_flags flags() const;
- size_t size() const;
- void *host_ptr() const;
+ void destroy_notify(std::function<void ()> f);
+ cl_mem_flags flags() const;
+ size_t size() const;
+ void *host_ptr() const;
- clover::context &ctx;
+ context &ctx;
-private:
- cl_mem_flags _flags;
- size_t _size;
- void *_host_ptr;
- std::function<void ()> _destroy_notify;
+ private:
+ cl_mem_flags _flags;
+ size_t _size;
+ void *_host_ptr;
+ std::function<void ()> _destroy_notify;
-protected:
- std::string data;
-};
+ protected:
+ std::string data;
+ };
-namespace clover {
- struct buffer : public memory_obj {
+ class buffer : public memory_obj {
protected:
- buffer(clover::context &ctx, cl_mem_flags flags,
+ buffer(context &ctx, cl_mem_flags flags,
size_t size, void *host_ptr);
public:
virtual cl_mem_object_type type() const;
};
- struct root_buffer : public buffer {
+ class root_buffer : public buffer {
public:
- root_buffer(clover::context &ctx, cl_mem_flags flags,
+ root_buffer(context &ctx, cl_mem_flags flags,
size_t size, void *host_ptr);
- virtual clover::resource &resource(clover::command_queue &q);
+ virtual clover::resource &resource(command_queue &q);
private:
- std::map<clover::device *,
- std::unique_ptr<clover::root_resource>> resources;
+ std::map<device *,
+ std::unique_ptr<root_resource>> resources;
};
- struct sub_buffer : public buffer {
+ class sub_buffer : public buffer {
public:
- sub_buffer(clover::root_buffer &parent, cl_mem_flags flags,
+ sub_buffer(root_buffer &parent, cl_mem_flags flags,
size_t offset, size_t size);
- virtual clover::resource &resource(clover::command_queue &q);
+ virtual clover::resource &resource(command_queue &q);
size_t offset() const;
- clover::root_buffer &parent;
+ root_buffer &parent;
private:
size_t _offset;
- std::map<clover::device *,
- std::unique_ptr<clover::sub_resource>> resources;
+ std::map<device *,
+ std::unique_ptr<sub_resource>> resources;
};
- struct image : public memory_obj {
+ class image : public memory_obj {
protected:
- image(clover::context &ctx, cl_mem_flags flags,
+ image(context &ctx, cl_mem_flags flags,
const cl_image_format *format,
size_t width, size_t height, size_t depth,
size_t row_pitch, size_t slice_pitch, size_t size,
void *host_ptr);
public:
- virtual clover::resource &resource(clover::command_queue &q);
+ virtual clover::resource &resource(command_queue &q);
cl_image_format format() const;
size_t width() const;
size_t height() const;
size_t _depth;
size_t _row_pitch;
size_t _slice_pitch;
- std::map<clover::device *,
- std::unique_ptr<clover::root_resource>> resources;
+ std::map<device *,
+ std::unique_ptr<root_resource>> resources;
};
- struct image2d : public image {
+ class image2d : public image {
public:
- image2d(clover::context &ctx, cl_mem_flags flags,
+ image2d(context &ctx, cl_mem_flags flags,
const cl_image_format *format, size_t width,
size_t height, size_t row_pitch,
void *host_ptr);
virtual cl_mem_object_type type() const;
};
- struct image3d : public image {
+ class image3d : public image {
public:
- image3d(clover::context &ctx, cl_mem_flags flags,
+ image3d(context &ctx, cl_mem_flags flags,
const cl_image_format *format,
size_t width, size_t height, size_t depth,
size_t row_pitch, size_t slice_pitch,