@@ -386,14 +386,14 @@ REGISTER_TEST(null_required_work_group_size)
386386
387387 struct KernelAttribInfo
388388 {
389- std::string str ;
390- cl_uint max_dim ;
389+ cl_int wgs[ 3 ] ;
390+ cl_uint min_dim ;
391391 };
392392
393393 std::vector<KernelAttribInfo> attribs;
394- attribs.push_back ({ " __attribute__((reqd_work_group_size(2,1,1))) " , 1 });
395- attribs.push_back ({ " __attribute__((reqd_work_group_size(2,3,1))) " , 2 });
396- attribs.push_back ({ " __attribute__((reqd_work_group_size(2,3,4))) " , 3 });
394+ attribs.push_back ({ { 2 , 1 , 1 } , 1 });
395+ attribs.push_back ({ { 2 , 3 , 1 } , 2 });
396+ attribs.push_back ({ { 2 , 3 , 4 } , 3 });
397397
398398 const std::string body_str = R"(
399399 __kernel void wg_size(__global int* dst)
@@ -410,7 +410,11 @@ REGISTER_TEST(null_required_work_group_size)
410410
411411 for (auto & attrib : attribs)
412412 {
413- const std::string source_str = attrib.str + body_str;
413+ const std::string attrib_str = " __attribute__((reqd_work_group_size("
414+ + std::to_string (attrib.wgs [0 ]) + " ,"
415+ + std::to_string (attrib.wgs [1 ]) + " ,"
416+ + std::to_string (attrib.wgs [2 ]) + " )))" ;
417+ const std::string source_str = attrib_str + body_str;
414418 const char * source = source_str.c_str ();
415419
416420 clProgramWrapper program;
@@ -422,21 +426,19 @@ REGISTER_TEST(null_required_work_group_size)
422426 error = clSetKernelArg (kernel, 0 , sizeof (cl_mem), &dst);
423427 test_error (error, " clSetKernelArg failed" );
424428
425- for (cl_uint work_dim = 1 ; work_dim <= attrib. max_dim ; work_dim++)
429+ for (cl_uint work_dim = attrib. min_dim ; work_dim <= 3 ; work_dim++)
426430 {
427- const cl_int expected[3 ] = { 2 , work_dim >= 2 ? 3 : 1 ,
428- work_dim >= 3 ? 4 : 1 };
429431 const size_t test_work_group_size =
430- expected [0 ] * expected [1 ] * expected [2 ];
431- if ((size_t )expected [0 ] > device_max_work_item_sizes[0 ]
432- || (size_t )expected [1 ] > device_max_work_item_sizes[1 ]
433- || (size_t )expected [2 ] > device_max_work_item_sizes[2 ]
432+ attrib. wgs [0 ] * attrib. wgs [1 ] * attrib. wgs [2 ];
433+ if ((size_t )attrib. wgs [0 ] > device_max_work_item_sizes[0 ]
434+ || (size_t )attrib. wgs [1 ] > device_max_work_item_sizes[1 ]
435+ || (size_t )attrib. wgs [2 ] > device_max_work_item_sizes[2 ]
434436 || test_work_group_size > device_max_work_group_size)
435437 {
436438 log_info (" Skipping test for work_dim = %u: required work group "
437439 " size (%i, %i, %i) (total %zu) exceeds device max "
438440 " work group size (%zu, %zu, %zu) (total %zu)\n " ,
439- work_dim, expected [0 ], expected [1 ], expected [2 ],
441+ work_dim, attrib. wgs [0 ], attrib. wgs [1 ], attrib. wgs [2 ],
440442 test_work_group_size, device_max_work_item_sizes[0 ],
441443 device_max_work_item_sizes[1 ],
442444 device_max_work_item_sizes[2 ],
@@ -445,8 +447,9 @@ REGISTER_TEST(null_required_work_group_size)
445447 }
446448
447449 const cl_int zero = 0 ;
448- error = clEnqueueFillBuffer (queue, dst, &zero, sizeof (zero), 0 ,
449- sizeof (expected), 0 , nullptr , nullptr );
450+ error =
451+ clEnqueueFillBuffer (queue, dst, &zero, sizeof (zero), 0 ,
452+ sizeof (attrib.wgs ), 0 , nullptr , nullptr );
450453 test_error (error, " clEnqueueFillBuffer failed" );
451454
452455 const size_t global_work_size[3 ] = { 2 * 32 , 3 * 32 , 4 * 32 };
@@ -460,12 +463,12 @@ REGISTER_TEST(null_required_work_group_size)
460463 results, 0 , nullptr , nullptr );
461464 test_error (error, " clEnqueueReadBuffer failed" );
462465
463- if (results[0 ] != expected [0 ] || results[1 ] != expected [1 ]
464- || results[2 ] != expected [2 ])
466+ if (results[0 ] != attrib. wgs [0 ] || results[1 ] != attrib. wgs [1 ]
467+ || results[2 ] != attrib. wgs [2 ])
465468 {
466469 log_error (" Executed local size mismatch with work_dim = %u: "
467470 " Expected (%d,%d,%d) got (%d,%d,%d)\n " ,
468- work_dim, expected [0 ], expected [1 ], expected [2 ],
471+ work_dim, attrib. wgs [0 ], attrib. wgs [1 ], attrib. wgs [2 ],
469472 results[0 ], results[1 ], results[2 ]);
470473 return TEST_FAIL;
471474 }
@@ -479,15 +482,15 @@ REGISTER_TEST(null_required_work_group_size)
479482 test_error (error,
480483 " clGetKernelSuggestedLocalWorkSizeKHR failed" );
481484
482- if ((cl_int) suggested[0 ] != expected [0 ]
483- || (cl_int) suggested[1 ] != expected [1 ]
484- || (cl_int) suggested[2 ] != expected [2 ])
485+ if (suggested[0 ] != ( size_t )attrib. wgs [0 ]
486+ || suggested[1 ] != ( size_t )attrib. wgs [1 ]
487+ || suggested[2 ] != ( size_t )attrib. wgs [2 ])
485488 {
486489 log_error (" Suggested local size mismatch with work_dim = "
487- " %u: Expected (%d,%d,%d) got (%d,%d,%d )\n " ,
488- work_dim, expected [0 ], expected[ 1 ], expected[ 2 ],
489- (cl_int) suggested[0 ], (cl_int) suggested[1 ],
490- (cl_int) suggested[2 ]);
490+ " %u: Expected (%d,%d,%d) got (%zu,%zu,%zu )\n " ,
491+ work_dim, attrib. wgs [0 ], attrib. wgs [ 1 ],
492+ attrib. wgs [ 2 ], suggested[0 ], suggested[1 ],
493+ suggested[2 ]);
491494 return TEST_FAIL;
492495 }
493496 }
0 commit comments