[Beignet] [PATCH 1/2] Modify clGetSamplerInfo using cl_get_info_helper.

junyan.he at inbox.com junyan.he at inbox.com
Sun Oct 9 09:15:37 UTC 2016


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

Signed-off-by: Junyan He <junyan.he at intel.com>
---
 src/CMakeLists.txt   |  3 ++-
 src/cl_api.c         | 29 --------------------------
 src/cl_api_sampler.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+), 30 deletions(-)
 create mode 100644 src/cl_api_sampler.c

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 42a4d1b..18fbcda 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -74,7 +74,8 @@ set(OPENCL_SRC
     cl_api_kernel.c
     cl_api_command_queue.c
     cl_api_event.c
-	cl_api_context.c
+    cl_api_context.c
+    cl_api_sampler.c
     cl_alloc.c
     cl_kernel.c
     cl_program.c
diff --git a/src/cl_api.c b/src/cl_api.c
index d9f8ad8..3811842 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -612,35 +612,6 @@ error:
   return err;
 }
 
-cl_int
-clGetSamplerInfo(cl_sampler       sampler,
-                 cl_sampler_info  param_name,
-                 size_t           param_value_size,
-                 void *           param_value,
-                 size_t *         param_value_size_ret)
-{
-  cl_int err = CL_SUCCESS;
-  CHECK_SAMPLER (sampler);
-
-  if (param_name == CL_SAMPLER_REFERENCE_COUNT) {
-    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) {
-    FILL_GETINFO_RET (cl_bool, 1, &sampler->normalized_coords, CL_SUCCESS);
-  } else if (param_name == CL_SAMPLER_ADDRESSING_MODE) {
-    FILL_GETINFO_RET (cl_addressing_mode, 1, &sampler->address, CL_SUCCESS);
-  } else if (param_name == CL_SAMPLER_FILTER_MODE ) {
-    FILL_GETINFO_RET (cl_filter_mode, 1, &sampler->filter, CL_SUCCESS);
-  } else{
-    return CL_INVALID_VALUE;
-  }
-
-error:
-  return err;
-}
-
 cl_program
 clCreateProgramWithSource(cl_context     context,
                           cl_uint        count,
diff --git a/src/cl_api_sampler.c b/src/cl_api_sampler.c
new file mode 100644
index 0000000..3172e1e
--- /dev/null
+++ b/src/cl_api_sampler.c
@@ -0,0 +1,57 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "cl_sampler.h"
+
+cl_int
+clGetSamplerInfo(cl_sampler sampler,
+                 cl_sampler_info param_name,
+                 size_t param_value_size,
+                 void *param_value,
+                 size_t *param_value_size_ret)
+{
+  const void *src_ptr = NULL;
+  size_t src_size = 0;
+
+  if (!CL_OBJECT_IS_SAMPLER(sampler)) {
+    return CL_INVALID_SAMPLER;
+  }
+
+  if (param_name == CL_SAMPLER_REFERENCE_COUNT) {
+    cl_int ref = CL_OBJECT_GET_REF(sampler);
+    src_ptr = &ref;
+    src_size = sizeof(cl_int);
+  } else if (param_name == CL_SAMPLER_CONTEXT) {
+    src_ptr = &sampler->ctx;
+    src_size = sizeof(cl_context);
+  } else if (param_name == CL_SAMPLER_NORMALIZED_COORDS) {
+    src_ptr = &sampler->normalized_coords;
+    src_size = sizeof(cl_bool);
+  } else if (param_name == CL_SAMPLER_ADDRESSING_MODE) {
+    src_ptr = &sampler->address;
+    src_size = sizeof(cl_addressing_mode);
+  } else if (param_name == CL_SAMPLER_FILTER_MODE) {
+    src_ptr = &sampler->filter;
+    src_size = sizeof(cl_filter_mode);
+  } else {
+    return CL_INVALID_VALUE;
+  }
+
+  return cl_get_info_helper(src_ptr, src_size,
+                            param_value, param_value_size, param_value_size_ret);
+}
-- 
2.7.4





More information about the Beignet mailing list