[Beignet] [PATCH OCL20 04/11] Runtime: Add clCreateSamplerWithProperties

Xiuli Pan xiuli.pan at intel.com
Wed Mar 2 03:01:57 UTC 2016


From: Pan Xiuli <xiuli.pan at intel.com>

Add api clCreateSamplerWithProperties

Signed-off-by: Pan Xiuli <xiuli.pan at intel.com>
---
 src/cl_api.c       | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/cl_device_id.c |  2 +-
 src/cl_khr_icd.c   |  2 +-
 3 files changed, 64 insertions(+), 2 deletions(-)

diff --git a/src/cl_api.c b/src/cl_api.c
index 3867261..0b333c6 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -1070,6 +1070,68 @@ error:
   return sampler;
 }
 
+cl_sampler
+clCreateSamplerWithProperties(cl_context                  context,
+                              const cl_sampler_properties *sampler_properties,
+                              cl_int *                    errcode_ret)
+{
+  cl_sampler sampler = NULL;
+  cl_int err = CL_SUCCESS;
+  CHECK_CONTEXT (context);
+  cl_bool normalized = 0xFFFFFFFF;
+  cl_addressing_mode addressing = 0xFFFFFFFF;
+  cl_filter_mode filter = 0xFFFFFFFF;
+  if(sampler_properties)
+  {
+    cl_ulong sam_type;
+    cl_ulong sam_val;
+    for(cl_uint i = 0;(sam_type = sampler_properties[i++])!=0;i++)
+    {
+      sam_val = sampler_properties[i];
+      switch(sam_type)
+      {
+        case CL_SAMPLER_NORMALIZED_COORDS:
+          if(normalized != 0xFFFFFFFF)
+            err = CL_INVALID_VALUE;
+          else if(sam_val == CL_TRUE || sam_val == CL_FALSE)
+            normalized = sam_val;
+          else
+            err = CL_INVALID_VALUE;
+          break;
+        case CL_SAMPLER_ADDRESSING_MODE:
+          if(addressing != 0xFFFFFFFF)
+            err = CL_INVALID_VALUE;
+          else if(sam_val == CL_ADDRESS_MIRRORED_REPEAT || sam_val == CL_ADDRESS_REPEAT ||
+                  sam_val == CL_ADDRESS_CLAMP_TO_EDGE || sam_val == CL_ADDRESS_CLAMP ||
+                  sam_val == CL_ADDRESS_NONE)
+            addressing = sam_val;
+          else
+            err = CL_INVALID_VALUE;
+          break;
+        case CL_SAMPLER_FILTER_MODE:
+          if(filter != 0xFFFFFFFF)
+            err = CL_INVALID_VALUE;
+          else if(sam_val == CL_FILTER_LINEAR || sam_val == CL_FILTER_NEAREST)
+            filter = sam_val;
+          else
+            err = CL_INVALID_VALUE;
+          break;
+        default:
+          err = CL_INVALID_VALUE;
+          break;
+      }
+    }
+  }
+  if(normalized == 0xFFFFFFFF) normalized = CL_TRUE;
+  if(addressing == 0xFFFFFFFF) addressing = CL_ADDRESS_CLAMP;
+  if(filter == 0xFFFFFFFF) filter = CL_FILTER_NEAREST;
+  sampler = cl_sampler_new(context, normalized, addressing, filter, &err);
+error:
+  if (errcode_ret)
+    *errcode_ret = err;
+  return sampler;
+}
+
 cl_int
 clRetainSampler(cl_sampler sampler)
 {
diff --git a/src/cl_device_id.c b/src/cl_device_id.c
index b518d48..99320be 100644
--- a/src/cl_device_id.c
+++ b/src/cl_device_id.c
@@ -613,7 +613,7 @@ cl_self_test(cl_device_id device, cl_self_test_res atomic_in_l3_flag)
   ctx = clCreateContext(NULL, 1, &device, NULL, NULL, &status);
   cl_driver_set_atomic_flag(ctx->drv, atomic_in_l3_flag);
   if (status == CL_SUCCESS) {
-    queue = clCreateCommandQueue(ctx, device, 0, &status);
+    queue = clCreateCommandQueueWithProperties(ctx, device, 0, &status);
     if (status == CL_SUCCESS) {
       program = clCreateProgramWithSource(ctx, 1, &kernel_source, NULL, &status);
       if (status == CL_SUCCESS) {
diff --git a/src/cl_khr_icd.c b/src/cl_khr_icd.c
index 1e63b73..f5fac43 100644
--- a/src/cl_khr_icd.c
+++ b/src/cl_khr_icd.c
@@ -186,7 +186,7 @@ struct _cl_icd_dispatch const cl_khr_icd_dispatch = {
   (void *) clEnqueueSVMMemFill,
   (void *) clEnqueueSVMMap,
   (void *) clEnqueueSVMUnmap,
-  (void *) NULL /* clCreateSamplerWithProperties */,
+  (void *) clCreateSamplerWithProperties,
   clSetKernelArgSVMPointer,
   clSetKernelExecInfo,
 #endif
-- 
2.5.0



More information about the Beignet mailing list