[Beignet] [PATCH 05/11] Runtime: Apply base object ot cl_sampler.
junyan.he at inbox.com
junyan.he at inbox.com
Tue Jul 19 11:25:51 UTC 2016
From: Junyan He <junyan.he at intel.com>
Signed-off-by: Junyan He <junyan.he at intel.com>
---
src/cl_api.c | 3 ++-
src/cl_kernel.c | 2 +-
src/cl_sampler.c | 9 ++++-----
src/cl_sampler.h | 8 +++++---
src/cl_utils.h | 2 +-
5 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/src/cl_api.c b/src/cl_api.c
index 4715e40..3a2b013 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -811,7 +811,8 @@ clGetSamplerInfo(cl_sampler sampler,
CHECK_SAMPLER (sampler);
if (param_name == CL_SAMPLER_REFERENCE_COUNT) {
- FILL_GETINFO_RET (cl_uint, 1, (cl_uint*)&sampler->ref_n, CL_SUCCESS);
+ cl_uint ref = CL_OBJECT_GET_REF(sampler);
+ FILL_GETINFO_RET (cl_uint, 1, &ref, CL_SUCCESS);
} else if (param_name == CL_SAMPLER_CONTEXT) {
FILL_GETINFO_RET (cl_context, 1, &sampler->ctx, CL_SUCCESS);
} else if (param_name == CL_SAMPLER_NORMALIZED_COORDS) {
diff --git a/src/cl_kernel.c b/src/cl_kernel.c
index b380abe..ccecd83 100644
--- a/src/cl_kernel.c
+++ b/src/cl_kernel.c
@@ -156,7 +156,7 @@ cl_kernel_set_arg(cl_kernel k, cl_uint index, size_t sz, const void *value)
return CL_INVALID_ARG_VALUE;
cl_sampler s = *(cl_sampler*)value;
- if(s->magic != CL_MAGIC_SAMPLER_HEADER)
+ if(!CL_OBJECT_IS_SAMPLER(s))
return CL_INVALID_SAMPLER;
} else {
// should be image, GLOBAL_PTR, CONSTANT_PTR
diff --git a/src/cl_sampler.c b/src/cl_sampler.c
index 45c1fdf..c67a900 100644
--- a/src/cl_sampler.c
+++ b/src/cl_sampler.c
@@ -82,9 +82,7 @@ cl_sampler_new(cl_context ctx,
/* Allocate and inialize the structure itself */
TRY_ALLOC (sampler, CALLOC(struct _cl_sampler));
- SET_ICD(sampler->dispatch)
- sampler->ref_n = 1;
- sampler->magic = CL_MAGIC_SAMPLER_HEADER;
+ CL_OBJECT_INIT_BASE(sampler, CL_OBJECT_SAMPLER_MAGIC);
sampler->normalized_coords = normalized_coords;
sampler->address = address;
sampler->filter = filter;
@@ -116,7 +114,7 @@ cl_sampler_delete(cl_sampler sampler)
{
if (UNLIKELY(sampler == NULL))
return;
- if (atomic_dec(&sampler->ref_n) > 1)
+ if (CL_OBJECT_DEC_REF(sampler) > 1)
return;
assert(sampler->ctx);
@@ -130,6 +128,7 @@ cl_sampler_delete(cl_sampler sampler)
pthread_mutex_unlock(&sampler->ctx->sampler_lock);
cl_context_delete(sampler->ctx);
+ CL_OBJECT_DESTROY_BASE(sampler);
cl_free(sampler);
}
@@ -137,6 +136,6 @@ LOCAL void
cl_sampler_add_ref(cl_sampler sampler)
{
assert(sampler);
- atomic_inc(&sampler->ref_n);
+ CL_OBJECT_INC_REF(sampler);
}
diff --git a/src/cl_sampler.h b/src/cl_sampler.h
index fc4b7e7..900f66e 100644
--- a/src/cl_sampler.h
+++ b/src/cl_sampler.h
@@ -21,14 +21,13 @@
#define __CL_SAMPLER_H__
#include "CL/cl.h"
+#include "cl_base_object.h"
#include "../backend/src/ocl_common_defines.h"
#include <stdint.h>
/* How to access images */
struct _cl_sampler {
- DEFINE_ICD(dispatch)
- uint64_t magic; /* To identify it as a sampler object */
- volatile int ref_n; /* This object is reference counted */
+ _cl_base_object base;
cl_sampler prev, next; /* We chain the samplers in the allocator */
cl_context ctx; /* Context it belongs to */
cl_bool normalized_coords; /* Are coordinates normalized? */
@@ -37,6 +36,9 @@ struct _cl_sampler {
uint32_t clkSamplerValue;
};
+#define CL_OBJECT_SAMPLER_MAGIC 0x686a0ecba79ce32fLL
+#define CL_OBJECT_IS_SAMPLER(obj) (((cl_base_object)obj)->magic == CL_OBJECT_SAMPLER_MAGIC)
+
/* Create a new sampler object */
extern cl_sampler cl_sampler_new(cl_context,
cl_bool,
diff --git a/src/cl_utils.h b/src/cl_utils.h
index d671090..e118ef1 100644
--- a/src/cl_utils.h
+++ b/src/cl_utils.h
@@ -227,7 +227,7 @@ do { \
err = CL_INVALID_SAMPLER; \
goto error; \
} \
- if (UNLIKELY(SAMPLER->magic != CL_MAGIC_SAMPLER_HEADER)) {\
+ if (UNLIKELY(!CL_OBJECT_IS_SAMPLER(SAMPLER))) { \
err = CL_INVALID_SAMPLER; \
goto error; \
} \
--
1.7.9.5
____________________________________________________________
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
Check it out at http://www.inbox.com/earth
More information about the Beignet
mailing list