/// Common argument checking shared by memory transfer commands.
///
void
- validate_base(cl_command_queue q, cl_uint num_deps, const cl_event *deps) {
- if (!q)
- throw error(CL_INVALID_COMMAND_QUEUE);
-
+ 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;
+ return &obj(ev).ctx != &q.ctx;
}, range(deps, num_deps)))
throw error(CL_INVALID_CONTEXT);
}
/// transfer commands.
///
void
- validate_obj(cl_command_queue q, cl_mem obj) {
- if (!obj)
+ validate_obj(command_queue &q, cl_mem mem) {
+ if (!mem)
throw error(CL_INVALID_MEM_OBJECT);
- if (&obj->ctx != &q->ctx)
+ if (&mem->ctx != &q.ctx)
throw error(CL_INVALID_CONTEXT);
}
template<> struct _map<memory_obj *> {
static mapping
- get(cl_command_queue q, memory_obj *obj, cl_map_flags flags,
- size_t offset, size_t size) {
- return { *q, obj->resource(q), flags, true,
+ 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 }}};
}
};
///
template<typename T, typename S>
std::function<void (event &)>
- hard_copy_op(cl_command_queue q, T dst_obj, const vector_t &dst_orig,
+ hard_copy_op(command_queue &q, T dst_obj, const vector_t &dst_orig,
S src_obj, const vector_t &src_orig, const vector_t ®ion) {
- return [=](event &) {
- dst_obj->resource(q).copy(*q, dst_orig, region,
+ return [=, &q](event &) {
+ dst_obj->resource(q).copy(q, dst_orig, region,
src_obj->resource(q), src_orig);
};
}
}
PUBLIC cl_int
-clEnqueueReadBuffer(cl_command_queue q, cl_mem obj, cl_bool blocking,
+clEnqueueReadBuffer(cl_command_queue d_q, cl_mem mem, cl_bool blocking,
size_t offset, size_t size, void *ptr,
cl_uint num_deps, const cl_event *d_deps,
- cl_event *ev) try {
+ cl_event *rd_ev) try {
+ auto &q = obj(d_q);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
validate_base(q, num_deps, d_deps);
- validate_obj(q, obj);
+ validate_obj(q, mem);
- if (!ptr || offset > obj->size() || offset + size > obj->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(q,
+ q, CL_COMMAND_READ_BUFFER, deps,
+ soft_copy_op(d_q,
ptr, {{ 0 }}, {{ 1 }},
- obj, {{ offset }}, {{ 1 }},
+ mem, {{ offset }}, {{ 1 }},
{{ size, 1, 1 }}));
- ret_object(ev, hev);
+ ret_object(rd_ev, hev);
return CL_SUCCESS;
} catch (error &e) {
}
PUBLIC cl_int
-clEnqueueWriteBuffer(cl_command_queue q, cl_mem obj, cl_bool blocking,
+clEnqueueWriteBuffer(cl_command_queue d_q, cl_mem mem, cl_bool blocking,
size_t offset, size_t size, const void *ptr,
cl_uint num_deps, const cl_event *d_deps,
- cl_event *ev) try {
+ cl_event *rd_ev) try {
+ auto &q = obj(d_q);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
validate_base(q, num_deps, d_deps);
- validate_obj(q, obj);
+ validate_obj(q, mem);
- if (!ptr || offset > obj->size() || offset + size > obj->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(q,
- obj, {{ offset }}, {{ 1 }},
+ q, CL_COMMAND_WRITE_BUFFER, deps,
+ soft_copy_op(d_q,
+ mem, {{ offset }}, {{ 1 }},
ptr, {{ 0 }}, {{ 1 }},
{{ size, 1, 1 }}));
- ret_object(ev, hev);
+ ret_object(rd_ev, hev);
return CL_SUCCESS;
} catch (error &e) {
}
PUBLIC cl_int
-clEnqueueReadBufferRect(cl_command_queue q, cl_mem obj, cl_bool blocking,
- const size_t *obj_origin, const size_t *host_origin,
+clEnqueueReadBufferRect(cl_command_queue d_q, cl_mem mem, cl_bool blocking,
+ const size_t *obj_origin,
+ const size_t *host_origin,
const size_t *region,
size_t obj_row_pitch, size_t obj_slice_pitch,
size_t host_row_pitch, size_t host_slice_pitch,
void *ptr,
cl_uint num_deps, const cl_event *d_deps,
- cl_event *ev) try {
+ cl_event *rd_ev) try {
+ auto &q = obj(d_q);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
validate_base(q, num_deps, d_deps);
- validate_obj(q, obj);
+ validate_obj(q, mem);
if (!ptr)
throw error(CL_INVALID_VALUE);
hard_event *hev = new hard_event(
- *q, CL_COMMAND_READ_BUFFER_RECT, deps,
- soft_copy_op(q,
+ q, CL_COMMAND_READ_BUFFER_RECT, deps,
+ soft_copy_op(d_q,
ptr, vector(host_origin),
{{ 1, host_row_pitch, host_slice_pitch }},
- obj, vector(obj_origin),
+ mem, vector(obj_origin),
{{ 1, obj_row_pitch, obj_slice_pitch }},
vector(region)));
- ret_object(ev, hev);
+ ret_object(rd_ev, hev);
return CL_SUCCESS;
} catch (error &e) {
}
PUBLIC cl_int
-clEnqueueWriteBufferRect(cl_command_queue q, cl_mem obj, cl_bool blocking,
- const size_t *obj_origin, const size_t *host_origin,
+clEnqueueWriteBufferRect(cl_command_queue d_q, cl_mem mem, cl_bool blocking,
+ const size_t *obj_origin,
+ const size_t *host_origin,
const size_t *region,
size_t obj_row_pitch, size_t obj_slice_pitch,
size_t host_row_pitch, size_t host_slice_pitch,
const void *ptr,
cl_uint num_deps, const cl_event *d_deps,
- cl_event *ev) try {
+ cl_event *rd_ev) try {
+ auto &q = obj(d_q);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
validate_base(q, num_deps, d_deps);
- validate_obj(q, obj);
+ validate_obj(q, mem);
if (!ptr)
throw error(CL_INVALID_VALUE);
hard_event *hev = new hard_event(
- *q, CL_COMMAND_WRITE_BUFFER_RECT, deps,
- soft_copy_op(q,
- obj, vector(obj_origin),
+ q, CL_COMMAND_WRITE_BUFFER_RECT, deps,
+ soft_copy_op(d_q,
+ mem, vector(obj_origin),
{{ 1, obj_row_pitch, obj_slice_pitch }},
ptr, vector(host_origin),
{{ 1, host_row_pitch, host_slice_pitch }},
vector(region)));
- ret_object(ev, hev);
+ ret_object(rd_ev, hev);
return CL_SUCCESS;
} catch (error &e) {
}
PUBLIC cl_int
-clEnqueueCopyBuffer(cl_command_queue q, cl_mem src_obj, cl_mem dst_obj,
+clEnqueueCopyBuffer(cl_command_queue d_q, cl_mem src_mem, cl_mem dst_mem,
size_t src_offset, size_t dst_offset, size_t size,
cl_uint num_deps, const cl_event *d_deps,
- cl_event *ev) try {
+ cl_event *rd_ev) try {
+ auto &q = obj(d_q);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
validate_base(q, num_deps, d_deps);
- validate_obj(q, src_obj);
- validate_obj(q, dst_obj);
+ validate_obj(q, src_mem);
+ validate_obj(q, dst_mem);
hard_event *hev = new hard_event(
- *q, CL_COMMAND_COPY_BUFFER, deps,
- hard_copy_op(q, dst_obj, {{ dst_offset }},
- src_obj, {{ src_offset }},
+ q, CL_COMMAND_COPY_BUFFER, deps,
+ hard_copy_op(q, dst_mem, {{ dst_offset }},
+ src_mem, {{ src_offset }},
{{ size, 1, 1 }}));
- ret_object(ev, hev);
+ ret_object(rd_ev, hev);
return CL_SUCCESS;
} catch (error &e) {
}
PUBLIC cl_int
-clEnqueueCopyBufferRect(cl_command_queue q, cl_mem src_obj, cl_mem dst_obj,
+clEnqueueCopyBufferRect(cl_command_queue d_q, cl_mem src_mem,
+ cl_mem 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,
size_t dst_row_pitch, size_t dst_slice_pitch,
cl_uint num_deps, const cl_event *d_deps,
- cl_event *ev) try {
+ cl_event *rd_ev) try {
+ auto &q = obj(d_q);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
validate_base(q, num_deps, d_deps);
- validate_obj(q, src_obj);
- validate_obj(q, dst_obj);
+ validate_obj(q, src_mem);
+ validate_obj(q, dst_mem);
hard_event *hev = new hard_event(
- *q, CL_COMMAND_COPY_BUFFER_RECT, deps,
- soft_copy_op(q,
- dst_obj, vector(dst_origin),
+ q, CL_COMMAND_COPY_BUFFER_RECT, deps,
+ soft_copy_op(d_q,
+ dst_mem, vector(dst_origin),
{{ 1, dst_row_pitch, dst_slice_pitch }},
- src_obj, vector(src_origin),
+ src_mem, vector(src_origin),
{{ 1, src_row_pitch, src_slice_pitch }},
vector(region)));
- ret_object(ev, hev);
+ ret_object(rd_ev, hev);
return CL_SUCCESS;
} catch (error &e) {
}
PUBLIC cl_int
-clEnqueueReadImage(cl_command_queue q, cl_mem obj, cl_bool blocking,
+clEnqueueReadImage(cl_command_queue d_q, cl_mem 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 *ev) try {
+ cl_event *rd_ev) try {
+ auto &q = obj(d_q);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
- image *img = dynamic_cast<image *>(obj);
+ image *img = dynamic_cast<image *>(mem);
validate_base(q, num_deps, d_deps);
validate_obj(q, img);
throw error(CL_INVALID_VALUE);
hard_event *hev = new hard_event(
- *q, CL_COMMAND_READ_IMAGE, deps,
- soft_copy_op(q,
+ q, CL_COMMAND_READ_IMAGE, deps,
+ soft_copy_op(d_q,
ptr, {},
{{ 1, row_pitch, slice_pitch }},
- obj, vector(origin),
+ mem, vector(origin),
{{ 1, img->row_pitch(), img->slice_pitch() }},
vector(region)));
- ret_object(ev, hev);
+ ret_object(rd_ev, hev);
return CL_SUCCESS;
} catch (error &e) {
}
PUBLIC cl_int
-clEnqueueWriteImage(cl_command_queue q, cl_mem obj, cl_bool blocking,
+clEnqueueWriteImage(cl_command_queue d_q, cl_mem 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 *ev) try {
+ cl_event *rd_ev) try {
+ auto &q = obj(d_q);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
- image *img = dynamic_cast<image *>(obj);
+ image *img = dynamic_cast<image *>(mem);
validate_base(q, num_deps, d_deps);
validate_obj(q, img);
throw error(CL_INVALID_VALUE);
hard_event *hev = new hard_event(
- *q, CL_COMMAND_WRITE_IMAGE, deps,
- soft_copy_op(q,
- obj, vector(origin),
+ q, CL_COMMAND_WRITE_IMAGE, deps,
+ soft_copy_op(d_q,
+ mem, vector(origin),
{{ 1, img->row_pitch(), img->slice_pitch() }},
ptr, {},
{{ 1, row_pitch, slice_pitch }},
vector(region)));
- ret_object(ev, hev);
+ ret_object(rd_ev, hev);
return CL_SUCCESS;
} catch (error &e) {
}
PUBLIC cl_int
-clEnqueueCopyImage(cl_command_queue q, cl_mem src_obj, cl_mem dst_obj,
+clEnqueueCopyImage(cl_command_queue d_q, cl_mem src_mem, cl_mem 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 *ev) try {
+ cl_event *rd_ev) try {
+ auto &q = obj(d_q);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
- image *src_img = dynamic_cast<image *>(src_obj);
- image *dst_img = dynamic_cast<image *>(dst_obj);
+ 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);
hard_event *hev = new hard_event(
- *q, CL_COMMAND_COPY_IMAGE, deps,
+ q, CL_COMMAND_COPY_IMAGE, deps,
hard_copy_op(q,
- dst_obj, vector(dst_origin),
- src_obj, vector(src_origin),
+ dst_img, vector(dst_origin),
+ src_img, vector(src_origin),
vector(region)));
- ret_object(ev, hev);
+ ret_object(rd_ev, hev);
return CL_SUCCESS;
} catch (error &e) {
}
PUBLIC cl_int
-clEnqueueCopyImageToBuffer(cl_command_queue q, cl_mem src_obj, cl_mem dst_obj,
+clEnqueueCopyImageToBuffer(cl_command_queue d_q,
+ cl_mem src_mem, cl_mem 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 *ev) try {
+ cl_event *rd_ev) try {
+ auto &q = obj(d_q);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
- image *src_img = dynamic_cast<image *>(src_obj);
+ image *src_img = dynamic_cast<image *>(src_mem);
validate_base(q, num_deps, d_deps);
validate_obj(q, src_img);
- validate_obj(q, dst_obj);
+ validate_obj(q, dst_mem);
hard_event *hev = new hard_event(
- *q, CL_COMMAND_COPY_IMAGE_TO_BUFFER, deps,
- soft_copy_op(q,
- dst_obj, {{ dst_offset }},
+ q, CL_COMMAND_COPY_IMAGE_TO_BUFFER, deps,
+ soft_copy_op(d_q,
+ dst_mem, {{ dst_offset }},
{{ 0, 0, 0 }},
- src_obj, vector(src_origin),
+ src_mem, vector(src_origin),
{{ 1, src_img->row_pitch(), src_img->slice_pitch() }},
vector(region)));
- ret_object(ev, hev);
+ ret_object(rd_ev, hev);
return CL_SUCCESS;
} catch (error &e) {
}
PUBLIC cl_int
-clEnqueueCopyBufferToImage(cl_command_queue q, cl_mem src_obj, cl_mem dst_obj,
+clEnqueueCopyBufferToImage(cl_command_queue d_q,
+ cl_mem src_mem, cl_mem 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 *ev) try {
+ cl_event *rd_ev) try {
+ auto &q = obj(d_q);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
- image *dst_img = dynamic_cast<image *>(dst_obj);
+ image *dst_img = dynamic_cast<image *>(dst_mem);
validate_base(q, num_deps, d_deps);
- validate_obj(q, src_obj);
+ validate_obj(q, src_mem);
validate_obj(q, dst_img);
hard_event *hev = new hard_event(
- *q, CL_COMMAND_COPY_BUFFER_TO_IMAGE, deps,
- soft_copy_op(q,
- dst_obj, vector(dst_origin),
+ 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_obj, {{ src_offset }},
+ src_mem, {{ src_offset }},
{{ 0, 0, 0 }},
vector(region)));
- ret_object(ev, hev);
+ ret_object(rd_ev, hev);
return CL_SUCCESS;
} catch (error &e) {
}
PUBLIC void *
-clEnqueueMapBuffer(cl_command_queue q, cl_mem obj, cl_bool blocking,
+clEnqueueMapBuffer(cl_command_queue d_q, cl_mem 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 *ev, cl_int *errcode_ret) try {
+ cl_event *rd_ev, cl_int *r_errcode) try {
+ auto &q = obj(d_q);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
+
validate_base(q, num_deps, d_deps);
- validate_obj(q, obj);
+ validate_obj(q, mem);
- if (offset > obj->size() || offset + size > obj->size())
+ if (offset > mem->size() || offset + size > mem->size())
throw error(CL_INVALID_VALUE);
- void *map = obj->resource(q).add_map(
- *q, flags, blocking, {{ offset }}, {{ size }});
+ void *map = mem->resource(q).add_map(
+ q, flags, blocking, {{ offset }}, {{ size }});
- ret_object(ev, new hard_event(*q, CL_COMMAND_MAP_BUFFER,
- deps));
- ret_error(errcode_ret, CL_SUCCESS);
+ ret_object(rd_ev, new hard_event(q, CL_COMMAND_MAP_BUFFER, deps));
+ ret_error(r_errcode, CL_SUCCESS);
return map;
} catch (error &e) {
- ret_error(errcode_ret, e);
+ ret_error(r_errcode, e);
return NULL;
}
PUBLIC void *
-clEnqueueMapImage(cl_command_queue q, cl_mem obj, cl_bool blocking,
+clEnqueueMapImage(cl_command_queue d_q, cl_mem 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 *ev, cl_int *errcode_ret) try {
+ cl_event *rd_ev, cl_int *r_errcode) try {
+ auto &q = obj(d_q);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
- image *img = dynamic_cast<image *>(obj);
+ image *img = dynamic_cast<image *>(mem);
validate_base(q, num_deps, d_deps);
validate_obj(q, img);
- void *map = obj->resource(q).add_map(
- *q, flags, blocking, vector(origin), vector(region));
+ void *map = img->resource(q).add_map(
+ q, flags, blocking, vector(origin), vector(region));
- ret_object(ev, new hard_event(*q, CL_COMMAND_MAP_IMAGE,
- deps));
- ret_error(errcode_ret, CL_SUCCESS);
+ ret_object(rd_ev, new hard_event(q, CL_COMMAND_MAP_IMAGE, deps));
+ ret_error(r_errcode, CL_SUCCESS);
return map;
} catch (error &e) {
- ret_error(errcode_ret, e);
+ ret_error(r_errcode, e);
return NULL;
}
PUBLIC cl_int
-clEnqueueUnmapMemObject(cl_command_queue q, cl_mem obj, void *ptr,
+clEnqueueUnmapMemObject(cl_command_queue d_q, cl_mem mem, void *ptr,
cl_uint num_deps, const cl_event *d_deps,
- cl_event *ev) try {
+ cl_event *rd_ev) try {
+ auto &q = obj(d_q);
auto deps = objs<wait_list_tag>(d_deps, num_deps);
validate_base(q, num_deps, d_deps);
- validate_obj(q, obj);
+ validate_obj(q, mem);
hard_event *hev = new hard_event(
- *q, CL_COMMAND_UNMAP_MEM_OBJECT, deps,
- [=](event &) {
- obj->resource(q).del_map(ptr);
+ q, CL_COMMAND_UNMAP_MEM_OBJECT, deps,
+ [=, &q, &mem](event &) {
+ mem->resource(q).del_map(ptr);
});
- ret_object(ev, hev);
+ ret_object(rd_ev, hev);
return CL_SUCCESS;
} catch (error &e) {