Skip to content

Commit 3d27d80

Browse files
haoxian2pcolberg
authored andcommitted
Added checks in acl_mem_test.cpp for 1D image
1D image does not have initialization of height and depth members. Some functions check for that before they check for height and depth. Added an image with 0 height and 0 depth to make sure that these functions don't mistakenly use the height and depth in image_desc.
1 parent 81c6ae9 commit 3d27d80

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

test/acl_mem_test.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,6 +2270,65 @@ MT_TEST(acl_mem, read_write_image) {
22702270
size_t origin[3];
22712271
size_t region[3];
22722272

2273+
// 1D Image
2274+
{
2275+
cl_image_format image_format_1D = {CL_R, CL_FLOAT};
2276+
cl_image_desc image_desc_1D = {
2277+
CL_MEM_OBJECT_IMAGE1D, width, 0, 0, 0, 0, 0, 0, 0, {NULL}};
2278+
image1 = clCreateImage(m_context, 0, &image_format_1D, &image_desc_1D, 0,
2279+
&status);
2280+
CHECK_EQUAL(CL_SUCCESS, status);
2281+
image2 = clCreateImage(m_context, 0, &image_format_1D, &image_desc_1D, 0,
2282+
&status);
2283+
CHECK_EQUAL(CL_SUCCESS, status);
2284+
2285+
origin[0] = 0;
2286+
origin[1] = 0;
2287+
origin[2] = 0;
2288+
2289+
region[0] = width;
2290+
region[1] = 1;
2291+
region[2] = 1;
2292+
2293+
input_ptr = (float *)acl_malloc(sizeof(float) * (width));
2294+
CHECK(input_ptr != 0);
2295+
output_ptr = (float *)acl_malloc(sizeof(float) * (width));
2296+
CHECK(output_ptr != 0);
2297+
for (size_t row = 0; row < width; ++row) {
2298+
input_ptr[row] = (float)row + (float)1.5;
2299+
output_ptr[row] = 0.0;
2300+
}
2301+
2302+
status = clEnqueueWriteImage(m_cq, image1, CL_TRUE, origin, region, 0, 0,
2303+
input_ptr, 0, NULL, NULL);
2304+
CHECK_EQUAL(CL_SUCCESS, status);
2305+
2306+
buffer1 = clCreateBuffer(m_context, 0, sizeof(float) * width, 0, &status);
2307+
CHECK_EQUAL(CL_SUCCESS, status);
2308+
2309+
// Copy from 1D image to buffer
2310+
status = clEnqueueCopyImageToBuffer(m_cq, image1, buffer1, origin, region,
2311+
0, 0, NULL, NULL);
2312+
CHECK_EQUAL(CL_SUCCESS, status);
2313+
status = clEnqueueCopyBufferToImage(m_cq, buffer1, image2, 0, origin,
2314+
region, 0, NULL, NULL);
2315+
CHECK_EQUAL(CL_SUCCESS, status);
2316+
status = clEnqueueReadImage(m_cq, image2, CL_TRUE, origin, region, 0, 0,
2317+
output_ptr, 0, NULL, NULL);
2318+
CHECK_EQUAL(CL_SUCCESS, status);
2319+
2320+
// Compare contents of first pointer with second pointer
2321+
for (size_t row = 0; row < width; ++row) {
2322+
CHECK(input_ptr[row] == output_ptr[row]);
2323+
}
2324+
2325+
CHECK_EQUAL(CL_SUCCESS, clReleaseMemObject(image1));
2326+
CHECK_EQUAL(CL_SUCCESS, clReleaseMemObject(image2));
2327+
CHECK_EQUAL(CL_SUCCESS, clReleaseMemObject(buffer1));
2328+
acl_free(input_ptr);
2329+
acl_free(output_ptr);
2330+
}
2331+
22732332
// 2D Image
22742333
cl_image_format image_format = {CL_R, CL_FLOAT};
22752334
cl_image_desc image_desc = {

0 commit comments

Comments
 (0)