Enable -Wnarrowing for the basic test suite (#2467)

Fixes #1156

---------

Signed-off-by: Ahmed Hesham <ahmed.hesham@arm.com>
This commit is contained in:
Ahmed Hesham
2025-07-31 12:24:03 +01:00
committed by GitHub
parent 77a987d547
commit 044e0be653
16 changed files with 73 additions and 63 deletions

View File

@@ -1,9 +1,5 @@
set(MODULE_NAME BASIC)
if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?Clang")
add_cxx_flag_if_supported(-Wno-narrowing)
endif()
set(${MODULE_NAME}_SOURCES
main.cpp
test_fpmath.cpp

View File

@@ -161,7 +161,7 @@ REGISTER_TEST(arraycopy)
err |= clSetKernelArg(kernel, 1, sizeof results, &results);
test_error(err, "clSetKernelArg failed");
size_t threads[3] = { num_elements, 0, 0 };
size_t threads[3] = { static_cast<size_t>(num_elements), 0, 0 };
err = clEnqueueNDRangeKernel( queue, kernel, 1, NULL, threads, NULL, 0, NULL, NULL );
test_error(err, "clEnqueueNDRangeKernel failed");

View File

@@ -35,9 +35,9 @@ static int test_arrayimagecopy_single_format(
std::unique_ptr<cl_uchar, decltype(&free)> bufptr{ nullptr, free },
imgptr{ nullptr, free };
clMemWrapper buffer, image;
int img_width = 512;
int img_height = 512;
int img_depth = (image_type == CL_MEM_OBJECT_IMAGE3D) ? 32 : 1;
size_t img_width = 512;
size_t img_height = 512;
size_t img_depth = (image_type == CL_MEM_OBJECT_IMAGE3D) ? 32 : 1;
size_t elem_size;
size_t buffer_size;
cl_int err;

View File

@@ -100,8 +100,8 @@ REGISTER_TEST(hostptr)
cl_image_format img_format;
cl_uchar *rgba8_inptr, *rgba8_outptr;
void *lock_buffer;
int img_width = 512;
int img_height = 512;
size_t img_width = 512;
size_t img_height = 512;
cl_int err;
MTdata d;
RoundingMode oldRoundMode;

View File

@@ -56,8 +56,9 @@ __kernel void test_if(__global int *src, __global int *dst)
int verify_if(std::vector<cl_int> input, std::vector<cl_int> output)
{
const cl_int results[] = {
0x12345678, 0x23456781, 0x34567812, 0x45678123,
0x56781234, 0x67812345, 0x78123456, 0x81234567,
(cl_int)0x12345678, (cl_int)0x23456781, (cl_int)0x34567812,
(cl_int)0x45678123, (cl_int)0x56781234, (cl_int)0x67812345,
(cl_int)0x78123456, (cl_int)0x81234567,
};
auto predicate = [&results](cl_int a, cl_int b) {

View File

@@ -144,8 +144,8 @@ verify_byte_image(unsigned char *image, unsigned char *outptr, int w, int h, int
REGISTER_TEST(image_multipass_integer_coord)
{
int img_width = 512;
int img_height = 512;
size_t img_width = 512;
size_t img_height = 512;
cl_image_format img_format;
int num_input_streams = 8;
@@ -397,8 +397,8 @@ REGISTER_TEST(image_multipass_integer_coord)
REGISTER_TEST(image_multipass_float_coord)
{
int img_width = 512;
int img_height = 512;
size_t img_width = 512;
size_t img_height = 512;
cl_image_format img_format;
int num_input_streams = 8;

View File

@@ -35,9 +35,9 @@ static int test_imagearraycopy_single_format(
std::unique_ptr<cl_uchar, decltype(&free)> bufptr{ nullptr, free },
imgptr{ nullptr, free };
clMemWrapper buffer, image;
const int img_width = 512;
const int img_height = 512;
const int img_depth = (image_type == CL_MEM_OBJECT_IMAGE3D) ? 32 : 1;
const size_t img_width = 512;
const size_t img_height = 512;
const size_t img_depth = (image_type == CL_MEM_OBJECT_IMAGE3D) ? 32 : 1;
size_t elem_size;
size_t buffer_size;
cl_int err;

View File

@@ -111,8 +111,8 @@ static int test_imagecopy_impl(cl_device_id device, cl_context context,
std::unique_ptr<unsigned short[]> rgba16_inptr, rgba16_outptr;
std::unique_ptr<float[]> rgbafp_inptr, rgbafp_outptr;
clMemWrapper streams[6];
int img_width = 512;
int img_height = 512;
size_t img_width = 512;
size_t img_height = 512;
int i, err;
MTdataHolder d(gRandomSeed);
@@ -153,7 +153,7 @@ static int test_imagecopy_impl(cl_device_id device, cl_context context,
for (i = 0; i < 3; i++)
{
void *p, *outp;
int x, y, delta_w = img_width / 8, delta_h = img_height / 16;
size_t x, y, delta_w = img_width / 8, delta_h = img_height / 16;
switch (i)
{
@@ -197,8 +197,9 @@ static int test_imagecopy_impl(cl_device_id device, cl_context context,
copy_origin, copy_region, 0, NULL, NULL);
if (err)
{
log_error("Copy %d (origin [%d, %d], size [%d, %d], image "
"size [%d x %d]) Failed\n",
log_error(
"Copy %d (origin [%zu, %zu], size [%zu, %zu], image "
"size [%zu x %zu]) Failed\n",
copy_number, x, y, delta_w, delta_h, img_width,
img_height);
}

View File

@@ -115,9 +115,9 @@ static int test_imagecopy3d_impl(cl_device_id device, cl_context context,
std::unique_ptr<unsigned short[]> rgba16_inptr, rgba16_outptr;
std::unique_ptr<float[]> rgbafp_inptr, rgbafp_outptr;
clMemWrapper streams[6];
int img_width = 128;
int img_height = 128;
int img_depth = 64;
size_t img_width = 128;
size_t img_height = 128;
size_t img_depth = 64;
int i;
cl_int err;
unsigned num_elements = img_width * img_height * img_depth * 4;

View File

@@ -82,8 +82,8 @@ REGISTER_TEST(imagenpot)
cl_kernel kernel;
size_t global_threads[3], local_threads[3];
size_t local_workgroup_size;
int img_width;
int img_height;
size_t img_width;
size_t img_height;
int err;
cl_uint m;
size_t max_local_workgroup_size[3];

View File

@@ -123,15 +123,15 @@ REGISTER_TEST(imagerandomcopy)
unsigned short *rgba16_inptr, *rgba16_outptr;
float *rgbafp_inptr, *rgbafp_outptr;
clMemWrapper streams[6];
int img_width = 512;
int img_height = 512;
size_t img_width = 512;
size_t img_height = 512;
int i, j;
cl_int err;
MTdata d;
PASSIVE_REQUIRE_IMAGE_SUPPORT( device )
log_info("Testing with image %d x %d.\n", img_width, img_height);
log_info("Testing with image %zu x %zu.\n", img_width, img_height);
d = init_genrand( gRandomSeed );
rgba8_inptr = (unsigned char *)generate_rgba8_image(img_width, img_height, d);
@@ -191,8 +191,8 @@ REGISTER_TEST(imagerandomcopy)
}
size_t origin[3]={0,0,0}, region[3]={img_width, img_height,1};
err = clEnqueueWriteImage(queue, streams[i*2], CL_TRUE, origin, region, 0, 0, p, 0, NULL, NULL);
// err = clWriteImage(context, streams[i*2], false, 0, 0, 0, img_width, img_height, 0, NULL, 0, 0, p, NULL);
err = clEnqueueWriteImage(queue, streams[i * 2], CL_TRUE, origin,
region, 0, 0, p, 0, NULL, NULL);
test_error(err, "clEnqueueWriteImage failed");
for (j=0; j<NUM_COPIES; j++)

View File

@@ -195,8 +195,8 @@ REGISTER_TEST(imagereadwrite)
std::unique_ptr<unsigned short[]> rgba16_inptr, rgba16_outptr;
std::unique_ptr<float[]> rgbafp_inptr, rgbafp_outptr;
clMemWrapper streams[3];
int img_width = 512;
int img_height = 512;
size_t img_width = 512;
size_t img_height = 512;
int num_tries = 200;
int i, j, err;
MTdataHolder d(gRandomSeed);
@@ -242,10 +242,10 @@ REGISTER_TEST(imagereadwrite)
for (i = 0, j = 0; i < num_tries * image_formats_count; i++, j++)
{
int x = (int)get_random_float(0, img_width, d);
int y = (int)get_random_float(0, img_height, d);
int w = (int)get_random_float(1, (img_width - x), d);
int h = (int)get_random_float(1, (img_height - y), d);
size_t x = (size_t)get_random_float(0, img_width, d);
size_t y = (size_t)get_random_float(0, img_height, d);
size_t w = (size_t)get_random_float(1, (img_width - x), d);
size_t h = (size_t)get_random_float(1, (img_height - y), d);
size_t input_pitch;
int set_input_pitch = (int)(genrand_int32(d) & 0x01);
int packed_update = (int)(genrand_int32(d) & 0x01);
@@ -386,7 +386,8 @@ REGISTER_TEST(imagereadwrite)
img_width, img_height);
if (err)
{
log_error("x=%d y=%d w=%d h=%d, pitch=%d, try=%d\n", x, y, w, h, (int)input_pitch, (int)i);
log_error("x=%zu y=%zu w=%zu h=%zu, pitch=%d, try=%d\n", x,
y, w, h, (int)input_pitch, (int)i);
log_error("IMAGE RGBA8 read, write %s test failed\n", update_packed_pitch_name);
}
break;
@@ -396,7 +397,8 @@ REGISTER_TEST(imagereadwrite)
img_width, img_height);
if (err)
{
log_error("x=%d y=%d w=%d h=%d, pitch=%d, try=%d\n", x, y, w, h, (int)input_pitch, (int)i);
log_error("x=%zu y=%zu w=%zu h=%zu, pitch=%d, try=%d\n", x,
y, w, h, (int)input_pitch, (int)i);
log_error("IMAGE RGBA16 read, write %s test failed\n", update_packed_pitch_name);
}
break;
@@ -406,7 +408,8 @@ REGISTER_TEST(imagereadwrite)
img_width, img_height);
if (err)
{
log_error("x=%d y=%d w=%d h=%d, pitch=%d, try=%d\n", x, y, w, h, (int)input_pitch, (int)i);
log_error("x=%zu y=%zu w=%zu h=%zu, pitch=%d, try=%d\n", x,
y, w, h, (int)input_pitch, (int)i);
log_error("IMAGE RGBA FP read, write %s test failed\n", update_packed_pitch_name);
}
break;

View File

@@ -205,10 +205,10 @@ REGISTER_TEST(imagereadwrite3d)
std::unique_ptr<unsigned short[]> rgba16_inptr, rgba16_outptr;
std::unique_ptr<float[]> rgbafp_inptr, rgbafp_outptr;
clMemWrapper streams[3];
int img_width = 64;
int img_height = 64;
int img_depth = 32;
int img_slice = img_width * img_height;
size_t img_width = 64;
size_t img_height = 64;
size_t img_depth = 32;
size_t img_slice = img_width * img_height;
int num_tries = 30;
int i, j, err;
MTdataHolder mtData(gRandomSeed);
@@ -257,12 +257,12 @@ REGISTER_TEST(imagereadwrite3d)
for (i = 0, j = 0; i < num_tries * image_formats_count; i++, j++)
{
int x = (int)get_random_float(0, (float)img_width - 1, mtData);
int y = (int)get_random_float(0, (float)img_height - 1, mtData);
int z = (int)get_random_float(0, (float)img_depth - 1, mtData);
int w = (int)get_random_float(1, (float)(img_width - x), mtData);
int h = (int)get_random_float(1, (float)(img_height - y), mtData);
int d = (int)get_random_float(1, (float)(img_depth - z), mtData);
size_t x = (size_t)get_random_float(0, (float)img_width - 1, mtData);
size_t y = (size_t)get_random_float(0, (float)img_height - 1, mtData);
size_t z = (size_t)get_random_float(0, (float)img_depth - 1, mtData);
size_t w = (size_t)get_random_float(1, (float)(img_width - x), mtData);
size_t h = (size_t)get_random_float(1, (float)(img_height - y), mtData);
size_t d = (size_t)get_random_float(1, (float)(img_depth - z), mtData);
size_t input_pitch, input_slice_pitch;
int set_input_pitch = (int)(genrand_int32(mtData) & 0x01);
int packed_update = (int)(genrand_int32(mtData) & 0x01);
@@ -401,7 +401,10 @@ REGISTER_TEST(imagereadwrite3d)
img_width, img_height, img_depth);
if (err)
{
log_error("x=%d y=%d z=%d w=%d h=%d d=%d pitch=%d, slice_pitch=%d, try=%d\n", x, y, z, w, h, d, (int)input_pitch, (int)input_slice_pitch, (int)i);
log_error("x=%zu y=%zu z=%zu w=%zu h=%zu d=%zu pitch=%d, "
"slice_pitch=%d, try=%d\n",
x, y, z, w, h, d, (int)input_pitch,
(int)input_slice_pitch, (int)i);
log_error("IMAGE RGBA8 read, write %s test failed\n", update_packed_pitch_name);
}
break;
@@ -411,7 +414,10 @@ REGISTER_TEST(imagereadwrite3d)
img_width, img_height, img_depth);
if (err)
{
log_error("x=%d y=%d z=%d w=%d h=%d d=%d pitch=%d, slice_pitch=%d, try=%d\n", x, y, z, w, h, d, (int)input_pitch, (int)input_slice_pitch, (int)i);
log_error("x=%zu y=%zu z=%zu w=%zu h=%zu d=%zu pitch=%d, "
"slice_pitch=%d, try=%d\n",
x, y, z, w, h, d, (int)input_pitch,
(int)input_slice_pitch, (int)i);
log_error("IMAGE RGBA16 read, write %s test failed\n", update_packed_pitch_name);
}
break;
@@ -421,7 +427,10 @@ REGISTER_TEST(imagereadwrite3d)
img_width, img_height, img_depth);
if (err)
{
log_error("x=%d y=%d z=%d w=%d h=%d d=%d pitch=%d, slice_pitch=%d, try=%d\n", x, y, z, w, h, d, (int)input_pitch, (int)input_slice_pitch, (int)i);
log_error("x=%zu y=%zu z=%zu w=%zu h=%zu d=%zu pitch=%d, "
"slice_pitch=%d, try=%d\n",
x, y, z, w, h, d, (int)input_pitch,
(int)input_slice_pitch, (int)i);
log_error("IMAGE RGBA FP read, write %s test failed\n", update_packed_pitch_name);
}
break;

View File

@@ -66,7 +66,7 @@ REGISTER_TEST(kernel_call_kernel_function)
clKernelWrapper kernel1, kernel2, kernel_to_call;
clMemWrapper streams[2];
size_t threads[] = {num_elements,1,1};
size_t threads[] = { static_cast<size_t>(num_elements), 1, 1 };
cl_int *input, *output, *expected;
cl_int times = 4;
int pass = 0;

View File

@@ -117,8 +117,8 @@ REGISTER_TEST(mri_multiple)
cl_program program;
cl_kernel kernel;
size_t threads[2];
int img_width = 512;
int img_height = 512;
size_t img_width = 512;
size_t img_height = 512;
int i, err;
MTdata d;

View File

@@ -100,8 +100,8 @@ REGISTER_TEST(mri_one)
cl_program program;
cl_kernel kernel;
size_t threads[2];
int img_width = 512;
int img_height = 512;
size_t img_width = 512;
size_t img_height = 512;
int i, err;
size_t origin[3] = {0, 0, 0};
size_t region[3] = {img_width, img_height, 1};