aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGil Pitney <gil.pitney@linaro.org>2015-10-02 00:26:07 +0000
committerGil Pitney <gil.pitney@linaro.org>2015-10-02 00:26:07 +0000
commit5e6a3c0c70334bd7aaad543bddba99a29e8c51f5 (patch)
tree22180d333b6f6fdca81c43cc04b5e0aa83dc136d
parent2e55588f322f5eebdee567d5ef524ca60b9d7702 (diff)
downloadshamrock-5e6a3c0c70334bd7aaad543bddba99a29e8c51f5.tar.gz
ICD: Update MemObject objects to be ICD compatible.
Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
-rw-r--r--src/api/api_enqueue.cpp90
-rw-r--r--src/api/api_memory.cpp41
-rw-r--r--src/core/cpu/worker.cpp16
-rw-r--r--src/core/events.cpp24
-rw-r--r--src/core/events.h8
-rw-r--r--src/core/kernel.cpp56
-rw-r--r--src/core/memobject.cpp10
-rw-r--r--src/core/memobject.h13
8 files changed, 154 insertions, 104 deletions
diff --git a/src/api/api_enqueue.cpp b/src/api/api_enqueue.cpp
index daa24cc..759ed92 100644
--- a/src/api/api_enqueue.cpp
+++ b/src/api/api_enqueue.cpp
@@ -112,7 +112,7 @@ static inline cl_int queueEvent(Coal::CommandQueue *queue,
// Enqueued Commands APIs
cl_int
clEnqueueReadBuffer(cl_command_queue d_command_queue,
- cl_mem buffer,
+ cl_mem d_buffer,
cl_bool blocking_read,
size_t offset,
size_t cb,
@@ -123,13 +123,14 @@ clEnqueueReadBuffer(cl_command_queue d_command_queue,
{
cl_int rs = CL_SUCCESS;
auto command_queue = pobj(d_command_queue);
+ auto buffer = pobj(d_buffer);
if (!command_queue->isA(Coal::Object::T_CommandQueue))
return CL_INVALID_COMMAND_QUEUE;
Coal::ReadBufferEvent *command = new Coal::ReadBufferEvent(
command_queue,
- (Coal::MemObject *)buffer,
+ buffer,
offset, cb, ptr,
num_events_in_wait_list, event_wait_list, &rs
);
@@ -145,7 +146,7 @@ clEnqueueReadBuffer(cl_command_queue d_command_queue,
cl_int
clEnqueueWriteBuffer(cl_command_queue d_command_queue,
- cl_mem buffer,
+ cl_mem d_buffer,
cl_bool blocking_write,
size_t offset,
size_t cb,
@@ -156,13 +157,14 @@ clEnqueueWriteBuffer(cl_command_queue d_command_queue,
{
cl_int rs = CL_SUCCESS;
auto command_queue = pobj(d_command_queue);
+ auto buffer = pobj(d_buffer);
if (!command_queue->isA(Coal::Object::T_CommandQueue))
return CL_INVALID_COMMAND_QUEUE;
Coal::WriteBufferEvent *command = new Coal::WriteBufferEvent(
command_queue,
- (Coal::MemObject *)buffer,
+ buffer,
offset, cb, (void *)ptr,
num_events_in_wait_list, event_wait_list, &rs
);
@@ -178,7 +180,7 @@ clEnqueueWriteBuffer(cl_command_queue d_command_queue,
cl_int
clEnqueueReadBufferRect(cl_command_queue d_command_queue,
- cl_mem buffer,
+ cl_mem d_buffer,
cl_bool blocking_read,
const size_t * buffer_origin,
const size_t * host_origin,
@@ -194,13 +196,14 @@ clEnqueueReadBufferRect(cl_command_queue d_command_queue,
{
cl_int rs = CL_SUCCESS;
auto command_queue = pobj(d_command_queue);
+ auto buffer = pobj(d_buffer);
if (!command_queue->isA(Coal::Object::T_CommandQueue))
return CL_INVALID_COMMAND_QUEUE;
Coal::ReadBufferRectEvent *command = new Coal::ReadBufferRectEvent(
command_queue,
- (Coal::MemObject *)buffer,
+ buffer,
buffer_origin, host_origin, region, buffer_row_pitch, buffer_slice_pitch,
host_row_pitch, host_slice_pitch, ptr,
num_events_in_wait_list, event_wait_list, &rs
@@ -217,7 +220,7 @@ clEnqueueReadBufferRect(cl_command_queue d_command_queue,
cl_int
clEnqueueWriteBufferRect(cl_command_queue d_command_queue,
- cl_mem buffer,
+ cl_mem d_buffer,
cl_bool blocking_write,
const size_t * buffer_origin,
const size_t * host_origin,
@@ -233,13 +236,14 @@ clEnqueueWriteBufferRect(cl_command_queue d_command_queue,
{
cl_int rs = CL_SUCCESS;
auto command_queue = pobj(d_command_queue);
+ auto buffer = pobj(d_buffer);
if (!command_queue->isA(Coal::Object::T_CommandQueue))
return CL_INVALID_COMMAND_QUEUE;
Coal::WriteBufferRectEvent *command = new Coal::WriteBufferRectEvent(
command_queue,
- (Coal::MemObject *)buffer,
+ buffer,
buffer_origin, host_origin, region, buffer_row_pitch, buffer_slice_pitch,
host_row_pitch, host_slice_pitch, (void *)ptr,
num_events_in_wait_list, event_wait_list, &rs
@@ -256,8 +260,8 @@ clEnqueueWriteBufferRect(cl_command_queue d_command_queue,
cl_int
clEnqueueCopyBufferRect(cl_command_queue d_command_queue,
- cl_mem src_buffer,
- cl_mem dst_buffer,
+ cl_mem d_src_buffer,
+ cl_mem d_dst_buffer,
const size_t * src_origin,
const size_t * dst_origin,
const size_t * region,
@@ -271,14 +275,16 @@ clEnqueueCopyBufferRect(cl_command_queue d_command_queue,
{
cl_int rs = CL_SUCCESS;
auto command_queue = pobj(d_command_queue);
+ auto src_buffer = pobj(d_src_buffer);
+ auto dst_buffer = pobj(d_dst_buffer);
if (!command_queue->isA(Coal::Object::T_CommandQueue))
return CL_INVALID_COMMAND_QUEUE;
Coal::CopyBufferRectEvent *command = new Coal::CopyBufferRectEvent(
command_queue,
- (Coal::MemObject *)src_buffer,
- (Coal::MemObject *)dst_buffer,
+ src_buffer,
+ dst_buffer,
src_origin, dst_origin, region, src_row_pitch, src_slice_pitch,
dst_row_pitch, dst_slice_pitch, 1,
num_events_in_wait_list, event_wait_list, &rs
@@ -295,8 +301,8 @@ clEnqueueCopyBufferRect(cl_command_queue d_command_queue,
cl_int
clEnqueueCopyBuffer(cl_command_queue d_command_queue,
- cl_mem src_buffer,
- cl_mem dst_buffer,
+ cl_mem d_src_buffer,
+ cl_mem d_dst_buffer,
size_t src_offset,
size_t dst_offset,
size_t cb,
@@ -306,14 +312,16 @@ clEnqueueCopyBuffer(cl_command_queue d_command_queue,
{
cl_int rs = CL_SUCCESS;
auto command_queue = pobj(d_command_queue);
+ auto src_buffer = pobj(d_src_buffer);
+ auto dst_buffer = pobj(d_dst_buffer);
if (!command_queue->isA(Coal::Object::T_CommandQueue))
return CL_INVALID_COMMAND_QUEUE;
Coal::CopyBufferEvent *command = new Coal::CopyBufferEvent(
command_queue,
- (Coal::MemObject *)src_buffer,
- (Coal::MemObject *)dst_buffer,
+ src_buffer,
+ dst_buffer,
src_offset, dst_offset, cb,
num_events_in_wait_list, event_wait_list, &rs
);
@@ -329,7 +337,7 @@ clEnqueueCopyBuffer(cl_command_queue d_command_queue,
cl_int
clEnqueueFillBuffer(cl_command_queue d_command_queue,
- cl_mem buffer,
+ cl_mem d_buffer,
const void * pattern,
size_t pattern_size,
size_t offset,
@@ -340,13 +348,14 @@ clEnqueueFillBuffer(cl_command_queue d_command_queue,
{
cl_int rs = CL_SUCCESS;
auto command_queue = pobj(d_command_queue);
+ auto buffer = pobj(d_buffer);
if (!command_queue->isA(Coal::Object::T_CommandQueue))
return CL_INVALID_COMMAND_QUEUE;
Coal::FillBufferEvent *command = new Coal::FillBufferEvent(
command_queue,
- (Coal::MemObject *)buffer,
+ buffer,
pattern, pattern_size, offset, size,
num_events_in_wait_list, event_wait_list, &rs);
@@ -361,7 +370,7 @@ clEnqueueFillBuffer(cl_command_queue d_command_queue,
cl_int
clEnqueueReadImage(cl_command_queue d_command_queue,
- cl_mem image,
+ cl_mem d_image,
cl_bool blocking_read,
const size_t * origin,
const size_t * region,
@@ -374,6 +383,7 @@ clEnqueueReadImage(cl_command_queue d_command_queue,
{
cl_int rs = CL_SUCCESS;
auto command_queue = pobj(d_command_queue);
+ auto image = pobj(d_image);
if (!command_queue->isA(Coal::Object::T_CommandQueue))
return CL_INVALID_COMMAND_QUEUE;
@@ -400,7 +410,7 @@ clEnqueueReadImage(cl_command_queue d_command_queue,
cl_int
clEnqueueWriteImage(cl_command_queue d_command_queue,
- cl_mem image,
+ cl_mem d_image,
cl_bool blocking_write,
const size_t * origin,
const size_t * region,
@@ -413,6 +423,7 @@ clEnqueueWriteImage(cl_command_queue d_command_queue,
{
cl_int rs = CL_SUCCESS;
auto command_queue = pobj(d_command_queue);
+ auto image = pobj(d_image);
if (!command_queue->isA(Coal::Object::T_CommandQueue))
return CL_INVALID_COMMAND_QUEUE;
@@ -435,8 +446,8 @@ clEnqueueWriteImage(cl_command_queue d_command_queue,
cl_int
clEnqueueCopyImage(cl_command_queue d_command_queue,
- cl_mem src_image,
- cl_mem dst_image,
+ cl_mem d_src_image,
+ cl_mem d_dst_image,
const size_t * src_origin,
const size_t * dst_origin,
const size_t * region,
@@ -446,6 +457,8 @@ clEnqueueCopyImage(cl_command_queue d_command_queue,
{
cl_int rs = CL_SUCCESS;
auto command_queue = pobj(d_command_queue);
+ auto src_image = pobj(d_src_image);
+ auto dst_image = pobj(d_dst_image);
if (!command_queue->isA(Coal::Object::T_CommandQueue))
return CL_INVALID_COMMAND_QUEUE;
@@ -468,8 +481,8 @@ clEnqueueCopyImage(cl_command_queue d_command_queue,
cl_int
clEnqueueCopyImageToBuffer(cl_command_queue d_command_queue,
- cl_mem src_image,
- cl_mem dst_buffer,
+ cl_mem d_src_image,
+ cl_mem d_dst_buffer,
const size_t * src_origin,
const size_t * region,
size_t dst_offset,
@@ -479,13 +492,15 @@ clEnqueueCopyImageToBuffer(cl_command_queue d_command_queue,
{
cl_int rs = CL_SUCCESS;
auto command_queue = pobj(d_command_queue);
+ auto src_image = pobj(d_src_image);
+ auto dst_buffer = pobj(d_dst_buffer);
if (!command_queue->isA(Coal::Object::T_CommandQueue))
return CL_INVALID_COMMAND_QUEUE;
Coal::CopyImageToBufferEvent *command = new Coal::CopyImageToBufferEvent(
command_queue,
- (Coal::Image2D *)src_image, (Coal::MemObject *)dst_buffer,
+ (Coal::Image2D *)src_image, dst_buffer,
src_origin, region, dst_offset,
num_events_in_wait_list, event_wait_list, &rs
);
@@ -501,8 +516,8 @@ clEnqueueCopyImageToBuffer(cl_command_queue d_command_queue,
cl_int
clEnqueueCopyBufferToImage(cl_command_queue d_command_queue,
- cl_mem src_buffer,
- cl_mem dst_image,
+ cl_mem d_src_buffer,
+ cl_mem d_dst_image,
size_t src_offset,
const size_t * dst_origin,
const size_t * region,
@@ -512,13 +527,15 @@ clEnqueueCopyBufferToImage(cl_command_queue d_command_queue,
{
cl_int rs = CL_SUCCESS;
auto command_queue = pobj(d_command_queue);
+ auto src_buffer = pobj(d_src_buffer);
+ auto dst_image = pobj(d_dst_image);
if (!command_queue->isA(Coal::Object::T_CommandQueue))
return CL_INVALID_COMMAND_QUEUE;
Coal::CopyBufferToImageEvent *command = new Coal::CopyBufferToImageEvent(
command_queue,
- (Coal::MemObject *)src_buffer, (Coal::Image2D *)dst_image,
+ src_buffer, (Coal::Image2D *)dst_image,
src_offset, dst_origin, region,
num_events_in_wait_list, event_wait_list, &rs
);
@@ -534,7 +551,7 @@ clEnqueueCopyBufferToImage(cl_command_queue d_command_queue,
void *
clEnqueueMapBuffer(cl_command_queue d_command_queue,
- cl_mem buffer,
+ cl_mem d_buffer,
cl_bool blocking_map,
cl_map_flags map_flags,
size_t offset,
@@ -546,6 +563,7 @@ clEnqueueMapBuffer(cl_command_queue d_command_queue,
{
cl_int dummy_errcode;
auto command_queue = pobj(d_command_queue);
+ auto buffer = pobj(d_buffer);
if (!errcode_ret)
errcode_ret = &dummy_errcode;
@@ -560,7 +578,7 @@ clEnqueueMapBuffer(cl_command_queue d_command_queue,
Coal::MapBufferEvent *command = new Coal::MapBufferEvent(
command_queue,
- (Coal::MemObject *)buffer,
+ buffer,
offset, cb, map_flags,
num_events_in_wait_list, event_wait_list, errcode_ret
);
@@ -596,7 +614,7 @@ clEnqueueMapBuffer(cl_command_queue d_command_queue,
void *
clEnqueueMapImage(cl_command_queue d_command_queue,
- cl_mem image,
+ cl_mem d_image,
cl_bool blocking_map,
cl_map_flags map_flags,
const size_t * origin,
@@ -610,6 +628,7 @@ clEnqueueMapImage(cl_command_queue d_command_queue,
{
cl_int rs;
auto command_queue = pobj(d_command_queue);
+ auto image = pobj(d_image);
if (!errcode_ret)
errcode_ret = &rs;
@@ -668,7 +687,7 @@ clEnqueueMapImage(cl_command_queue d_command_queue,
cl_int
clEnqueueUnmapMemObject(cl_command_queue d_command_queue,
- cl_mem memobj,
+ cl_mem d_memobj,
void * mapped_ptr,
cl_uint num_events_in_wait_list,
const cl_event * event_wait_list,
@@ -676,6 +695,7 @@ clEnqueueUnmapMemObject(cl_command_queue d_command_queue,
{
cl_int rs = CL_SUCCESS;
auto command_queue = pobj(d_command_queue);
+ auto memobj = pobj(d_memobj);
if (!command_queue->isA(Coal::Object::T_CommandQueue))
{
@@ -684,7 +704,7 @@ clEnqueueUnmapMemObject(cl_command_queue d_command_queue,
Coal::UnmapBufferEvent *command = new Coal::UnmapBufferEvent(
command_queue,
- (Coal::MemObject *)memobj,
+ memobj,
mapped_ptr,
num_events_in_wait_list, event_wait_list, &rs
);
@@ -786,7 +806,7 @@ clEnqueueNativeKernel(cl_command_queue d_command_queue,
Coal::NativeKernelEvent *command = new Coal::NativeKernelEvent(
command_queue,
user_func, args, cb_args, num_mem_objects,
- (const Coal::MemObject **)mem_list, args_mem_loc,
+ mem_list, args_mem_loc,
num_events_in_wait_list, event_wait_list, &rs
);
@@ -949,7 +969,7 @@ clEnqueueMigrateMemObjects(cl_command_queue d_command_queue,
Coal::MigrateMemObjectsEvent *command = new Coal::MigrateMemObjectsEvent(
command_queue,
- num_mem_objects, (const Coal::MemObject **)mem_objects, flags,
+ num_mem_objects, mem_objects, flags,
num_events_in_wait_list, event_wait_list, &rs);
if (rs != CL_SUCCESS)
diff --git a/src/api/api_memory.cpp b/src/api/api_memory.cpp
index 00eb4d4..6cab011 100644
--- a/src/api/api_memory.cpp
+++ b/src/api/api_memory.cpp
@@ -67,17 +67,19 @@ clCreateBuffer(cl_context d_context,
return 0;
}
- return (cl_mem)buf;
+ return desc(buf);
}
cl_mem
-clCreateSubBuffer(cl_mem buffer,
+clCreateSubBuffer(cl_mem d_buffer,
cl_mem_flags flags,
cl_buffer_create_type buffer_create_type,
const void * buffer_create_info,
cl_int * errcode_ret)
{
cl_int dummy_errcode;
+ // code below seems to be expecting a Coal::Buffer *, so convert to such:
+ Coal::Buffer * buffer = (Coal::Buffer *)pobj(d_buffer);
if (!errcode_ret)
errcode_ret = &dummy_errcode;
@@ -112,7 +114,7 @@ clCreateSubBuffer(cl_mem buffer,
*errcode_ret = CL_SUCCESS;
- Coal::SubBuffer *buf = new Coal::SubBuffer((Coal::Buffer *)buffer,
+ Coal::SubBuffer *buf = new Coal::SubBuffer(buffer,
region->origin, region->size,
flags, errcode_ret);
@@ -122,7 +124,7 @@ clCreateSubBuffer(cl_mem buffer,
return 0;
}
- return (cl_mem)buf;
+ return desc(buf);
}
cl_mem
@@ -153,12 +155,12 @@ clCreateImage(cl_context d_context,
/* Just pass on to corresponding clCreateImage2D or clCreateImage3D functions: */
if (image_depth == 1) {
- image = clCreateImage2D(context, flags, image_format, image_width, image_height, image_row_pitch,
- host_ptr, errcode_ret);
+ image = clCreateImage2D(context, flags, image_format, image_width, image_height,
+ image_row_pitch, host_ptr, errcode_ret);
}
else {
- image = clCreateImage3D(context, flags, image_format, image_width, image_height, image_depth,
- image_row_pitch, image_slice_pitch, host_ptr, errcode_ret);
+ image = clCreateImage3D(context, flags, image_format, image_width, image_height,
+ image_depth, image_row_pitch, image_slice_pitch, host_ptr, errcode_ret);
}
return image;
}
@@ -198,7 +200,7 @@ clCreateImage2D(cl_context d_context,
return 0;
}
- return (cl_mem)image;
+ return desc(image);
}
cl_mem
@@ -238,12 +240,14 @@ clCreateImage3D(cl_context d_context,
return 0;
}
- return (cl_mem)image;
+ return desc(image);
}
cl_int
-clRetainMemObject(cl_mem memobj)
+clRetainMemObject(cl_mem d_memobj)
{
+ auto memobj = pobj(d_memobj);
+
if (!memobj->isA(Coal::Object::T_MemObject))
return CL_INVALID_MEM_OBJECT;
@@ -253,8 +257,10 @@ clRetainMemObject(cl_mem memobj)
}
cl_int
-clReleaseMemObject(cl_mem memobj)
+clReleaseMemObject(cl_mem d_memobj)
{
+ auto memobj = pobj(d_memobj);
+
if (!memobj->isA(Coal::Object::T_MemObject))
return CL_INVALID_MEM_OBJECT;
@@ -415,12 +421,14 @@ clGetSupportedImageFormats(cl_context d_context,
}
cl_int
-clGetMemObjectInfo(cl_mem memobj,
+clGetMemObjectInfo(cl_mem d_memobj,
cl_mem_info param_name,
size_t param_value_size,
void * param_value,
size_t * param_value_size_ret)
{
+ auto memobj = pobj(d_memobj);
+
if (!memobj->isA(Coal::Object::T_MemObject))
return CL_INVALID_MEM_OBJECT;
@@ -429,12 +437,13 @@ clGetMemObjectInfo(cl_mem memobj,
}
cl_int
-clGetImageInfo(cl_mem image,
+clGetImageInfo(cl_mem d_image,
cl_image_info param_name,
size_t param_value_size,
void * param_value,
size_t * param_value_size_ret)
{
+ auto image = pobj(d_image);
if (!image->isA(Coal::Object::T_MemObject) ||
(image->type() != Coal::MemObject::Image2D &&
image->type() != Coal::MemObject::Image3D))
@@ -447,11 +456,13 @@ clGetImageInfo(cl_mem image,
}
cl_int
-clSetMemObjectDestructorCallback(cl_mem memobj,
+clSetMemObjectDestructorCallback(cl_mem d_memobj,
void (CL_CALLBACK *pfn_notify)(cl_mem memobj,
void *user_data),
void * user_data)
{
+ auto memobj = pobj(d_memobj);
+
if (!memobj->isA(Coal::Object::T_MemObject))
return CL_INVALID_MEM_OBJECT;
diff --git a/src/core/cpu/worker.cpp b/src/core/cpu/worker.cpp
index 635706b..409c4a6 100644
--- a/src/core/cpu/worker.cpp
+++ b/src/core/cpu/worker.cpp
@@ -248,11 +248,11 @@ void *worker(void *data)
break;
}
- case Event::MigrateMemObjects:
- {
+ case Event::MigrateMemObjects:
+ {
MigrateMemObjectsEvent *e = (MigrateMemObjectsEvent *)event;
- int num_mem_objects = e->num_mem_objects();
- Coal::MemObject ** mem_objects = (Coal::MemObject **)e->mem_objects();
+ int num_mem_objects = e->num_mem_objects();
+ const cl_mem * mem_objects = e->mem_objects();
cl_mem_migration_flags flags = e->flags();
std::cout << "Event::MigrateMemObjects " << std::endl;
@@ -262,10 +262,10 @@ void *worker(void *data)
// only migrate date from HOST to Device.
// Force pre-allocation (or copying) of the CPUBuffers for this device:
for (int i = 0; i < num_mem_objects; i++) {
- mem_objects[i]->allocate(device);
- }
- break;
- }
+ pobj(mem_objects[i])->allocate(device);
+ }
+ break;
+ }
default:
break;
diff --git a/src/core/events.cpp b/src/core/events.cpp
index 22676f1..f4b7c09 100644
--- a/src/core/events.cpp
+++ b/src/core/events.cpp
@@ -56,7 +56,7 @@ BufferEvent::BufferEvent(CommandQueue *parent,
: Event(parent, CL_QUEUED, num_events_in_wait_list, event_wait_list, errcode_ret),
p_buffer(buffer)
{
- clRetainMemObject((cl_mem) p_buffer);
+ clRetainMemObject(desc(p_buffer));
if (*errcode_ret != CL_SUCCESS) return;
@@ -103,7 +103,7 @@ BufferEvent::BufferEvent(CommandQueue *parent,
BufferEvent::~BufferEvent()
{
- clReleaseMemObject((cl_mem) p_buffer);
+ clReleaseMemObject(desc(p_buffer));
}
MemObject *BufferEvent::buffer() const
@@ -431,7 +431,7 @@ CopyBufferEvent::CopyBufferEvent(CommandQueue *parent,
errcode_ret), p_destination(destination), p_src_offset(src_offset),
p_dst_offset(dst_offset), p_cb(cb)
{
- clRetainMemObject((cl_mem) p_destination);
+ clRetainMemObject(desc(p_destination));
if (*errcode_ret != CL_SUCCESS) return;
@@ -483,7 +483,7 @@ CopyBufferEvent::CopyBufferEvent(CommandQueue *parent,
CopyBufferEvent::~CopyBufferEvent()
{
- clReleaseMemObject((cl_mem) p_destination);
+ clReleaseMemObject(desc(p_destination));
}
MemObject *CopyBufferEvent::source() const
@@ -587,7 +587,7 @@ NativeKernelEvent::NativeKernelEvent(CommandQueue *parent,
void *args,
size_t cb_args,
cl_uint num_mem_objects,
- const MemObject **mem_list,
+ const cl_mem *mem_list,
const void **args_mem_loc,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
@@ -665,7 +665,7 @@ NativeKernelEvent::NativeKernelEvent(CommandQueue *parent,
// Replace memory objects with global pointers
for (cl_uint i=0; i<num_mem_objects; ++i)
{
- const MemObject *buffer = mem_list[i];
+ const MemObject *buffer = pobj(mem_list[i]);
const char *loc = (const char *)args_mem_loc[i];
if (!buffer)
@@ -729,7 +729,7 @@ KernelEvent::KernelEvent(CommandQueue *parent,
if (a->kind() == Kernel::Arg::Buffer && a->file() != Kernel::Arg::Local)
{
MemObject *buffer = *(MemObject **)(a->value(0));
- clRetainMemObject((cl_mem)buffer);
+ clRetainMemObject(desc(buffer));
}
}
@@ -955,7 +955,7 @@ KernelEvent::~KernelEvent()
if (a->kind() == Kernel::Arg::Buffer && a->file() != Kernel::Arg::Local)
{
MemObject *buffer = *(MemObject **)(a->value(0));
- clReleaseMemObject((cl_mem)buffer);
+ clReleaseMemObject(desc(buffer));
}
}
clReleaseKernel(desc(p_kernel));
@@ -1619,7 +1619,7 @@ Event::Type MarkerEvent::type() const
MigrateMemObjectsEvent::MigrateMemObjectsEvent(CommandQueue *parent,
cl_uint num_mem_objects,
- const Coal::MemObject **mem_objects,
+ const cl_mem * mem_objects,
cl_mem_migration_flags flags,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
@@ -1642,9 +1642,9 @@ MigrateMemObjectsEvent::MigrateMemObjectsEvent(CommandQueue *parent,
Context *ctx = (Context *)parent->parent();
for (int i = 0; i < num_mem_objects; i++)
{
- if (!mem_objects[i]->isA(Coal::Object::T_MemObject))
+ if (!pobj(mem_objects[i])->isA(Coal::Object::T_MemObject))
{ *errcode_ret = CL_INVALID_MEM_OBJECT; break; }
- else if (ctx != (Context *)mem_objects[i]->parent())
+ else if (ctx != (Context *)pobj(mem_objects[i])->parent())
{ *errcode_ret = CL_INVALID_CONTEXT; break; }
}
}
@@ -1654,7 +1654,7 @@ cl_uint MigrateMemObjectsEvent::num_mem_objects() const
return p_num_mem_objects;
}
-const Coal::MemObject ** MigrateMemObjectsEvent::mem_objects() const
+const cl_mem * MigrateMemObjectsEvent::mem_objects() const
{
return p_mem_objects;
}
diff --git a/src/core/events.h b/src/core/events.h
index 00b6fb1..aad5792 100644
--- a/src/core/events.h
+++ b/src/core/events.h
@@ -598,7 +598,7 @@ class NativeKernelEvent : public Event
void *args,
size_t cb_args,
cl_uint num_mem_objects,
- const MemObject **mem_list,
+ const cl_mem *mem_list,
const void **args_mem_loc,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
@@ -748,7 +748,7 @@ class MigrateMemObjectsEvent: public Event
public:
MigrateMemObjectsEvent(CommandQueue *parent,
cl_uint num_mem_objects,
- const Coal::MemObject **mem_objects,
+ const cl_mem * mem_objects,
cl_mem_migration_flags flags,
cl_uint num_events_in_wait_list,
const cl_event *event_wait_list,
@@ -757,12 +757,12 @@ class MigrateMemObjectsEvent: public Event
Type type() const; /*!< \brief Say the event is a \c Coal::Event::MigrateMemObjects one */
cl_uint num_mem_objects() const; /*!< \brief Number of MemObjects to migrate */
- const Coal::MemObject **mem_objects() const;/*!< \brief List of MemObjects to migrate */
+ const cl_mem *mem_objects() const; /*!< \brief List of MemObjects to migrate */
cl_mem_migration_flags flags() const; /*!< \brief Migrate flags */
private:
cl_uint p_num_mem_objects;
- const Coal::MemObject **p_mem_objects;
+ const cl_mem *p_mem_objects;
cl_mem_migration_flags p_flags;
};
diff --git a/src/core/kernel.cpp b/src/core/kernel.cpp
index 4f1b7b1..dd8c116 100644
--- a/src/core/kernel.cpp
+++ b/src/core/kernel.cpp
@@ -317,6 +317,11 @@ llvm::Function *Kernel::function(DeviceInterface *device) const
/******************************************************************************
* cl_int Kernel::setArg
+*
+* Note: the argument void *value can either be a pointer to raw data, or a
+* derived type of MemObject, upcast to an ICD descriptor (see icd.h).
+* In this case, we must be careful to distinguish between the two and do the
+* downcast to a clover object if valule is a pointer to an ICD object.
******************************************************************************/
cl_int Kernel::setArg(cl_uint index, size_t size, const void *value)
{
@@ -345,18 +350,21 @@ cl_int Kernel::setArg(cl_uint index, size_t size, const void *value)
/*-------------------------------------------------------------------------
* Special case for samplers (pointers in C++, uint32 in OpenCL).
*------------------------------------------------------------------------*/
- if (size == sizeof(cl_sampler) && arg_size == 4 &&
- (*(Object **)value)->isA(T_Sampler))
+ if (arg->kind() == Arg::Sampler && size == sizeof(cl_sampler) && arg_size == 4)
{
- unsigned int bitfield = (*(Sampler **)value)->bitfield();
+ // Test if this is a sampler object:
+ MemObject * val = pobj(*(cl_mem *)value);
+ if (((Object *)val)->isA(T_Sampler))
+ {
+ unsigned int bitfield = ((Sampler *)val)->bitfield();
- arg->refineKind(Arg::Sampler);
- arg->alloc();
- arg->loadData(&bitfield, size);
+ arg->refineKind(Arg::Sampler);
+ arg->alloc();
+ arg->loadData(&bitfield, size);
- return CL_SUCCESS;
+ return CL_SUCCESS;
+ }
}
-
// LLVM IR redefines function parameter types to fit the smallest integer type width for the ABI
// eg: <2xi8> (2 bytes) may actually be pushed as an i32 (4 bytes!), but this knowledge is
// not known to shamrock. But, we do know the parameter type alignment in addFunction().
@@ -364,24 +372,30 @@ cl_int Kernel::setArg(cl_uint index, size_t size, const void *value)
if ((size != arg_size) && (size > arg->targetAlignment())) return CL_INVALID_ARG_SIZE;
/*-------------------------------------------------------------------------
- * Check for null values
+ * Downcast 'void *value' from a potential &cl_mem argument to a MemObject
+ * if arg type is one of Arg::Buffer, Arg::Image2D, or Arg::Image3D.
+ * Also, check for null values.
*------------------------------------------------------------------------*/
- cl_mem null_mem = 0;
+ MemObject *mem_value = NULL;
- if (!value)
+ switch (arg->kind())
{
- switch (arg->kind())
- {
- /*-------------------------------------------------------------
- * Special case buffers : value can be 0 (or point to 0)
- *------------------------------------------------------------*/
- case Arg::Buffer:
- case Arg::Image2D:
- case Arg::Image3D: value = &null_mem;
- default: return CL_INVALID_ARG_VALUE;
- }
+ /*-------------------------------------------------------------
+ * Special case buffers : value can be 0 (or point to 0)
+ *------------------------------------------------------------*/
+ case Arg::Buffer:
+ case Arg::Image2D:
+ case Arg::Image3D:
+ if (value) {
+ mem_value = pobj(*(cl_mem *)value);
+ }
+ value = &mem_value;
+ break;
+ default:
+ if (!value) return CL_INVALID_ARG_VALUE;
}
+
/*-------------------------------------------------------------------------
* Copy just the data actually passed. Expect LLVM to do the signext/zeroext.
*------------------------------------------------------------------------*/
diff --git a/src/core/memobject.cpp b/src/core/memobject.cpp
index c72c3c9..81e6fb3 100644
--- a/src/core/memobject.cpp
+++ b/src/core/memobject.cpp
@@ -115,7 +115,7 @@ MemObject::~MemObject()
{
dtor_callback_t callback;
if (p_dtor_callback_stack.pop(callback))
- callback.first((cl_mem)this, callback.second);
+ callback.first(desc(this), callback.second);
}
if (p_devicebuffers)
@@ -378,14 +378,14 @@ cl_int MemObject::info(cl_mem_info param_name,
if (type() != SubBuffer)
SIMPLE_ASSIGN(cl_mem, 0)
else
- SIMPLE_ASSIGN(cl_mem, subbuf->parent());
+ SIMPLE_ASSIGN(cl_mem, desc(subbuf->parent()));
break;
case CL_MEM_OFFSET:
if (type() != SubBuffer)
- SIMPLE_ASSIGN(cl_mem, 0)
+ SIMPLE_ASSIGN(size_t, 0)
else
- SIMPLE_ASSIGN(cl_mem, subbuf->offset());
+ SIMPLE_ASSIGN(size_t, subbuf->offset());
break;
default:
@@ -500,7 +500,7 @@ SubBuffer::SubBuffer(class Buffer *parent, size_t offset, size_t size,
: MemObject((Context *)parent->parent(), flags, 0, errcode_ret), p_offset(offset),
p_size(size), p_parent(parent)
{
- clRetainMemObject((cl_mem) p_parent);
+ clRetainMemObject(desc(p_parent));
if (size == 0)
{
diff --git a/src/core/memobject.h b/src/core/memobject.h
index ede6050..55f2fe3 100644
--- a/src/core/memobject.h
+++ b/src/core/memobject.h
@@ -35,12 +35,20 @@
#define __MEMOBJECT_H__
#include "object.h"
+#include "icd.h"
#include "dsp/u_concurrent_stack.h"
#include <CL/cl.h>
namespace Coal
{
+ class MemObject;
+}
+struct _cl_mem: public Coal::descriptor<Coal::MemObject, _cl_mem> {};
+
+
+namespace Coal
+{
class DeviceBuffer;
class Context;
@@ -50,7 +58,7 @@ class BufferEvent;
/**
* \brief Base class for all the memory objects
*/
-class MemObject : public Object
+class MemObject : public _cl_mem, public Object
{
public:
/**
@@ -298,7 +306,4 @@ class Image3D : public Image2D
}
-struct _cl_mem : public Coal::MemObject
-{};
-
#endif