aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGil Pitney <gil.pitney@linaro.org>2015-09-30 21:19:34 +0000
committerGil Pitney <gil.pitney@linaro.org>2015-09-30 21:19:34 +0000
commit5037fc5b9a8aea560db9d287fa96a413609359b7 (patch)
tree8632d59fa34963c346ebcbd1842d73acd799ed47
parente3cecdef8cc6ab0ee616f4e4f5380ce9277c0f4e (diff)
downloadshamrock-5037fc5b9a8aea560db9d287fa96a413609359b7.tar.gz
ICD: Update Context objects to be ICD compatible.
This was validated by running the sanity tests, and the Khronos conformance tests without an ICD loader; then installing the Khronos ICD loader, and running that subset of conformance tests that would just invoke OpenCL Context APIs. Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
-rw-r--r--src/api/api_command.cpp5
-rw-r--r--src/api/api_context.cpp28
-rw-r--r--src/api/api_event.cpp19
-rw-r--r--src/api/api_memory.cpp16
-rw-r--r--src/api/api_program.cpp9
-rw-r--r--src/api/api_sampler.cpp13
-rw-r--r--src/core/commandqueue.cpp6
-rw-r--r--src/core/context.h16
-rw-r--r--src/core/events.cpp13
-rw-r--r--src/core/kernel.cpp3
-rw-r--r--src/core/memobject.cpp2
-rw-r--r--src/core/program.cpp50
-rw-r--r--src/core/sampler.cpp2
13 files changed, 106 insertions, 76 deletions
diff --git a/src/api/api_command.cpp b/src/api/api_command.cpp
index 5486ea4..2400738 100644
--- a/src/api/api_command.cpp
+++ b/src/api/api_command.cpp
@@ -38,13 +38,14 @@
// Command Queue APIs
cl_command_queue
-clCreateCommandQueue(cl_context context,
+clCreateCommandQueue(cl_context d_context,
cl_device_id d_device,
cl_command_queue_properties properties,
cl_int * errcode_ret)
{
cl_int default_errcode_ret;
auto device = pobj(d_device);
+ auto context = pobj(d_context);
// No errcode_ret ?
if (!errcode_ret)
@@ -64,7 +65,7 @@ clCreateCommandQueue(cl_context context,
*errcode_ret = CL_SUCCESS;
Coal::CommandQueue *queue = new Coal::CommandQueue(
- (Coal::Context *)context,
+ context,
device,
properties,
errcode_ret);
diff --git a/src/api/api_context.cpp b/src/api/api_context.cpp
index abe7be6..20b0d84 100644
--- a/src/api/api_context.cpp
+++ b/src/api/api_context.cpp
@@ -37,6 +37,8 @@
#include <core/platform.h>
#include <stdlib.h>
+using namespace Coal;
+
// Context APIs
cl_context
@@ -62,7 +64,7 @@ clCreateContext(const cl_context_properties *properties,
}
*errcode_ret = CL_SUCCESS;
- Coal::Context *ctx = new Coal::Context(properties, num_devices, devices,
+ Context *ctx = new Context(properties, num_devices, devices,
pfn_notify, user_data, errcode_ret);
if (*errcode_ret != CL_SUCCESS)
@@ -72,7 +74,7 @@ clCreateContext(const cl_context_properties *properties,
return 0;
}
- return (_cl_context *)ctx;
+ return desc(ctx);
}
cl_context
@@ -84,10 +86,10 @@ clCreateContextFromType(const cl_context_properties *properties,
{
cl_device_id* devices;
cl_uint num_devices;
- cl_int local_error;
- cl_context result = NULL;
+ cl_int local_error;
+ cl_context result = 0;
- local_error = clGetDeviceIDs(&the_platform, device_type, 0, NULL,
+ local_error = clGetDeviceIDs(&the_platform, device_type, 0, NULL,
&num_devices);
if (!num_devices) { local_error = CL_INVALID_DEVICE; goto bail; }
@@ -105,15 +107,17 @@ clCreateContextFromType(const cl_context_properties *properties,
free (devices);
bail:
- if (errcode_ret)
- *errcode_ret = local_error;
+ if (errcode_ret)
+ *errcode_ret = local_error;
return result;
}
cl_int
-clRetainContext(cl_context context)
+clRetainContext(cl_context d_context)
{
+ auto context = pobj(d_context);
+
if (!context->isA(Coal::Object::T_Context))
return CL_INVALID_CONTEXT;
@@ -123,8 +127,10 @@ clRetainContext(cl_context context)
}
cl_int
-clReleaseContext(cl_context context)
+clReleaseContext(cl_context d_context)
{
+ auto context = pobj(d_context);
+
if (!context->isA(Coal::Object::T_Context))
return CL_INVALID_CONTEXT;
@@ -135,12 +141,14 @@ clReleaseContext(cl_context context)
}
cl_int
-clGetContextInfo(cl_context context,
+clGetContextInfo(cl_context d_context,
cl_context_info param_name,
size_t param_value_size,
void * param_value,
size_t * param_value_size_ret)
{
+ auto context = pobj(d_context);
+
if (!context->isA(Coal::Object::T_Context))
return CL_INVALID_CONTEXT;
diff --git a/src/api/api_event.cpp b/src/api/api_event.cpp
index d76f6bb..8f052e3 100644
--- a/src/api/api_event.cpp
+++ b/src/api/api_event.cpp
@@ -37,6 +37,8 @@
#include <core/context.h>
#include <stdio.h>
+using namespace Coal;
+
// Event Object APIs
cl_int
clWaitForEvents(cl_uint num_events,
@@ -46,7 +48,7 @@ clWaitForEvents(cl_uint num_events,
return CL_INVALID_VALUE;
// Check the events in the list to ensure thay have same context
- cl_context global_ctx = 0;
+ Context * global_ctx = NULL;
for (cl_uint i=0; i<num_events; ++i)
{
@@ -56,12 +58,12 @@ clWaitForEvents(cl_uint num_events,
if (event_list[i]->status() < 0)
return CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST;
- cl_context evt_ctx;
+ Context * evt_ctx;
if (event_list[i]->type() == Coal::Event::User) {
- evt_ctx = (cl_context)((Coal::UserEvent *)event_list[i])->context();
+ evt_ctx = ((Coal::UserEvent *)event_list[i])->context();
}
else {
- evt_ctx = (cl_context)event_list[i]->parent()->parent();
+ evt_ctx = (Context *)(event_list[i]->parent()->parent());
}
#if 0 // YUAN: no need to wait for queue to be flushed
@@ -70,7 +72,7 @@ clWaitForEvents(cl_uint num_events,
evt_queue->flush();
#endif
- if (global_ctx == 0)
+ if (global_ctx == NULL)
global_ctx = evt_ctx;
else if (global_ctx != evt_ctx)
return CL_INVALID_CONTEXT;
@@ -148,10 +150,11 @@ clReleaseEvent(cl_event event)
}
cl_event
-clCreateUserEvent(cl_context context,
+clCreateUserEvent(cl_context d_context,
cl_int * errcode_ret)
{
cl_int dummy_errcode;
+ auto context = pobj(d_context);
if (!errcode_ret)
errcode_ret = &dummy_errcode;
@@ -164,9 +167,7 @@ clCreateUserEvent(cl_context context,
*errcode_ret = CL_SUCCESS;
- Coal::UserEvent *command = new Coal::UserEvent(
- (Coal::Context *)context, errcode_ret
- );
+ Coal::UserEvent *command = new Coal::UserEvent(context, errcode_ret);
if (*errcode_ret != CL_SUCCESS)
{
diff --git a/src/api/api_memory.cpp b/src/api/api_memory.cpp
index b9c7145..00eb4d4 100644
--- a/src/api/api_memory.cpp
+++ b/src/api/api_memory.cpp
@@ -38,13 +38,14 @@
// Memory Object APIs
cl_mem
-clCreateBuffer(cl_context context,
+clCreateBuffer(cl_context d_context,
cl_mem_flags flags,
size_t size,
void * host_ptr,
cl_int * errcode_ret)
{
cl_int dummy_errcode;
+ auto context = pobj(d_context);
if (!errcode_ret)
errcode_ret = &dummy_errcode;
@@ -125,7 +126,7 @@ clCreateSubBuffer(cl_mem buffer,
}
cl_mem
-clCreateImage(cl_context context,
+clCreateImage(cl_context d_context,
cl_mem_flags flags,
const cl_image_format * image_format,
const cl_image_desc * image_desc,
@@ -134,6 +135,7 @@ clCreateImage(cl_context context,
{
cl_int dummy_errcode;
cl_mem image;
+ auto context = pobj(d_context);
if (!errcode_ret)
errcode_ret = &dummy_errcode;
@@ -163,7 +165,7 @@ clCreateImage(cl_context context,
cl_mem
-clCreateImage2D(cl_context context,
+clCreateImage2D(cl_context d_context,
cl_mem_flags flags,
const cl_image_format * image_format,
size_t image_width,
@@ -173,6 +175,7 @@ clCreateImage2D(cl_context context,
cl_int * errcode_ret)
{
cl_int dummy_errcode;
+ auto context = pobj(d_context);
if (!errcode_ret)
errcode_ret = &dummy_errcode;
@@ -199,7 +202,7 @@ clCreateImage2D(cl_context context,
}
cl_mem
-clCreateImage3D(cl_context context,
+clCreateImage3D(cl_context d_context,
cl_mem_flags flags,
const cl_image_format * image_format,
size_t image_width,
@@ -211,6 +214,7 @@ clCreateImage3D(cl_context context,
cl_int * errcode_ret)
{
cl_int dummy_errcode;
+ auto context = pobj(d_context);
if (!errcode_ret)
errcode_ret = &dummy_errcode;
@@ -379,13 +383,15 @@ static cl_image_format supported_formats[] = {
#define MIN(a, b) ((a) < (b) ? (a) : (b))
cl_int
-clGetSupportedImageFormats(cl_context context,
+clGetSupportedImageFormats(cl_context d_context,
cl_mem_flags flags,
cl_mem_object_type image_type,
cl_uint num_entries,
cl_image_format * image_formats,
cl_uint * num_image_formats)
{
+ auto context = pobj(d_context);
+
if (!context->isA(Coal::Object::T_Context))
return CL_INVALID_CONTEXT;
diff --git a/src/api/api_program.cpp b/src/api/api_program.cpp
index 8adcde7..49df322 100644
--- a/src/api/api_program.cpp
+++ b/src/api/api_program.cpp
@@ -40,13 +40,14 @@
// Program Object APIs
cl_program
-clCreateProgramWithSource(cl_context context,
+clCreateProgramWithSource(cl_context d_context,
cl_uint count,
const char ** strings,
const size_t * lengths,
cl_int * errcode_ret)
{
cl_int dummy_errcode;
+ auto context = pobj(d_context);
if (!errcode_ret)
errcode_ret = &dummy_errcode;
@@ -78,7 +79,7 @@ clCreateProgramWithSource(cl_context context,
}
cl_program
-clCreateProgramWithBinary(cl_context context,
+clCreateProgramWithBinary(cl_context d_context,
cl_uint num_devices,
const cl_device_id * device_list,
const size_t * lengths,
@@ -87,6 +88,7 @@ clCreateProgramWithBinary(cl_context context,
cl_int * errcode_ret)
{
cl_int dummy_errcode;
+ auto context = pobj(d_context);
if (!errcode_ret)
errcode_ret = &dummy_errcode;
@@ -355,7 +357,7 @@ clCompileProgram(cl_program program,
}
cl_program
-clLinkProgram(cl_context context,
+clLinkProgram(cl_context d_context,
cl_uint num_devices,
const cl_device_id * device_list,
const char * options,
@@ -366,6 +368,7 @@ clLinkProgram(cl_context context,
cl_int * errcode_ret)
{
cl_int retcode = CL_SUCCESS;
+ auto context = pobj(d_context);
if (!num_input_programs || ((num_input_programs > 0) && !input_programs))
retcode = CL_INVALID_VALUE;
diff --git a/src/api/api_sampler.cpp b/src/api/api_sampler.cpp
index 9bd2dec..6bee50e 100644
--- a/src/api/api_sampler.cpp
+++ b/src/api/api_sampler.cpp
@@ -30,20 +30,23 @@
* \brief Samplers
*/
-#include "CL/cl.h"
+#include <CL/cl.h>
-#include "core/sampler.h"
-#include "core/context.h"
+#include <core/sampler.h>
+#include <core/context.h>
+
+using namespace Coal;
// Sampler APIs
cl_sampler
-clCreateSampler(cl_context context,
+clCreateSampler(cl_context d_context,
cl_bool normalized_coords,
cl_addressing_mode addressing_mode,
cl_filter_mode filter_mode,
cl_int * errcode_ret)
{
cl_int dummy_errcode;
+ auto context = pobj(d_context);
if (!errcode_ret)
errcode_ret = &dummy_errcode;
@@ -56,7 +59,7 @@ clCreateSampler(cl_context context,
*errcode_ret = CL_SUCCESS;
- Coal::Sampler *sampler = new Coal::Sampler((Coal::Context *)context,
+ Coal::Sampler *sampler = new Coal::Sampler(context,
normalized_coords,
addressing_mode,
filter_mode,
diff --git a/src/core/commandqueue.cpp b/src/core/commandqueue.cpp
index ab1d677..504b61c 100644
--- a/src/core/commandqueue.cpp
+++ b/src/core/commandqueue.cpp
@@ -108,7 +108,7 @@ cl_int CommandQueue::info(cl_command_queue_info param_name,
switch (param_name)
{
case CL_QUEUE_CONTEXT:
- SIMPLE_ASSIGN(cl_context, parent());
+ SIMPLE_ASSIGN(cl_context, desc((Context *)parent()));
break;
case CL_QUEUE_DEVICE:
@@ -928,12 +928,12 @@ cl_int Event::info(cl_event_info param_name,
case CL_EVENT_CONTEXT:
if (parent())
{
- SIMPLE_ASSIGN(cl_context, parent()->parent());
+ SIMPLE_ASSIGN(cl_context, desc((Context *)(parent()->parent())));
}
else
{
if (type() == User)
- SIMPLE_ASSIGN(cl_context, ((UserEvent *)this)->context())
+ SIMPLE_ASSIGN(cl_context, desc((Context *)(((UserEvent *)this)->context())))
else
SIMPLE_ASSIGN(cl_context, 0);
}
diff --git a/src/core/context.h b/src/core/context.h
index f4427a4..d0ccfb8 100644
--- a/src/core/context.h
+++ b/src/core/context.h
@@ -34,20 +34,29 @@
#define __CONTEXT_H__
#include "object.h"
+#include "icd.h"
#include <CL/cl.h>
namespace Coal
{
+ class Context;
+}
+struct _cl_context: public Coal::descriptor<Coal::Context, _cl_context> {};
+
+namespace Coal
+{
class DeviceInterface;
/**
* \brief OpenCL context
*
- * This class is the root of all OpenCL objects, except \c Coal::DeviceInterface.
+ * This class represents a context for managing objects such as command-queues, memory,
+ * program and kernel objects and for executing kernels on one or more devices specified
+ * in the context.
*/
-class Context : public Object
+class Context : public _cl_context, public Object
{
public:
/**
@@ -99,7 +108,4 @@ class Context : public Object
}
-struct _cl_context : public Coal::Context
-{};
-
#endif
diff --git a/src/core/events.cpp b/src/core/events.cpp
index add60d6..a968124 100644
--- a/src/core/events.cpp
+++ b/src/core/events.cpp
@@ -36,6 +36,7 @@
#include "memobject.h"
#include "kernel.h"
#include "deviceinterface.h"
+#include "context.h"
#include <cstdlib>
#include <cstring>
@@ -67,12 +68,12 @@ BufferEvent::BufferEvent(CommandQueue *parent,
}
// Buffer's context must match the CommandQueue one
- Context *ctx = 0;
- *errcode_ret = parent->info(CL_QUEUE_CONTEXT, sizeof(Context *), &ctx, 0);
+ cl_context d_ctx = 0;
+ *errcode_ret = parent->info(CL_QUEUE_CONTEXT, sizeof(cl_context), &d_ctx, 0);
if (*errcode_ret != CL_SUCCESS) return;
- if ((Context *)buffer->parent() != ctx)
+ if ((Context *)buffer->parent() != pobj(d_ctx))
{
*errcode_ret = CL_INVALID_CONTEXT;
return;
@@ -745,7 +746,7 @@ KernelEvent::KernelEvent(CommandQueue *parent,
// Check that the kernel was built for parent's device.
cl_device_id d_device = 0;
- Context *k_ctx, *q_ctx;
+ cl_context k_ctx, q_ctx;
size_t max_work_group_size;
cl_uint max_dims = 0;
@@ -755,8 +756,8 @@ KernelEvent::KernelEvent(CommandQueue *parent,
return;
auto device = pobj(d_device);
- *errcode_ret = parent->info(CL_QUEUE_CONTEXT, sizeof(Context *), &q_ctx, 0);
- *errcode_ret |= kernel->info(CL_KERNEL_CONTEXT, sizeof(Context *), &k_ctx, 0);
+ *errcode_ret = parent->info(CL_QUEUE_CONTEXT, sizeof(cl_context), &q_ctx, 0);
+ *errcode_ret |= kernel->info(CL_KERNEL_CONTEXT, sizeof(cl_context), &k_ctx, 0);
*errcode_ret |= device->info(CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(size_t),
&max_work_group_size, 0);
*errcode_ret |= device->info(CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, sizeof(size_t),
diff --git a/src/core/kernel.cpp b/src/core/kernel.cpp
index 05b276e..073d726 100644
--- a/src/core/kernel.cpp
+++ b/src/core/kernel.cpp
@@ -36,6 +36,7 @@
#include "program.h"
#include "memobject.h"
#include "sampler.h"
+#include "context.h"
#include "deviceinterface.h"
#include <string>
@@ -455,7 +456,7 @@ cl_int Kernel::info(cl_kernel_info param_name,
break;
case CL_KERNEL_CONTEXT:
- SIMPLE_ASSIGN(cl_context, parent()->parent());
+ SIMPLE_ASSIGN(cl_context, desc((Context *)(parent()->parent())));
break;
case CL_KERNEL_PROGRAM:
diff --git a/src/core/memobject.cpp b/src/core/memobject.cpp
index 1d88fd0..c72c3c9 100644
--- a/src/core/memobject.cpp
+++ b/src/core/memobject.cpp
@@ -371,7 +371,7 @@ cl_int MemObject::info(cl_mem_info param_name,
break;
case CL_MEM_CONTEXT:
- SIMPLE_ASSIGN(cl_context, parent());
+ SIMPLE_ASSIGN(cl_context, desc((Context *)parent()));
break;
case CL_MEM_ASSOCIATED_MEMOBJECT:
diff --git a/src/core/program.cpp b/src/core/program.cpp
index ddece95..30f5637 100644
--- a/src/core/program.cpp
+++ b/src/core/program.cpp
@@ -945,37 +945,37 @@ cl_int Program::info(cl_program_info param_name,
break;
case CL_PROGRAM_NUM_DEVICES:
- // Use devices associated with any built kernels, otherwise use
+ // Use devices associated with any built kernels, otherwise use
// the devices associated with the program context
- if (p_device_dependent.size() != 0)
- { SIMPLE_ASSIGN(cl_uint, p_device_dependent.size()); }
- else
- return ((Context *)parent())->info(CL_CONTEXT_NUM_DEVICES,
- param_value_size, param_value, param_value_size_ret);
- break;
+ if (p_device_dependent.size() != 0)
+ { SIMPLE_ASSIGN(cl_uint, p_device_dependent.size()); }
+ else
+ return ((Context *)parent())->info(CL_CONTEXT_NUM_DEVICES,
+ param_value_size, param_value, param_value_size_ret);
+ break;
case CL_PROGRAM_DEVICES:
- // Use devices associated with any built kernels, otherwise use
+ // Use devices associated with any built kernels, otherwise use
// the devices associated with the program context
- if (p_device_dependent.size() != 0)
- {
- for (size_t i=0; i<p_device_dependent.size(); ++i)
- {
- const DeviceDependent &dep = p_device_dependent[i];
-
- devices.push_back(desc(dep.device));
- }
-
- value = devices.data();
- value_length = devices.size() * sizeof(cl_device_id);
- }
- else
- return ((Context *)parent())->info(CL_CONTEXT_DEVICES,
- param_value_size, param_value, param_value_size_ret);
- break;
+ if (p_device_dependent.size() != 0)
+ {
+ for (size_t i=0; i<p_device_dependent.size(); ++i)
+ {
+ const DeviceDependent &dep = p_device_dependent[i];
+
+ devices.push_back(desc(dep.device));
+ }
+
+ value = devices.data();
+ value_length = devices.size() * sizeof(cl_device_id);
+ }
+ else
+ return ((Context *)parent())->info(CL_CONTEXT_DEVICES,
+ param_value_size, param_value, param_value_size_ret);
+ break;
case CL_PROGRAM_CONTEXT:
- SIMPLE_ASSIGN(cl_context, parent());
+ SIMPLE_ASSIGN(cl_context, desc((Context *)parent()));
break;
case CL_PROGRAM_SOURCE:
diff --git a/src/core/sampler.cpp b/src/core/sampler.cpp
index 1201327..fa19f0c 100644
--- a/src/core/sampler.cpp
+++ b/src/core/sampler.cpp
@@ -187,7 +187,7 @@ cl_int Sampler::info(cl_sampler_info param_name,
break;
case CL_SAMPLER_CONTEXT:
- SIMPLE_ASSIGN(cl_context, parent());
+ SIMPLE_ASSIGN(cl_context, desc((Context *)parent()));
break;
case CL_SAMPLER_NORMALIZED_COORDS: