[Beignet] [PATCH] Add device API struct to define device behavior

junyan.he at inbox.com junyan.he at inbox.com
Thu Mar 2 09:50:27 UTC 2017


From: Junyan He <junyan.he at intel.com>

Each device has its own behavior according to CL APIs.
For example, when call clNDrangeKernel, the actions
of GEN devices should be different from other kind of
devices. After we handle all the common logic in
clNDrangeKernel API, we need to call device->ndrange_kernel()
to do the real work for GEN device.

Signed-off-by: Junyan He <junyan.he at intel.com>
---
 src/cl_device_api.h | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/cl_device_id.h  |  6 ++++
 2 files changed, 86 insertions(+)
 create mode 100644 src/cl_device_api.h

diff --git a/src/cl_device_api.h b/src/cl_device_api.h
new file mode 100644
index 0000000..31ed44c
--- /dev/null
+++ b/src/cl_device_api.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: He Junyan <junyan.he at intel.com>
+ */
+
+#ifndef __CL_DEVICE_API_H__
+#define __CL_DEVICE_API_H__
+
+#include "CL/cl.h"
+
+#define DEV_PRIVATE_DATA(PARENT, DEV, PRIV)                             \
+  do {                                                                  \
+    PRIV = NULL;                                                        \
+    assert(PARENT->each_device_num > 0);                                \
+    for (cl_uint eedev = 0; eedev < PARENT->each_device_num; eedev++) { \
+      if (DEV == (PARENT->each_device[eedev])->device) {                \
+        PRIV = (void *)PARENT->each_device[eedev];                      \
+        break;                                                          \
+      }                                                                 \
+    }                                                                   \
+    assert(PRIV != NULL);                                               \
+  } while (0);
+
+typedef struct _cl_device_api {
+  cl_int (*compiler_unload)(cl_device_id device);
+
+  void *(*context_new)(cl_device_id device, cl_context ctx);
+  cl_int (*context_create)(cl_device_id device, cl_context ctx);
+  void (*context_delete)(cl_device_id device, cl_context ctx);
+
+  void *(*program_new)(cl_device_id device, cl_program p);
+  cl_int (*program_load_binary)(cl_device_id device, cl_program prog);
+  void (*program_delete)(cl_device_id device, cl_program p);
+  cl_int (*get_program_info)(cl_device_id device, cl_program program,
+                             cl_uint param_name, void *param_value);
+
+  void *(*kernel_new)(cl_device_id device, cl_kernel kernel);
+  void (*kernel_delete)(cl_device_id device, cl_kernel kernel);
+  cl_int (*kernel_create)(cl_device_id device, cl_kernel kernel);
+  cl_int (*get_kernel_info)(cl_device_id device, cl_kernel kernel,
+                            cl_uint param_name, void *param_value);
+
+  cl_int (*ND_range_kernel)(cl_command_queue queue, cl_kernel ker,
+                            cl_event event, const uint32_t work_dim,
+                            const size_t *global_wk_off, const size_t *global_wk_sz,
+                            const size_t *local_wk_sz);
+  cl_int (*mem_copy)(cl_command_queue queue, cl_event event, cl_mem src, cl_mem dst,
+                     size_t src_offset, size_t dst_offset, size_t cb);
+  cl_int (*mem_fill)(cl_command_queue queue, cl_event event, const void *pattern,
+                     size_t pattern_size, cl_mem buffer, size_t offset, size_t size);
+  cl_int (*mem_copy_rect)(cl_command_queue queue, cl_event event, cl_mem src_buf,
+                          cl_mem dst_buf, 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_int (*image_fill)(cl_command_queue queue, cl_event e, const void *pattern, cl_mem src_image,
+                       const size_t *origin, const size_t *region);
+  cl_int (*image_copy)(cl_command_queue queue, cl_event event, cl_mem src_image, cl_mem dst_image,
+                       const size_t *src_origin, const size_t *dst_origin, const size_t *region);
+  cl_int (*copy_image_to_buffer)(cl_command_queue queue, cl_event event, cl_mem image, cl_mem buffer,
+                                 const size_t *src_origin, const size_t dst_offset, const size_t *region);
+  cl_int (*copy_buffer_to_image)(cl_command_queue queue, cl_event event, cl_mem buffer, cl_mem image,
+                                 const size_t src_offset, const size_t *dst_origin, const size_t *region);
+} _cl_device_api;
+typedef _cl_device_api *cl_device_api;
+
+#endif /* End of __CL_DEVICE_API_H__ */
diff --git a/src/cl_device_id.h b/src/cl_device_id.h
index 6b8f2eb..b3136e7 100644
--- a/src/cl_device_id.h
+++ b/src/cl_device_id.h
@@ -23,6 +23,9 @@
 #define EXTENSTION_LENGTH 512
 
 #include "cl_base_object.h"
+#include "cl_compiler.h"
+#include "cl_device_api.h"
+
 /* Store complete information about the device */
 struct _cl_device_id {
   _cl_base_object base;
@@ -137,6 +140,9 @@ struct _cl_device_id {
   cl_uint image_pitch_alignment;
   cl_uint image_base_address_alignment;
 
+  _cl_device_api api;
+  _cl_compiler compiler;
+
   //inited as NULL, created only when cmrt kernel is used
   void* cmrt_device;  //realtype: CmDevice*
 };
-- 
2.7.4



More information about the Beignet mailing list