[Beignet] [PATCH 2/4] [opencl-2.0] clCreateSampler replaced by clCreateSamplerWithProperties.
xionghu.luo at intel.com
xionghu.luo at intel.com
Wed Apr 29 01:04:00 PDT 2015
From: Luo Xionghu <xionghu.luo at intel.com>
api ungrade for opencl-2.0.
set sampler normalized_coords default value per spec.
the CL_SAMPLER_NORMALIZED_COORDS should be CL_FALSE for these cases.
v2: icd entry update for opencl-2.0.
Signed-off-by: Luo Xionghu <xionghu.luo at intel.com>
---
src/cl_api.c | 33 ++++++++++++++++++++++++++++++++
src/cl_khr_icd.c | 6 +++++-
utests/compare_image_2d_and_1d_array.cpp | 7 ++++++-
utests/compiler_copy_image.cpp | 8 +++++++-
utests/compiler_copy_image1.cpp | 8 +++++++-
utests/compiler_copy_image_1d.cpp | 8 +++++++-
utests/compiler_copy_image_3d.cpp | 7 ++++++-
utests/compiler_movforphi_undef.cpp | 7 ++++++-
utests/image_1D_buffer.cpp | 7 ++++++-
utests/utest_helper.hpp | 4 ++--
10 files changed, 85 insertions(+), 10 deletions(-)
diff --git a/src/cl_api.c b/src/cl_api.c
index a6f5332..5e24c36 100644
--- a/src/cl_api.c
+++ b/src/cl_api.c
@@ -770,6 +770,39 @@ error:
return sampler;
}
+cl_sampler
+clCreateSamplerWithProperties(cl_context context,
+ const cl_sampler_properties * normalized_coords,
+ cl_int * errcode_ret)
+{
+ cl_sampler sampler = NULL;
+ cl_int err = CL_SUCCESS;
+ CHECK_CONTEXT (context);
+ cl_bool normalized = CL_TRUE;
+ cl_addressing_mode addressing = CL_ADDRESS_CLAMP;
+ cl_filter_mode filter = CL_FILTER_NEAREST;
+
+ while(*normalized_coords) {
+ switch (*normalized_coords) {
+ case CL_SAMPLER_NORMALIZED_COORDS:
+ normalized = *(normalized_coords + 1);
+ break;
+ case CL_SAMPLER_ADDRESSING_MODE:
+ addressing = *(normalized_coords + 1);
+ break;
+ case CL_SAMPLER_FILTER_MODE:
+ filter = *(normalized_coords + 1);
+ break;
+ }
+ normalized_coords += 2;
+ }
+ 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_khr_icd.c b/src/cl_khr_icd.c
index febb93e..7f9f88a 100644
--- a/src/cl_khr_icd.c
+++ b/src/cl_khr_icd.c
@@ -69,7 +69,11 @@ struct _cl_icd_dispatch const cl_khr_icd_dispatch = {
clGetSupportedImageFormats,
clGetMemObjectInfo,
clGetImageInfo,
+#ifdef CL_VERSION_2_0
+ (void *) NULL, /* clCreateSampler deprecated */
+#else
clCreateSampler,
+#endif
clRetainSampler,
clReleaseSampler,
clGetSamplerInfo,
@@ -201,7 +205,7 @@ struct _cl_icd_dispatch const cl_khr_icd_dispatch = {
CL_2_0_NOTYET(clEnqueueSVMMemFill),
CL_2_0_NOTYET(clEnqueueSVMMap),
CL_2_0_NOTYET(clEnqueueSVMUnmap),
- CL_2_0_NOTYET(clCreateSamplerWithProperties),
+ clCreateSamplerWithProperties,
CL_2_0_NOTYET(clSetKernelArgSVMPointer),
CL_2_0_NOTYET(clSetKernelExecInfo),
#else
diff --git a/utests/compare_image_2d_and_1d_array.cpp b/utests/compare_image_2d_and_1d_array.cpp
index dfa4273..b66aa5e 100644
--- a/utests/compare_image_2d_and_1d_array.cpp
+++ b/utests/compare_image_2d_and_1d_array.cpp
@@ -49,7 +49,12 @@ static void compare_image_2d_and_1d_array(void)
desc.image_row_pitch = w * sizeof(uint32_t);
OCL_CREATE_IMAGE(buf[1], CL_MEM_COPY_HOST_PTR, &format, &desc, image_data2);
- OCL_CREATE_SAMPLER(sampler, CL_ADDRESS_REPEAT, CL_FILTER_LINEAR);
+ cl_sampler_properties properties[] = {
+ CL_SAMPLER_NORMALIZED_COORDS, CL_FALSE,
+ CL_SAMPLER_ADDRESSING_MODE, CL_ADDRESS_REPEAT,
+ CL_SAMPLER_FILTER_MODE, CL_FILTER_LINEAR,
+ 0 };
+ OCL_CREATE_SAMPLER_WITH_PROPERTIES(sampler, properties);
// Setup kernel and images
OCL_CREATE_KERNEL("compare_image_2d_and_1d_array");
diff --git a/utests/compiler_copy_image.cpp b/utests/compiler_copy_image.cpp
index 150fd8a..2c58729 100644
--- a/utests/compiler_copy_image.cpp
+++ b/utests/compiler_copy_image.cpp
@@ -29,7 +29,13 @@ static void compiler_copy_image(void)
desc.image_row_pitch = 0;
OCL_CREATE_IMAGE(buf[1], 0, &format, &desc, NULL);
- OCL_CREATE_SAMPLER(sampler, CL_ADDRESS_REPEAT, CL_FILTER_NEAREST);
+
+ cl_sampler_properties properties[] = {
+ CL_SAMPLER_NORMALIZED_COORDS, false,
+ CL_SAMPLER_ADDRESSING_MODE, CL_ADDRESS_REPEAT,
+ CL_SAMPLER_FILTER_MODE, CL_FILTER_NEAREST,
+ 0 };
+ OCL_CREATE_SAMPLER_WITH_PROPERTIES(sampler, properties);
free(buf_data[0]);
buf_data[0] = NULL;
diff --git a/utests/compiler_copy_image1.cpp b/utests/compiler_copy_image1.cpp
index 659dddc..0b92d81 100644
--- a/utests/compiler_copy_image1.cpp
+++ b/utests/compiler_copy_image1.cpp
@@ -26,7 +26,13 @@ static void compiler_copy_image1(void)
desc.image_height = h;
desc.image_row_pitch = w * sizeof(uint32_t);
OCL_CREATE_IMAGE(buf[0], CL_MEM_COPY_HOST_PTR, &format, &desc, buf_data[0]);
- OCL_CREATE_SAMPLER(sampler, CL_ADDRESS_REPEAT, CL_FILTER_NEAREST);
+
+ cl_sampler_properties properties[] = {
+ CL_SAMPLER_NORMALIZED_COORDS, CL_FALSE,
+ CL_SAMPLER_ADDRESSING_MODE, CL_ADDRESS_REPEAT,
+ CL_SAMPLER_FILTER_MODE, CL_FILTER_NEAREST,
+ 0 };
+ OCL_CREATE_SAMPLER_WITH_PROPERTIES(sampler, properties);
desc.image_row_pitch = 0;
OCL_CREATE_IMAGE(buf[1], 0, &format, &desc, NULL);
diff --git a/utests/compiler_copy_image_1d.cpp b/utests/compiler_copy_image_1d.cpp
index 5af6a77..2b81f87 100644
--- a/utests/compiler_copy_image_1d.cpp
+++ b/utests/compiler_copy_image_1d.cpp
@@ -26,7 +26,13 @@ static void compiler_copy_image_1d(void)
desc.image_row_pitch = 0;
OCL_CREATE_IMAGE(buf[1], 0, &format, &desc, NULL);
- OCL_CREATE_SAMPLER(sampler, CL_ADDRESS_REPEAT, CL_FILTER_NEAREST);
+
+ cl_sampler_properties properties[] = {
+ CL_SAMPLER_NORMALIZED_COORDS, CL_FALSE,
+ CL_SAMPLER_ADDRESSING_MODE, CL_ADDRESS_REPEAT,
+ CL_SAMPLER_FILTER_MODE, CL_FILTER_NEAREST,
+ 0 };
+ OCL_CREATE_SAMPLER_WITH_PROPERTIES(sampler, properties);
free(buf_data[0]);
buf_data[0] = NULL;
diff --git a/utests/compiler_copy_image_3d.cpp b/utests/compiler_copy_image_3d.cpp
index de7cd45..81bc6c6 100644
--- a/utests/compiler_copy_image_3d.cpp
+++ b/utests/compiler_copy_image_3d.cpp
@@ -40,7 +40,12 @@ static void compiler_copy_image_3d(void)
for(uint32_t i = 0; i < depth; i++)
OCL_CREATE_IMAGE(buf[2 + i], 0, &format, &desc, NULL);
- OCL_CREATE_SAMPLER(sampler, CL_ADDRESS_REPEAT, CL_FILTER_NEAREST);
+ cl_sampler_properties properties[] = {
+ CL_SAMPLER_NORMALIZED_COORDS, CL_FALSE,
+ CL_SAMPLER_ADDRESSING_MODE, CL_ADDRESS_REPEAT,
+ CL_SAMPLER_FILTER_MODE, CL_FILTER_NEAREST,
+ 0 };
+ OCL_CREATE_SAMPLER_WITH_PROPERTIES(sampler, properties);
free(buf_data[0]);
buf_data[0] = NULL;
diff --git a/utests/compiler_movforphi_undef.cpp b/utests/compiler_movforphi_undef.cpp
index 8f1e66e..5f4b9fc 100644
--- a/utests/compiler_movforphi_undef.cpp
+++ b/utests/compiler_movforphi_undef.cpp
@@ -27,7 +27,12 @@ static void compiler_movforphi_undef(void)
desc.image_row_pitch = 0;
OCL_CREATE_IMAGE(buf[1], 0, &format, &desc, NULL);
- OCL_CREATE_SAMPLER(sampler, CL_ADDRESS_REPEAT, CL_FILTER_NEAREST);
+ cl_sampler_properties properties[] = {
+ CL_SAMPLER_NORMALIZED_COORDS, CL_FALSE,
+ CL_SAMPLER_ADDRESSING_MODE, CL_ADDRESS_REPEAT,
+ CL_SAMPLER_FILTER_MODE, CL_FILTER_NEAREST,
+ 0 };
+ OCL_CREATE_SAMPLER_WITH_PROPERTIES(sampler, properties);
free(buf_data[0]);
buf_data[0] = NULL;
diff --git a/utests/image_1D_buffer.cpp b/utests/image_1D_buffer.cpp
index d8d761f..1bcd2ef 100644
--- a/utests/image_1D_buffer.cpp
+++ b/utests/image_1D_buffer.cpp
@@ -49,7 +49,12 @@ void image_1D_buffer(void)
OCL_ASSERT(error == CL_SUCCESS);
// Create sampler to use
- sampler = clCreateSampler(ctx, false, CL_ADDRESS_NONE, CL_FILTER_NEAREST, &error );
+ cl_sampler_properties properties[] = {
+ CL_SAMPLER_NORMALIZED_COORDS, CL_FALSE,
+ CL_SAMPLER_ADDRESSING_MODE, CL_ADDRESS_NONE,
+ CL_SAMPLER_FILTER_MODE, CL_FILTER_NEAREST,
+ 0 };
+ OCL_CREATE_SAMPLER_WITH_PROPERTIES(sampler, properties);
OCL_ASSERT(error == CL_SUCCESS);
cl_mem result_buf = buf[0] = clCreateBuffer(ctx, 0, buffer_sz, NULL, &error);
diff --git a/utests/utest_helper.hpp b/utests/utest_helper.hpp
index 6d09766..b7115e0 100644
--- a/utests/utest_helper.hpp
+++ b/utests/utest_helper.hpp
@@ -119,8 +119,8 @@ extern EGLSurface eglSurface;
#define OCL_SWAP_EGL_BUFFERS() \
eglSwapBuffers(eglDisplay, eglSurface);
-#define OCL_CREATE_SAMPLER(SAMPLER, ADDRESS_MODE, FILTER_MODE) \
- OCL_CALL2(clCreateSampler, SAMPLER, ctx, 0, ADDRESS_MODE, FILTER_MODE)
+#define OCL_CREATE_SAMPLER_WITH_PROPERTIES(SAMPLER, PROPERTIES) \
+ OCL_CALL2(clCreateSamplerWithProperties, SAMPLER, ctx, PROPERTIES)
#define OCL_MAP_BUFFER(ID) \
OCL_CALL2(clMapBufferIntel, buf_data[ID], buf[ID])
--
1.9.1
More information about the Beignet
mailing list