aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGil Pitney <gil.pitney@linaro.org>2015-09-29 21:41:17 +0000
committerGil Pitney <gil.pitney@linaro.org>2015-09-29 21:41:17 +0000
commite38928f57633b960c4d54c3678df487d964d9c7d (patch)
tree6b50ca2b45163dfcfe120a2dccd7291bdb085432
parent5fe461416ab30b6af50a24d638b30b5a8924ffac (diff)
downloadshamrock-e38928f57633b960c4d54c3678df487d964d9c7d.tar.gz
ICD: Update Dispatch table and add OpenCL object type conversion templates
Update the dispatch table to match the OCL 1.2 disptach table of the file ICD loader, which is available from the Khronos website: www.khronos.org/registry/cl/specs/opencl-icd-1.2.11.0 Also, define templates to enable conversion between Coal namespace internal C++ objects and OpenCL C API objects, containing the dispatch table pointer as the first pointer field, as expected by the Khronos ICD loader. This template design is based on the solution employed by Francisco Jerez in the clover state tracker of Mesa: http://cgit.freedesktop.org/mesa/mesa/tree/src/gallium/state_trackers/clover/core/object.hpp with some simplifications. For example, validation is done in shamrock using isA() methods, and not in the templates. Also conversion of lists is done simply, using for loops, rather than maps and vectors. Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
-rw-r--r--src/core/icd.cpp11
-rw-r--r--src/core/icd.h82
2 files changed, 87 insertions, 6 deletions
diff --git a/src/core/icd.cpp b/src/core/icd.cpp
index 7378d41..75b3815 100644
--- a/src/core/icd.cpp
+++ b/src/core/icd.cpp
@@ -29,7 +29,10 @@
#include "platform.h"
#include "icd.h"
-// TODO: Ensure this matches OCL 1.2 disptach table:
+// Note: This must match the OCL 1.2 disptach table in the file icd/icd_dispatch.h
+// which is part of the ICD loader source from the Khronos website.
+// Most recently: https://www.khronos.org/registry/cl/specs/opencl-icd-1.2.11.0.tgz
+
void * dispatch_table[] =
{
(void*) clGetPlatformIDs,
@@ -107,12 +110,14 @@ void * dispatch_table[] =
(void*) 0, //clEnqueueAcquireGLObjects,
(void*) 0, //clEnqueueReleaseGLObjects,
(void*) 0, //clGetGLContextInfoKHR,
+
(void*) 0, //clGetDeviceIDsFromD3D10KHR,
(void*) 0, //clCreateFromD3D10BufferKHR,
(void*) 0, //clCreateFromD3D10Texture2DKHR,
(void*) 0, //clCreateFromD3D10Texture3DKHR,
(void*) 0, //clEnqueueAcquireD3D10ObjectsKHR,
(void*) 0, //clEnqueueReleaseD3D10ObjectsKHR,
+
(void*) clSetEventCallback,
(void*) clCreateSubBuffer,
(void*) clSetMemObjectDestructorCallback,
@@ -122,6 +127,10 @@ void * dispatch_table[] =
(void*) clEnqueueWriteBufferRect,
(void*) clEnqueueCopyBufferRect,
+ (void*) 0, //clCreateSubDevicesEXT;
+ (void*) 0, //clRetainDeviceEXT;
+ (void*) 0, //clReleaseDeviceEXT;
+
(void *) 0, //clCreateEventFromGLsyncKHR;
(void *) clCreateSubDevices,
diff --git a/src/core/icd.h b/src/core/icd.h
index 591aed6..b7d00c9 100644
--- a/src/core/icd.h
+++ b/src/core/icd.h
@@ -27,18 +27,90 @@
*****************************************************************************/
#ifndef _ICD_H
#define _ICD_H
+
+#include <iostream>
+#include <cassert>
+
#include "CL/cl.h"
typedef void *(KHRicdVendorDispatch)[];
extern KHRicdVendorDispatch dispatch_table;
-class Dispatch
+namespace Coal
{
- public:
- Dispatch() : dispatch(&dispatch_table) {}
- private:
- KHRicdVendorDispatch *dispatch;
+
+// Templates to define the transformations between internal clover objects
+// and external OpenCL C API objects expected by the ICD loader.
+// This is based on the template system used by the clover state tracker of
+// Mesa, at freedesktop.org
+// See: src/gallium/state_trackers/clover/core/object.hpp
+
+// Proxy template class that represents an OpenCL API object, and is the base
+// class of all clover objects.
+template<typename T, typename S>
+struct descriptor {
+ typedef T object_type;
+ typedef S descriptor_type;
+
+ descriptor() : dispatch(&dispatch_table) {
+ static_assert(std::is_standard_layout<descriptor_type>::value,
+ "ICD requires CL API objects to be standard layout.");
+ }
+
+ const void *dispatch;
};
+// Downcast an API object ptr to a Clover object ptr
+// Note: clover object validation is done by subsequent ->isA methods.
+template<typename D>
+typename D::object_type *
+pobj(D *d) {
+ return static_cast<typename D::object_type *>(d);
+}
+
+
+// Upcast a Clover object ptr to an API object ptr.
+template<typename O>
+typename O::descriptor_type *
+desc(O *o) {
+ return static_cast<typename O::descriptor_type *>(o);
+}
+
+// Convert a list of API objects into Clover objects,
+// copying into a previously allocated list of at least size n.
+template<typename O, typename D>
+void pobj_list(O **objs, D **descs, int n) {
+ for (int i=0;i<n;i++) {
+ objs[i] = pobj(descs[i]);
+ }
+}
+
+// Const overload of above
+template<typename O, typename D>
+void pobj_list(O **objs, D * const *descs, int n) {
+ for (int i=0;i<n;i++) {
+ objs[i] = pobj(descs[i]);
+ }
+}
+
+// Convert a list of Clover objects to a list of API objects,
+// copying into a previously allocated list of at least size n.
+template<typename O, typename D>
+void desc_list(D **descs, O **objs, int n) {
+ for (int i=0;i<n;i++) {
+ descs[i] = desc(objs[i]);
+ }
+}
+
+// Const overload of above
+template<typename O, typename D>
+void desc_list(D **descs, O * const*objs, int n) {
+ for (int i=0;i<n;i++) {
+ descs[i] = desc(objs[i]);
+ }
+}
+
+}
+
#endif // _ICD_H