Test IMAGE1D_BUFFER in more scenario (#1806)

* cl_copy_images

* cl_get_info

* cl_fill_image

* cl_read_write_image

* kernel_image_methods

* IMAGE1D_BUFFER cannot be created with (USE_|ALLOC_|COPY_)_HOST_PTR

* do not allow mipmap with 1D buffer

* adjust M to be within maximum_sizes and max_pixels

* remove unused variables

* make sure M will never be 0

* fix region[0] after refactoring removing mipmap

* fix formatting

* format with clang-format-11

* fix image1d_buffer creation with gEnablePitch

* add missing case in switch

* use align_malloc when CL version is at least 2.0

* use CL_DEVICE_NUMERIC_VERSION and align_free

* fix free of pitch buffer

* fix formatting

* fix formatting

* fix data->is_aligned
This commit is contained in:
Romaric Jodin
2024-04-16 17:48:05 +02:00
committed by GitHub
parent 7fa567c7a5
commit be8b56d949
25 changed files with 1838 additions and 87 deletions

View File

@@ -7,6 +7,7 @@ set(${MODULE_NAME}_SOURCES
test_2D.cpp
test_loops.cpp
test_3D.cpp
test_1D_buffer.cpp
../common.cpp
)

View File

@@ -54,13 +54,15 @@ int test_2Darray(cl_device_id device, cl_context context, cl_command_queue queue
{
return test_image_set( device, context, CL_MEM_OBJECT_IMAGE2D_ARRAY );
}
int test_1Dbuffer(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements)
{
return test_image_set(device, context, CL_MEM_OBJECT_IMAGE1D_BUFFER);
}
test_definition test_list[] = {
ADD_TEST( 1D ),
ADD_TEST( 2D ),
ADD_TEST( 3D ),
ADD_TEST( 1Darray ),
ADD_TEST( 2Darray ),
ADD_TEST(1D), ADD_TEST(2D), ADD_TEST(3D),
ADD_TEST(1Darray), ADD_TEST(2Darray), ADD_TEST(1Dbuffer),
};
const int test_num = ARRAY_SIZE( test_list );

View File

@@ -0,0 +1,128 @@
//
// Copyright (c) 2023 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "../testBase.h"
#include <CL/cl.h>
extern int test_get_image_info_single(cl_context context,
image_descriptor *imageInfo, MTdata d,
cl_mem_flags flags, size_t row_pitch,
size_t slice_pitch);
int test_get_image_info_1D_buffer(cl_device_id device, cl_context context,
cl_image_format *format, cl_mem_flags flags)
{
size_t maxWidth;
cl_ulong maxAllocSize, memSize;
image_descriptor imageInfo = { 0 };
RandomSeed seed(gRandomSeed);
size_t pixelSize;
memset(&imageInfo, 0x0, sizeof(image_descriptor));
imageInfo.type = CL_MEM_OBJECT_IMAGE1D_BUFFER;
imageInfo.format = format;
pixelSize = get_pixel_size(imageInfo.format);
int error = clGetDeviceInfo(device, CL_DEVICE_IMAGE_MAX_BUFFER_SIZE,
sizeof(maxWidth), &maxWidth, NULL);
error |= clGetDeviceInfo(device, CL_DEVICE_MAX_MEM_ALLOC_SIZE,
sizeof(maxAllocSize), &maxAllocSize, NULL);
error |= clGetDeviceInfo(device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof(memSize),
&memSize, NULL);
test_error(error, "Unable to get max image 1D size from device");
if (memSize > (cl_ulong)SIZE_MAX)
{
memSize = (cl_ulong)SIZE_MAX;
maxAllocSize = (cl_ulong)SIZE_MAX;
}
if (gTestSmallImages)
{
for (imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++)
{
imageInfo.rowPitch = imageInfo.width * pixelSize;
if (gDebugTrace)
log_info(" at size %d (flags 0x%x pitch %d)\n",
(int)imageInfo.width, (unsigned int)flags,
(int)imageInfo.rowPitch);
if (test_get_image_info_single(context, &imageInfo, seed, flags, 0,
0))
return -1;
}
}
else if (gTestMaxImages)
{
// Try a specific set of maximum sizes
size_t numbeOfSizes;
size_t sizes[100][3];
get_max_sizes(&numbeOfSizes, 100, sizes, maxWidth, 1, 1, 1,
maxAllocSize, memSize, CL_MEM_OBJECT_IMAGE1D_BUFFER,
imageInfo.format);
for (size_t idx = 0; idx < numbeOfSizes; idx++)
{
imageInfo.width = sizes[idx][0];
imageInfo.rowPitch = imageInfo.width * pixelSize;
log_info("Testing %d x 1\n", (int)sizes[idx][0]);
if (gDebugTrace)
log_info(" at max size %d (flags 0x%x pitch %d)\n",
(int)imageInfo.width, (unsigned int)flags,
(int)imageInfo.rowPitch);
if (test_get_image_info_single(context, &imageInfo, seed, flags, 0,
0))
return -1;
}
}
else
{
for (int i = 0; i < NUM_IMAGE_ITERATIONS; i++)
{
cl_ulong size;
// Loop until we get a size that a) will fit in the max alloc size
// and b) that an allocation of that image, the result array, plus
// offset arrays, will fit in the global ram space
do
{
imageInfo.width =
(size_t)random_log_in_range(16, (int)maxWidth / 32, seed);
imageInfo.rowPitch = imageInfo.width * pixelSize;
size_t extraWidth = (int)random_log_in_range(0, 64, seed);
imageInfo.rowPitch += extraWidth;
do
{
extraWidth++;
imageInfo.rowPitch += extraWidth;
} while ((imageInfo.rowPitch % pixelSize) != 0);
size = (cl_ulong)imageInfo.rowPitch * 4;
} while (size > maxAllocSize || (size * 3) > memSize);
if (gDebugTrace)
log_info(" at size %d (flags 0x%x pitch %d) out of %d\n",
(int)imageInfo.width, (unsigned int)flags,
(int)imageInfo.rowPitch, (int)maxWidth);
if (test_get_image_info_single(context, &imageInfo, seed, flags, 0,
0))
return -1;
}
}
return 0;
}

View File

@@ -19,6 +19,7 @@ int test_get_image_info_single( cl_context context, image_descriptor *imageInfo,
{
int error;
clMemWrapper image;
clMemWrapper buffer;
cl_image_desc imageDesc;
void *host_ptr = NULL;
@@ -69,6 +70,24 @@ int test_get_image_info_single( cl_context context, image_descriptor *imageInfo,
if ( gDebugTrace )
log_info( " - Creating 2D image array %d by %d by %d with flags=0x%lx row_pitch=%d slice_pitch=%d host_ptr=%p...\n", (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->arraySize, (unsigned long)flags, (int)row_pitch, (int)slice_pitch, host_ptr );
break;
case CL_MEM_OBJECT_IMAGE1D_BUFFER:
if (gDebugTrace)
log_info(" - Creating 1D buffer image %d with flags=0x%lx "
"row_pitch=%d slice_pitch=%d host_ptr=%p...\n",
(int)imageInfo->width, (unsigned long)flags,
(int)row_pitch, (int)slice_pitch, host_ptr);
int err;
buffer = clCreateBuffer(context, flags, imageInfo->rowPitch,
host_ptr, &err);
if (err != CL_SUCCESS)
{
log_error("ERROR: Unable to create buffer for 1D image buffer "
"of size %d (%s)",
(int)imageInfo->rowPitch, IGetErrorString(err));
return -1;
}
imageDesc.buffer = imageInfo->buffer = buffer;
break;
}
image = clCreateImage(context, flags, imageInfo->format, &imageDesc, host_ptr, &error);
@@ -92,6 +111,11 @@ int test_get_image_info_single( cl_context context, image_descriptor *imageInfo,
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
log_error( "ERROR: Unable to create 2D image array of size %d x %d x %d (%s)", (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->arraySize, IGetErrorString( error ) );
break;
case CL_MEM_OBJECT_IMAGE1D_BUFFER:
log_error(
"ERROR: Unable to create 1D image buffer of size %d (%s)",
(int)imageInfo->width, IGetErrorString(error));
break;
}
return -1;
}
@@ -148,6 +172,7 @@ int test_get_image_info_single( cl_context context, image_descriptor *imageInfo,
switch (imageInfo->type)
{
case CL_MEM_OBJECT_IMAGE1D:
case CL_MEM_OBJECT_IMAGE1D_BUFFER:
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
required_height = 0;
break;
@@ -175,8 +200,7 @@ int test_get_image_info_single( cl_context context, image_descriptor *imageInfo,
case CL_MEM_OBJECT_IMAGE2D:
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
required_depth = 0;
break;
case CL_MEM_OBJECT_IMAGE1D_BUFFER: required_depth = 0; break;
case CL_MEM_OBJECT_IMAGE3D:
required_depth = imageInfo->depth;
break;
@@ -198,8 +222,7 @@ int test_get_image_info_single( cl_context context, image_descriptor *imageInfo,
case CL_MEM_OBJECT_IMAGE1D:
case CL_MEM_OBJECT_IMAGE2D:
case CL_MEM_OBJECT_IMAGE3D:
required_array_size = 0;
break;
case CL_MEM_OBJECT_IMAGE1D_BUFFER: required_array_size = 0; break;
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
required_array_size = imageInfo->arraySize;

View File

@@ -21,6 +21,10 @@ extern int test_get_image_info_2D( cl_device_id device, cl_context context, cl_i
extern int test_get_image_info_3D( cl_device_id device, cl_context context, cl_image_format *format, cl_mem_flags flags );
extern int test_get_image_info_1D_array( cl_device_id device, cl_context context, cl_image_format *format, cl_mem_flags flags );
extern int test_get_image_info_2D_array( cl_device_id device, cl_context context, cl_image_format *format, cl_mem_flags flags );
extern int test_get_image_info_1D_buffer(cl_device_id device,
cl_context context,
cl_image_format *format,
cl_mem_flags flags);
int test_image_type( cl_device_id device, cl_context context, cl_mem_object_type image_type, cl_mem_flags flags )
{
@@ -66,6 +70,10 @@ int test_image_type( cl_device_id device, cl_context context, cl_mem_object_type
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
test_return = test_get_image_info_2D_array( device, context, &formatList[ i ], flags );
break;
case CL_MEM_OBJECT_IMAGE1D_BUFFER:
test_return = test_get_image_info_1D_buffer(
device, context, &formatList[i], flags);
break;
}
if (test_return) {