mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-24 15:59:03 +00:00
Initial open source release of OpenCL 2.0 CTS.
This commit is contained in:
26
test_conformance/images/clFillImage/CMakeLists.txt
Normal file
26
test_conformance/images/clFillImage/CMakeLists.txt
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
set(MODULE_NAME CL_FILL_IMAGES)
|
||||
|
||||
set(${MODULE_NAME}_SOURCES
|
||||
main.cpp
|
||||
test_fill_1D.cpp
|
||||
test_fill_1D_array.cpp
|
||||
test_fill_2D.cpp
|
||||
test_fill_2D_array.cpp
|
||||
test_fill_generic.cpp
|
||||
test_loops.cpp
|
||||
test_fill_3D.cpp
|
||||
# test_fill_2D_3D.cpp
|
||||
../../../test_common/harness/testHarness.c
|
||||
../../../test_common/harness/errorHelpers.c
|
||||
../../../test_common/harness/threadTesting.c
|
||||
../../../test_common/harness/kernelHelpers.c
|
||||
../../../test_common/harness/imageHelpers.cpp
|
||||
../../../test_common/harness/mt19937.c
|
||||
../../../test_common/harness/conversions.c
|
||||
../../../test_common/harness/typeWrappers.cpp
|
||||
../../../test_common/harness/msvc9.c
|
||||
)
|
||||
|
||||
|
||||
include(../../CMakeCommon.txt)
|
||||
19
test_conformance/images/clFillImage/Jamfile
Normal file
19
test_conformance/images/clFillImage/Jamfile
Normal file
@@ -0,0 +1,19 @@
|
||||
project
|
||||
: requirements
|
||||
# <toolset>gcc:<cflags>-xc++
|
||||
# <toolset>msvc:<cflags>"/TP"
|
||||
;
|
||||
|
||||
exe test_cl_fill_images
|
||||
: main.cpp
|
||||
test_fill_2D_3D.cpp
|
||||
test_fill_2D.cpp
|
||||
test_fill_3D.cpp
|
||||
test_loops.cpp
|
||||
;
|
||||
|
||||
install dist
|
||||
: test_cl_fill_images
|
||||
: <variant>debug:<location>$(DIST)/debug/tests/test_conformance/images/clFillImage
|
||||
<variant>release:<location>$(DIST)/release/tests/test_conformance/images/clFillImage
|
||||
;
|
||||
53
test_conformance/images/clFillImage/Makefile
Normal file
53
test_conformance/images/clFillImage/Makefile
Normal file
@@ -0,0 +1,53 @@
|
||||
ifdef BUILD_WITH_ATF
|
||||
ATF = -framework ATF
|
||||
USE_ATF = -DUSE_ATF
|
||||
endif
|
||||
|
||||
SRCS = main.cpp \
|
||||
test_fill_generic.cpp \
|
||||
test_fill_1D.cpp \
|
||||
test_fill_2D.cpp \
|
||||
test_fill_3D.cpp \
|
||||
test_fill_1D_array.cpp \
|
||||
test_fill_2D_array.cpp \
|
||||
test_loops.cpp \
|
||||
../../../test_common/harness/errorHelpers.c \
|
||||
../../../test_common/harness/threadTesting.c \
|
||||
../../../test_common/harness/kernelHelpers.c \
|
||||
../../../test_common/harness/imageHelpers.cpp \
|
||||
../../../test_common/harness/conversions.c \
|
||||
../../../test_common/harness/testHarness.cpp \
|
||||
../../../test_common/harness/typeWrappers.cpp \
|
||||
../../../test_common/harness/mt19937.c
|
||||
|
||||
|
||||
DEFINES = DONT_TEST_GARBAGE_POINTERS
|
||||
|
||||
SOURCES = $(abspath $(SRCS))
|
||||
LIBPATH += -L/System/Library/Frameworks/OpenCL.framework/Libraries
|
||||
LIBPATH += -L.
|
||||
FRAMEWORK =
|
||||
HEADERS =
|
||||
TARGET = test_cl_fill_images
|
||||
INCLUDE =
|
||||
COMPILERFLAGS = -c -Wall -g -Wshorten-64-to-32 -Os
|
||||
CC = c++
|
||||
CXX = c++
|
||||
CFLAGS = $(COMPILERFLAGS) ${RC_CFLAGS} ${USE_ATF} $(DEFINES:%=-D%) $(INCLUDE)
|
||||
CXXFLAGS = $(COMPILERFLAGS) ${RC_CFLAGS} ${USE_ATF} $(DEFINES:%=-D%) $(INCLUDE)
|
||||
LIBRARIES = -framework OpenCL -framework OpenGL -framework GLUT -framework AppKit ${ATF}
|
||||
|
||||
OBJECTS := ${SOURCES:.c=.o}
|
||||
OBJECTS := ${OBJECTS:.cpp=.o}
|
||||
|
||||
TARGETOBJECT =
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJECTS)
|
||||
$(CC) $(RC_CFLAGS) $(OBJECTS) -o $@ $(LIBPATH) $(LIBRARIES)
|
||||
|
||||
clean:
|
||||
rm -f $(TARGET) $(OBJECTS)
|
||||
|
||||
.DEFAULT:
|
||||
@echo The target \"$@\" does not exist in Makefile.
|
||||
281
test_conformance/images/clFillImage/main.cpp
Normal file
281
test_conformance/images/clFillImage/main.cpp
Normal file
@@ -0,0 +1,281 @@
|
||||
//
|
||||
// Copyright (c) 2017 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 "../../../test_common/harness/compat.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(_WIN32)
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include "../testBase.h"
|
||||
#include "../../../test_common/harness/testHarness.h"
|
||||
|
||||
bool gDebugTrace = false, gTestSmallImages = false, gTestMaxImages = false, gTestRounding = false, gEnablePitch = false;
|
||||
int gTypesToTest = 0;
|
||||
cl_channel_type gChannelTypeToUse = (cl_channel_type)-1;
|
||||
cl_channel_order gChannelOrderToUse = (cl_channel_order)-1;
|
||||
cl_device_type gDeviceType = CL_DEVICE_TYPE_DEFAULT;
|
||||
cl_context context;
|
||||
cl_command_queue queue;
|
||||
static cl_device_id device;
|
||||
|
||||
extern int test_image_set( cl_device_id device, MethodsToTest testMethod );
|
||||
static void printUsage( const char *execName );
|
||||
|
||||
#define MAX_ALLOWED_STD_DEVIATION_IN_MB 8.0
|
||||
|
||||
int test_1D(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements)
|
||||
{
|
||||
return test_image_set(device, k1D);
|
||||
}
|
||||
int test_2D(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements)
|
||||
{
|
||||
return test_image_set(device, k2D);
|
||||
}
|
||||
int test_1Darray(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements)
|
||||
{
|
||||
return test_image_set(device, k1DArray);
|
||||
}
|
||||
int test_2Darray(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements)
|
||||
{
|
||||
return test_image_set(device, k2DArray);
|
||||
}
|
||||
int test_3D(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements)
|
||||
{
|
||||
return test_image_set(device, k3D);
|
||||
}
|
||||
|
||||
basefn basefn_list[] = {
|
||||
test_1D,
|
||||
test_2D,
|
||||
test_1Darray,
|
||||
test_2Darray,
|
||||
test_3D,
|
||||
};
|
||||
|
||||
const char *basefn_names[] = {
|
||||
"1D",
|
||||
"2D",
|
||||
"1Darray",
|
||||
"2Darray",
|
||||
"3D",
|
||||
};
|
||||
|
||||
ct_assert((sizeof(basefn_names) / sizeof(basefn_names[0])) == (sizeof(basefn_list) / sizeof(basefn_list[0])));
|
||||
|
||||
int num_fns = sizeof(basefn_names) / sizeof(char *);
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
cl_platform_id platform;
|
||||
cl_channel_type chanType;
|
||||
cl_channel_order chanOrder;
|
||||
bool randomize = false;
|
||||
|
||||
test_start();
|
||||
|
||||
checkDeviceTypeOverride( &gDeviceType );
|
||||
|
||||
const char ** argList = (const char **)calloc( argc, sizeof( char*) );
|
||||
|
||||
if( NULL == argList )
|
||||
{
|
||||
log_error( "Failed to allocate memory for argList array.\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
argList[0] = argv[0];
|
||||
size_t argCount = 1;
|
||||
|
||||
// Parse arguments
|
||||
for ( int i = 1; i < argc; i++ )
|
||||
{
|
||||
if ( strcmp( argv[i], "cpu" ) == 0 || strcmp( argv[i], "CL_DEVICE_TYPE_CPU" ) == 0 )
|
||||
gDeviceType = CL_DEVICE_TYPE_CPU;
|
||||
else if ( strcmp( argv[i], "gpu" ) == 0 || strcmp( argv[i], "CL_DEVICE_TYPE_GPU" ) == 0 )
|
||||
gDeviceType = CL_DEVICE_TYPE_GPU;
|
||||
else if ( strcmp( argv[i], "accelerator" ) == 0 || strcmp( argv[i], "CL_DEVICE_TYPE_ACCELERATOR" ) == 0 )
|
||||
gDeviceType = CL_DEVICE_TYPE_ACCELERATOR;
|
||||
else if ( strcmp( argv[i], "CL_DEVICE_TYPE_DEFAULT" ) == 0 )
|
||||
gDeviceType = CL_DEVICE_TYPE_DEFAULT;
|
||||
|
||||
else if ( strcmp( argv[i], "debug_trace" ) == 0 )
|
||||
gDebugTrace = true;
|
||||
|
||||
else if ( strcmp( argv[i], "small_images" ) == 0 )
|
||||
gTestSmallImages = true;
|
||||
else if ( strcmp( argv[i], "max_images" ) == 0 )
|
||||
gTestMaxImages = true;
|
||||
|
||||
else if ( strcmp( argv[i], "use_pitches" ) == 0 )
|
||||
gEnablePitch = true;
|
||||
|
||||
else if ( strcmp( argv[i], "randomize" ) == 0 )
|
||||
randomize = true;
|
||||
|
||||
else if( strcmp( argv[i], "int" ) == 0 )
|
||||
gTypesToTest |= kTestInt;
|
||||
else if( strcmp( argv[i], "uint" ) == 0 )
|
||||
gTypesToTest |= kTestUInt;
|
||||
else if( strcmp( argv[i], "float" ) == 0 )
|
||||
gTypesToTest |= kTestFloat;
|
||||
|
||||
else if ( strcmp( argv[i], "--help" ) == 0 || strcmp( argv[i], "-h" ) == 0 )
|
||||
{
|
||||
printUsage( argv[ 0 ] );
|
||||
return -1;
|
||||
}
|
||||
|
||||
else if ( ( chanType = get_channel_type_from_name( argv[i] ) ) != (cl_channel_type)-1 )
|
||||
gChannelTypeToUse = chanType;
|
||||
|
||||
else if ( ( chanOrder = get_channel_order_from_name( argv[i] ) ) != (cl_channel_order)-1 )
|
||||
gChannelOrderToUse = chanOrder;
|
||||
else
|
||||
{
|
||||
argList[argCount] = argv[i];
|
||||
argCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if ( gTypesToTest == 0 )
|
||||
gTypesToTest = kTestAllTypes;
|
||||
|
||||
// Seed the random # generators
|
||||
if ( randomize )
|
||||
{
|
||||
gRandomSeed = (cl_uint) time( NULL );
|
||||
log_info( "Random seed: %u.\n", gRandomSeed );
|
||||
gReSeed = 1;
|
||||
}
|
||||
|
||||
int error;
|
||||
// Get our platform
|
||||
error = clGetPlatformIDs(1, &platform, NULL);
|
||||
if ( error )
|
||||
{
|
||||
print_error( error, "Unable to get platform" );
|
||||
test_finish();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Get our device
|
||||
error = clGetDeviceIDs(platform, gDeviceType, 1, &device, NULL );
|
||||
if ( error )
|
||||
{
|
||||
print_error( error, "Unable to get specified device" );
|
||||
test_finish();
|
||||
return -1;
|
||||
}
|
||||
|
||||
char deviceName[ 128 ], deviceVendor[ 128 ], deviceVersion[ 128 ];
|
||||
error = clGetDeviceInfo( device, CL_DEVICE_NAME, sizeof( deviceName ), deviceName, NULL );
|
||||
error |= clGetDeviceInfo( device, CL_DEVICE_VENDOR, sizeof( deviceVendor ), deviceVendor, NULL );
|
||||
error |= clGetDeviceInfo( device, CL_DEVICE_VERSION, sizeof( deviceVersion ), deviceVersion, NULL );
|
||||
if ( error != CL_SUCCESS )
|
||||
{
|
||||
print_error( error, "Unable to get device information" );
|
||||
test_finish();
|
||||
return -1;
|
||||
}
|
||||
log_info("Using compute device: Name = %s, Vendor = %s, Version = %s\n", deviceName, deviceVendor, deviceVersion );
|
||||
|
||||
// Check for image support
|
||||
if (checkForImageSupport( device ) == CL_IMAGE_FORMAT_NOT_SUPPORTED) {
|
||||
log_info("Device does not support images. Skipping test.\n");
|
||||
test_finish();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Create a context to test with
|
||||
context = clCreateContext( NULL, 1, &device, notify_callback, NULL, &error );
|
||||
if ( error != CL_SUCCESS )
|
||||
{
|
||||
print_error( error, "Unable to create testing context" );
|
||||
test_finish();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Create a queue against the context
|
||||
queue = clCreateCommandQueueWithProperties( context, device, 0, &error );
|
||||
if ( error != CL_SUCCESS )
|
||||
{
|
||||
print_error( error, "Unable to create testing command queue" );
|
||||
test_finish();
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( gTestSmallImages )
|
||||
log_info( "Note: Using small test images\n" );
|
||||
|
||||
int ret = parseAndCallCommandLineTests( argCount, argList, NULL, num_fns, basefn_list, basefn_names, true, 0, 0 );
|
||||
|
||||
error = clFinish(queue);
|
||||
if (error)
|
||||
print_error(error, "clFinish failed.");
|
||||
|
||||
if (gTestFailure == 0) {
|
||||
if (gTestCount > 1)
|
||||
log_info("PASSED %d of %d sub-tests.\n", gTestCount, gTestCount);
|
||||
else
|
||||
log_info("PASSED sub-test.\n");
|
||||
}
|
||||
else if (gTestFailure > 0) {
|
||||
if (gTestCount > 1)
|
||||
log_error("FAILED %d of %d sub-tests.\n", gTestFailure, gTestCount);
|
||||
else
|
||||
log_error("FAILED sub-test.\n");
|
||||
}
|
||||
|
||||
// Clean up
|
||||
clReleaseCommandQueue(queue);
|
||||
clReleaseContext(context);
|
||||
free(argList);
|
||||
test_finish();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void printUsage( const char *execName )
|
||||
{
|
||||
const char *p = strrchr( execName, '/' );
|
||||
if ( p != NULL )
|
||||
execName = p + 1;
|
||||
|
||||
log_info( "Usage: %s [options] [test_names]\n", execName );
|
||||
log_info( "Options:\n" );
|
||||
log_info( "\tThe following flags specify the types to test. They can be combined; if none are specified, all are tested:\n" );
|
||||
log_info( "\t\tint - Test integer fill\n" );
|
||||
log_info( "\t\tuint - Test unsigned integer fill\n" );
|
||||
log_info( "\t\tfloat - Test float fill\n" );
|
||||
log_info( "\n" );
|
||||
log_info( "\trandomize - Uses random seed\n" );
|
||||
log_info( "\tdebug_trace - Enables additional debug info logging\n" );
|
||||
log_info( "\tsmall_images - Runs every format through a loop of widths 1-13 and heights 1-9, instead of random sizes\n" );
|
||||
log_info( "\tmax_images - Runs every format through a set of size combinations with the max values, max values - 1, and max values / 128\n" );
|
||||
log_info( "\tuse_pitches - Enables row and slice pitches\n" );
|
||||
log_info( "\n" );
|
||||
log_info( "Test names:\n" );
|
||||
for( int i = 0; i < num_fns; i++ )
|
||||
{
|
||||
log_info( "\t%s\n", basefn_names[i] );
|
||||
}
|
||||
log_info( "\n" );
|
||||
log_info( "You may also use appropriate CL_ channel type and ordering constants.\n" );
|
||||
}
|
||||
181
test_conformance/images/clFillImage/test_fill_1D.cpp
Normal file
181
test_conformance/images/clFillImage/test_fill_1D.cpp
Normal file
@@ -0,0 +1,181 @@
|
||||
//
|
||||
// Copyright (c) 2017 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"
|
||||
|
||||
#define MAX_ERR 0.005f
|
||||
#define MAX_HALF_LINEAR_ERR 0.3f
|
||||
|
||||
extern bool gDebugTrace, gDisableOffsets, gTestSmallImages, gEnablePitch, gTestMaxImages, gTestRounding;
|
||||
extern cl_filter_mode gFilterModeToUse;
|
||||
extern cl_addressing_mode gAddressModeToUse;
|
||||
extern uint64_t gRoundingStartValue;
|
||||
extern cl_command_queue queue;
|
||||
extern cl_context context;
|
||||
|
||||
// Defined in test_fill_2D_3D.cpp
|
||||
extern int test_fill_image_generic( cl_device_id device, image_descriptor *imageInfo,
|
||||
const size_t origin[], const size_t region[], ExplicitType outputType, MTdata d );
|
||||
|
||||
|
||||
int test_fill_image_size_1D( cl_device_id device, image_descriptor *imageInfo, ExplicitType outputType, MTdata d )
|
||||
{
|
||||
size_t origin[ 3 ], region[ 3 ];
|
||||
int ret = 0, retCode;
|
||||
|
||||
// First, try just a full covering region fill
|
||||
origin[ 0 ] = origin[ 1 ] = origin[ 2 ] = 0;
|
||||
region[ 0 ] = imageInfo->width;
|
||||
region[ 1 ] = 1;
|
||||
region[ 2 ] = 1;
|
||||
|
||||
retCode = test_fill_image_generic( device, imageInfo, origin, region, outputType, d );
|
||||
if ( retCode < 0 )
|
||||
return retCode;
|
||||
else
|
||||
ret += retCode;
|
||||
|
||||
// Now try a sampling of different random regions
|
||||
for ( int i = 0; i < 8; i++ )
|
||||
{
|
||||
// Pick a random size
|
||||
region[ 0 ] = ( imageInfo->width > 8 ) ? (size_t)random_in_range( 8, (int)imageInfo->width - 1, d ) : imageInfo->width;
|
||||
|
||||
// Now pick positions within valid ranges
|
||||
origin[ 0 ] = ( imageInfo->width > region[ 0 ] ) ? (size_t)random_in_range( 0, (int)( imageInfo->width - region[ 0 ] - 1 ), d ) : 0;
|
||||
|
||||
// Go for it!
|
||||
retCode = test_fill_image_generic( device, imageInfo, origin, region, outputType, d );
|
||||
if ( retCode < 0 )
|
||||
return retCode;
|
||||
else
|
||||
ret += retCode;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int test_fill_image_set_1D( cl_device_id device, cl_image_format *format, ExplicitType outputType )
|
||||
{
|
||||
size_t maxWidth;
|
||||
cl_ulong maxAllocSize, memSize;
|
||||
image_descriptor imageInfo = { 0 };
|
||||
RandomSeed seed(gRandomSeed);
|
||||
const size_t rowPadding_default = 48;
|
||||
size_t rowPadding = gEnablePitch ? rowPadding_default : 0;
|
||||
size_t pixelSize;
|
||||
|
||||
memset(&imageInfo, 0x0, sizeof(image_descriptor));
|
||||
imageInfo.type = CL_MEM_OBJECT_IMAGE1D;
|
||||
imageInfo.format = format;
|
||||
pixelSize = get_pixel_size( imageInfo.format );
|
||||
|
||||
int error = clGetDeviceInfo( device, CL_DEVICE_IMAGE2D_MAX_WIDTH, 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 2D size from device" );
|
||||
|
||||
if (memSize > (cl_ulong)SIZE_MAX) {
|
||||
memSize = (cl_ulong)SIZE_MAX;
|
||||
}
|
||||
|
||||
if ( gTestSmallImages )
|
||||
{
|
||||
for ( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
|
||||
{
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
|
||||
if (gEnablePitch)
|
||||
{
|
||||
rowPadding = rowPadding_default;
|
||||
do {
|
||||
rowPadding++;
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
} while ((imageInfo.rowPitch % pixelSize) != 0);
|
||||
}
|
||||
|
||||
if ( gDebugTrace )
|
||||
log_info( " at size %d,%d\n", (int)imageInfo.width, (int)imageInfo.height );
|
||||
|
||||
int ret = test_fill_image_size_1D( device, &imageInfo, outputType, seed );
|
||||
if ( ret )
|
||||
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, imageInfo.format);
|
||||
|
||||
for ( size_t idx = 0; idx < numbeOfSizes; idx++ )
|
||||
{
|
||||
imageInfo.width = sizes[ idx ][ 0 ];
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
|
||||
if (gEnablePitch)
|
||||
{
|
||||
rowPadding = rowPadding_default;
|
||||
do {
|
||||
rowPadding++;
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
} while ((imageInfo.rowPitch % pixelSize) != 0);
|
||||
}
|
||||
|
||||
log_info( "Testing %d\n", (int)sizes[ idx ][ 0 ] );
|
||||
if ( gDebugTrace )
|
||||
log_info( " at max size %d\n", (int)sizes[ idx ][ 0 ] );
|
||||
if ( test_fill_image_size_1D( device, &imageInfo, outputType, seed ) )
|
||||
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 + rowPadding;
|
||||
|
||||
if (gEnablePitch)
|
||||
{
|
||||
rowPadding = rowPadding_default;
|
||||
do {
|
||||
rowPadding++;
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
} while ((imageInfo.rowPitch % pixelSize) != 0);
|
||||
}
|
||||
|
||||
size = (size_t)imageInfo.rowPitch * 4;
|
||||
} while ( size > maxAllocSize || ( size * 3 ) > memSize );
|
||||
|
||||
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_fill_image_size_1D( device, &imageInfo, outputType, seed );
|
||||
if ( ret )
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
193
test_conformance/images/clFillImage/test_fill_1D_array.cpp
Normal file
193
test_conformance/images/clFillImage/test_fill_1D_array.cpp
Normal file
@@ -0,0 +1,193 @@
|
||||
//
|
||||
// Copyright (c) 2017 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"
|
||||
|
||||
#define MAX_ERR 0.005f
|
||||
#define MAX_HALF_LINEAR_ERR 0.3f
|
||||
|
||||
extern bool gDebugTrace, gDisableOffsets, gTestSmallImages, gEnablePitch, gTestMaxImages, gTestRounding;
|
||||
extern cl_filter_mode gFilterModeToUse;
|
||||
extern cl_addressing_mode gAddressModeToUse;
|
||||
extern uint64_t gRoundingStartValue;
|
||||
extern cl_command_queue queue;
|
||||
extern cl_context context;
|
||||
|
||||
// Defined in test_fill_2D_3D.cpp
|
||||
extern int test_fill_image_generic( cl_device_id device, image_descriptor *imageInfo,
|
||||
const size_t origin[], const size_t region[], ExplicitType outputType, MTdata d );
|
||||
|
||||
|
||||
int test_fill_image_size_1D_array( cl_device_id device, image_descriptor *imageInfo, ExplicitType outputType, MTdata d )
|
||||
{
|
||||
size_t origin[ 3 ], region[ 3 ];
|
||||
int ret = 0, retCode;
|
||||
|
||||
// First, try just a full covering region fill
|
||||
origin[ 0 ] = origin[ 1 ] = origin[ 2 ] = 0;
|
||||
region[ 0 ] = imageInfo->width;
|
||||
region[ 1 ] = imageInfo->arraySize;
|
||||
region[ 2 ] = 1;
|
||||
|
||||
retCode = test_fill_image_generic( device, imageInfo, origin, region, outputType, d );
|
||||
if ( retCode < 0 )
|
||||
return retCode;
|
||||
else
|
||||
ret += retCode;
|
||||
|
||||
// Now try a sampling of different random regions
|
||||
for ( int i = 0; i < 8; i++ )
|
||||
{
|
||||
// Pick a random size
|
||||
region[ 0 ] = ( imageInfo->width > 8 ) ? (size_t)random_in_range( 8, (int)imageInfo->width - 1, d ) : imageInfo->width;
|
||||
region[ 1 ] = ( imageInfo->arraySize > 8 ) ? (size_t)random_in_range( 8, (int)imageInfo->arraySize - 1, d ) : imageInfo->arraySize;
|
||||
|
||||
// Now pick positions within valid ranges
|
||||
origin[ 0 ] = ( imageInfo->width > region[ 0 ] ) ? (size_t)random_in_range( 0, (int)( imageInfo->width - region[ 0 ] - 1 ), d ) : 0;
|
||||
origin[ 1 ] = ( imageInfo->arraySize > region[ 1 ] ) ? (size_t)random_in_range( 0, (int)( imageInfo->arraySize - region[ 1 ] - 1 ), d ) : 0;
|
||||
|
||||
// Go for it!
|
||||
retCode = test_fill_image_generic( device, imageInfo, origin, region, outputType, d );
|
||||
if ( retCode < 0 )
|
||||
return retCode;
|
||||
else
|
||||
ret += retCode;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int test_fill_image_set_1D_array( cl_device_id device, cl_image_format *format, ExplicitType outputType )
|
||||
{
|
||||
size_t maxWidth, maxArraySize;
|
||||
cl_ulong maxAllocSize, memSize;
|
||||
image_descriptor imageInfo = { 0 };
|
||||
RandomSeed seed(gRandomSeed);
|
||||
const size_t rowPadding_default = 48;
|
||||
size_t rowPadding = gEnablePitch ? rowPadding_default : 0;
|
||||
size_t pixelSize;
|
||||
|
||||
memset(&imageInfo, 0x0, sizeof(image_descriptor));
|
||||
imageInfo.type = CL_MEM_OBJECT_IMAGE1D_ARRAY;
|
||||
imageInfo.format = format;
|
||||
pixelSize = get_pixel_size( imageInfo.format );
|
||||
|
||||
int error = clGetDeviceInfo( device, CL_DEVICE_IMAGE2D_MAX_WIDTH, sizeof( maxWidth ), &maxWidth, NULL );
|
||||
error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE_MAX_ARRAY_SIZE, sizeof( maxArraySize ), &maxArraySize, 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 array size from device" );
|
||||
|
||||
if (memSize > (cl_ulong)SIZE_MAX) {
|
||||
memSize = (cl_ulong)SIZE_MAX;
|
||||
}
|
||||
|
||||
if ( gTestSmallImages )
|
||||
{
|
||||
for ( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
|
||||
{
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
|
||||
if (gEnablePitch)
|
||||
{
|
||||
rowPadding = rowPadding_default;
|
||||
do {
|
||||
rowPadding++;
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
} while ((imageInfo.rowPitch % pixelSize) != 0);
|
||||
}
|
||||
|
||||
imageInfo.slicePitch = imageInfo.rowPitch;
|
||||
for ( imageInfo.arraySize = 2; imageInfo.arraySize < 9; imageInfo.arraySize++ )
|
||||
{
|
||||
if ( gDebugTrace )
|
||||
log_info( " at size %d,%d\n", (int)imageInfo.width, (int)imageInfo.arraySize );
|
||||
|
||||
int ret = test_fill_image_size_1D_array( device, &imageInfo, outputType, seed );
|
||||
if ( ret )
|
||||
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, maxArraySize, maxAllocSize, memSize, CL_MEM_OBJECT_IMAGE1D_ARRAY, imageInfo.format);
|
||||
|
||||
for ( size_t idx = 0; idx < numbeOfSizes; idx++ )
|
||||
{
|
||||
imageInfo.width = sizes[ idx ][ 0 ];
|
||||
imageInfo.arraySize = sizes[ idx ][ 2 ];
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
|
||||
if (gEnablePitch)
|
||||
{
|
||||
rowPadding = rowPadding_default;
|
||||
do {
|
||||
rowPadding++;
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
} while ((imageInfo.rowPitch % pixelSize) != 0);
|
||||
}
|
||||
|
||||
imageInfo.slicePitch = imageInfo.rowPitch;
|
||||
log_info( "Testing %d x %d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 2 ] );
|
||||
if ( gDebugTrace )
|
||||
log_info( " at max size %d,%d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 2 ] );
|
||||
if ( test_fill_image_size_1D_array( device, &imageInfo, outputType, seed ) )
|
||||
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.arraySize = (size_t)random_log_in_range( 16, (int)maxArraySize / 32, seed );
|
||||
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
|
||||
if (gEnablePitch)
|
||||
{
|
||||
rowPadding = rowPadding_default;
|
||||
do {
|
||||
rowPadding++;
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
} while ((imageInfo.rowPitch % pixelSize) != 0);
|
||||
}
|
||||
|
||||
imageInfo.slicePitch = imageInfo.rowPitch;
|
||||
|
||||
size = (size_t)imageInfo.rowPitch * (size_t)imageInfo.arraySize * 4;
|
||||
} while ( size > maxAllocSize || ( size * 3 ) > memSize );
|
||||
|
||||
if ( gDebugTrace )
|
||||
log_info( " at size %d,%d (row pitch %d) out of %d,%d\n", (int)imageInfo.width, (int)imageInfo.arraySize, (int)imageInfo.rowPitch, (int)maxWidth, (int)maxArraySize );
|
||||
int ret = test_fill_image_size_1D_array( device, &imageInfo, outputType, seed );
|
||||
if ( ret )
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
189
test_conformance/images/clFillImage/test_fill_2D.cpp
Normal file
189
test_conformance/images/clFillImage/test_fill_2D.cpp
Normal file
@@ -0,0 +1,189 @@
|
||||
//
|
||||
// Copyright (c) 2017 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"
|
||||
|
||||
#define MAX_ERR 0.005f
|
||||
#define MAX_HALF_LINEAR_ERR 0.3f
|
||||
|
||||
extern bool gDebugTrace, gDisableOffsets, gTestSmallImages, gEnablePitch, gTestMaxImages, gTestRounding;
|
||||
extern cl_filter_mode gFilterModeToUse;
|
||||
extern cl_addressing_mode gAddressModeToUse;
|
||||
extern uint64_t gRoundingStartValue;
|
||||
extern cl_command_queue queue;
|
||||
extern cl_context context;
|
||||
|
||||
// Defined in test_fill_2D_3D.cpp
|
||||
extern int test_fill_image_generic( cl_device_id device, image_descriptor *imageInfo,
|
||||
const size_t origin[], const size_t region[], ExplicitType outputType, MTdata d );
|
||||
|
||||
|
||||
int test_fill_image_size_2D( cl_device_id device, image_descriptor *imageInfo, ExplicitType outputType, MTdata d )
|
||||
{
|
||||
size_t origin[ 3 ], region[ 3 ];
|
||||
int ret = 0, retCode;
|
||||
|
||||
// First, try just a full covering region fill
|
||||
origin[ 0 ] = origin[ 1 ] = origin[ 2 ] = 0;
|
||||
region[ 0 ] = imageInfo->width;
|
||||
region[ 1 ] = imageInfo->height;
|
||||
region[ 2 ] = 1;
|
||||
|
||||
retCode = test_fill_image_generic( device, imageInfo, origin, region, outputType, d );
|
||||
if ( retCode < 0 )
|
||||
return retCode;
|
||||
else
|
||||
ret += retCode;
|
||||
|
||||
// Now try a sampling of different random regions
|
||||
for ( int i = 0; i < 8; i++ )
|
||||
{
|
||||
// Pick a random size
|
||||
region[ 0 ] = ( imageInfo->width > 8 ) ? (size_t)random_in_range( 8, (int)imageInfo->width - 1, d ) : imageInfo->width;
|
||||
region[ 1 ] = ( imageInfo->height > 8 ) ? (size_t)random_in_range( 8, (int)imageInfo->height - 1, d ) : imageInfo->height;
|
||||
|
||||
// Now pick positions within valid ranges
|
||||
origin[ 0 ] = ( imageInfo->width > region[ 0 ] ) ? (size_t)random_in_range( 0, (int)( imageInfo->width - region[ 0 ] - 1 ), d ) : 0;
|
||||
origin[ 1 ] = ( imageInfo->height > region[ 1 ] ) ? (size_t)random_in_range( 0, (int)( imageInfo->height - region[ 1 ] - 1 ), d ) : 0;
|
||||
|
||||
// Go for it!
|
||||
retCode = test_fill_image_generic( device, imageInfo, origin, region, outputType, d );
|
||||
if ( retCode < 0 )
|
||||
return retCode;
|
||||
else
|
||||
ret += retCode;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int test_fill_image_set_2D( cl_device_id device, cl_image_format *format, ExplicitType outputType )
|
||||
{
|
||||
size_t maxWidth, maxHeight;
|
||||
cl_ulong maxAllocSize, memSize;
|
||||
image_descriptor imageInfo = { 0 };
|
||||
RandomSeed seed(gRandomSeed);
|
||||
const size_t rowPadding_default = 48;
|
||||
size_t rowPadding = gEnablePitch ? rowPadding_default : 0;
|
||||
size_t pixelSize;
|
||||
|
||||
memset(&imageInfo, 0x0, sizeof(image_descriptor));
|
||||
imageInfo.type = CL_MEM_OBJECT_IMAGE2D;
|
||||
imageInfo.format = format;
|
||||
pixelSize = get_pixel_size( imageInfo.format );
|
||||
|
||||
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 );
|
||||
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 2D size from device" );
|
||||
|
||||
if (memSize > (cl_ulong)SIZE_MAX) {
|
||||
memSize = (cl_ulong)SIZE_MAX;
|
||||
}
|
||||
|
||||
if ( gTestSmallImages )
|
||||
{
|
||||
for ( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
|
||||
{
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
|
||||
if (gEnablePitch)
|
||||
{
|
||||
rowPadding = rowPadding_default;
|
||||
do {
|
||||
rowPadding++;
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
} while ((imageInfo.rowPitch % pixelSize) != 0);
|
||||
}
|
||||
|
||||
for ( imageInfo.height = 1; imageInfo.height < 9; imageInfo.height++ )
|
||||
{
|
||||
if ( gDebugTrace )
|
||||
log_info( " at size %d,%d\n", (int)imageInfo.width, (int)imageInfo.height );
|
||||
|
||||
int ret = test_fill_image_size_2D( device, &imageInfo, outputType, seed );
|
||||
if ( ret )
|
||||
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, maxHeight, 1, 1, maxAllocSize, memSize, CL_MEM_OBJECT_IMAGE2D, imageInfo.format);
|
||||
|
||||
for ( size_t idx = 0; idx < numbeOfSizes; idx++ )
|
||||
{
|
||||
imageInfo.width = sizes[ idx ][ 0 ];
|
||||
imageInfo.height = sizes[ idx ][ 1 ];
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
|
||||
if (gEnablePitch)
|
||||
{
|
||||
rowPadding = rowPadding_default;
|
||||
do {
|
||||
rowPadding++;
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
} while ((imageInfo.rowPitch % pixelSize) != 0);
|
||||
}
|
||||
|
||||
log_info( "Testing %d x %d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 1 ] );
|
||||
if ( gDebugTrace )
|
||||
log_info( " at max size %d,%d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 1 ] );
|
||||
if ( test_fill_image_size_2D( device, &imageInfo, outputType, seed ) )
|
||||
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.height = (size_t)random_log_in_range( 16, (int)maxHeight / 32, seed );
|
||||
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
|
||||
if (gEnablePitch)
|
||||
{
|
||||
rowPadding = rowPadding_default;
|
||||
do {
|
||||
rowPadding++;
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
} while ((imageInfo.rowPitch % pixelSize) != 0);
|
||||
}
|
||||
|
||||
size = (size_t)imageInfo.rowPitch * (size_t)imageInfo.height * 4;
|
||||
} while ( size > maxAllocSize || ( size * 3 ) > memSize );
|
||||
|
||||
if ( gDebugTrace )
|
||||
log_info( " at size %d,%d (row pitch %d) out of %d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.rowPitch, (int)maxWidth, (int)maxHeight );
|
||||
int ret = test_fill_image_size_2D( device, &imageInfo, outputType, seed );
|
||||
if ( ret )
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
200
test_conformance/images/clFillImage/test_fill_2D_array.cpp
Normal file
200
test_conformance/images/clFillImage/test_fill_2D_array.cpp
Normal file
@@ -0,0 +1,200 @@
|
||||
//
|
||||
// Copyright (c) 2017 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"
|
||||
|
||||
#define MAX_ERR 0.005f
|
||||
#define MAX_HALF_LINEAR_ERR 0.3f
|
||||
|
||||
extern bool gDebugTrace, gDisableOffsets, gTestSmallImages, gTestMaxImages, gEnablePitch, gTestRounding;
|
||||
extern cl_filter_mode gFilterModeToUse;
|
||||
extern cl_addressing_mode gAddressModeToUse;
|
||||
extern cl_command_queue queue;
|
||||
extern cl_context context;
|
||||
|
||||
// Defined in test_fill_2D_3D.cpp
|
||||
extern int test_fill_image_generic( cl_device_id device, image_descriptor *imageInfo,
|
||||
const size_t origin[], const size_t region[], ExplicitType outputType, MTdata d );
|
||||
|
||||
|
||||
static int test_fill_image_2D_array( cl_device_id device, image_descriptor *imageInfo, ExplicitType outputType, MTdata d )
|
||||
{
|
||||
size_t origin[ 3 ], region[ 3 ];
|
||||
int ret = 0, retCode;
|
||||
|
||||
// First, try just a full covering region
|
||||
origin[ 0 ] = origin[ 1 ] = origin[ 2 ] = 0;
|
||||
region[ 0 ] = imageInfo->width;
|
||||
region[ 1 ] = imageInfo->height;
|
||||
region[ 2 ] = imageInfo->arraySize;
|
||||
|
||||
retCode = test_fill_image_generic( device, imageInfo, origin, region, outputType, d );
|
||||
if ( retCode < 0 )
|
||||
return retCode;
|
||||
else
|
||||
ret += retCode;
|
||||
|
||||
// Now try a sampling of different random regions
|
||||
for ( int i = 0; i < 8; i++ )
|
||||
{
|
||||
// Pick a random size
|
||||
region[ 0 ] = ( imageInfo->width > 8 ) ? (size_t)random_in_range( 8, (int)imageInfo->width - 1, d ) : imageInfo->width;
|
||||
region[ 1 ] = ( imageInfo->height > 8 ) ? (size_t)random_in_range( 8, (int)imageInfo->height - 1, d ) : imageInfo->height;
|
||||
region[ 2 ] = ( imageInfo->arraySize > 8 ) ? (size_t)random_in_range( 8, (int)imageInfo->arraySize - 1, d ) : imageInfo->arraySize;
|
||||
|
||||
// Now pick positions within valid ranges
|
||||
origin[ 0 ] = ( imageInfo->width > region[ 0 ] ) ? (size_t)random_in_range( 0, (int)( imageInfo->width - region[ 0 ] - 1 ), d ) : 0;
|
||||
origin[ 1 ] = ( imageInfo->height > region[ 1 ] ) ? (size_t)random_in_range( 0, (int)( imageInfo->height - region[ 1 ] - 1 ), d ) : 0;
|
||||
origin[ 2 ] = ( imageInfo->arraySize > region[ 2 ] ) ? (size_t)random_in_range( 0, (int)( imageInfo->arraySize - region[ 2 ] - 1 ), d ) : 0;
|
||||
|
||||
// Go for it!
|
||||
retCode = test_fill_image_generic( device, imageInfo, origin, region, outputType, d );
|
||||
if ( retCode < 0 )
|
||||
return retCode;
|
||||
else
|
||||
ret += retCode;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int test_fill_image_set_2D_array( cl_device_id device, cl_image_format *format, ExplicitType outputType )
|
||||
{
|
||||
size_t maxWidth, maxHeight, maxArraySize;
|
||||
cl_ulong maxAllocSize, memSize;
|
||||
image_descriptor imageInfo = { 0 };
|
||||
RandomSeed seed( gRandomSeed );
|
||||
const size_t rowPadding_default = 80;
|
||||
size_t rowPadding = gEnablePitch ? rowPadding_default : 0;
|
||||
size_t slicePadding = gEnablePitch ? 3 : 0;
|
||||
size_t pixelSize;
|
||||
|
||||
memset(&imageInfo, 0x0, sizeof(image_descriptor));
|
||||
imageInfo.type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
|
||||
imageInfo.format = format;
|
||||
pixelSize = get_pixel_size( imageInfo.format );
|
||||
|
||||
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 );
|
||||
error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE_MAX_ARRAY_SIZE, sizeof( maxArraySize ), &maxArraySize, 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 2D array size from device" );
|
||||
|
||||
if (memSize > (cl_ulong)SIZE_MAX) {
|
||||
memSize = (cl_ulong)SIZE_MAX;
|
||||
}
|
||||
|
||||
if ( gTestSmallImages )
|
||||
{
|
||||
for ( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
|
||||
{
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
|
||||
if (gEnablePitch)
|
||||
{
|
||||
rowPadding = rowPadding_default;
|
||||
do {
|
||||
rowPadding++;
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
} while ((imageInfo.rowPitch % pixelSize) != 0);
|
||||
}
|
||||
|
||||
for ( imageInfo.height = 1; imageInfo.height < 9; imageInfo.height++ )
|
||||
{
|
||||
imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + slicePadding);
|
||||
for ( imageInfo.arraySize = 2; imageInfo.arraySize < 9; imageInfo.arraySize++ )
|
||||
{
|
||||
if ( gDebugTrace )
|
||||
log_info( " at size %d,%d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.arraySize );
|
||||
int ret = test_fill_image_2D_array( device, &imageInfo, outputType, seed );
|
||||
if ( ret )
|
||||
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, maxHeight, 1, maxArraySize, maxAllocSize, memSize, CL_MEM_OBJECT_IMAGE2D_ARRAY, imageInfo.format);
|
||||
|
||||
for ( size_t idx = 0; idx < numbeOfSizes; idx++ )
|
||||
{
|
||||
imageInfo.width = sizes[ idx ][ 0 ];
|
||||
imageInfo.height = sizes[ idx ][ 1 ];
|
||||
imageInfo.arraySize = sizes[ idx ][ 2 ];
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
|
||||
if (gEnablePitch)
|
||||
{
|
||||
rowPadding = rowPadding_default;
|
||||
do {
|
||||
rowPadding++;
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
} while ((imageInfo.rowPitch % pixelSize) != 0);
|
||||
}
|
||||
|
||||
imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + slicePadding);
|
||||
|
||||
log_info( "Testing %d x %d x %d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 1 ], (int)sizes[ idx ][ 2 ] );
|
||||
if ( gDebugTrace )
|
||||
log_info( " at max size %d,%d,%d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 1 ], (int)sizes[ idx ][ 2 ] );
|
||||
if ( test_fill_image_2D_array( device, &imageInfo, outputType, seed ) )
|
||||
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 / 64, seed );
|
||||
imageInfo.height = (size_t)random_log_in_range( 16, (int)maxHeight / 64, seed );
|
||||
imageInfo.arraySize = (size_t)random_log_in_range( 16, (int)maxArraySize / 32,seed );
|
||||
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
|
||||
if (gEnablePitch)
|
||||
{
|
||||
rowPadding = rowPadding_default;
|
||||
do {
|
||||
rowPadding++;
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
} while ((imageInfo.rowPitch % pixelSize) != 0);
|
||||
}
|
||||
|
||||
imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + slicePadding);
|
||||
|
||||
size = (cl_ulong)imageInfo.slicePitch * (cl_ulong)imageInfo.arraySize * 4 * 4;
|
||||
} while ( size > maxAllocSize || ( size * 3 ) > memSize );
|
||||
|
||||
if ( gDebugTrace )
|
||||
log_info( " at size %d,%d,%d (pitch %d,%d) out of %d,%d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.arraySize, (int)imageInfo.rowPitch, (int)imageInfo.slicePitch, (int)maxWidth, (int)maxHeight, (int)maxArraySize );
|
||||
int ret = test_fill_image_2D_array( device, &imageInfo, outputType, seed );
|
||||
if ( ret )
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
200
test_conformance/images/clFillImage/test_fill_3D.cpp
Normal file
200
test_conformance/images/clFillImage/test_fill_3D.cpp
Normal file
@@ -0,0 +1,200 @@
|
||||
//
|
||||
// Copyright (c) 2017 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"
|
||||
|
||||
#define MAX_ERR 0.005f
|
||||
#define MAX_HALF_LINEAR_ERR 0.3f
|
||||
|
||||
extern bool gDebugTrace, gDisableOffsets, gTestSmallImages, gTestMaxImages, gEnablePitch, gTestRounding;
|
||||
extern cl_filter_mode gFilterModeToUse;
|
||||
extern cl_addressing_mode gAddressModeToUse;
|
||||
extern cl_command_queue queue;
|
||||
extern cl_context context;
|
||||
|
||||
// Defined in test_fill_2D_3D.cpp
|
||||
extern int test_fill_image_generic( cl_device_id device, image_descriptor *imageInfo,
|
||||
const size_t origin[], const size_t region[], ExplicitType outputType, MTdata d );
|
||||
|
||||
|
||||
int test_fill_image_3D( cl_device_id device, image_descriptor *imageInfo, ExplicitType outputType, MTdata d )
|
||||
{
|
||||
size_t origin[ 3 ], region[ 3 ];
|
||||
int ret = 0, retCode;
|
||||
|
||||
// First, try just a full covering region
|
||||
origin[ 0 ] = origin[ 1 ] = origin[ 2 ] = 0;
|
||||
region[ 0 ] = imageInfo->width;
|
||||
region[ 1 ] = imageInfo->height;
|
||||
region[ 2 ] = imageInfo->depth;
|
||||
|
||||
retCode = test_fill_image_generic( device, imageInfo, origin, region, outputType, d );
|
||||
if ( retCode < 0 )
|
||||
return retCode;
|
||||
else
|
||||
ret += retCode;
|
||||
|
||||
// Now try a sampling of different random regions
|
||||
for ( int i = 0; i < 8; i++ )
|
||||
{
|
||||
// Pick a random size
|
||||
region[ 0 ] = ( imageInfo->width > 8 ) ? (size_t)random_in_range( 8, (int)imageInfo->width - 1, d ) : imageInfo->width;
|
||||
region[ 1 ] = ( imageInfo->height > 8 ) ? (size_t)random_in_range( 8, (int)imageInfo->height - 1, d ) : imageInfo->height;
|
||||
region[ 2 ] = ( imageInfo->depth > 8 ) ? (size_t)random_in_range( 8, (int)imageInfo->depth - 1, d ) : imageInfo->depth;
|
||||
|
||||
// Now pick positions within valid ranges
|
||||
origin[ 0 ] = ( imageInfo->width > region[ 0 ] ) ? (size_t)random_in_range( 0, (int)( imageInfo->width - region[ 0 ] - 1 ), d ) : 0;
|
||||
origin[ 1 ] = ( imageInfo->height > region[ 1 ] ) ? (size_t)random_in_range( 0, (int)( imageInfo->height - region[ 1 ] - 1 ), d ) : 0;
|
||||
origin[ 2 ] = ( imageInfo->depth > region[ 2 ] ) ? (size_t)random_in_range( 0, (int)( imageInfo->depth - region[ 2 ] - 1 ), d ) : 0;
|
||||
|
||||
// Go for it!
|
||||
retCode = test_fill_image_generic( device, imageInfo, origin, region, outputType, d );
|
||||
if ( retCode < 0 )
|
||||
return retCode;
|
||||
else
|
||||
ret += retCode;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int test_fill_image_set_3D( cl_device_id device, cl_image_format *format, ExplicitType outputType )
|
||||
{
|
||||
size_t maxWidth, maxHeight, maxDepth;
|
||||
cl_ulong maxAllocSize, memSize;
|
||||
image_descriptor imageInfo = { 0 };
|
||||
RandomSeed seed( gRandomSeed );
|
||||
const size_t rowPadding_default = 80;
|
||||
size_t rowPadding = gEnablePitch ? rowPadding_default : 0;
|
||||
size_t slicePadding = gEnablePitch ? 3 : 0;
|
||||
size_t pixelSize;
|
||||
|
||||
memset(&imageInfo, 0x0, sizeof(image_descriptor));
|
||||
imageInfo.type = CL_MEM_OBJECT_IMAGE3D;
|
||||
imageInfo.format = format;
|
||||
pixelSize = get_pixel_size( imageInfo.format );
|
||||
|
||||
int error = clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_WIDTH, sizeof( maxWidth ), &maxWidth, NULL );
|
||||
error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_HEIGHT, sizeof( maxHeight ), &maxHeight, NULL );
|
||||
error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_DEPTH, sizeof( maxDepth ), &maxDepth, 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 3D size from device" );
|
||||
|
||||
if (memSize > (cl_ulong)SIZE_MAX) {
|
||||
memSize = (cl_ulong)SIZE_MAX;
|
||||
}
|
||||
|
||||
if ( gTestSmallImages )
|
||||
{
|
||||
for ( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
|
||||
{
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
|
||||
if (gEnablePitch)
|
||||
{
|
||||
rowPadding = rowPadding_default;
|
||||
do {
|
||||
rowPadding++;
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
} while ((imageInfo.rowPitch % pixelSize) != 0);
|
||||
}
|
||||
|
||||
for ( imageInfo.height = 1; imageInfo.height < 9; imageInfo.height++ )
|
||||
{
|
||||
imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + slicePadding);
|
||||
for ( imageInfo.depth = 2; imageInfo.depth < 9; imageInfo.depth++ )
|
||||
{
|
||||
if ( gDebugTrace )
|
||||
log_info( " at size %d,%d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.depth );
|
||||
int ret = test_fill_image_3D( device, &imageInfo, outputType, seed );
|
||||
if ( ret )
|
||||
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, maxHeight, maxDepth, 1, maxAllocSize, memSize, CL_MEM_OBJECT_IMAGE3D, imageInfo.format);
|
||||
|
||||
for ( size_t idx = 0; idx < numbeOfSizes; idx++ )
|
||||
{
|
||||
imageInfo.width = sizes[ idx ][ 0 ];
|
||||
imageInfo.height = sizes[ idx ][ 1 ];
|
||||
imageInfo.depth = sizes[ idx ][ 2 ];
|
||||
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
|
||||
if (gEnablePitch)
|
||||
{
|
||||
rowPadding = rowPadding_default;
|
||||
do {
|
||||
rowPadding++;
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
} while ((imageInfo.rowPitch % pixelSize) != 0);
|
||||
}
|
||||
|
||||
imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + slicePadding);
|
||||
log_info( "Testing %d x %d x %d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 1 ], (int)sizes[ idx ][ 2 ] );
|
||||
if ( gDebugTrace )
|
||||
log_info( " at max size %d,%d,%d\n", (int)sizes[ idx ][ 0 ], (int)sizes[ idx ][ 1 ], (int)sizes[ idx ][ 2 ] );
|
||||
if ( test_fill_image_3D( device, &imageInfo, outputType, seed ) )
|
||||
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.height = (size_t)random_log_in_range( 16, (int)maxHeight / 32, seed );
|
||||
imageInfo.depth = (size_t)random_log_in_range( 16, (int)maxDepth / 32, seed );
|
||||
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
|
||||
if (gEnablePitch)
|
||||
{
|
||||
rowPadding = rowPadding_default;
|
||||
do {
|
||||
rowPadding++;
|
||||
imageInfo.rowPitch = imageInfo.width * pixelSize + rowPadding;
|
||||
} while ((imageInfo.rowPitch % pixelSize) != 0);
|
||||
}
|
||||
|
||||
imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + slicePadding);
|
||||
|
||||
size = (cl_ulong)imageInfo.slicePitch * (cl_ulong)imageInfo.depth * 4 * 4;
|
||||
} while ( size > maxAllocSize || ( size * 3 ) > memSize );
|
||||
|
||||
if ( gDebugTrace )
|
||||
log_info( " at size %d,%d,%d (pitch %d,%d) out of %d,%d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.depth, (int)imageInfo.rowPitch, (int)imageInfo.slicePitch, (int)maxWidth, (int)maxHeight, (int)maxDepth );
|
||||
int ret = test_fill_image_3D( device, &imageInfo, outputType, seed );
|
||||
if ( ret )
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
556
test_conformance/images/clFillImage/test_fill_generic.cpp
Normal file
556
test_conformance/images/clFillImage/test_fill_generic.cpp
Normal file
@@ -0,0 +1,556 @@
|
||||
//
|
||||
// Copyright (c) 2017 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"
|
||||
|
||||
#define MAX_ERR 0.005f
|
||||
#define MAX_HALF_LINEAR_ERR 0.3f
|
||||
|
||||
extern bool gDebugTrace, gDisableOffsets, gTestSmallImages, gTestMaxImages, gTestRounding, gEnablePitch;
|
||||
extern cl_filter_mode gFilterModeToUse;
|
||||
extern cl_addressing_mode gAddressModeToUse;
|
||||
extern uint64_t gRoundingStartValue;
|
||||
extern cl_command_queue queue;
|
||||
extern cl_context context;
|
||||
|
||||
extern void read_image_pixel_float( void *imageData, image_descriptor *imageInfo, int x, int y, int z, float *outData );
|
||||
|
||||
|
||||
static void CL_CALLBACK free_pitch_buffer( cl_mem image, void *buf )
|
||||
{
|
||||
free( buf );
|
||||
}
|
||||
|
||||
|
||||
cl_mem create_image( cl_context context, BufferOwningPtr<char>& data, image_descriptor *imageInfo, int *error )
|
||||
{
|
||||
cl_mem img;
|
||||
cl_image_desc imageDesc;
|
||||
cl_mem_flags mem_flags = CL_MEM_READ_ONLY;
|
||||
void *host_ptr = NULL;
|
||||
|
||||
memset(&imageDesc, 0x0, sizeof(cl_image_desc));
|
||||
imageDesc.image_type = imageInfo->type;
|
||||
imageDesc.image_width = imageInfo->width;
|
||||
imageDesc.image_height = imageInfo->height;
|
||||
imageDesc.image_depth = imageInfo->depth;
|
||||
imageDesc.image_array_size = imageInfo->arraySize;
|
||||
imageDesc.image_row_pitch = gEnablePitch ? imageInfo->rowPitch : 0;
|
||||
imageDesc.image_slice_pitch = gEnablePitch ? imageInfo->slicePitch : 0;
|
||||
|
||||
switch (imageInfo->type)
|
||||
{
|
||||
case CL_MEM_OBJECT_IMAGE1D:
|
||||
if ( gDebugTrace )
|
||||
log_info( " - Creating 1D image %d ...\n", (int)imageInfo->width );
|
||||
if ( gEnablePitch )
|
||||
host_ptr = malloc( imageInfo->rowPitch );
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE2D:
|
||||
if ( gDebugTrace )
|
||||
log_info( " - Creating 2D image %d by %d ...\n", (int)imageInfo->width, (int)imageInfo->height );
|
||||
if ( gEnablePitch )
|
||||
host_ptr = malloc( imageInfo->height * imageInfo->rowPitch );
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE3D:
|
||||
if ( gDebugTrace )
|
||||
log_info( " - Creating 3D image %d by %d by %d...\n", (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->depth );
|
||||
if ( gEnablePitch )
|
||||
host_ptr = malloc( imageInfo->depth * imageInfo->slicePitch );
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
|
||||
if ( gDebugTrace )
|
||||
log_info( " - Creating 1D image array %d by %d...\n", (int)imageInfo->width, (int)imageInfo->arraySize );
|
||||
if ( gEnablePitch )
|
||||
host_ptr = malloc( imageInfo->arraySize * imageInfo->slicePitch );
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
|
||||
if ( gDebugTrace )
|
||||
log_info( " - Creating 2D image array %d by %d by %d...\n", (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->arraySize );
|
||||
if ( gEnablePitch )
|
||||
host_ptr = malloc( imageInfo->arraySize * imageInfo->slicePitch );
|
||||
break;
|
||||
}
|
||||
|
||||
if (gEnablePitch)
|
||||
{
|
||||
if ( NULL == host_ptr )
|
||||
{
|
||||
log_error( "ERROR: Unable to create backing store for pitched 3D image. %ld bytes\n", imageInfo->depth * imageInfo->slicePitch );
|
||||
return NULL;
|
||||
}
|
||||
mem_flags = CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR;
|
||||
}
|
||||
|
||||
img = clCreateImage(context, mem_flags, imageInfo->format, &imageDesc, host_ptr, error);
|
||||
|
||||
if (gEnablePitch)
|
||||
{
|
||||
if ( *error == CL_SUCCESS )
|
||||
{
|
||||
int callbackError = clSetMemObjectDestructorCallback( img, free_pitch_buffer, host_ptr );
|
||||
if ( CL_SUCCESS != callbackError )
|
||||
{
|
||||
free( host_ptr );
|
||||
log_error( "ERROR: Unable to attach destructor callback to pitched 3D image. Err: %d\n", callbackError );
|
||||
clReleaseMemObject( img );
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
free(host_ptr);
|
||||
}
|
||||
|
||||
if ( *error != CL_SUCCESS )
|
||||
{
|
||||
long long unsigned imageSize = get_image_size_mb( imageInfo );
|
||||
switch (imageInfo->type)
|
||||
{
|
||||
case CL_MEM_OBJECT_IMAGE1D:
|
||||
log_error( "ERROR: Unable to create 1D image of size %d (%llu MB): %s\n", (int)imageInfo->width, imageSize, IGetErrorString( *error ) );
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE2D:
|
||||
log_error( "ERROR: Unable to create 2D image of size %d x %d (%llu MB): %s\n", (int)imageInfo->width, (int)imageInfo->height, imageSize, IGetErrorString( *error ) );
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE3D:
|
||||
log_error( "ERROR: Unable to create 3D image of size %d x %d x %d (%llu MB): %s\n", (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->depth, imageSize, IGetErrorString( *error ) );
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
|
||||
log_error( "ERROR: Unable to create 1D image array of size %d x %d (%llu MB): %s\n", (int)imageInfo->width, (int)imageInfo->arraySize, imageSize, IGetErrorString( *error ) );
|
||||
break;
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
|
||||
log_error( "ERROR: Unable to create 2D image array of size %d x %d x %d (%llu MB): %s\n", (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->arraySize, imageSize, IGetErrorString( *error ) );
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Copy the specified data to the image via a Map operation.
|
||||
size_t mappedRow, mappedSlice;
|
||||
size_t height;
|
||||
size_t depth;
|
||||
size_t imageSize = 0;
|
||||
|
||||
switch (imageInfo->type)
|
||||
{
|
||||
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
|
||||
height = imageInfo->arraySize;
|
||||
depth = 1;
|
||||
imageSize = imageInfo->rowPitch * imageInfo->arraySize;
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE1D:
|
||||
height = depth = 1;
|
||||
imageSize = imageInfo->rowPitch;
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE2D:
|
||||
height = imageInfo->height;
|
||||
depth = 1;
|
||||
imageSize = imageInfo->rowPitch * imageInfo->height;
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
|
||||
height = imageInfo->height;
|
||||
depth = imageInfo->arraySize;
|
||||
imageSize = imageInfo->slicePitch * imageInfo->arraySize;
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE3D:
|
||||
height = imageInfo->height;
|
||||
depth = imageInfo->depth;
|
||||
imageSize = imageInfo->slicePitch * imageInfo->depth;
|
||||
break;
|
||||
}
|
||||
|
||||
size_t origin[ 3 ] = { 0, 0, 0 };
|
||||
size_t region[ 3 ] = { imageInfo->width, height, depth };
|
||||
|
||||
void* mapped = (char*)clEnqueueMapImage(queue, img, CL_TRUE, CL_MAP_WRITE, origin, region, &mappedRow, &mappedSlice, 0, NULL, NULL, error);
|
||||
if (*error != CL_SUCCESS || !mapped)
|
||||
{
|
||||
log_error( "ERROR: Unable to map image for writing: %s\n", IGetErrorString( *error ) );
|
||||
return NULL;
|
||||
}
|
||||
size_t mappedSlicePad = mappedSlice - (mappedRow * height);
|
||||
|
||||
// Copy the image.
|
||||
size_t scanlineSize = imageInfo->rowPitch;
|
||||
size_t sliceSize = imageInfo->slicePitch - scanlineSize * height;
|
||||
|
||||
char* src = (char*)data;
|
||||
char* dst = (char*)mapped;
|
||||
|
||||
if ((mappedRow == scanlineSize) && ((mappedSlice == imageInfo->slicePitch) || (imageInfo->depth==0 && imageInfo->arraySize==0))) {
|
||||
// Copy the whole image.
|
||||
memcpy( dst, src, imageSize );
|
||||
}
|
||||
else {
|
||||
// Else copy one scan line at a time.
|
||||
for ( size_t z = 0; z < depth; z++ )
|
||||
{
|
||||
for ( size_t y = 0; y < height; y++ )
|
||||
{
|
||||
memcpy( dst, src, imageInfo->width * get_pixel_size(imageInfo->format) );
|
||||
dst += mappedRow;
|
||||
src += scanlineSize;
|
||||
}
|
||||
|
||||
// mappedSlicePad is incorrect for 2D images here, but we will exit the z loop before this is a problem.
|
||||
dst += mappedSlicePad;
|
||||
src += sliceSize;
|
||||
}
|
||||
}
|
||||
|
||||
// Unmap the image.
|
||||
*error = clEnqueueUnmapMemObject(queue, img, mapped, 0, NULL, NULL);
|
||||
if (*error != CL_SUCCESS)
|
||||
{
|
||||
log_error( "ERROR: Unable to unmap image after writing: %s\n", IGetErrorString( *error ) );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return img;
|
||||
}
|
||||
|
||||
static void fill_region_with_value( image_descriptor *imageInfo, void *imageValues,
|
||||
void *value, const size_t origin[], const size_t region[] )
|
||||
{
|
||||
size_t pixelSize = get_pixel_size( imageInfo->format );
|
||||
|
||||
// Get initial pointer
|
||||
char *destPtr = (char *)imageValues + origin[ 2 ] * imageInfo->slicePitch
|
||||
+ origin[ 1 ] * imageInfo->rowPitch + pixelSize * origin[ 0 ];
|
||||
|
||||
char *fillColor = (char *)malloc(pixelSize);
|
||||
memcpy(fillColor, value, pixelSize);
|
||||
|
||||
// Use pixel at origin to fill region.
|
||||
for( size_t z = 0; z < ( region[ 2 ] > 0 ? region[ 2 ] : 1 ); z++ ) {
|
||||
char *rowDestPtr = destPtr;
|
||||
for( size_t y = 0; y < region[ 1 ]; y++ ) {
|
||||
char *pixelDestPtr = rowDestPtr;
|
||||
|
||||
for( size_t x = 0; x < region[ 0 ]; x++ ) {
|
||||
memcpy( pixelDestPtr, fillColor, pixelSize );
|
||||
pixelDestPtr += pixelSize;
|
||||
}
|
||||
rowDestPtr += imageInfo->rowPitch;
|
||||
}
|
||||
destPtr += imageInfo->slicePitch;
|
||||
}
|
||||
|
||||
free(fillColor);
|
||||
}
|
||||
|
||||
int test_fill_image_generic( cl_device_id device, image_descriptor *imageInfo,
|
||||
const size_t origin[], const size_t region[], ExplicitType outputType, MTdata d )
|
||||
{
|
||||
BufferOwningPtr<char> imgData;
|
||||
BufferOwningPtr<char> imgHost;
|
||||
|
||||
int error;
|
||||
clMemWrapper image;
|
||||
|
||||
if ( gDebugTrace )
|
||||
log_info( " ++ Entering inner test loop...\n" );
|
||||
|
||||
// Generate some data to test against
|
||||
size_t dataBytes = 0;
|
||||
|
||||
switch (imageInfo->type)
|
||||
{
|
||||
case CL_MEM_OBJECT_IMAGE1D:
|
||||
dataBytes = imageInfo->rowPitch;
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE2D:
|
||||
dataBytes = imageInfo->height * imageInfo->rowPitch;
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE3D:
|
||||
dataBytes = imageInfo->depth * imageInfo->slicePitch;
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
|
||||
dataBytes = imageInfo->arraySize * imageInfo->slicePitch;
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
|
||||
dataBytes = imageInfo->arraySize * imageInfo->slicePitch;
|
||||
break;
|
||||
}
|
||||
|
||||
if (dataBytes > imgData.getSize())
|
||||
{
|
||||
if ( gDebugTrace )
|
||||
log_info( " - Resizing random image data...\n" );
|
||||
|
||||
generate_random_image_data( imageInfo, imgData, d );
|
||||
|
||||
imgHost.reset( NULL ); // Free previously allocated memory first.
|
||||
imgHost.reset(malloc(dataBytes),NULL,0,dataBytes);
|
||||
if (imgHost == NULL)
|
||||
{
|
||||
log_error( "ERROR: Unable to malloc %lu bytes for imgHost\n", dataBytes );
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Reset the host verification copy of the data.
|
||||
memcpy(imgHost, imgData, dataBytes);
|
||||
|
||||
// Construct testing sources
|
||||
if ( gDebugTrace )
|
||||
log_info( " - Creating image...\n" );
|
||||
|
||||
image = create_image( context, imgData, imageInfo, &error );
|
||||
if ( image == NULL )
|
||||
return error;
|
||||
|
||||
// Now fill the region defined by origin, region with the pixel value found at origin.
|
||||
if ( gDebugTrace )
|
||||
log_info( " - Filling at %d,%d,%d size %d,%d,%d\n", (int)origin[ 0 ], (int)origin[ 1 ], (int)origin[ 2 ],
|
||||
(int)region[ 0 ], (int)region[ 1 ], (int)region[ 2 ] );
|
||||
|
||||
// We need to know the rounding mode, in the case of half to allow the
|
||||
// pixel pack that generates the verification value to succeed.
|
||||
if (imageInfo->format->image_channel_data_type == CL_HALF_FLOAT)
|
||||
DetectFloatToHalfRoundingMode(queue);
|
||||
|
||||
if( outputType == kFloat )
|
||||
{
|
||||
cl_float fillColor[ 4 ];
|
||||
read_image_pixel_float( imgHost, imageInfo, origin[ 0 ], origin[ 1 ], origin[ 2 ], fillColor );
|
||||
if ( gDebugTrace )
|
||||
log_info( " - with value %g, %g, %g, %g\n", fillColor[ 0 ], fillColor[ 1 ], fillColor[ 2 ], fillColor[ 3 ] );
|
||||
error = clEnqueueFillImage ( queue, image, fillColor, origin, region, 0, NULL, NULL );
|
||||
if ( error != CL_SUCCESS )
|
||||
{
|
||||
log_error( "ERROR: Unable to fill image at %d,%d,%d size %d,%d,%d! (%s)\n",
|
||||
(int)origin[ 0 ], (int)origin[ 1 ], (int)origin[ 2 ],
|
||||
(int)region[ 0 ], (int)region[ 1 ], (int)region[ 2 ], IGetErrorString( error ) );
|
||||
return error;
|
||||
}
|
||||
|
||||
// Write the approriate verification value to the correct region.
|
||||
void* verificationValue = malloc(get_pixel_size(imageInfo->format));
|
||||
pack_image_pixel(fillColor, imageInfo->format, verificationValue);
|
||||
fill_region_with_value( imageInfo, imgHost, verificationValue, origin, region );
|
||||
free(verificationValue);
|
||||
}
|
||||
else if( outputType == kInt )
|
||||
{
|
||||
cl_int fillColor[ 4 ];
|
||||
read_image_pixel<cl_int>( imgHost, imageInfo, origin[ 0 ], origin[ 1 ], origin[ 2 ], fillColor );
|
||||
if ( gDebugTrace )
|
||||
log_info( " - with value %d, %d, %d, %d\n", fillColor[ 0 ], fillColor[ 1 ], fillColor[ 2 ], fillColor[ 3 ] );
|
||||
error = clEnqueueFillImage ( queue, image, fillColor, origin, region, 0, NULL, NULL );
|
||||
if ( error != CL_SUCCESS )
|
||||
{
|
||||
log_error( "ERROR: Unable to fill image at %d,%d,%d size %d,%d,%d! (%s)\n",
|
||||
(int)origin[ 0 ], (int)origin[ 1 ], (int)origin[ 2 ],
|
||||
(int)region[ 0 ], (int)region[ 1 ], (int)region[ 2 ], IGetErrorString( error ) );
|
||||
return error;
|
||||
}
|
||||
|
||||
// Write the approriate verification value to the correct region.
|
||||
void* verificationValue = malloc(get_pixel_size(imageInfo->format));
|
||||
pack_image_pixel(fillColor, imageInfo->format, verificationValue);
|
||||
fill_region_with_value( imageInfo, imgHost, verificationValue, origin, region );
|
||||
free(verificationValue);
|
||||
}
|
||||
else // if( outputType == kUInt )
|
||||
{
|
||||
cl_uint fillColor[ 4 ];
|
||||
read_image_pixel<cl_uint>( imgHost, imageInfo, origin[ 0 ], origin[ 1 ], origin[ 2 ], fillColor );
|
||||
if ( gDebugTrace )
|
||||
log_info( " - with value %u, %u, %u, %u\n", fillColor[ 0 ], fillColor[ 1 ], fillColor[ 2 ], fillColor[ 3 ] );
|
||||
error = clEnqueueFillImage ( queue, image, fillColor, origin, region, 0, NULL, NULL );
|
||||
if ( error != CL_SUCCESS )
|
||||
{
|
||||
log_error( "ERROR: Unable to fill image at %d,%d,%d size %d,%d,%d! (%s)\n",
|
||||
(int)origin[ 0 ], (int)origin[ 1 ], (int)origin[ 2 ],
|
||||
(int)region[ 0 ], (int)region[ 1 ], (int)region[ 2 ], IGetErrorString( error ) );
|
||||
return error;
|
||||
}
|
||||
|
||||
// Write the approriate verification value to the correct region.
|
||||
void* verificationValue = malloc(get_pixel_size(imageInfo->format));
|
||||
pack_image_pixel(fillColor, imageInfo->format, verificationValue);
|
||||
fill_region_with_value( imageInfo, imgHost, verificationValue, origin, region );
|
||||
free(verificationValue);
|
||||
}
|
||||
|
||||
// Map the destination image to verify the results with the host
|
||||
// copy. The contents of the entire buffer are compared.
|
||||
if ( gDebugTrace )
|
||||
log_info( " - Mapping results...\n" );
|
||||
|
||||
size_t imageOrigin[ 3 ] = { 0, 0, 0 };
|
||||
size_t imageRegion[ 3 ] = { imageInfo->width, 1, 1 };
|
||||
switch (imageInfo->type)
|
||||
{
|
||||
case CL_MEM_OBJECT_IMAGE1D:
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE2D:
|
||||
imageRegion[ 1 ] = imageInfo->height;
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE3D:
|
||||
imageRegion[ 1 ] = imageInfo->height;
|
||||
imageRegion[ 2 ] = imageInfo->depth;
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
|
||||
imageRegion[ 1 ] = imageInfo->arraySize;
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
|
||||
imageRegion[ 1 ] = imageInfo->height;
|
||||
imageRegion[ 2 ] = imageInfo->arraySize;
|
||||
break;
|
||||
}
|
||||
|
||||
size_t mappedRow, mappedSlice;
|
||||
void* mapped = (char*)clEnqueueMapImage(queue, image, CL_TRUE, CL_MAP_READ, imageOrigin, imageRegion, &mappedRow, &mappedSlice, 0, NULL, NULL, &error);
|
||||
if (error != CL_SUCCESS)
|
||||
{
|
||||
log_error( "ERROR: Unable to map image for verification: %s\n", IGetErrorString( error ) );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Verify scanline by scanline, since the pitches are different
|
||||
char *sourcePtr = imgHost;
|
||||
char *destPtr = (char*)mapped;
|
||||
|
||||
size_t scanlineSize = imageInfo->width * get_pixel_size( imageInfo->format );
|
||||
|
||||
if ( gDebugTrace )
|
||||
log_info( " - Scanline verification...\n" );
|
||||
|
||||
size_t thirdDim = 1;
|
||||
size_t secondDim = 1;
|
||||
|
||||
switch (imageInfo->type) {
|
||||
case CL_MEM_OBJECT_IMAGE1D:
|
||||
secondDim = 1;
|
||||
thirdDim = 1;
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE2D:
|
||||
secondDim = imageInfo->height;
|
||||
thirdDim = 1;
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE3D:
|
||||
secondDim = imageInfo->height;
|
||||
thirdDim = imageInfo->depth;
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
|
||||
secondDim = imageInfo->arraySize;
|
||||
thirdDim = 1;
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
|
||||
secondDim = imageInfo->height;
|
||||
thirdDim = imageInfo->arraySize;
|
||||
break;
|
||||
default:
|
||||
log_error("Test error: unhandled image type at %s:%d\n",__FILE__,__LINE__);
|
||||
};
|
||||
|
||||
// Count the number of bytes successfully matched
|
||||
size_t total_matched = 0;
|
||||
|
||||
for ( size_t z = 0; z < thirdDim; z++ )
|
||||
{
|
||||
for ( size_t y = 0; y < secondDim; y++ )
|
||||
{
|
||||
// If the data type is 101010 ignore bits 31 and 32 when comparing the row
|
||||
if (imageInfo->format->image_channel_data_type == CL_UNORM_INT_101010) {
|
||||
for (size_t w=0;w!=scanlineSize/4;++w) {
|
||||
((cl_uint*)sourcePtr)[w] &= 0x3FFFFFFF;
|
||||
((cl_uint*)destPtr)[w] &= 0x3FFFFFFF;
|
||||
}
|
||||
}
|
||||
|
||||
if (memcmp( sourcePtr, destPtr, scanlineSize ) != 0)
|
||||
{
|
||||
log_error( "ERROR: Scanline %d did not verify for image size %d,%d,%d pitch %d (extra %d bytes)\n", (int)y, (int)imageInfo->width, (int)imageInfo->height, (int)thirdDim, (int)imageInfo->rowPitch, (int)imageInfo->rowPitch - (int)imageInfo->width * (int)get_pixel_size( imageInfo->format ) );
|
||||
|
||||
// Find the first missing pixel
|
||||
size_t pixel_size = get_pixel_size( imageInfo->format );
|
||||
size_t where = 0;
|
||||
for ( where = 0; where < imageInfo->width; where++ )
|
||||
if ( memcmp( sourcePtr + pixel_size * where, destPtr + pixel_size * where, pixel_size) )
|
||||
break;
|
||||
log_error( "Failed at column: %ld ", where );
|
||||
switch ( pixel_size )
|
||||
{
|
||||
case 1:
|
||||
log_error( "*0x%2.2x vs. 0x%2.2x\n", ((cl_uchar*)(sourcePtr + pixel_size * where))[0], ((cl_uchar*)(destPtr + pixel_size * where))[0] );
|
||||
break;
|
||||
case 2:
|
||||
log_error( "*0x%4.4x vs. 0x%4.4x\n", ((cl_ushort*)(sourcePtr + pixel_size * where))[0], ((cl_ushort*)(destPtr + pixel_size * where))[0] );
|
||||
break;
|
||||
case 3:
|
||||
log_error( "*{0x%2.2x, 0x%2.2x, 0x%2.2x} vs. {0x%2.2x, 0x%2.2x, 0x%2.2x}\n",
|
||||
((cl_uchar*)(sourcePtr + pixel_size * where))[0], ((cl_uchar*)(sourcePtr + pixel_size * where))[1], ((cl_uchar*)(sourcePtr + pixel_size * where))[2],
|
||||
((cl_uchar*)(destPtr + pixel_size * where))[0], ((cl_uchar*)(destPtr + pixel_size * where))[1], ((cl_uchar*)(destPtr + pixel_size * where))[2]
|
||||
);
|
||||
break;
|
||||
case 4:
|
||||
log_error( "*0x%8.8x vs. 0x%8.8x\n", ((cl_uint*)(sourcePtr + pixel_size * where))[0], ((cl_uint*)(destPtr + pixel_size * where))[0] );
|
||||
break;
|
||||
case 6:
|
||||
log_error( "*{0x%4.4x, 0x%4.4x, 0x%4.4x} vs. {0x%4.4x, 0x%4.4x, 0x%4.4x}\n",
|
||||
((cl_ushort*)(sourcePtr + pixel_size * where))[0], ((cl_ushort*)(sourcePtr + pixel_size * where))[1], ((cl_ushort*)(sourcePtr + pixel_size * where))[2],
|
||||
((cl_ushort*)(destPtr + pixel_size * where))[0], ((cl_ushort*)(destPtr + pixel_size * where))[1], ((cl_ushort*)(destPtr + pixel_size * where))[2]
|
||||
);
|
||||
break;
|
||||
case 8:
|
||||
log_error( "*0x%16.16llx vs. 0x%16.16llx\n", ((cl_ulong*)(sourcePtr + pixel_size * where))[0], ((cl_ulong*)(destPtr + pixel_size * where))[0] );
|
||||
break;
|
||||
case 12:
|
||||
log_error( "*{0x%8.8x, 0x%8.8x, 0x%8.8x} vs. {0x%8.8x, 0x%8.8x, 0x%8.8x}\n",
|
||||
((cl_uint*)(sourcePtr + pixel_size * where))[0], ((cl_uint*)(sourcePtr + pixel_size * where))[1], ((cl_uint*)(sourcePtr + pixel_size * where))[2],
|
||||
((cl_uint*)(destPtr + pixel_size * where))[0], ((cl_uint*)(destPtr + pixel_size * where))[1], ((cl_uint*)(destPtr + pixel_size * where))[2]
|
||||
);
|
||||
break;
|
||||
case 16:
|
||||
log_error( "*{0x%8.8x, 0x%8.8x, 0x%8.8x, 0x%8.8x} vs. {0x%8.8x, 0x%8.8x, 0x%8.8x, 0x%8.8x}\n",
|
||||
((cl_uint*)(sourcePtr + pixel_size * where))[0], ((cl_uint*)(sourcePtr + pixel_size * where))[1], ((cl_uint*)(sourcePtr + pixel_size * where))[2], ((cl_uint*)(sourcePtr + pixel_size * where))[3],
|
||||
((cl_uint*)(destPtr + pixel_size * where))[0], ((cl_uint*)(destPtr + pixel_size * where))[1], ((cl_uint*)(destPtr + pixel_size * where))[2], ((cl_uint*)(destPtr + pixel_size * where))[3]
|
||||
);
|
||||
break;
|
||||
default:
|
||||
log_error( "Don't know how to print pixel size of %ld\n", pixel_size );
|
||||
break;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
total_matched += scanlineSize;
|
||||
sourcePtr += imageInfo->rowPitch;
|
||||
destPtr += mappedRow;
|
||||
}
|
||||
|
||||
sourcePtr += imageInfo->slicePitch - ( imageInfo->rowPitch * (imageInfo->height > 0 ? imageInfo->height : 1) );
|
||||
destPtr += mappedSlice - ( mappedRow * (imageInfo->height > 0 ? imageInfo->height : 1) );
|
||||
}
|
||||
|
||||
// Unmap the image.
|
||||
error = clEnqueueUnmapMemObject(queue, image, mapped, 0, NULL, NULL);
|
||||
if (error != CL_SUCCESS)
|
||||
{
|
||||
log_error( "ERROR: Unable to unmap image after verify: %s\n", IGetErrorString( error ) );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
imgHost.reset(0x0);
|
||||
imgData.reset(0x0);
|
||||
|
||||
size_t expected_bytes = scanlineSize * imageRegion[1] * imageRegion[2];
|
||||
return (total_matched == expected_bytes) ? 0 : -1;
|
||||
}
|
||||
327
test_conformance/images/clFillImage/test_loops.cpp
Normal file
327
test_conformance/images/clFillImage/test_loops.cpp
Normal file
@@ -0,0 +1,327 @@
|
||||
//
|
||||
// Copyright (c) 2017 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"
|
||||
|
||||
extern bool gDebugTrace;
|
||||
extern cl_filter_mode gFilterModeToUse;
|
||||
extern cl_addressing_mode gAddressModeToUse;
|
||||
extern int gTypesToTest;
|
||||
extern int gNormalizedModeToUse;
|
||||
extern cl_channel_type gChannelTypeToUse;
|
||||
extern cl_channel_order gChannelOrderToUse;
|
||||
extern cl_command_queue queue;
|
||||
extern cl_context context;
|
||||
|
||||
|
||||
extern int test_fill_image_set_1D( cl_device_id device, cl_image_format *format, ExplicitType outputType );
|
||||
extern int test_fill_image_set_2D( cl_device_id device, cl_image_format *format, ExplicitType outputType );
|
||||
extern int test_fill_image_set_3D( cl_device_id device, cl_image_format *format, ExplicitType outputType );
|
||||
extern int test_fill_image_set_1D_array( cl_device_id device, cl_image_format *format, ExplicitType outputType );
|
||||
extern int test_fill_image_set_2D_array( cl_device_id device, cl_image_format *format, ExplicitType outputType );
|
||||
|
||||
|
||||
int filter_formats( cl_image_format *formatList, bool *filterFlags, unsigned int formatCount, cl_channel_type *channelDataTypesToFilter )
|
||||
{
|
||||
int numSupported = 0;
|
||||
for ( unsigned int j = 0; j < formatCount; j++ )
|
||||
{
|
||||
// If this format has been previously filtered, remove the filter
|
||||
if ( filterFlags[ j ] )
|
||||
filterFlags[ j ] = false;
|
||||
|
||||
// Have we already discarded this via the command line?
|
||||
if ( gChannelTypeToUse != (cl_channel_type)-1 && gChannelTypeToUse != formatList[ j ].image_channel_data_type )
|
||||
{
|
||||
filterFlags[ j ] = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Have we already discarded the channel order via the command line?
|
||||
if ( gChannelOrderToUse != (cl_channel_order)-1 && gChannelOrderToUse != formatList[ j ].image_channel_order )
|
||||
{
|
||||
filterFlags[ j ] = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Is given format standard channel order and type given by spec. We don't want to test it if this is vendor extension
|
||||
if( !IsChannelOrderSupported( formatList[ j ].image_channel_order ) || !IsChannelTypeSupported( formatList[ j ].image_channel_data_type ) )
|
||||
{
|
||||
filterFlags[ j ] = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
// We don't filter by channel type
|
||||
if( !channelDataTypesToFilter )
|
||||
{
|
||||
numSupported++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Is the format supported?
|
||||
int i;
|
||||
for ( i = 0; channelDataTypesToFilter[ i ] != (cl_channel_type)-1; i++ )
|
||||
{
|
||||
if ( formatList[ j ].image_channel_data_type == channelDataTypesToFilter[ i ] )
|
||||
{
|
||||
numSupported++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( channelDataTypesToFilter[ i ] == (cl_channel_type)-1 )
|
||||
{
|
||||
// Format is NOT supported, so mark it as such
|
||||
filterFlags[ j ] = true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return numSupported;
|
||||
}
|
||||
|
||||
|
||||
int get_format_list( cl_device_id device, cl_mem_object_type image_type, cl_image_format * &outFormatList,
|
||||
unsigned int &outFormatCount, cl_mem_flags flags )
|
||||
{
|
||||
int error;
|
||||
|
||||
cl_image_format tempList[ 128 ];
|
||||
error = clGetSupportedImageFormats( context, (cl_mem_flags)flags,
|
||||
image_type, 128, tempList, &outFormatCount );
|
||||
test_error( error, "Unable to get count of supported image formats" );
|
||||
|
||||
outFormatList = new cl_image_format[ outFormatCount ];
|
||||
error = clGetSupportedImageFormats( context, (cl_mem_flags)flags,
|
||||
image_type, outFormatCount, outFormatList, NULL );
|
||||
test_error( error, "Unable to get list of supported image formats" );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int test_image_type( cl_device_id device, MethodsToTest testMethod, cl_mem_flags flags )
|
||||
{
|
||||
const char *name;
|
||||
cl_mem_object_type imageType;
|
||||
|
||||
if ( testMethod == k1D )
|
||||
{
|
||||
name = "1D Image Fill";
|
||||
imageType = CL_MEM_OBJECT_IMAGE1D;
|
||||
}
|
||||
else if ( testMethod == k2D )
|
||||
{
|
||||
name = "2D Image Fill";
|
||||
imageType = CL_MEM_OBJECT_IMAGE2D;
|
||||
}
|
||||
else if ( testMethod == k1DArray )
|
||||
{
|
||||
name = "1D Image Array Fill";
|
||||
imageType = CL_MEM_OBJECT_IMAGE1D_ARRAY;
|
||||
}
|
||||
else if ( testMethod == k2DArray )
|
||||
{
|
||||
name = "2D Image Array Fill";
|
||||
imageType = CL_MEM_OBJECT_IMAGE2D_ARRAY;
|
||||
}
|
||||
else if ( testMethod == k3D )
|
||||
{
|
||||
name = "3D Image Fill";
|
||||
imageType = CL_MEM_OBJECT_IMAGE3D;
|
||||
}
|
||||
|
||||
log_info( "Running %s tests...\n", name );
|
||||
|
||||
int ret = 0;
|
||||
|
||||
// Grab the list of supported image formats
|
||||
cl_image_format *formatList;
|
||||
bool *filterFlags;
|
||||
unsigned int numFormats;
|
||||
|
||||
if ( get_format_list( device, imageType, formatList, numFormats, flags ) )
|
||||
return -1;
|
||||
|
||||
filterFlags = new bool[ numFormats ];
|
||||
if ( filterFlags == NULL )
|
||||
{
|
||||
log_error( "ERROR: Out of memory allocating filter flags list!\n" );
|
||||
return -1;
|
||||
}
|
||||
memset( filterFlags, 0, sizeof( bool ) * numFormats );
|
||||
|
||||
/////// float tests ///////
|
||||
|
||||
if( gTypesToTest & kTestFloat )
|
||||
{
|
||||
cl_channel_type floatFormats[] = { CL_UNORM_SHORT_565, CL_UNORM_SHORT_555, CL_UNORM_INT_101010,
|
||||
#ifdef OBSOLETE_FORAMT
|
||||
CL_UNORM_SHORT_565_REV, CL_UNORM_SHORT_555_REV, CL_UNORM_INT_8888, CL_UNORM_INT_8888_REV, CL_UNORM_INT_101010_REV,
|
||||
#endif
|
||||
#ifdef CL_SFIXED14_APPLE
|
||||
CL_SFIXED14_APPLE,
|
||||
#endif
|
||||
CL_UNORM_INT8, CL_SNORM_INT8,
|
||||
CL_UNORM_INT16, CL_SNORM_INT16, CL_FLOAT, CL_HALF_FLOAT, (cl_channel_type)-1 };
|
||||
if( filter_formats( formatList, filterFlags, numFormats, floatFormats ) == 0 )
|
||||
{
|
||||
log_info( "No formats supported for float type\n" );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Run the format list
|
||||
for ( unsigned int i = 0; i < numFormats; i++ )
|
||||
{
|
||||
int test_return = 0;
|
||||
if ( filterFlags[i] )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
print_header( &formatList[ i ], false );
|
||||
|
||||
gTestCount++;
|
||||
|
||||
if ( testMethod == k1D )
|
||||
test_return = test_fill_image_set_1D( device, &formatList[ i ], kFloat );
|
||||
else if ( testMethod == k2D )
|
||||
test_return = test_fill_image_set_2D( device, &formatList[ i ], kFloat );
|
||||
else if ( testMethod == k1DArray )
|
||||
test_return = test_fill_image_set_1D_array( device, &formatList[ i ], kFloat );
|
||||
else if ( testMethod == k2DArray )
|
||||
test_return = test_fill_image_set_2D_array( device, &formatList[ i ], kFloat );
|
||||
else if ( testMethod == k3D )
|
||||
test_return = test_fill_image_set_3D( device, &formatList[ i ], kFloat );
|
||||
|
||||
if (test_return)
|
||||
{
|
||||
gTestFailure++;
|
||||
log_error( "FAILED: " );
|
||||
print_header( &formatList[ i ], true );
|
||||
log_info( "\n" );
|
||||
}
|
||||
|
||||
ret += test_return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/////// int tests ///////
|
||||
if( gTypesToTest & kTestInt )
|
||||
{
|
||||
cl_channel_type intFormats[] = { CL_SIGNED_INT8, CL_SIGNED_INT16, CL_SIGNED_INT32, (cl_channel_type)-1 };
|
||||
if( filter_formats( formatList, filterFlags, numFormats, intFormats ) == 0 )
|
||||
{
|
||||
log_info( "No formats supported for integer type\n" );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Run the format list
|
||||
for ( unsigned int i = 0; i < numFormats; i++ )
|
||||
{
|
||||
int test_return = 0;
|
||||
if ( filterFlags[i] )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
print_header( &formatList[ i ], false );
|
||||
|
||||
gTestCount++;
|
||||
|
||||
if ( testMethod == k1D )
|
||||
test_return = test_fill_image_set_1D( device, &formatList[ i ], kInt );
|
||||
else if ( testMethod == k2D )
|
||||
test_return = test_fill_image_set_2D( device, &formatList[ i ], kInt );
|
||||
else if ( testMethod == k1DArray )
|
||||
test_return = test_fill_image_set_1D_array( device, &formatList[ i ], kInt );
|
||||
else if ( testMethod == k2DArray )
|
||||
test_return = test_fill_image_set_2D_array( device, &formatList[ i ], kInt );
|
||||
else if ( testMethod == k3D )
|
||||
test_return = test_fill_image_set_3D( device, &formatList[ i ], kInt );
|
||||
|
||||
if (test_return) {
|
||||
gTestFailure++;
|
||||
log_error( "FAILED: " );
|
||||
print_header( &formatList[ i ], true );
|
||||
log_info( "\n" );
|
||||
}
|
||||
|
||||
ret += test_return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/////// uint tests ///////
|
||||
|
||||
if( gTypesToTest & kTestUInt )
|
||||
{
|
||||
cl_channel_type uintFormats[] = { CL_UNSIGNED_INT8, CL_UNSIGNED_INT16, CL_UNSIGNED_INT32, (cl_channel_type)-1 };
|
||||
if( filter_formats( formatList, filterFlags, numFormats, uintFormats ) == 0 )
|
||||
{
|
||||
log_info( "No formats supported for unsigned int type\n" );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Run the format list
|
||||
for ( unsigned int i = 0; i < numFormats; i++ )
|
||||
{
|
||||
int test_return = 0;
|
||||
if ( filterFlags[i] )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
print_header( &formatList[ i ], false );
|
||||
|
||||
gTestCount++;
|
||||
|
||||
if ( testMethod == k1D )
|
||||
test_return = test_fill_image_set_1D( device, &formatList[ i ], kUInt );
|
||||
else if ( testMethod == k2D )
|
||||
test_return = test_fill_image_set_2D( device, &formatList[ i ], kUInt );
|
||||
else if ( testMethod == k1DArray )
|
||||
test_return = test_fill_image_set_1D_array( device, &formatList[ i ], kUInt );
|
||||
else if ( testMethod == k2DArray )
|
||||
test_return = test_fill_image_set_2D_array( device, &formatList[ i ], kUInt );
|
||||
else if ( testMethod == k3D )
|
||||
test_return = test_fill_image_set_3D( device, &formatList[ i ], kUInt );
|
||||
|
||||
if (test_return) {
|
||||
gTestFailure++;
|
||||
log_error( "FAILED: " );
|
||||
print_header( &formatList[ i ], true );
|
||||
log_info( "\n" );
|
||||
}
|
||||
|
||||
ret += test_return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete filterFlags;
|
||||
delete formatList;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int test_image_set( cl_device_id device, MethodsToTest testMethod )
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
ret += test_image_type( device, testMethod, CL_MEM_READ_ONLY );
|
||||
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user