[Beignet] [Patch v2 1/2] runtime: extension size not enough.

xionghu.luo at intel.com xionghu.luo at intel.com
Tue Nov 10 23:35:27 PST 2015


From: Luo Xionghu <xionghu.luo at intel.com>

define a MACRO to hold the value.

v2: use same MACRO in cl_extensions.h; add header file protection for
cl_extension.h.

Signed-off-by: Luo Xionghu <xionghu.luo at intel.com>
---
 src/cl_device_id.h  | 5 ++++-
 src/cl_extensions.c | 2 +-
 src/cl_extensions.h | 6 +++++-
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/cl_device_id.h b/src/cl_device_id.h
index 4a923ef..e971735 100644
--- a/src/cl_device_id.h
+++ b/src/cl_device_id.h
@@ -20,6 +20,9 @@
 #ifndef __CL_DEVICE_ID_H__
 #define __CL_DEVICE_ID_H__
 
+#define EXTENSTION_LENGTH 512
+
+#include "cl_khr_icd.h"
 /* Store complete information about the device */
 struct _cl_device_id {
   DEFINE_ICD(dispatch)
@@ -95,7 +98,7 @@ struct _cl_device_id {
   const char *version;
   const char *profile;
   const char *opencl_c_version;
-  const char extensions[256];
+  const char extensions[EXTENSTION_LENGTH];
   const char *driver_version;
   const char *spir_versions;
   const char *built_in_kernels;
diff --git a/src/cl_extensions.c b/src/cl_extensions.c
index 3e714ac..ede4278 100644
--- a/src/cl_extensions.c
+++ b/src/cl_extensions.c
@@ -140,7 +140,7 @@ cl_intel_platform_enable_extension(cl_device_id device, uint32_t ext)
       memcpy((char*)device->extensions, ext_str, strlen(ext_str));
       device->extensions_sz = strlen(ext_str) + 1;
     } else {
-      assert(device->extensions_sz + 1 + strlen(ext_str) < 256);
+      assert(device->extensions_sz + 1 + strlen(ext_str) < EXTENSTION_LENGTH);
       *(char*)(device->extensions + device->extensions_sz - 1) = ' ';
       memcpy((char*)device->extensions + device->extensions_sz, ext_str, strlen(ext_str));
       device->extensions_sz = device->extensions_sz + strlen(ext_str) + 1;
diff --git a/src/cl_extensions.h b/src/cl_extensions.h
index 0006651..c42d364 100644
--- a/src/cl_extensions.h
+++ b/src/cl_extensions.h
@@ -1,3 +1,5 @@
+#ifndef __CL_EXTENSIONS_H__
+#define __CL_EXTENSIONS_H__
 /* The following approved Khronos extension
  * names must be returned by all device that
  * support OpenCL C 1.2. */
@@ -87,9 +89,10 @@ typedef union {
   #undef DECL_EXT
 } extension_union;
 
+#include "cl_device_id.h"
 typedef struct cl_extensions {
   extension_union extensions[cl_khr_extension_id_max];
-  char ext_str[256];
+  char ext_str[EXTENSTION_LENGTH];
 } cl_extensions_t;
 
 extern void
@@ -98,3 +101,4 @@ extern void
 cl_intel_platform_enable_extension(cl_device_id device, uint32_t name);
 extern void
 cl_intel_platform_get_default_extension(cl_device_id device);
+#endif /* __CL_EXTENSIONS_H__ */
-- 
1.9.1



More information about the Beignet mailing list