[Beignet] [PATCH 11/11] Runtime: Apply base object to cl_accelerator_intel

junyan.he at inbox.com junyan.he at inbox.com
Tue Jul 19 11:25:57 UTC 2016


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

Signed-off-by: Junyan He <junyan.he at intel.com>
---
 src/cl_accelerator_intel.c |    9 ++++-----
 src/cl_accelerator_intel.h |   11 +++++++----
 src/cl_api.c               |    3 ++-
 src/cl_utils.h             |    2 +-
 4 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/src/cl_accelerator_intel.c b/src/cl_accelerator_intel.c
index cda8963..545a613 100644
--- a/src/cl_accelerator_intel.c
+++ b/src/cl_accelerator_intel.c
@@ -19,9 +19,7 @@ cl_accelerator_intel_new(cl_context ctx,
 
   /* Allocate and inialize the structure itself */
   TRY_ALLOC(accel, CALLOC(struct _cl_accelerator_intel));
-  SET_ICD(accel->dispatch)
-  accel->ref_n = 1;
-  accel->magic = CL_MAGIC_ACCELERATOR_INTEL_HEADER;
+  CL_OBJECT_INIT_BASE(accel, CL_OBJECT_ACCELERATOR_INTEL_MAGIC);
 
   if (accel_type != CL_ACCELERATOR_TYPE_MOTION_ESTIMATION_INTEL) {
     err = CL_INVALID_ACCELERATOR_TYPE_INTEL;
@@ -60,7 +58,7 @@ error:
 LOCAL void
 cl_accelerator_intel_add_ref(cl_accelerator_intel accel)
 {
-  atomic_inc(&accel->ref_n);
+  CL_OBJECT_INC_REF(accel);
 }
 
 LOCAL void
@@ -68,7 +66,7 @@ cl_accelerator_intel_delete(cl_accelerator_intel accel)
 {
   if (UNLIKELY(accel == NULL))
     return;
-  if (atomic_dec(&accel->ref_n) > 1)
+  if (CL_OBJECT_DEC_REF(accel) > 1)
     return;
 
   /* Remove the accelerator_intel in the context accelerator_intel list */
@@ -82,5 +80,6 @@ cl_accelerator_intel_delete(cl_accelerator_intel accel)
   pthread_mutex_unlock(&accel->ctx->accelerator_intel_lock);
 
   cl_context_delete(accel->ctx);
+  CL_OBJECT_DESTROY_BASE(accel);
   cl_free(accel);
 }
diff --git a/src/cl_accelerator_intel.h b/src/cl_accelerator_intel.h
index cecfd2a..435ae73 100644
--- a/src/cl_accelerator_intel.h
+++ b/src/cl_accelerator_intel.h
@@ -1,22 +1,25 @@
 #ifndef __CL_ACCELERATOR_INTEL_H__
 #define __CL_ACCELERATOR_INTEL_H__
 
+#include "cl_base_object.h"
 #include "CL/cl.h"
 #include "CL/cl_ext.h"
 #include <stdint.h>
 
 struct _cl_accelerator_intel {
-  DEFINE_ICD(dispatch)
-  uint64_t magic;            /* To identify it as a accelerator_intel object */
-  volatile int ref_n;        /* This object is reference counted */
+  _cl_base_object base;
   cl_accelerator_intel prev, next;     /* We chain in the allocator, why chain? */
   cl_context ctx;            /* Context it belongs to */
   cl_accelerator_type_intel type;
   union {
     cl_motion_estimation_desc_intel me;
-  }desc;                     /* save desc before we decide how to handle it */
+  } desc;                     /* save desc before we decide how to handle it */
 };
 
+#define CL_OBJECT_ACCELERATOR_INTEL_MAGIC 0x7e6a08c9a7ac3e3fLL
+#define CL_OBJECT_IS_ACCELERATOR_INTEL(obj) \
+    (((cl_base_object)obj)->magic == CL_OBJECT_ACCELERATOR_INTEL_MAGIC)
+
 cl_accelerator_intel cl_accelerator_intel_new(cl_context ctx,
                          cl_accelerator_type_intel accel_type,
                          size_t desc_sz,
diff --git a/src/cl_api.c b/src/cl_api.c
index 9a52ed3..cdf2fbe 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -3558,7 +3558,8 @@ clGetAcceleratorInfoINTEL(cl_accelerator_intel           accel,
   CHECK_ACCELERATOR_INTEL(accel);
 
   if (param_name == CL_ACCELERATOR_REFERENCE_COUNT_INTEL) {
-    FILL_GETINFO_RET (cl_uint, 1, (cl_uint*)&accel->ref_n, CL_SUCCESS);
+    cl_uint ref = CL_OBJECT_GET_REF(accel);
+    FILL_GETINFO_RET (cl_uint, 1, &ref, CL_SUCCESS);
   } else if (param_name == CL_ACCELERATOR_CONTEXT_INTEL) {
     FILL_GETINFO_RET (cl_context, 1, &accel->ctx, CL_SUCCESS);
   } else if (param_name == CL_ACCELERATOR_TYPE_INTEL) {
diff --git a/src/cl_utils.h b/src/cl_utils.h
index d779955..77b9bd8 100644
--- a/src/cl_utils.h
+++ b/src/cl_utils.h
@@ -239,7 +239,7 @@ do {
     err = CL_INVALID_ACCELERATOR_INTEL;                                         \
     goto error;                                                                 \
   }                                                                             \
-  if (UNLIKELY(ACCELERATOR_INTEL->magic != CL_MAGIC_ACCELERATOR_INTEL_HEADER)) {\
+  if (UNLIKELY(!CL_OBJECT_IS_ACCELERATOR_INTEL(ACCELERATOR_INTEL))) {          \
     err = CL_INVALID_ACCELERATOR_INTEL;                                         \
     goto error;                                                                 \
   }                                                                             \
-- 
1.7.9.5

____________________________________________________________
Can't remember your password? Do you need a strong and secure password?
Use Password manager! It stores your passwords & protects your account.
Check it out at http://mysecurelogon.com/manager




More information about the Beignet mailing list