@@ -2270,6 +2270,65 @@ MT_TEST(acl_mem, read_write_image) {
2270
2270
size_t origin[3 ];
2271
2271
size_t region[3 ];
2272
2272
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
+
2273
2332
// 2D Image
2274
2333
cl_image_format image_format = {CL_R, CL_FLOAT};
2275
2334
cl_image_desc image_desc = {
0 commit comments