Refactor clCopyImage and clFillImage tests (#2283)

This change mainly extends `clFillImage` and `clCopyImage` test function
to include memory flags to be used during creating the image instead of
hard-coding these values. The memory flags are also different parameters
for source and destination images in `clCopyImage` tests.

---------

Signed-off-by: Michael Rizkalla <michael.rizkalla@arm.com>
This commit is contained in:
Michael Rizkalla
2025-04-01 17:53:37 +01:00
committed by GitHub
parent 78bd3ddece
commit 5930d45fc6
19 changed files with 1762 additions and 1043 deletions

View File

@@ -36,12 +36,8 @@ static void set_image_dimensions( image_descriptor *imageInfo, size_t width, siz
} while ((imageInfo->rowPitch % pixelSize) != 0);
}
imageInfo->slicePitch = imageInfo->rowPitch * (imageInfo->height + slicePadding);
if (depth == 0)
imageInfo->type = CL_MEM_OBJECT_IMAGE2D;
else
imageInfo->type = CL_MEM_OBJECT_IMAGE3D;
imageInfo->slicePitch =
imageInfo->rowPitch * (imageInfo->height + slicePadding);
}
@@ -209,15 +205,33 @@ int test_copy_image_size_2D_3D( cl_context context, cl_command_queue queue, imag
}
int test_copy_image_set_2D_3D( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format, bool reverse = false )
int test_copy_image_set_2D_3D(cl_device_id device, cl_context context,
cl_command_queue queue, cl_mem_flags src_flags,
cl_mem_object_type src_type,
cl_mem_flags dst_flags,
cl_mem_object_type dst_type,
cl_image_format *format)
{
size_t maxWidth, maxHeight, max3DWidth, max3DHeight, max3DDepth;
cl_ulong maxAllocSize, memSize;
image_descriptor srcImageInfo = { 0 };
image_descriptor dstImageInfo = { 0 };
const bool reverse = (dst_type == CL_MEM_OBJECT_IMAGE2D);
image_descriptor imageInfo2D = { 0 };
image_descriptor imageInfo3D = { 0 };
RandomSeed seed( gRandomSeed );
srcImageInfo.format = dstImageInfo.format = format;
imageInfo2D.format = imageInfo3D.format = format;
imageInfo2D.type = CL_MEM_OBJECT_IMAGE2D;
imageInfo3D.type = CL_MEM_OBJECT_IMAGE3D;
if (reverse)
{
imageInfo3D.mem_flags = src_flags;
imageInfo2D.mem_flags = dst_flags;
}
else
{
imageInfo2D.mem_flags = src_flags;
imageInfo3D.mem_flags = dst_flags;
}
int error = clGetDeviceInfo( device, CL_DEVICE_IMAGE2D_MAX_WIDTH, sizeof( maxWidth ), &maxWidth, NULL );
error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE2D_MAX_HEIGHT, sizeof( maxHeight ), &maxHeight, NULL );
@@ -235,38 +249,62 @@ int test_copy_image_set_2D_3D( cl_device_id device, cl_context context, cl_comma
if( gTestSmallImages )
{
for( dstImageInfo.width = 4; dstImageInfo.width < 17; dstImageInfo.width++ )
for (imageInfo3D.width = 4; imageInfo3D.width < 17; imageInfo3D.width++)
{
for( dstImageInfo.height = 4; dstImageInfo.height < 13; dstImageInfo.height++ )
for (imageInfo3D.height = 4; imageInfo3D.height < 13;
imageInfo3D.height++)
{
for( dstImageInfo.depth = 4; dstImageInfo.depth < 9; dstImageInfo.depth++ )
for (imageInfo3D.depth = 4; imageInfo3D.depth < 9;
imageInfo3D.depth++)
{
size_t rowPadding = gEnablePitch ? 256 : 0;
size_t slicePadding = gEnablePitch ? 3 : 0;
set_image_dimensions( &dstImageInfo, dstImageInfo.width, dstImageInfo.height, dstImageInfo.depth, rowPadding, slicePadding );
set_image_dimensions( &srcImageInfo, dstImageInfo.width, dstImageInfo.height, 0, rowPadding, slicePadding );
set_image_dimensions(&imageInfo3D, imageInfo3D.width,
imageInfo3D.height, imageInfo3D.depth,
rowPadding, slicePadding);
set_image_dimensions(&imageInfo2D, imageInfo3D.width,
imageInfo3D.height, 0, rowPadding,
slicePadding);
if (gTestMipmaps)
{
srcImageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(srcImageInfo.width, srcImageInfo.height, 0), seed);
srcImageInfo.type = CL_MEM_OBJECT_IMAGE2D;
dstImageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(dstImageInfo.width, dstImageInfo.height, dstImageInfo.depth), seed);
dstImageInfo.type = CL_MEM_OBJECT_IMAGE3D;
srcImageInfo.rowPitch = srcImageInfo.width * get_pixel_size( srcImageInfo.format );
srcImageInfo.slicePitch = 0;
dstImageInfo.rowPitch = dstImageInfo.width * get_pixel_size( dstImageInfo.format );
dstImageInfo.slicePitch = dstImageInfo.rowPitch * dstImageInfo.height;
imageInfo2D.num_mip_levels =
(cl_uint)random_log_in_range(
2,
(int)compute_max_mip_levels(
imageInfo2D.width, imageInfo2D.height, 0),
seed);
imageInfo3D.num_mip_levels =
(cl_uint)random_log_in_range(
2,
(int)compute_max_mip_levels(imageInfo3D.width,
imageInfo3D.height,
imageInfo3D.depth),
seed);
imageInfo2D.rowPitch = imageInfo2D.width
* get_pixel_size(imageInfo2D.format);
imageInfo2D.slicePitch = 0;
imageInfo3D.rowPitch = imageInfo3D.width
* get_pixel_size(imageInfo3D.format);
imageInfo3D.slicePitch =
imageInfo3D.rowPitch * imageInfo3D.height;
}
if( gDebugTrace )
log_info( " at size %d,%d to %d,%d,%d\n", (int)srcImageInfo.width, (int)srcImageInfo.height, (int)dstImageInfo.width, (int)dstImageInfo.height, (int)dstImageInfo.depth );
log_info(
" at size %d,%d to %d,%d,%d\n",
(int)imageInfo2D.width, (int)imageInfo2D.height,
(int)imageInfo3D.width, (int)imageInfo3D.height,
(int)imageInfo3D.depth);
int ret;
if( reverse )
ret = test_copy_image_size_2D_3D( context, queue, &dstImageInfo, &srcImageInfo, seed );
ret = test_copy_image_size_2D_3D(
context, queue, &imageInfo3D, &imageInfo2D, seed);
else
ret = test_copy_image_size_2D_3D( context, queue, &srcImageInfo, &dstImageInfo, seed );
ret = test_copy_image_size_2D_3D(
context, queue, &imageInfo2D, &imageInfo3D, seed);
if( ret )
return -1;
}
@@ -280,8 +318,12 @@ int test_copy_image_set_2D_3D( cl_device_id device, cl_context context, cl_comma
size_t sizes3D[100][3], sizes2D[100][3];
// Try to allocate a bit smaller images because we need the 2D ones as well for the copy.
get_max_sizes(&numberOfSizes3D, 100, sizes3D, max3DWidth, max3DHeight, max3DDepth, 1, maxAllocSize/2, memSize/2, CL_MEM_OBJECT_IMAGE3D, dstImageInfo.format);
get_max_sizes(&numberOfSizes2D, 100, sizes2D, maxWidth, maxHeight, 1, 1, maxAllocSize/2, memSize/2, CL_MEM_OBJECT_IMAGE2D, srcImageInfo.format);
get_max_sizes(&numberOfSizes3D, 100, sizes3D, max3DWidth, max3DHeight,
max3DDepth, 1, maxAllocSize / 2, memSize / 2,
CL_MEM_OBJECT_IMAGE3D, imageInfo3D.format);
get_max_sizes(&numberOfSizes2D, 100, sizes2D, maxWidth, maxHeight, 1, 1,
maxAllocSize / 2, memSize / 2, CL_MEM_OBJECT_IMAGE2D,
imageInfo2D.format);
for( size_t i = 0; i < numberOfSizes2D; i++ )
for( size_t j = 0; j < numberOfSizes3D; j++ )
@@ -289,42 +331,65 @@ int test_copy_image_set_2D_3D( cl_device_id device, cl_context context, cl_comma
size_t rowPadding = gEnablePitch ? 256 : 0;
size_t slicePadding = gEnablePitch ? 3 : 0;
set_image_dimensions( &dstImageInfo, sizes3D[ j ][ 0 ], sizes3D[ j ][ 1 ], sizes3D[ j ][ 2 ], rowPadding, slicePadding );
set_image_dimensions( &srcImageInfo, sizes2D[ i ][ 0 ], sizes2D[ i ][ 1 ], 0, rowPadding, slicePadding );
cl_ulong dstSize = get_image_size(&dstImageInfo);
cl_ulong srcSize = get_image_size(&srcImageInfo);
set_image_dimensions(&imageInfo3D, sizes3D[j][0], sizes3D[j][1],
sizes3D[j][2], rowPadding, slicePadding);
set_image_dimensions(&imageInfo2D, sizes2D[i][0], sizes2D[i][1], 0,
rowPadding, slicePadding);
cl_ulong dstSize = get_image_size(&imageInfo3D);
cl_ulong srcSize = get_image_size(&imageInfo2D);
if (gTestMipmaps)
{
srcImageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(srcImageInfo.width, srcImageInfo.height, 0), seed);
srcImageInfo.type = CL_MEM_OBJECT_IMAGE2D;
dstImageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(dstImageInfo.width, dstImageInfo.height, dstImageInfo.depth), seed);
dstImageInfo.type = CL_MEM_OBJECT_IMAGE3D;
srcImageInfo.rowPitch = srcImageInfo.width * get_pixel_size( srcImageInfo.format );
srcImageInfo.slicePitch = 0;
dstImageInfo.rowPitch = dstImageInfo.width * get_pixel_size( dstImageInfo.format );
dstImageInfo.slicePitch = dstImageInfo.rowPitch * dstImageInfo.height;
dstSize = 4 * compute_mipmapped_image_size( dstImageInfo );
srcSize = 4 * compute_mipmapped_image_size( srcImageInfo );
imageInfo2D.num_mip_levels = (cl_uint)random_log_in_range(
2,
(int)compute_max_mip_levels(imageInfo2D.width,
imageInfo2D.height, 0),
seed);
imageInfo3D.num_mip_levels = (cl_uint)random_log_in_range(
2,
(int)compute_max_mip_levels(imageInfo3D.width,
imageInfo3D.height,
imageInfo3D.depth),
seed);
imageInfo2D.rowPitch =
imageInfo2D.width * get_pixel_size(imageInfo2D.format);
imageInfo2D.slicePitch = 0;
imageInfo3D.rowPitch =
imageInfo3D.width * get_pixel_size(imageInfo3D.format);
imageInfo3D.slicePitch =
imageInfo3D.rowPitch * imageInfo3D.height;
dstSize = 4 * compute_mipmapped_image_size(imageInfo3D);
srcSize = 4 * compute_mipmapped_image_size(imageInfo2D);
}
if( dstSize < maxAllocSize && dstSize < ( memSize / 3 ) && srcSize < maxAllocSize && srcSize < ( memSize / 3 ) )
{
log_info( "Testing %d x %d to %d x %d x %d\n", (int)srcImageInfo.width, (int)srcImageInfo.height, (int)dstImageInfo.width, (int)dstImageInfo.height, (int)dstImageInfo.depth );
log_info("Testing %d x %d to %d x %d x %d\n",
(int)imageInfo2D.width, (int)imageInfo2D.height,
(int)imageInfo3D.width, (int)imageInfo3D.height,
(int)imageInfo3D.depth);
if( gDebugTrace )
log_info( " at max size %d,%d to %d,%d,%d\n", (int)srcImageInfo.width, (int)srcImageInfo.height, (int)dstImageInfo.width, (int)dstImageInfo.height, (int)dstImageInfo.depth );
log_info(" at max size %d,%d to %d,%d,%d\n",
(int)imageInfo2D.width, (int)imageInfo2D.height,
(int)imageInfo3D.width, (int)imageInfo3D.height,
(int)imageInfo3D.depth);
int ret;
if( reverse )
ret = test_copy_image_size_2D_3D( context, queue, &dstImageInfo, &srcImageInfo, seed );
ret = test_copy_image_size_2D_3D(
context, queue, &imageInfo3D, &imageInfo2D, seed);
else
ret = test_copy_image_size_2D_3D( context, queue, &srcImageInfo, &dstImageInfo, seed );
ret = test_copy_image_size_2D_3D(
context, queue, &imageInfo2D, &imageInfo3D, seed);
if( ret )
return -1;
}
else
{
log_info("Not testing max size %d x %d to %d x %d x %d due to memory constraints.\n",
(int)srcImageInfo.width, (int)srcImageInfo.height, (int)dstImageInfo.width, (int)dstImageInfo.height, (int)dstImageInfo.depth);
log_info("Not testing max size %d x %d to %d x %d x %d due to "
"memory constraints.\n",
(int)imageInfo2D.width, (int)imageInfo2D.height,
(int)imageInfo3D.width, (int)imageInfo3D.height,
(int)imageInfo3D.depth);
}
}
@@ -341,42 +406,68 @@ int test_copy_image_set_2D_3D( cl_device_id device, cl_context context, cl_comma
// image, the result array, plus offset arrays, will fit in the global ram space
do
{
dstImageInfo.width = (size_t)random_log_in_range( 16, (int)max3DWidth / 32, seed );
dstImageInfo.height = (size_t)random_log_in_range( 16, (int)max3DHeight / 32, seed );
dstImageInfo.depth = (size_t)random_log_in_range( 16, (int)max3DDepth / 32, seed );
srcImageInfo.width = (size_t)random_log_in_range( 16, (int)maxWidth / 32, seed );
srcImageInfo.height = (size_t)random_log_in_range( 16, (int)maxHeight / 32, seed );
imageInfo3D.width =
(size_t)random_log_in_range(16, (int)max3DWidth / 32, seed);
imageInfo3D.height = (size_t)random_log_in_range(
16, (int)max3DHeight / 32, seed);
imageInfo3D.depth =
(size_t)random_log_in_range(16, (int)max3DDepth / 32, seed);
imageInfo2D.width =
(size_t)random_log_in_range(16, (int)maxWidth / 32, seed);
imageInfo2D.height =
(size_t)random_log_in_range(16, (int)maxHeight / 32, seed);
if (gTestMipmaps)
{
srcImageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(srcImageInfo.width, srcImageInfo.height, 0), seed);
srcImageInfo.type = CL_MEM_OBJECT_IMAGE2D;
dstImageInfo.num_mip_levels = (cl_uint) random_log_in_range(2, (int)compute_max_mip_levels(dstImageInfo.width, dstImageInfo.height, dstImageInfo.depth), seed);
dstImageInfo.type = CL_MEM_OBJECT_IMAGE3D;
srcImageInfo.rowPitch = srcImageInfo.width * get_pixel_size( srcImageInfo.format );
srcImageInfo.slicePitch = 0;
dstImageInfo.rowPitch = dstImageInfo.width * get_pixel_size( dstImageInfo.format );
dstImageInfo.slicePitch = dstImageInfo.rowPitch * dstImageInfo.height;
srcSize = 4 * compute_mipmapped_image_size( srcImageInfo );
dstSize = 4 * compute_mipmapped_image_size( dstImageInfo );
imageInfo2D.num_mip_levels = (cl_uint)random_log_in_range(
2,
(int)compute_max_mip_levels(imageInfo2D.width,
imageInfo2D.height, 0),
seed);
imageInfo3D.num_mip_levels = (cl_uint)random_log_in_range(
2,
(int)compute_max_mip_levels(imageInfo3D.width,
imageInfo3D.height,
imageInfo3D.depth),
seed);
imageInfo2D.rowPitch =
imageInfo2D.width * get_pixel_size(imageInfo2D.format);
imageInfo2D.slicePitch = 0;
imageInfo3D.rowPitch =
imageInfo3D.width * get_pixel_size(imageInfo3D.format);
imageInfo3D.slicePitch =
imageInfo3D.rowPitch * imageInfo3D.height;
srcSize = 4 * compute_mipmapped_image_size(imageInfo2D);
dstSize = 4 * compute_mipmapped_image_size(imageInfo3D);
}
else
{
set_image_dimensions( &srcImageInfo, srcImageInfo.width, srcImageInfo.height, 0, rowPadding, slicePadding );
set_image_dimensions( &dstImageInfo, dstImageInfo.width, dstImageInfo.height, dstImageInfo.depth, rowPadding, slicePadding );
set_image_dimensions(&imageInfo2D, imageInfo2D.width,
imageInfo2D.height, 0, rowPadding,
slicePadding);
set_image_dimensions(&imageInfo3D, imageInfo3D.width,
imageInfo3D.height, imageInfo3D.depth,
rowPadding, slicePadding);
srcSize = (cl_ulong)srcImageInfo.rowPitch * (cl_ulong)srcImageInfo.height * 4;
dstSize = (cl_ulong)dstImageInfo.slicePitch * (cl_ulong)dstImageInfo.depth * 4;
srcSize = (cl_ulong)imageInfo2D.rowPitch
* (cl_ulong)imageInfo2D.height * 4;
dstSize = (cl_ulong)imageInfo3D.slicePitch
* (cl_ulong)imageInfo3D.depth * 4;
}
} while( srcSize > maxAllocSize || ( srcSize * 3 ) > memSize || dstSize > maxAllocSize || ( dstSize * 3 ) > memSize);
if( gDebugTrace )
log_info( " at size %d,%d to %d,%d,%d\n", (int)srcImageInfo.width, (int)srcImageInfo.height, (int)dstImageInfo.width, (int)dstImageInfo.height, (int)dstImageInfo.depth );
log_info(" at size %d,%d to %d,%d,%d\n",
(int)imageInfo2D.width, (int)imageInfo2D.height,
(int)imageInfo3D.width, (int)imageInfo3D.height,
(int)imageInfo3D.depth);
int ret;
if( reverse )
ret = test_copy_image_size_2D_3D( context, queue, &dstImageInfo, &srcImageInfo, seed );
ret = test_copy_image_size_2D_3D(context, queue, &imageInfo3D,
&imageInfo2D, seed);
else
ret = test_copy_image_size_2D_3D( context, queue, &srcImageInfo, &dstImageInfo, seed );
ret = test_copy_image_size_2D_3D(context, queue, &imageInfo2D,
&imageInfo3D, seed);
if( ret )
return -1;
}