[Beignet] [PATCH 11/57] Add cl_platform define in runtime.

junyan.he at inbox.com junyan.he at inbox.com
Sun Jun 11 05:49:57 UTC 2017


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

We define intel_platform the default and only one platform id
for runtime. We only support intel platform in beignet.

Signed-off-by: Junyan He <junyan.he at intel.com>
---
 runtime/cl_platform_id.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++
 runtime/cl_platform_id.h |  82 ++++++++++++++++++++++++++++++++++
 2 files changed, 195 insertions(+)
 create mode 100644 runtime/cl_platform_id.c
 create mode 100644 runtime/cl_platform_id.h

diff --git a/runtime/cl_platform_id.c b/runtime/cl_platform_id.c
new file mode 100644
index 0000000..f52b7fa
--- /dev/null
+++ b/runtime/cl_platform_id.c
@@ -0,0 +1,113 @@
+/*
+ * 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: Benjamin Segovia <benjamin.segovia at intel.com>
+ */
+
+#include "cl_platform_id.h"
+#include "cl_alloc.h"
+#include "cl_utils.h"
+#include "CL/cl.h"
+#include "CL/cl_ext.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#define DECL_INFO_STRING(FIELD, STRING) \
+  .FIELD = STRING,                      \
+  .JOIN(FIELD, _sz) = sizeof(STRING),
+
+static struct _cl_platform_id intel_platform_data = {
+  DECL_INFO_STRING(profile, "FULL_PROFILE")
+    DECL_INFO_STRING(version, GEN9_LIBCL_VERSION_STRING)
+      DECL_INFO_STRING(name, "Intel Gen OCL Driver")
+        DECL_INFO_STRING(vendor, "Intel")
+          DECL_INFO_STRING(icd_suffix_khr, "Intel")};
+
+#undef DECL_INFO_STRING
+
+/* Intel platform.
+   It is used as default when the API's platform ptr is NULL */
+static cl_platform_id intel_platform = NULL;
+
+LOCAL cl_platform_id
+cl_get_platform_default(void)
+{
+  if (intel_platform)
+    return intel_platform;
+
+  CL_ALLOC_DEBUG_INIT();
+
+  intel_platform = &intel_platform_data;
+  CL_OBJECT_INIT_BASE(intel_platform, CL_OBJECT_PLATFORM_MAGIC);
+  cl_intel_platform_extension_init(intel_platform);
+  return intel_platform;
+}
+
+LOCAL cl_int
+cl_platform_get_ids(cl_uint num_entries,
+                    cl_platform_id *platforms,
+                    cl_uint *num_platforms)
+{
+  if (num_platforms != NULL)
+    *num_platforms = 1;
+
+  /* Easy right now, only one platform is supported */
+  if (platforms)
+    *platforms = cl_get_platform_default();
+
+  return CL_SUCCESS;
+}
+
+#define EXTFUNC(x)                \
+  if (strcmp(#x, func_name) == 0) \
+    return (void *)x;
+
+LOCAL void *
+cl_platform_get_extension_function_address(const char *func_name)
+{
+  if (func_name == NULL)
+    return NULL;
+
+#ifdef HAS_OCLIcd
+  /* cl_khr_icd */
+  EXTFUNC(clIcdGetPlatformIDsKHR)
+#endif
+  EXTFUNC(clGetKernelSubGroupInfoKHR)
+
+  /*
+  EXTFUNC(clCreateProgramWithLLVMIntel)
+  EXTFUNC(clGetGenVersionIntel)
+  EXTFUNC(clMapBufferIntel)
+  EXTFUNC(clUnmapBufferIntel)
+  EXTFUNC(clMapBufferGTTIntel)
+  EXTFUNC(clUnmapBufferGTTIntel)
+  EXTFUNC(clPinBufferIntel)
+  EXTFUNC(clUnpinBufferIntel)
+  EXTFUNC(clReportUnfreedIntel)
+  EXTFUNC(clCreateBufferFromLibvaIntel)
+  EXTFUNC(clCreateImageFromLibvaIntel)
+  EXTFUNC(clGetMemObjectFdIntel)
+  EXTFUNC(clCreateBufferFromFdINTEL)
+  EXTFUNC(clCreateImageFromFdINTEL)
+  EXTFUNC(clCreateAcceleratorINTEL)
+  EXTFUNC(clRetainAcceleratorINTEL)
+  EXTFUNC(clReleaseAcceleratorINTEL)
+  EXTFUNC(clGetAcceleratorInfoINTEL)
+*/
+
+  return NULL;
+}
diff --git a/runtime/cl_platform_id.h b/runtime/cl_platform_id.h
new file mode 100644
index 0000000..597fbef
--- /dev/null
+++ b/runtime/cl_platform_id.h
@@ -0,0 +1,82 @@
+/*
+ * 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: Benjamin Segovia <benjamin.segovia at intel.com>
+ */
+
+#ifndef __CL_PLATFORM_ID_H__
+#define __CL_PLATFORM_ID_H__
+
+#include "CL/cl.h"
+#include "cl_extensions.h"
+#include "cl_base_object.h"
+#include "git_sha1.h"
+#include "OCLConfig.h"
+
+struct _cl_platform_id {
+  _cl_base_object base;
+  const char *profile;
+  const char *version;
+  const char *name;
+  const char *vendor;
+  char *extensions;
+  const char *icd_suffix_khr;
+  size_t profile_sz;
+  size_t version_sz;
+  size_t name_sz;
+  size_t vendor_sz;
+  size_t extensions_sz;
+  size_t icd_suffix_khr_sz;
+  struct cl_extensions *internal_extensions;
+};
+
+#define CL_OBJECT_PLATFORM_MAGIC 0xaacdbb00123ccd85LL
+#define CL_OBJECT_IS_PLATFORM(obj) ((obj &&                                                      \
+                                     ((cl_base_object)obj)->magic == CL_OBJECT_PLATFORM_MAGIC && \
+                                     CL_OBJECT_GET_REF(obj) >= 1))
+
+/* Return the default platform */
+extern cl_platform_id cl_get_platform_default(void);
+
+/* Return the valid platform */
+extern cl_int cl_platform_get_ids(cl_uint num_entries, cl_platform_id *platforms, cl_uint *num_platforms);
+extern void *cl_platform_get_extension_function_address(const char *func_name);
+
+#define _STR(x) #x
+#define _JOINT(x, y) \
+  _STR(x)            \
+  "." _STR(y)
+#define _JOINT3(x, y, z) \
+  _STR(x)                \
+  "." _STR(y) "." _STR(z)
+
+#ifdef BEIGNET_GIT_SHA1
+#define BEIGNET_GIT_SHA1_STRING " (" BEIGNET_GIT_SHA1 ")"
+#else
+#define BEIGNET_GIT_SHA1_STRING
+#endif
+
+#ifdef LIBCL_DRIVER_VERSION_PATCH
+#define LIBCL_DRIVER_VERSION_STRING _JOINT3(LIBCL_DRIVER_VERSION_MAJOR, LIBCL_DRIVER_VERSION_MINOR, LIBCL_DRIVER_VERSION_PATCH)
+#else
+#define LIBCL_DRIVER_VERSION_STRING _JOINT(LIBCL_DRIVER_VERSION_MAJOR, LIBCL_DRIVER_VERSION_MINOR)
+#endif
+#define GEN9_LIBCL_VERSION_STRING "OpenCL " _JOINT(LIBCL_C_VERSION_MAJOR, LIBCL_C_VERSION_MINOR) " beignet " LIBCL_DRIVER_VERSION_STRING BEIGNET_GIT_SHA1_STRING
+#define GEN9_LIBCL_C_VERSION_STRING "OpenCL C " _JOINT(LIBCL_C_VERSION_MAJOR, LIBCL_C_VERSION_MINOR) " beignet " LIBCL_DRIVER_VERSION_STRING BEIGNET_GIT_SHA1_STRING
+#define NONGEN9_LIBCL_VERSION_STRING "OpenCL 1.2 beignet " LIBCL_DRIVER_VERSION_STRING BEIGNET_GIT_SHA1_STRING
+#define NONGEN9_LIBCL_C_VERSION_STRING "OpenCL C 1.2 beignet " LIBCL_DRIVER_VERSION_STRING BEIGNET_GIT_SHA1_STRING
+
+#endif /* __CL_PLATFORM_ID_H__ */
-- 
2.7.4





More information about the Beignet mailing list