Fix write-only image tests in kernel_image_methods (#330) (#1014)

Pass the right flags to the tests that create images to ensure valid
usage.

Fixes issue #330

Signed-off-by: James Morrissey <james.morrissey@arm.com>

Co-authored-by: Alessandro Navone <alessandro.navone@arm.com>
This commit is contained in:
james-morrissey-arm
2020-11-21 08:33:04 +00:00
committed by GitHub
parent 993447a74a
commit 5bd85b7384
6 changed files with 227 additions and 131 deletions

View File

@@ -27,24 +27,28 @@ struct image_kernel_data
};
static const char *methodTest1DImageKernelPattern =
"typedef struct {\n"
" int width;\n"
" int channelType;\n"
" int channelOrder;\n"
" int expectedChannelType;\n"
" int expectedChannelOrder;\n"
" } image_kernel_data;\n"
"__kernel void sample_kernel( read_only image1d_t input, __global image_kernel_data *outData )\n"
"{\n"
" outData->width = get_image_width( input );\n"
" outData->channelType = get_image_channel_data_type( input );\n"
" outData->channelOrder = get_image_channel_order( input );\n"
"\n"
" outData->expectedChannelType = %s;\n"
" outData->expectedChannelOrder = %s;\n"
"}";
"typedef struct {\n"
" int width;\n"
" int channelType;\n"
" int channelOrder;\n"
" int expectedChannelType;\n"
" int expectedChannelOrder;\n"
" } image_kernel_data;\n"
"__kernel void sample_kernel( %s image1d_t input, __global "
"image_kernel_data *outData )\n"
"{\n"
" outData->width = get_image_width( input );\n"
" outData->channelType = get_image_channel_data_type( input );\n"
" outData->channelOrder = get_image_channel_order( input );\n"
"\n"
" outData->expectedChannelType = %s;\n"
" outData->expectedChannelOrder = %s;\n"
"}";
static int test_get_1Dimage_info_single( cl_context context, cl_command_queue queue, image_descriptor *imageInfo, MTdata d )
static int test_get_1Dimage_info_single(cl_context context,
cl_command_queue queue,
image_descriptor *imageInfo, MTdata d,
cl_mem_flags flags)
{
int error = 0;
@@ -62,7 +66,9 @@ static int test_get_1Dimage_info_single( cl_context context, cl_command_queue qu
// Construct testing source
if( gDebugTrace )
log_info( " - Creating 1D image %d ...\n", (int)imageInfo->width );
image = create_image_1d( context, (cl_mem_flags)(CL_MEM_READ_ONLY), imageInfo->format, imageInfo->width, 0, NULL, NULL, &error );
image = create_image_1d(context, flags, imageInfo->format, imageInfo->width,
0, NULL, NULL, &error);
if( image == NULL )
{
log_error( "ERROR: Unable to create 1D image of size %d (%s)", (int)imageInfo->width, IGetErrorString( error ) );
@@ -74,6 +80,8 @@ static int test_get_1Dimage_info_single( cl_context context, cl_command_queue qu
const char* channelTypeName = GetChannelTypeName( imageInfo->format->image_channel_data_type );
const char* channelOrderName = GetChannelOrderName( imageInfo->format->image_channel_order );
const char *image_access_qualifier =
(flags == CL_MEM_READ_ONLY) ? "read_only" : "write_only";
if(channelTypeName && strlen(channelTypeName))
sprintf(channelTypeConstantString, "CLK_%s", &channelTypeName[3]); // replace CL_* with CLK_*
@@ -82,7 +90,7 @@ static int test_get_1Dimage_info_single( cl_context context, cl_command_queue qu
sprintf(channelOrderConstantString, "CLK_%s", &channelOrderName[3]); // replace CL_* with CLK_*
// Create a program to run against
sprintf( programSrc, methodTest1DImageKernelPattern,
sprintf(programSrc, methodTest1DImageKernelPattern, image_access_qualifier,
channelTypeConstantString, channelOrderConstantString);
//log_info("-----------------------------------\n%s\n", programSrc);
@@ -141,7 +149,9 @@ static int test_get_1Dimage_info_single( cl_context context, cl_command_queue qu
return error;
}
int test_get_image_info_1D( cl_device_id device, cl_context context, cl_command_queue queue, cl_image_format *format )
int test_get_image_info_1D(cl_device_id device, cl_context context,
cl_command_queue queue, cl_image_format *format,
cl_mem_flags flags)
{
size_t maxWidth;
cl_ulong maxAllocSize, memSize;
@@ -171,7 +181,8 @@ int test_get_image_info_1D( cl_device_id device, cl_context context, cl_command_
if( gDebugTrace )
log_info( " at size %d\n", (int)imageInfo.width );
int ret = test_get_1Dimage_info_single( context, queue, &imageInfo, seed );
int ret = test_get_1Dimage_info_single(context, queue, &imageInfo,
seed, flags);
if( ret )
return -1;
}
@@ -192,7 +203,8 @@ int test_get_image_info_1D( cl_device_id device, cl_context context, cl_command_
log_info( "Testing %d\n", (int)sizes[ idx ][ 0 ]);
if( gDebugTrace )
log_info( " at max size %d\n", (int)sizes[ idx ][ 0 ] );
if( test_get_1Dimage_info_single( context, queue, &imageInfo, seed ) )
if (test_get_1Dimage_info_single(context, queue, &imageInfo, seed,
flags))
return -1;
}
}
@@ -221,7 +233,8 @@ int test_get_image_info_1D( cl_device_id device, cl_context context, cl_command_
if( gDebugTrace )
log_info( " at size %d (row pitch %d) out of %d\n", (int)imageInfo.width, (int)imageInfo.rowPitch, (int)maxWidth );
int ret = test_get_1Dimage_info_single( context, queue, &imageInfo, seed );
int ret = test_get_1Dimage_info_single(context, queue, &imageInfo,
seed, flags);
if( ret )
return -1;
}