[02/11] Runtime: Apply CL base object to program.

Submitted by junyan.he@inbox.com on July 19, 2016, 11:25 a.m.

Details

Message ID 1468927557-5051-2-git-send-email-junyan.he@inbox.com
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in Beignet

Browsing this patch as part of:
"Series without cover letter" rev 1 in Beignet
<< prev patch [2/11] next patch >>

Commit Message

junyan.he@inbox.com July 19, 2016, 11:25 a.m.
From: Junyan He <junyan.he@intel.com>

Signed-off-by: Junyan He <junyan.he@intel.com>
---
 src/cl_api.c     |    2 +-
 src/cl_program.c |   16 +++++++---------
 src/cl_program.h |    8 +++++---
 src/cl_utils.h   |    2 +-
 4 files changed, 14 insertions(+), 14 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/cl_api.c b/src/cl_api.c
index d0d4dc5..4715e40 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -1066,7 +1066,7 @@  clGetProgramInfo(cl_program       program,
   CHECK_PROGRAM (program);
 
   if (param_name == CL_PROGRAM_REFERENCE_COUNT) {
-    cl_uint ref = program->ref_n;
+    cl_uint ref = CL_OBJECT_GET_REF(program);
     FILL_GETINFO_RET (cl_uint, 1, (&ref), CL_SUCCESS);
   } else if (param_name == CL_PROGRAM_CONTEXT) {
     cl_context context = program->ctx;
diff --git a/src/cl_program.c b/src/cl_program.c
index 644856c..7f404bf 100644
--- a/src/cl_program.c
+++ b/src/cl_program.c
@@ -66,7 +66,7 @@  cl_program_delete(cl_program p)
     return;
 
   /* We are not done with it yet */
-  if ((ref = atomic_dec(&p->ref_n)) > 1) return;
+  if ((ref = CL_OBJECT_DEC_REF(p)) > 1) return;
 
   /* Destroy the sources and binary if still allocated */
   cl_program_release_sources(p);
@@ -120,7 +120,7 @@  cl_program_delete(cl_program p)
       interp_program_delete(p->opaque);
   }
 
-  p->magic = CL_MAGIC_DEAD_HEADER; /* For safety */
+  CL_OBJECT_DESTROY_BASE(p);
   cl_free(p);
 }
 
@@ -132,11 +132,9 @@  cl_program_new(cl_context ctx)
 
   /* Allocate the structure */
   TRY_ALLOC_NO_ERR (p, CALLOC(struct _cl_program));
-  SET_ICD(p->dispatch)
-  p->build_status = CL_BUILD_NONE;
-  p->ref_n = 1;
-  p->magic = CL_MAGIC_PROGRAM_HEADER;
+  CL_OBJECT_INIT_BASE(p, CL_OBJECT_PROGRAM_MAGIC);
   p->ctx = ctx;
+  p->build_status = CL_BUILD_NONE;
   p->cmrt_program = NULL;
   p->build_log = calloc(BUILD_LOG_MAX_SIZE, sizeof(char));
   if (p->build_log)
@@ -155,7 +153,7 @@  LOCAL void
 cl_program_add_ref(cl_program p)
 {
   assert(p);
-  atomic_inc(&p->ref_n);
+  CL_OBJECT_INC_REF(p);
 }
 
 static cl_int
@@ -541,7 +539,7 @@  cl_program_build(cl_program p, const char *options)
   int i = 0;
   int copyed = 0;
 
-  if (p->ref_n > 1) {
+  if (CL_OBJECT_GET_REF(p) > 1) {
     err = CL_INVALID_OPERATION;
     goto error;
   }
@@ -768,7 +766,7 @@  cl_program_compile(cl_program            p,
   cl_int err = CL_SUCCESS;
   int i = 0;
 
-  if (p->ref_n > 1) {
+  if (CL_OBJECT_GET_REF(p) > 1) {
     err = CL_INVALID_OPERATION;
     goto error;
   }
diff --git a/src/cl_program.h b/src/cl_program.h
index b69e00c..85f8df3 100644
--- a/src/cl_program.h
+++ b/src/cl_program.h
@@ -22,6 +22,7 @@ 
 
 #include "cl_internals.h"
 #include "cl_gbe_loader.h"
+#include "cl_base_object.h"
 #include "CL/cl.h"
 
 #include <stdint.h>
@@ -49,9 +50,7 @@  typedef enum _BINARY_HEADER_INDEX {
 
 /* This maps an OCL file containing some kernels */
 struct _cl_program {
-  DEFINE_ICD(dispatch)
-  uint64_t magic;         /* To identify it as a program */
-  volatile int ref_n;     /* We reference count this object */
+  _cl_base_object base;
   gbe_program opaque;     /* (Opaque) program as ouput by the compiler */
   cl_kernel *ker;         /* All kernels included by the OCL file */
   cl_program prev, next;  /* We chain the programs together */
@@ -75,6 +74,9 @@  struct _cl_program {
   void* cmrt_program;      /* real type: CmProgram* */
 };
 
+#define CL_OBJECT_PROGRAM_MAGIC 0x34562ab12789cdefLL
+#define CL_OBJECT_IS_PROGRAM(obj) (((cl_base_object)obj)->magic == CL_OBJECT_PROGRAM_MAGIC)
+
 /* Create a empty program */
 extern cl_program cl_program_new(cl_context);
 
diff --git a/src/cl_utils.h b/src/cl_utils.h
index 2926611..d671090 100644
--- a/src/cl_utils.h
+++ b/src/cl_utils.h
@@ -263,7 +263,7 @@  do {                                                        \
     err = CL_INVALID_PROGRAM;                               \
     goto error;                                             \
   }                                                         \
-  if (UNLIKELY(PROGRAM->magic != CL_MAGIC_PROGRAM_HEADER)) {\
+  if (UNLIKELY(!CL_OBJECT_IS_PROGRAM(PROGRAM))) {          \
     err = CL_INVALID_PROGRAM;                               \
     goto error;                                             \
   }                                                         \