[Beignet] [PATCH v2 3/3] runtime: fix some get image info bugs.
Zhigang Gong
zhigang.gong at intel.com
Thu Jun 19 00:36:37 PDT 2014
According to ocl spec:
Return height of the image in pixels. For a
1D image, 1D image buffer and 1D image
array object, height = 0.
Return depth of the image in pixels. For a
1D image, 1D image buffer, 2D image or
1D and 2D image array object, depth = 0.
Signed-off-by: Zhigang Gong <zhigang.gong at intel.com>
---
src/cl_mem.c | 38 +++++++++++++++++++++++++-------------
utests/get_cl_info.cpp | 2 +-
2 files changed, 26 insertions(+), 14 deletions(-)
diff --git a/src/cl_mem.c b/src/cl_mem.c
index a7a0f59..bf0e416 100644
--- a/src/cl_mem.c
+++ b/src/cl_mem.c
@@ -130,6 +130,18 @@ cl_get_mem_object_info(cl_mem mem,
return CL_SUCCESS;
}
+#define IS_1D(image) (image->image_type == CL_MEM_OBJECT_IMAGE1D || \
+ image->image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY || \
+ image->image_type == CL_MEM_OBJECT_IMAGE1D_BUFFER)
+
+#define IS_2D(image) (image->image_type == CL_MEM_OBJECT_IMAGE2D || \
+ image->image_type == CL_MEM_OBJECT_IMAGE2D_ARRAY)
+
+#define IS_3D(image) (image->image_type == CL_MEM_OBJECT_IMAGE3D)
+
+#define IS_ARRAY(image) (image->image_type == CL_MEM_OBJECT_IMAGE1D_ARRAY || \
+ image->image_type == CL_MEM_OBJECT_IMAGE2D_ARRAY)
+
LOCAL cl_int
cl_get_image_info(cl_mem mem,
cl_image_info param_name,
@@ -149,17 +161,14 @@ cl_get_image_info(cl_mem mem,
FIELD_SIZE(IMAGE_WIDTH, size_t);
FIELD_SIZE(IMAGE_HEIGHT, size_t);
FIELD_SIZE(IMAGE_DEPTH, size_t);
+ FIELD_SIZE(IMAGE_ARRAY_SIZE, size_t);
FIELD_SIZE(IMAGE_BUFFER, cl_mem);
+ FIELD_SIZE(IMAGE_NUM_MIP_LEVELS, cl_uint);
+ FIELD_SIZE(IMAGE_NUM_SAMPLES, cl_uint);
default:
return CL_INVALID_VALUE;
}
- /* Do some further check. */
- if (param_name == CL_IMAGE_BUFFER &&
- image->image_type != CL_MEM_OBJECT_IMAGE1D_BUFFER) {
- return CL_INVALID_VALUE;
- }
-
switch(param_name)
{
case CL_IMAGE_FORMAT:
@@ -178,14 +187,21 @@ cl_get_image_info(cl_mem mem,
*(size_t *)param_value = image->w;
break;
case CL_IMAGE_HEIGHT:
- *(size_t *)param_value = image->h;
+ *(size_t *)param_value = IS_1D(image) ? 0 : image->h;
break;
case CL_IMAGE_DEPTH:
- *(size_t *)param_value = image->depth;
+ *(size_t *)param_value = IS_3D(image) ? image->depth : 0;
+ break;
+ case CL_IMAGE_ARRAY_SIZE:
+ *(size_t *)param_value = IS_ARRAY(image) ? image->depth : 0;
break;
case CL_IMAGE_BUFFER:
*(cl_mem *)param_value = image->buffer_1d;
break;
+ case CL_IMAGE_NUM_MIP_LEVELS:
+ case CL_IMAGE_NUM_SAMPLES:
+ *(cl_mem *)param_value = 0;
+ break;
}
return CL_SUCCESS;
@@ -591,12 +607,8 @@ _cl_mem_new_image(cl_context ctx,
pitch = min_pitch;
h = 1;
- if (image_type != CL_MEM_OBJECT_IMAGE1D_ARRAY)
- depth = 1;
- else if (data && slice_pitch == 0)
- slice_pitch = pitch;
+ depth = 1;
if (UNLIKELY(w > ctx->device->image2d_max_width)) DO_IMAGE_ERROR;
- if (UNLIKELY(depth > ctx->device->image_max_array_size)) DO_IMAGE_ERROR;
if (UNLIKELY(data && min_pitch > pitch)) DO_IMAGE_ERROR;
if (UNLIKELY(data && (slice_pitch % pitch != 0))) DO_IMAGE_ERROR;
if (UNLIKELY(!data && pitch != 0)) DO_IMAGE_ERROR;
diff --git a/utests/get_cl_info.cpp b/utests/get_cl_info.cpp
index 0e87e28..b2c1686 100644
--- a/utests/get_cl_info.cpp
+++ b/utests/get_cl_info.cpp
@@ -546,7 +546,7 @@ void get_image_info(void)
size_t depth;
OCL_CALL(clGetImageInfo, image, CL_IMAGE_DEPTH, sizeof(depth), &depth, NULL);
- OCL_ASSERT(depth == 1);
+ OCL_ASSERT(depth == 0);
}
MAKE_UTEST_FROM_FUNCTION(get_image_info);
--
1.8.3.2
More information about the Beignet
mailing list