Synchronise with Khronos-private Gitlab branch

The maintenance of the conformance tests is moving to Github.

This commit contains all the changes that have been done in
Gitlab since the first public release of the conformance tests.

Signed-off-by: Kevin Petit <kevin.petit@arm.com>
This commit is contained in:
Kevin Petit
2019-02-20 16:36:05 +00:00
committed by Kévin Petit
parent 95196e7fb4
commit d8733efc0f
576 changed files with 212486 additions and 191776 deletions

View File

@@ -1,19 +1,19 @@
project
: requirements
# <toolset>gcc:<cflags>-xc++
# <toolset>msvc:<cflags>"/TP"
;
exe test_kernel_image_methods
: main.cpp
test_2D.cpp
test_3D.cpp
test_loops.cpp
/images//image_helpers
;
install dist
: test_kernel_image_methods
: <variant>debug:<location>$(DIST)/debug/tests/test_conformance/images/kernel_image_methods
<variant>release:<location>$(DIST)/release/tests/test_conformance/images/kernel_image_methods
;
project
: requirements
# <toolset>gcc:<cflags>-xc++
# <toolset>msvc:<cflags>"/TP"
;
exe test_kernel_image_methods
: main.cpp
test_2D.cpp
test_3D.cpp
test_loops.cpp
/images//image_helpers
;
install dist
: test_kernel_image_methods
: <variant>debug:<location>$(DIST)/debug/tests/test_conformance/images/kernel_image_methods
<variant>release:<location>$(DIST)/release/tests/test_conformance/images/kernel_image_methods
;

View File

@@ -1,52 +1,52 @@
ifdef BUILD_WITH_ATF
ATF = -framework ATF
USE_ATF = -DUSE_ATF
endif
SRCS = main.cpp \
test_1D.cpp \
test_1D_array.cpp \
test_2D.cpp \
test_2D_array.cpp \
../image_helpers.cpp \
test_loops.cpp \
test_3D.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.c \
../../../test_common/harness/mt19937.c \
../../../test_common/harness/typeWrappers.cpp
DEFINES = DONT_TEST_GARBAGE_POINTERS
SOURCES = $(abspath $(SRCS))
LIBPATH += -L/System/Library/Frameworks/OpenCL.framework/Libraries
LIBPATH += -L.
FRAMEWORK =
HEADERS =
TARGET = test_kernel_image_methods
INCLUDE =
COMPILERFLAGS = -c -Wall -g -Wshorten-64-to-32 -Os
CC = c++
CXX = c++
CFLAGS = $(COMPILERFLAGS) ${RC_CFLAGS} ${USE_ATF} $(DEFINES:%=-D%)
CXXFLAGS = $(COMPILERFLAGS) ${RC_CFLAGS} ${USE_ATF} $(DEFINES:%=-D%)
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.
ifdef BUILD_WITH_ATF
ATF = -framework ATF
USE_ATF = -DUSE_ATF
endif
SRCS = main.cpp \
test_1D.cpp \
test_1D_array.cpp \
test_2D.cpp \
test_2D_array.cpp \
../image_helpers.cpp \
test_loops.cpp \
test_3D.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.c \
../../../test_common/harness/mt19937.c \
../../../test_common/harness/typeWrappers.cpp
DEFINES = DONT_TEST_GARBAGE_POINTERS
SOURCES = $(abspath $(SRCS))
LIBPATH += -L/System/Library/Frameworks/OpenCL.framework/Libraries
LIBPATH += -L.
FRAMEWORK =
HEADERS =
TARGET = test_kernel_image_methods
INCLUDE =
COMPILERFLAGS = -c -Wall -g -Wshorten-64-to-32 -Os
CC = c++
CXX = c++
CFLAGS = $(COMPILERFLAGS) ${RC_CFLAGS} ${USE_ATF} $(DEFINES:%=-D%)
CXXFLAGS = $(COMPILERFLAGS) ${RC_CFLAGS} ${USE_ATF} $(DEFINES:%=-D%)
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.

View File

@@ -1,258 +1,258 @@
//
// 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 <stdio.h>
#include <stdlib.h>
#if !defined(_WIN32)
#include <stdbool.h>
#endif
#include <math.h>
#include <string.h>
#if !defined(_WIN32)
#include <unistd.h>
#include <sys/time.h>
#endif
#include "../testBase.h"
bool gDebugTrace = false, gTestSmallImages = false, gTestMaxImages = false, gTestRounding = false;
int gTypesToTest = 0;
cl_channel_type gChannelTypeToUse = (cl_channel_type)-1;
cl_device_type gDeviceType = CL_DEVICE_TYPE_DEFAULT;
extern int test_image_set( cl_device_id device, cl_mem_object_type imageType );
#define MAX_ALLOWED_STD_DEVIATION_IN_MB 8.0
clCommandQueueWrapper queue;
clContextWrapper context;
void printUsage( const char *execName )
{
const char *p = strrchr( execName, '/' );
if( p != NULL )
execName = p + 1;
log_info( "Usage: %s [debug_trace] [small_images]\n", execName );
log_info( "Where:\n" );
log_info( "\t1D - Only test 1D images\n" );
log_info( "\t2D - Only test 2D images\n" );
log_info( "\t3D - Only test 3D images\n" );
log_info( "\t1Darray - Only test 1D image arrays\n" );
log_info( "\t2Darray - Only test 2D image arrays\n" );
log_info( "\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" );
}
int main(int argc, const char *argv[])
{
cl_platform_id platform;
cl_device_id device;
cl_channel_type chanType;
char str[ 128 ];
int testMethods = 0;
bool randomize = false;
test_start();
checkDeviceTypeOverride( &gDeviceType );
// Parse arguments
for( int i = 1; i < argc; i++ )
{
strncpy( str, argv[ i ], sizeof( str ) - 1 );
if( strcmp( str, "cpu" ) == 0 || strcmp( str, "CL_DEVICE_TYPE_CPU" ) == 0 )
gDeviceType = CL_DEVICE_TYPE_CPU;
else if( strcmp( str, "gpu" ) == 0 || strcmp( str, "CL_DEVICE_TYPE_GPU" ) == 0 )
gDeviceType = CL_DEVICE_TYPE_GPU;
else if( strcmp( str, "accelerator" ) == 0 || strcmp( str, "CL_DEVICE_TYPE_ACCELERATOR" ) == 0 )
gDeviceType = CL_DEVICE_TYPE_ACCELERATOR;
else if( strcmp( str, "CL_DEVICE_TYPE_DEFAULT" ) == 0 )
gDeviceType = CL_DEVICE_TYPE_DEFAULT;
else if( strcmp( str, "debug_trace" ) == 0 )
gDebugTrace = true;
else if( strcmp( str, "small_images" ) == 0 )
gTestSmallImages = true;
else if( strcmp( str, "max_images" ) == 0 )
gTestMaxImages = true;
else if( strcmp( str, "randomize" ) == 0 )
randomize = true;
else if ( strcmp( str, "1D" ) == 0 )
testMethods |= k1D;
else if( strcmp( str, "2D" ) == 0 )
testMethods |= k2D;
else if( strcmp( str, "3D" ) == 0 )
testMethods |= k3D;
else if( strcmp( str, "1Darray" ) == 0 )
testMethods |= k1DArray;
else if( strcmp( str, "2Darray" ) == 0 )
testMethods |= k2DArray;
else if( strcmp( str, "help" ) == 0 || strcmp( str, "?" ) == 0 )
{
printUsage( argv[ 0 ] );
return -1;
}
else if( ( chanType = get_channel_type_from_name( str ) ) != (cl_channel_type)-1 )
gChannelTypeToUse = chanType;
else
{
log_error( "ERROR: Unknown argument %d: %s. Exiting....\n", i, str );
return -1;
}
}
if (testMethods == 0)
testMethods = k1D | k2D | k3D | k1DArray | k2DArray;
// Seed the random # generators
if( randomize )
{
gRandomSeed = (cl_uint) clock();
gReSeed = 1;
}
// Get our device
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
unsigned int num_devices;
error = clGetDeviceIDs(platform, gDeviceType, 0, NULL, &num_devices);
if( error )
{
print_error( error, "Unable to get number of devices" );
test_finish();
return -1;
}
uint32_t gDeviceIndex = 0;
const char* device_index_env = getenv("CL_DEVICE_INDEX");
if (device_index_env) {
if (device_index_env) {
gDeviceIndex = atoi(device_index_env);
}
if (gDeviceIndex >= num_devices) {
vlog("Specified CL_DEVICE_INDEX=%d out of range, using index 0.\n", gDeviceIndex);
gDeviceIndex = 0;
}
}
cl_device_id *gDeviceList = (cl_device_id *)malloc( num_devices * sizeof( cl_device_id ) );
error = clGetDeviceIDs(platform, gDeviceType, num_devices, gDeviceList, NULL);
if( error )
{
print_error( error, "Unable to get devices" );
free( gDeviceList );
test_finish();
return -1;
}
device = gDeviceList[gDeviceIndex];
free( gDeviceList );
log_info( "Using " );
if( printDeviceHeader( device ) != CL_SUCCESS )
{
test_finish();
return -1;
}
// 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 = clCreateCommandQueue( 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" );
// Run the test now
int ret = 0;
if (testMethods & k1D)
ret += test_image_set( device, CL_MEM_OBJECT_IMAGE1D );
if (testMethods & k2D)
ret += test_image_set( device, CL_MEM_OBJECT_IMAGE2D );
if (testMethods & k3D)
ret += test_image_set( device, CL_MEM_OBJECT_IMAGE3D );
if (testMethods & k1DArray)
ret += test_image_set( device, CL_MEM_OBJECT_IMAGE1D_ARRAY );
if (testMethods & k2DArray)
ret += test_image_set( device, CL_MEM_OBJECT_IMAGE2D_ARRAY );
// Clean up
error = clFinish(queue);
if (error)
print_error(error, "clFinish failed.");
if (gTestFailure == 0) {
if (gTestCount > 1)
log_info("PASSED %d of %d tests.\n", gTestCount, gTestCount);
else
log_info("PASSED test.\n");
} else if (gTestFailure > 0) {
if (gTestCount > 1)
log_error("FAILED %d of %d tests.\n", gTestFailure, gTestCount);
else
log_error("FAILED test.\n");
}
test_finish();
if (gTestFailure > 0)
return gTestFailure;
return ret;
}
//
// 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 <stdio.h>
#include <stdlib.h>
#if !defined(_WIN32)
#include <stdbool.h>
#endif
#include <math.h>
#include <string.h>
#if !defined(_WIN32)
#include <unistd.h>
#include <sys/time.h>
#endif
#include "../testBase.h"
bool gDebugTrace = false, gTestSmallImages = false, gTestMaxImages = false, gTestRounding = false;
int gTypesToTest = 0;
cl_channel_type gChannelTypeToUse = (cl_channel_type)-1;
cl_device_type gDeviceType = CL_DEVICE_TYPE_DEFAULT;
extern int test_image_set( cl_device_id device, cl_mem_object_type imageType );
#define MAX_ALLOWED_STD_DEVIATION_IN_MB 8.0
clCommandQueueWrapper queue;
clContextWrapper context;
void printUsage( const char *execName )
{
const char *p = strrchr( execName, '/' );
if( p != NULL )
execName = p + 1;
log_info( "Usage: %s [debug_trace] [small_images]\n", execName );
log_info( "Where:\n" );
log_info( "\t1D - Only test 1D images\n" );
log_info( "\t2D - Only test 2D images\n" );
log_info( "\t3D - Only test 3D images\n" );
log_info( "\t1Darray - Only test 1D image arrays\n" );
log_info( "\t2Darray - Only test 2D image arrays\n" );
log_info( "\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" );
}
int main(int argc, const char *argv[])
{
cl_platform_id platform;
cl_device_id device;
cl_channel_type chanType;
char str[ 128 ];
int testMethods = 0;
bool randomize = false;
test_start();
checkDeviceTypeOverride( &gDeviceType );
// Parse arguments
for( int i = 1; i < argc; i++ )
{
strncpy( str, argv[ i ], sizeof( str ) - 1 );
if( strcmp( str, "cpu" ) == 0 || strcmp( str, "CL_DEVICE_TYPE_CPU" ) == 0 )
gDeviceType = CL_DEVICE_TYPE_CPU;
else if( strcmp( str, "gpu" ) == 0 || strcmp( str, "CL_DEVICE_TYPE_GPU" ) == 0 )
gDeviceType = CL_DEVICE_TYPE_GPU;
else if( strcmp( str, "accelerator" ) == 0 || strcmp( str, "CL_DEVICE_TYPE_ACCELERATOR" ) == 0 )
gDeviceType = CL_DEVICE_TYPE_ACCELERATOR;
else if( strcmp( str, "CL_DEVICE_TYPE_DEFAULT" ) == 0 )
gDeviceType = CL_DEVICE_TYPE_DEFAULT;
else if( strcmp( str, "debug_trace" ) == 0 )
gDebugTrace = true;
else if( strcmp( str, "small_images" ) == 0 )
gTestSmallImages = true;
else if( strcmp( str, "max_images" ) == 0 )
gTestMaxImages = true;
else if( strcmp( str, "randomize" ) == 0 )
randomize = true;
else if ( strcmp( str, "1D" ) == 0 )
testMethods |= k1D;
else if( strcmp( str, "2D" ) == 0 )
testMethods |= k2D;
else if( strcmp( str, "3D" ) == 0 )
testMethods |= k3D;
else if( strcmp( str, "1Darray" ) == 0 )
testMethods |= k1DArray;
else if( strcmp( str, "2Darray" ) == 0 )
testMethods |= k2DArray;
else if( strcmp( str, "help" ) == 0 || strcmp( str, "?" ) == 0 )
{
printUsage( argv[ 0 ] );
return -1;
}
else if( ( chanType = get_channel_type_from_name( str ) ) != (cl_channel_type)-1 )
gChannelTypeToUse = chanType;
else
{
log_error( "ERROR: Unknown argument %d: %s. Exiting....\n", i, str );
return -1;
}
}
if (testMethods == 0)
testMethods = k1D | k2D | k3D | k1DArray | k2DArray;
// Seed the random # generators
if( randomize )
{
gRandomSeed = (cl_uint) clock();
gReSeed = 1;
}
// Get our device
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
unsigned int num_devices;
error = clGetDeviceIDs(platform, gDeviceType, 0, NULL, &num_devices);
if( error )
{
print_error( error, "Unable to get number of devices" );
test_finish();
return -1;
}
uint32_t gDeviceIndex = 0;
const char* device_index_env = getenv("CL_DEVICE_INDEX");
if (device_index_env) {
if (device_index_env) {
gDeviceIndex = atoi(device_index_env);
}
if (gDeviceIndex >= num_devices) {
vlog("Specified CL_DEVICE_INDEX=%d out of range, using index 0.\n", gDeviceIndex);
gDeviceIndex = 0;
}
}
cl_device_id *gDeviceList = (cl_device_id *)malloc( num_devices * sizeof( cl_device_id ) );
error = clGetDeviceIDs(platform, gDeviceType, num_devices, gDeviceList, NULL);
if( error )
{
print_error( error, "Unable to get devices" );
free( gDeviceList );
test_finish();
return -1;
}
device = gDeviceList[gDeviceIndex];
free( gDeviceList );
log_info( "Using " );
if( printDeviceHeader( device ) != CL_SUCCESS )
{
test_finish();
return -1;
}
// 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 = clCreateCommandQueue( 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" );
// Run the test now
int ret = 0;
if (testMethods & k1D)
ret += test_image_set( device, CL_MEM_OBJECT_IMAGE1D );
if (testMethods & k2D)
ret += test_image_set( device, CL_MEM_OBJECT_IMAGE2D );
if (testMethods & k3D)
ret += test_image_set( device, CL_MEM_OBJECT_IMAGE3D );
if (testMethods & k1DArray)
ret += test_image_set( device, CL_MEM_OBJECT_IMAGE1D_ARRAY );
if (testMethods & k2DArray)
ret += test_image_set( device, CL_MEM_OBJECT_IMAGE2D_ARRAY );
// Clean up
error = clFinish(queue);
if (error)
print_error(error, "clFinish failed.");
if (gTestFailure == 0) {
if (gTestCount > 1)
log_info("PASSED %d of %d tests.\n", gTestCount, gTestCount);
else
log_info("PASSED test.\n");
} else if (gTestFailure > 0) {
if (gTestCount > 1)
log_error("FAILED %d of %d tests.\n", gTestFailure, gTestCount);
else
log_error("FAILED test.\n");
}
test_finish();
if (gTestFailure > 0)
return gTestFailure;
return ret;
}

View File

@@ -1,231 +1,231 @@
//
// 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, gTestSmallImages, gTestMaxImages;
extern clCommandQueueWrapper queue;
extern clContextWrapper context;
typedef struct image_kernel_data
{
cl_int width;
cl_int channelType;
cl_int channelOrder;
cl_int expectedChannelType;
cl_int expectedChannelOrder;
};
static const char *methodTest1DImageKernelPattern =
"typedef struct {\n"
" int width;\n"
" int channelType;\n"
" int channelOrder;\n"
" int expectedChannelType;\n"
" int expectedChannelOrder;\n"
" } image_kernel_data;\n"
"__kernel void sample_kernel( read_only image1d_t input, __global image_kernel_data *outData )\n"
"{\n"
" outData->width = get_image_width( input );\n"
" outData->channelType = get_image_channel_data_type( input );\n"
" outData->channelOrder = get_image_channel_order( input );\n"
"\n"
" outData->expectedChannelType = %s;\n"
" outData->expectedChannelOrder = %s;\n"
"}";
static int test_get_1Dimage_info_single( cl_device_id device, image_descriptor *imageInfo, MTdata d )
{
int error;
clProgramWrapper program;
clKernelWrapper kernel;
clMemWrapper image, outDataBuffer;
char programSrc[ 10240 ];
image_kernel_data outKernelData;
// Generate some data to test against
BufferOwningPtr<char> imageValues;
generate_random_image_data( imageInfo, imageValues, d );
// Construct testing source
if( gDebugTrace )
log_info( " - Creating 1D image %d ...\n", (int)imageInfo->width );
image = create_image_1d( context, (cl_mem_flags)(CL_MEM_READ_ONLY), imageInfo->format, imageInfo->width, 0, NULL, NULL, &error );
if( image == NULL )
{
log_error( "ERROR: Unable to create 1D image of size %d (%s)", (int)imageInfo->width, IGetErrorString( error ) );
return -1;
}
char channelTypeConstantString[256] = {0};
char channelOrderConstantString[256] = {0};
const char* channelTypeName = GetChannelTypeName( imageInfo->format->image_channel_data_type );
const char* channelOrderName = GetChannelOrderName( imageInfo->format->image_channel_order );
if(channelTypeName && strlen(channelTypeName))
sprintf(channelTypeConstantString, "CLK_%s", &channelTypeName[3]); // replace CL_* with CLK_*
if(channelOrderName && strlen(channelOrderName))
sprintf(channelOrderConstantString, "CLK_%s", &channelOrderName[3]); // replace CL_* with CLK_*
// Create a program to run against
sprintf( programSrc, methodTest1DImageKernelPattern,
channelTypeConstantString, channelOrderConstantString);
//log_info("-----------------------------------\n%s\n", programSrc);
error = clFinish(queue);
if (error)
print_error(error, "clFinish failed.\n");
const char *ptr = programSrc;
error = create_single_kernel_helper( context, &program, &kernel, 1, &ptr, "sample_kernel" );
test_error( error, "Unable to create kernel to test against" );
// Create an output buffer
outDataBuffer = clCreateBuffer( context, (cl_mem_flags)(CL_MEM_READ_WRITE), sizeof( outKernelData ), NULL, &error );
test_error( error, "Unable to create output buffer" );
// Set up arguments and run
error = clSetKernelArg( kernel, 0, sizeof( image ), &image );
test_error( error, "Unable to set kernel argument" );
error = clSetKernelArg( kernel, 1, sizeof( outDataBuffer ), &outDataBuffer );
test_error( error, "Unable to set kernel argument" );
size_t threads[1] = { 1 }, localThreads[1] = { 1 };
error = clEnqueueNDRangeKernel( queue, kernel, 1, NULL, threads, localThreads, 0, NULL, NULL );
test_error( error, "Unable to run kernel" );
error = clEnqueueReadBuffer( queue, outDataBuffer, CL_TRUE, 0, sizeof( outKernelData ), &outKernelData, 0, NULL, NULL );
test_error( error, "Unable to read data buffer" );
// Verify the results now
if( outKernelData.width != (cl_int)imageInfo->width )
{
log_error( "ERROR: Returned width did not validate (expected %d, got %d)\n", (int)imageInfo->width, (int)outKernelData.width );
// return -1;
}
if( outKernelData.channelType != (cl_int)outKernelData.expectedChannelType )
{
log_error( "ERROR: Returned channel type did not validate (expected %s (%d), got %d)\n", GetChannelTypeName( imageInfo->format->image_channel_data_type ),
(int)outKernelData.expectedChannelType, (int)outKernelData.channelType );
// return -1;
}
if( outKernelData.channelOrder != (cl_int)outKernelData.expectedChannelOrder )
{
log_error( "ERROR: Returned channel order did not validate (expected %s (%d), got %d)\n", GetChannelOrderName( imageInfo->format->image_channel_order ),
(int)outKernelData.expectedChannelOrder, (int)outKernelData.channelOrder );
// return -1;
}
error = clFinish(queue);
if (error)
print_error(error, "clFinish failed.");
return 0;
}
int test_get_image_info_1D( cl_device_id device, cl_image_format *format )
{
size_t maxWidth;
cl_ulong maxAllocSize, memSize;
image_descriptor imageInfo;
RandomSeed seed( gRandomSeed );
size_t pixelSize;
imageInfo.type = CL_MEM_OBJECT_IMAGE1D;
imageInfo.format = format;
imageInfo.height = imageInfo.depth = imageInfo.slicePitch = 0;
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 1D size from device" );
if( gTestSmallImages )
{
for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
{
imageInfo.rowPitch = imageInfo.width * pixelSize;
if( gDebugTrace )
log_info( " at size %d\n", (int)imageInfo.width );
int ret = test_get_1Dimage_info_single( device, &imageInfo, 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;
log_info( "Testing %d\n", (int)sizes[ idx ][ 0 ]);
if( gDebugTrace )
log_info( " at max size %d\n", (int)sizes[ idx ][ 0 ] );
if( test_get_1Dimage_info_single( device, &imageInfo, 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;
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 * (cl_ulong)imageInfo.height * 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_get_1Dimage_info_single( device, &imageInfo, seed );
if( ret )
return -1;
}
}
return 0;
}
//
// 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, gTestSmallImages, gTestMaxImages;
extern clCommandQueueWrapper queue;
extern clContextWrapper context;
typedef struct image_kernel_data
{
cl_int width;
cl_int channelType;
cl_int channelOrder;
cl_int expectedChannelType;
cl_int expectedChannelOrder;
};
static const char *methodTest1DImageKernelPattern =
"typedef struct {\n"
" int width;\n"
" int channelType;\n"
" int channelOrder;\n"
" int expectedChannelType;\n"
" int expectedChannelOrder;\n"
" } image_kernel_data;\n"
"__kernel void sample_kernel( read_only image1d_t input, __global image_kernel_data *outData )\n"
"{\n"
" outData->width = get_image_width( input );\n"
" outData->channelType = get_image_channel_data_type( input );\n"
" outData->channelOrder = get_image_channel_order( input );\n"
"\n"
" outData->expectedChannelType = %s;\n"
" outData->expectedChannelOrder = %s;\n"
"}";
static int test_get_1Dimage_info_single( cl_device_id device, image_descriptor *imageInfo, MTdata d )
{
int error;
clProgramWrapper program;
clKernelWrapper kernel;
clMemWrapper image, outDataBuffer;
char programSrc[ 10240 ];
image_kernel_data outKernelData;
// Generate some data to test against
BufferOwningPtr<char> imageValues;
generate_random_image_data( imageInfo, imageValues, d );
// Construct testing source
if( gDebugTrace )
log_info( " - Creating 1D image %d ...\n", (int)imageInfo->width );
image = create_image_1d( context, (cl_mem_flags)(CL_MEM_READ_ONLY), imageInfo->format, imageInfo->width, 0, NULL, NULL, &error );
if( image == NULL )
{
log_error( "ERROR: Unable to create 1D image of size %d (%s)", (int)imageInfo->width, IGetErrorString( error ) );
return -1;
}
char channelTypeConstantString[256] = {0};
char channelOrderConstantString[256] = {0};
const char* channelTypeName = GetChannelTypeName( imageInfo->format->image_channel_data_type );
const char* channelOrderName = GetChannelOrderName( imageInfo->format->image_channel_order );
if(channelTypeName && strlen(channelTypeName))
sprintf(channelTypeConstantString, "CLK_%s", &channelTypeName[3]); // replace CL_* with CLK_*
if(channelOrderName && strlen(channelOrderName))
sprintf(channelOrderConstantString, "CLK_%s", &channelOrderName[3]); // replace CL_* with CLK_*
// Create a program to run against
sprintf( programSrc, methodTest1DImageKernelPattern,
channelTypeConstantString, channelOrderConstantString);
//log_info("-----------------------------------\n%s\n", programSrc);
error = clFinish(queue);
if (error)
print_error(error, "clFinish failed.\n");
const char *ptr = programSrc;
error = create_single_kernel_helper( context, &program, &kernel, 1, &ptr, "sample_kernel" );
test_error( error, "Unable to create kernel to test against" );
// Create an output buffer
outDataBuffer = clCreateBuffer( context, (cl_mem_flags)(CL_MEM_READ_WRITE), sizeof( outKernelData ), NULL, &error );
test_error( error, "Unable to create output buffer" );
// Set up arguments and run
error = clSetKernelArg( kernel, 0, sizeof( image ), &image );
test_error( error, "Unable to set kernel argument" );
error = clSetKernelArg( kernel, 1, sizeof( outDataBuffer ), &outDataBuffer );
test_error( error, "Unable to set kernel argument" );
size_t threads[1] = { 1 }, localThreads[1] = { 1 };
error = clEnqueueNDRangeKernel( queue, kernel, 1, NULL, threads, localThreads, 0, NULL, NULL );
test_error( error, "Unable to run kernel" );
error = clEnqueueReadBuffer( queue, outDataBuffer, CL_TRUE, 0, sizeof( outKernelData ), &outKernelData, 0, NULL, NULL );
test_error( error, "Unable to read data buffer" );
// Verify the results now
if( outKernelData.width != (cl_int)imageInfo->width )
{
log_error( "ERROR: Returned width did not validate (expected %d, got %d)\n", (int)imageInfo->width, (int)outKernelData.width );
// return -1;
}
if( outKernelData.channelType != (cl_int)outKernelData.expectedChannelType )
{
log_error( "ERROR: Returned channel type did not validate (expected %s (%d), got %d)\n", GetChannelTypeName( imageInfo->format->image_channel_data_type ),
(int)outKernelData.expectedChannelType, (int)outKernelData.channelType );
// return -1;
}
if( outKernelData.channelOrder != (cl_int)outKernelData.expectedChannelOrder )
{
log_error( "ERROR: Returned channel order did not validate (expected %s (%d), got %d)\n", GetChannelOrderName( imageInfo->format->image_channel_order ),
(int)outKernelData.expectedChannelOrder, (int)outKernelData.channelOrder );
// return -1;
}
error = clFinish(queue);
if (error)
print_error(error, "clFinish failed.");
return 0;
}
int test_get_image_info_1D( cl_device_id device, cl_image_format *format )
{
size_t maxWidth;
cl_ulong maxAllocSize, memSize;
image_descriptor imageInfo;
RandomSeed seed( gRandomSeed );
size_t pixelSize;
imageInfo.type = CL_MEM_OBJECT_IMAGE1D;
imageInfo.format = format;
imageInfo.height = imageInfo.depth = imageInfo.slicePitch = 0;
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 1D size from device" );
if( gTestSmallImages )
{
for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
{
imageInfo.rowPitch = imageInfo.width * pixelSize;
if( gDebugTrace )
log_info( " at size %d\n", (int)imageInfo.width );
int ret = test_get_1Dimage_info_single( device, &imageInfo, 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;
log_info( "Testing %d\n", (int)sizes[ idx ][ 0 ]);
if( gDebugTrace )
log_info( " at max size %d\n", (int)sizes[ idx ][ 0 ] );
if( test_get_1Dimage_info_single( device, &imageInfo, 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;
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 * (cl_ulong)imageInfo.height * 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_get_1Dimage_info_single( device, &imageInfo, seed );
if( ret )
return -1;
}
}
return 0;
}

View File

@@ -1,249 +1,249 @@
//
// 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, gTestSmallImages, gTestMaxImages;
extern clCommandQueueWrapper queue;
extern clContextWrapper context;
typedef struct image_kernel_data
{
cl_int width;
cl_int arraySize;
cl_int channelType;
cl_int channelOrder;
cl_int expectedChannelType;
cl_int expectedChannelOrder;
};
static const char *methodTestKernelPattern =
"typedef struct {\n"
" int width;\n"
" int arraySize;\n"
" int channelType;\n"
" int channelOrder;\n"
" int expectedChannelType;\n"
" int expectedChannelOrder;\n"
" } image_kernel_data;\n"
"__kernel void sample_kernel( read_only image1d_array_t input, __global image_kernel_data *outData )\n"
"{\n"
" outData->width = get_image_width( input );\n"
" outData->arraySize = get_image_array_size( input );\n"
" outData->channelType = get_image_channel_data_type( input );\n"
" outData->channelOrder = get_image_channel_order( input );\n"
"\n"
" outData->expectedChannelType = %s;\n"
" outData->expectedChannelOrder = %s;\n"
"}";
int test_get_1Dimage_array_info_single( cl_device_id device, image_descriptor *imageInfo, MTdata d )
{
int error;
clProgramWrapper program;
clKernelWrapper kernel;
clMemWrapper image, outDataBuffer;
char programSrc[ 10240 ];
image_kernel_data outKernelData;
// Generate some data to test against
BufferOwningPtr<char> imageValues;
generate_random_image_data( imageInfo, imageValues, d );
// Construct testing source
if( gDebugTrace )
log_info( " - Creating 1D image array %d by %d...\n", (int)imageInfo->width, (int)imageInfo->arraySize );
image = create_image_1d_array( context, (cl_mem_flags)(CL_MEM_READ_ONLY), imageInfo->format, imageInfo->width, imageInfo->arraySize, 0, 0, NULL, &error );
if( image == NULL )
{
log_error( "ERROR: Unable to create 1D image array of size %d x %d (%s)", (int)imageInfo->width, (int)imageInfo->arraySize, IGetErrorString( error ) );
return -1;
}
char channelTypeConstantString[256] = {0};
char channelOrderConstantString[256] = {0};
const char* channelTypeName = GetChannelTypeName( imageInfo->format->image_channel_data_type );
const char* channelOrderName = GetChannelOrderName( imageInfo->format->image_channel_order );
if(channelTypeName && strlen(channelTypeName))
sprintf(channelTypeConstantString, "CLK_%s", &channelTypeName[3]); // replace CL_* with CLK_*
if(channelOrderName && strlen(channelOrderName))
sprintf(channelOrderConstantString, "CLK_%s", &channelOrderName[3]); // replace CL_* with CLK_*
// Create a program to run against
sprintf( programSrc, methodTestKernelPattern,
channelTypeConstantString, channelOrderConstantString);
//log_info("-----------------------------------\n%s\n", programSrc);
error = clFinish(queue);
if (error)
print_error(error, "clFinish failed.\n");
const char *ptr = programSrc;
error = create_single_kernel_helper( context, &program, &kernel, 1, &ptr, "sample_kernel" );
test_error( error, "Unable to create kernel to test against" );
// Create an output buffer
outDataBuffer = clCreateBuffer( context, (cl_mem_flags)(CL_MEM_READ_WRITE), sizeof( outKernelData ), NULL, &error );
test_error( error, "Unable to create output buffer" );
// Set up arguments and run
error = clSetKernelArg( kernel, 0, sizeof( image ), &image );
test_error( error, "Unable to set kernel argument" );
error = clSetKernelArg( kernel, 1, sizeof( outDataBuffer ), &outDataBuffer );
test_error( error, "Unable to set kernel argument" );
size_t threads[1] = { 1 }, localThreads[1] = { 1 };
error = clEnqueueNDRangeKernel( queue, kernel, 1, NULL, threads, localThreads, 0, NULL, NULL );
test_error( error, "Unable to run kernel" );
error = clEnqueueReadBuffer( queue, outDataBuffer, CL_TRUE, 0, sizeof( outKernelData ), &outKernelData, 0, NULL, NULL );
test_error( error, "Unable to read data buffer" );
// Verify the results now
if( outKernelData.width != (cl_int)imageInfo->width )
{
log_error( "ERROR: Returned width did not validate (expected %d, got %d)\n", (int)imageInfo->width, (int)outKernelData.width );
// return -1;
}
if( outKernelData.arraySize != (cl_int)imageInfo->arraySize )
{
log_error( "ERROR: Returned array size did not validate (expected %d, got %d)\n", (int)imageInfo->arraySize, (int)outKernelData.arraySize );
// return -1;
}
if( outKernelData.channelType != (cl_int)outKernelData.expectedChannelType )
{
log_error( "ERROR: Returned channel type did not validate (expected %s (%d), got %d)\n", GetChannelTypeName( imageInfo->format->image_channel_data_type ),
(int)outKernelData.expectedChannelType, (int)outKernelData.channelType );
// return -1;
}
if( outKernelData.channelOrder != (cl_int)outKernelData.expectedChannelOrder )
{
log_error( "ERROR: Returned channel order did not validate (expected %s (%d), got %d)\n", GetChannelOrderName( imageInfo->format->image_channel_order ),
(int)outKernelData.expectedChannelOrder, (int)outKernelData.channelOrder );
// return -1;
}
error = clFinish(queue);
if (error)
print_error(error, "clFinish failed.");
return 0;
}
int test_get_image_info_1D_array( cl_device_id device, cl_image_format *format )
{
size_t maxWidth, maxArraySize;
cl_ulong maxAllocSize, memSize;
image_descriptor imageInfo;
RandomSeed seed( gRandomSeed );
size_t pixelSize;
imageInfo.type = CL_MEM_OBJECT_IMAGE1D_ARRAY;
imageInfo.format = format;
imageInfo.height = imageInfo.depth = imageInfo.slicePitch = 0;
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 2D size from device" );
if( gTestSmallImages )
{
for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
{
imageInfo.rowPitch = imageInfo.width * pixelSize;
imageInfo.slicePitch = imageInfo.rowPitch;
for( imageInfo.arraySize = 1; imageInfo.arraySize < 9; imageInfo.arraySize++ )
{
if( gDebugTrace )
log_info( " at size %d,%d\n", (int)imageInfo.width, (int)imageInfo.arraySize );
int ret = test_get_1Dimage_array_info_single( device, &imageInfo, 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;
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_get_1Dimage_array_info_single( device, &imageInfo, 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;
size_t extraWidth = (int)random_log_in_range( 0, 64, seed );
imageInfo.rowPitch += extraWidth;
do {
extraWidth++;
imageInfo.rowPitch += extraWidth;
} while ((imageInfo.rowPitch % pixelSize) != 0);
imageInfo.slicePitch = imageInfo.rowPitch;
size = (cl_ulong)imageInfo.rowPitch * (cl_ulong)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_get_1Dimage_array_info_single( device, &imageInfo, seed );
if( ret )
return -1;
}
}
return 0;
}
//
// 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, gTestSmallImages, gTestMaxImages;
extern clCommandQueueWrapper queue;
extern clContextWrapper context;
typedef struct image_kernel_data
{
cl_int width;
cl_int arraySize;
cl_int channelType;
cl_int channelOrder;
cl_int expectedChannelType;
cl_int expectedChannelOrder;
};
static const char *methodTestKernelPattern =
"typedef struct {\n"
" int width;\n"
" int arraySize;\n"
" int channelType;\n"
" int channelOrder;\n"
" int expectedChannelType;\n"
" int expectedChannelOrder;\n"
" } image_kernel_data;\n"
"__kernel void sample_kernel( read_only image1d_array_t input, __global image_kernel_data *outData )\n"
"{\n"
" outData->width = get_image_width( input );\n"
" outData->arraySize = get_image_array_size( input );\n"
" outData->channelType = get_image_channel_data_type( input );\n"
" outData->channelOrder = get_image_channel_order( input );\n"
"\n"
" outData->expectedChannelType = %s;\n"
" outData->expectedChannelOrder = %s;\n"
"}";
int test_get_1Dimage_array_info_single( cl_device_id device, image_descriptor *imageInfo, MTdata d )
{
int error;
clProgramWrapper program;
clKernelWrapper kernel;
clMemWrapper image, outDataBuffer;
char programSrc[ 10240 ];
image_kernel_data outKernelData;
// Generate some data to test against
BufferOwningPtr<char> imageValues;
generate_random_image_data( imageInfo, imageValues, d );
// Construct testing source
if( gDebugTrace )
log_info( " - Creating 1D image array %d by %d...\n", (int)imageInfo->width, (int)imageInfo->arraySize );
image = create_image_1d_array( context, (cl_mem_flags)(CL_MEM_READ_ONLY), imageInfo->format, imageInfo->width, imageInfo->arraySize, 0, 0, NULL, &error );
if( image == NULL )
{
log_error( "ERROR: Unable to create 1D image array of size %d x %d (%s)", (int)imageInfo->width, (int)imageInfo->arraySize, IGetErrorString( error ) );
return -1;
}
char channelTypeConstantString[256] = {0};
char channelOrderConstantString[256] = {0};
const char* channelTypeName = GetChannelTypeName( imageInfo->format->image_channel_data_type );
const char* channelOrderName = GetChannelOrderName( imageInfo->format->image_channel_order );
if(channelTypeName && strlen(channelTypeName))
sprintf(channelTypeConstantString, "CLK_%s", &channelTypeName[3]); // replace CL_* with CLK_*
if(channelOrderName && strlen(channelOrderName))
sprintf(channelOrderConstantString, "CLK_%s", &channelOrderName[3]); // replace CL_* with CLK_*
// Create a program to run against
sprintf( programSrc, methodTestKernelPattern,
channelTypeConstantString, channelOrderConstantString);
//log_info("-----------------------------------\n%s\n", programSrc);
error = clFinish(queue);
if (error)
print_error(error, "clFinish failed.\n");
const char *ptr = programSrc;
error = create_single_kernel_helper( context, &program, &kernel, 1, &ptr, "sample_kernel" );
test_error( error, "Unable to create kernel to test against" );
// Create an output buffer
outDataBuffer = clCreateBuffer( context, (cl_mem_flags)(CL_MEM_READ_WRITE), sizeof( outKernelData ), NULL, &error );
test_error( error, "Unable to create output buffer" );
// Set up arguments and run
error = clSetKernelArg( kernel, 0, sizeof( image ), &image );
test_error( error, "Unable to set kernel argument" );
error = clSetKernelArg( kernel, 1, sizeof( outDataBuffer ), &outDataBuffer );
test_error( error, "Unable to set kernel argument" );
size_t threads[1] = { 1 }, localThreads[1] = { 1 };
error = clEnqueueNDRangeKernel( queue, kernel, 1, NULL, threads, localThreads, 0, NULL, NULL );
test_error( error, "Unable to run kernel" );
error = clEnqueueReadBuffer( queue, outDataBuffer, CL_TRUE, 0, sizeof( outKernelData ), &outKernelData, 0, NULL, NULL );
test_error( error, "Unable to read data buffer" );
// Verify the results now
if( outKernelData.width != (cl_int)imageInfo->width )
{
log_error( "ERROR: Returned width did not validate (expected %d, got %d)\n", (int)imageInfo->width, (int)outKernelData.width );
// return -1;
}
if( outKernelData.arraySize != (cl_int)imageInfo->arraySize )
{
log_error( "ERROR: Returned array size did not validate (expected %d, got %d)\n", (int)imageInfo->arraySize, (int)outKernelData.arraySize );
// return -1;
}
if( outKernelData.channelType != (cl_int)outKernelData.expectedChannelType )
{
log_error( "ERROR: Returned channel type did not validate (expected %s (%d), got %d)\n", GetChannelTypeName( imageInfo->format->image_channel_data_type ),
(int)outKernelData.expectedChannelType, (int)outKernelData.channelType );
// return -1;
}
if( outKernelData.channelOrder != (cl_int)outKernelData.expectedChannelOrder )
{
log_error( "ERROR: Returned channel order did not validate (expected %s (%d), got %d)\n", GetChannelOrderName( imageInfo->format->image_channel_order ),
(int)outKernelData.expectedChannelOrder, (int)outKernelData.channelOrder );
// return -1;
}
error = clFinish(queue);
if (error)
print_error(error, "clFinish failed.");
return 0;
}
int test_get_image_info_1D_array( cl_device_id device, cl_image_format *format )
{
size_t maxWidth, maxArraySize;
cl_ulong maxAllocSize, memSize;
image_descriptor imageInfo;
RandomSeed seed( gRandomSeed );
size_t pixelSize;
imageInfo.type = CL_MEM_OBJECT_IMAGE1D_ARRAY;
imageInfo.format = format;
imageInfo.height = imageInfo.depth = imageInfo.slicePitch = 0;
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 2D size from device" );
if( gTestSmallImages )
{
for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
{
imageInfo.rowPitch = imageInfo.width * pixelSize;
imageInfo.slicePitch = imageInfo.rowPitch;
for( imageInfo.arraySize = 1; imageInfo.arraySize < 9; imageInfo.arraySize++ )
{
if( gDebugTrace )
log_info( " at size %d,%d\n", (int)imageInfo.width, (int)imageInfo.arraySize );
int ret = test_get_1Dimage_array_info_single( device, &imageInfo, 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;
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_get_1Dimage_array_info_single( device, &imageInfo, 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;
size_t extraWidth = (int)random_log_in_range( 0, 64, seed );
imageInfo.rowPitch += extraWidth;
do {
extraWidth++;
imageInfo.rowPitch += extraWidth;
} while ((imageInfo.rowPitch % pixelSize) != 0);
imageInfo.slicePitch = imageInfo.rowPitch;
size = (cl_ulong)imageInfo.rowPitch * (cl_ulong)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_get_1Dimage_array_info_single( device, &imageInfo, seed );
if( ret )
return -1;
}
}
return 0;
}

View File

@@ -1,288 +1,288 @@
//
// 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, gTestSmallImages, gTestMaxImages;
extern clCommandQueueWrapper queue;
extern clContextWrapper context;
typedef struct image_kernel_data
{
cl_int width;
cl_int height;
cl_int depth;
cl_int widthDim;
cl_int heightDim;
cl_int depthDim;
cl_int channelType;
cl_int channelOrder;
cl_int expectedChannelType;
cl_int expectedChannelOrder;
};
static const char *methodTestKernelPattern =
"typedef struct {\n"
" int width;\n"
" int height;\n"
" int depth;\n"
" int widthDim;\n"
" int heightDim;\n"
" int depthDim;\n"
" int channelType;\n"
" int channelOrder;\n"
" int expectedChannelType;\n"
" int expectedChannelOrder;\n"
" } image_kernel_data;\n"
"__kernel void sample_kernel( read_only image%dd_t input, __global image_kernel_data *outData )\n"
"{\n"
" outData->width = get_image_width( input );\n"
" outData->height = get_image_height( input );\n"
"%s\n"
" int%d dim = get_image_dim( input );\n"
" outData->widthDim = dim.x;\n"
" outData->heightDim = dim.y;\n"
"%s\n"
" outData->channelType = get_image_channel_data_type( input );\n"
" outData->channelOrder = get_image_channel_order( input );\n"
"\n"
" outData->expectedChannelType = %s;\n"
" outData->expectedChannelOrder = %s;\n"
"}";
static const char *depthKernelLine = " outData->depth = get_image_depth( input );\n";
static const char *depthDimKernelLine = " outData->depthDim = dim.z;\n";
int test_get_image_info_single( cl_device_id device, image_descriptor *imageInfo, MTdata d )
{
int error;
clProgramWrapper program;
clKernelWrapper kernel;
clMemWrapper image, outDataBuffer;
char programSrc[ 10240 ];
image_kernel_data outKernelData;
// Generate some data to test against
BufferOwningPtr<char> imageValues;
generate_random_image_data( imageInfo, imageValues, d );
// Construct testing source
if( gDebugTrace )
log_info( " - Creating image %d by %d...\n", (int)imageInfo->width, (int)imageInfo->height );
if( imageInfo->depth != 0 )
image = create_image_3d( context, (cl_mem_flags)(CL_MEM_READ_ONLY), imageInfo->format, imageInfo->width, imageInfo->height, imageInfo->depth, 0, 0, NULL, &error );
else
image = create_image_2d( context, (cl_mem_flags)(CL_MEM_READ_ONLY), imageInfo->format, imageInfo->width, imageInfo->height, 0, NULL, &error );
if( image == NULL )
{
log_error( "ERROR: Unable to create image of size %d x %d x %d (%s)", (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->depth, IGetErrorString( error ) );
return -1;
}
char channelTypeConstantString[256] = {0};
char channelOrderConstantString[256] = {0};
const char* channelTypeName = GetChannelTypeName( imageInfo->format->image_channel_data_type );
const char* channelOrderName = GetChannelOrderName( imageInfo->format->image_channel_order );
if(channelTypeName && strlen(channelTypeName))
sprintf(channelTypeConstantString, "CLK_%s", &channelTypeName[3]); // replace CL_* with CLK_*
if(channelOrderName && strlen(channelOrderName))
sprintf(channelOrderConstantString, "CLK_%s", &channelOrderName[3]); // replace CL_* with CLK_*
// Create a program to run against
sprintf( programSrc, methodTestKernelPattern,
( imageInfo->depth != 0 ) ? 3 : 2,
( imageInfo->depth != 0 ) ? depthKernelLine : "",
( imageInfo->depth != 0 ) ? 4 : 2,
( imageInfo->depth != 0 ) ? depthDimKernelLine : "",
channelTypeConstantString, channelOrderConstantString);
//log_info("-----------------------------------\n%s\n", programSrc);
error = clFinish(queue);
if (error)
print_error(error, "clFinish failed.\n");
const char *ptr = programSrc;
error = create_single_kernel_helper( context, &program, &kernel, 1, &ptr, "sample_kernel" );
test_error( error, "Unable to create kernel to test against" );
// Create an output buffer
outDataBuffer = clCreateBuffer( context, (cl_mem_flags)(CL_MEM_READ_WRITE), sizeof( outKernelData ), NULL, &error );
test_error( error, "Unable to create output buffer" );
// Set up arguments and run
error = clSetKernelArg( kernel, 0, sizeof( image ), &image );
test_error( error, "Unable to set kernel argument" );
error = clSetKernelArg( kernel, 1, sizeof( outDataBuffer ), &outDataBuffer );
test_error( error, "Unable to set kernel argument" );
size_t threads[1] = { 1 }, localThreads[1] = { 1 };
error = clEnqueueNDRangeKernel( queue, kernel, 1, NULL, threads, localThreads, 0, NULL, NULL );
test_error( error, "Unable to run kernel" );
error = clEnqueueReadBuffer( queue, outDataBuffer, CL_TRUE, 0, sizeof( outKernelData ), &outKernelData, 0, NULL, NULL );
test_error( error, "Unable to read data buffer" );
// Verify the results now
if( outKernelData.width != (cl_int)imageInfo->width )
{
log_error( "ERROR: Returned width did not validate (expected %d, got %d)\n", (int)imageInfo->width, (int)outKernelData.width );
// return -1;
}
if( outKernelData.height != (cl_int)imageInfo->height )
{
log_error( "ERROR: Returned height did not validate (expected %d, got %d)\n", (int)imageInfo->height, (int)outKernelData.height );
// return -1;
}
if( ( imageInfo->depth != 0 ) && ( outKernelData.depth != (cl_int)imageInfo->depth ) )
{
log_error( "ERROR: Returned depth did not validate (expected %d, got %d)\n", (int)imageInfo->depth, (int)outKernelData.depth );
// return -1;
}
if( outKernelData.widthDim != (cl_int)imageInfo->width )
{
log_error( "ERROR: Returned width from get_image_dim did not validate (expected %d, got %d)\n", (int)imageInfo->width, (int)outKernelData.widthDim );
// return -1;
}
if( outKernelData.heightDim != (cl_int)imageInfo->height )
{
log_error( "ERROR: Returned height from get_image_dim did not validate (expected %d, got %d)\n", (int)imageInfo->height, (int)outKernelData.heightDim );
// return -1;
}
if( ( imageInfo->depth != 0 ) && ( outKernelData.depthDim != (cl_int)imageInfo->depth ) )
{
log_error( "ERROR: Returned depth from get_image_dim did not validate (expected %d, got %d)\n", (int)imageInfo->depth, (int)outKernelData.depthDim );
// return -1;
}
if( outKernelData.channelType != (cl_int)outKernelData.expectedChannelType )
{
log_error( "ERROR: Returned channel type did not validate (expected %s (%d), got %d)\n", GetChannelTypeName( imageInfo->format->image_channel_data_type ),
(int)outKernelData.expectedChannelType, (int)outKernelData.channelType );
// return -1;
}
if( outKernelData.channelOrder != (cl_int)outKernelData.expectedChannelOrder )
{
log_error( "ERROR: Returned channel order did not validate (expected %s (%d), got %d)\n", GetChannelOrderName( imageInfo->format->image_channel_order ),
(int)outKernelData.expectedChannelOrder, (int)outKernelData.channelOrder );
// return -1;
}
error = clFinish(queue);
if (error)
print_error(error, "clFinish failed.");
return 0;
}
int test_get_image_info_2D( cl_device_id device, cl_image_format *format )
{
size_t maxWidth, maxHeight;
cl_ulong maxAllocSize, memSize;
image_descriptor imageInfo;
RandomSeed seed( gRandomSeed );
size_t pixelSize;
imageInfo.type = CL_MEM_OBJECT_IMAGE2D;
imageInfo.format = format;
imageInfo.depth = imageInfo.slicePitch = 0;
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( gTestSmallImages )
{
for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
{
imageInfo.rowPitch = imageInfo.width * pixelSize;
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_get_image_info_single( device, &imageInfo, 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;
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_get_image_info_single( device, &imageInfo, 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;
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 * (cl_ulong)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_get_image_info_single( device, &imageInfo, seed );
if( ret )
return -1;
}
}
return 0;
}
//
// 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, gTestSmallImages, gTestMaxImages;
extern clCommandQueueWrapper queue;
extern clContextWrapper context;
typedef struct image_kernel_data
{
cl_int width;
cl_int height;
cl_int depth;
cl_int widthDim;
cl_int heightDim;
cl_int depthDim;
cl_int channelType;
cl_int channelOrder;
cl_int expectedChannelType;
cl_int expectedChannelOrder;
};
static const char *methodTestKernelPattern =
"typedef struct {\n"
" int width;\n"
" int height;\n"
" int depth;\n"
" int widthDim;\n"
" int heightDim;\n"
" int depthDim;\n"
" int channelType;\n"
" int channelOrder;\n"
" int expectedChannelType;\n"
" int expectedChannelOrder;\n"
" } image_kernel_data;\n"
"__kernel void sample_kernel( read_only image%dd_t input, __global image_kernel_data *outData )\n"
"{\n"
" outData->width = get_image_width( input );\n"
" outData->height = get_image_height( input );\n"
"%s\n"
" int%d dim = get_image_dim( input );\n"
" outData->widthDim = dim.x;\n"
" outData->heightDim = dim.y;\n"
"%s\n"
" outData->channelType = get_image_channel_data_type( input );\n"
" outData->channelOrder = get_image_channel_order( input );\n"
"\n"
" outData->expectedChannelType = %s;\n"
" outData->expectedChannelOrder = %s;\n"
"}";
static const char *depthKernelLine = " outData->depth = get_image_depth( input );\n";
static const char *depthDimKernelLine = " outData->depthDim = dim.z;\n";
int test_get_image_info_single( cl_device_id device, image_descriptor *imageInfo, MTdata d )
{
int error;
clProgramWrapper program;
clKernelWrapper kernel;
clMemWrapper image, outDataBuffer;
char programSrc[ 10240 ];
image_kernel_data outKernelData;
// Generate some data to test against
BufferOwningPtr<char> imageValues;
generate_random_image_data( imageInfo, imageValues, d );
// Construct testing source
if( gDebugTrace )
log_info( " - Creating image %d by %d...\n", (int)imageInfo->width, (int)imageInfo->height );
if( imageInfo->depth != 0 )
image = create_image_3d( context, (cl_mem_flags)(CL_MEM_READ_ONLY), imageInfo->format, imageInfo->width, imageInfo->height, imageInfo->depth, 0, 0, NULL, &error );
else
image = create_image_2d( context, (cl_mem_flags)(CL_MEM_READ_ONLY), imageInfo->format, imageInfo->width, imageInfo->height, 0, NULL, &error );
if( image == NULL )
{
log_error( "ERROR: Unable to create image of size %d x %d x %d (%s)", (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->depth, IGetErrorString( error ) );
return -1;
}
char channelTypeConstantString[256] = {0};
char channelOrderConstantString[256] = {0};
const char* channelTypeName = GetChannelTypeName( imageInfo->format->image_channel_data_type );
const char* channelOrderName = GetChannelOrderName( imageInfo->format->image_channel_order );
if(channelTypeName && strlen(channelTypeName))
sprintf(channelTypeConstantString, "CLK_%s", &channelTypeName[3]); // replace CL_* with CLK_*
if(channelOrderName && strlen(channelOrderName))
sprintf(channelOrderConstantString, "CLK_%s", &channelOrderName[3]); // replace CL_* with CLK_*
// Create a program to run against
sprintf( programSrc, methodTestKernelPattern,
( imageInfo->depth != 0 ) ? 3 : 2,
( imageInfo->depth != 0 ) ? depthKernelLine : "",
( imageInfo->depth != 0 ) ? 4 : 2,
( imageInfo->depth != 0 ) ? depthDimKernelLine : "",
channelTypeConstantString, channelOrderConstantString);
//log_info("-----------------------------------\n%s\n", programSrc);
error = clFinish(queue);
if (error)
print_error(error, "clFinish failed.\n");
const char *ptr = programSrc;
error = create_single_kernel_helper( context, &program, &kernel, 1, &ptr, "sample_kernel" );
test_error( error, "Unable to create kernel to test against" );
// Create an output buffer
outDataBuffer = clCreateBuffer( context, (cl_mem_flags)(CL_MEM_READ_WRITE), sizeof( outKernelData ), NULL, &error );
test_error( error, "Unable to create output buffer" );
// Set up arguments and run
error = clSetKernelArg( kernel, 0, sizeof( image ), &image );
test_error( error, "Unable to set kernel argument" );
error = clSetKernelArg( kernel, 1, sizeof( outDataBuffer ), &outDataBuffer );
test_error( error, "Unable to set kernel argument" );
size_t threads[1] = { 1 }, localThreads[1] = { 1 };
error = clEnqueueNDRangeKernel( queue, kernel, 1, NULL, threads, localThreads, 0, NULL, NULL );
test_error( error, "Unable to run kernel" );
error = clEnqueueReadBuffer( queue, outDataBuffer, CL_TRUE, 0, sizeof( outKernelData ), &outKernelData, 0, NULL, NULL );
test_error( error, "Unable to read data buffer" );
// Verify the results now
if( outKernelData.width != (cl_int)imageInfo->width )
{
log_error( "ERROR: Returned width did not validate (expected %d, got %d)\n", (int)imageInfo->width, (int)outKernelData.width );
// return -1;
}
if( outKernelData.height != (cl_int)imageInfo->height )
{
log_error( "ERROR: Returned height did not validate (expected %d, got %d)\n", (int)imageInfo->height, (int)outKernelData.height );
// return -1;
}
if( ( imageInfo->depth != 0 ) && ( outKernelData.depth != (cl_int)imageInfo->depth ) )
{
log_error( "ERROR: Returned depth did not validate (expected %d, got %d)\n", (int)imageInfo->depth, (int)outKernelData.depth );
// return -1;
}
if( outKernelData.widthDim != (cl_int)imageInfo->width )
{
log_error( "ERROR: Returned width from get_image_dim did not validate (expected %d, got %d)\n", (int)imageInfo->width, (int)outKernelData.widthDim );
// return -1;
}
if( outKernelData.heightDim != (cl_int)imageInfo->height )
{
log_error( "ERROR: Returned height from get_image_dim did not validate (expected %d, got %d)\n", (int)imageInfo->height, (int)outKernelData.heightDim );
// return -1;
}
if( ( imageInfo->depth != 0 ) && ( outKernelData.depthDim != (cl_int)imageInfo->depth ) )
{
log_error( "ERROR: Returned depth from get_image_dim did not validate (expected %d, got %d)\n", (int)imageInfo->depth, (int)outKernelData.depthDim );
// return -1;
}
if( outKernelData.channelType != (cl_int)outKernelData.expectedChannelType )
{
log_error( "ERROR: Returned channel type did not validate (expected %s (%d), got %d)\n", GetChannelTypeName( imageInfo->format->image_channel_data_type ),
(int)outKernelData.expectedChannelType, (int)outKernelData.channelType );
// return -1;
}
if( outKernelData.channelOrder != (cl_int)outKernelData.expectedChannelOrder )
{
log_error( "ERROR: Returned channel order did not validate (expected %s (%d), got %d)\n", GetChannelOrderName( imageInfo->format->image_channel_order ),
(int)outKernelData.expectedChannelOrder, (int)outKernelData.channelOrder );
// return -1;
}
error = clFinish(queue);
if (error)
print_error(error, "clFinish failed.");
return 0;
}
int test_get_image_info_2D( cl_device_id device, cl_image_format *format )
{
size_t maxWidth, maxHeight;
cl_ulong maxAllocSize, memSize;
image_descriptor imageInfo;
RandomSeed seed( gRandomSeed );
size_t pixelSize;
imageInfo.type = CL_MEM_OBJECT_IMAGE2D;
imageInfo.format = format;
imageInfo.depth = imageInfo.slicePitch = 0;
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( gTestSmallImages )
{
for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
{
imageInfo.rowPitch = imageInfo.width * pixelSize;
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_get_image_info_single( device, &imageInfo, 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;
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_get_image_info_single( device, &imageInfo, 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;
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 * (cl_ulong)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_get_image_info_single( device, &imageInfo, seed );
if( ret )
return -1;
}
}
return 0;
}

View File

@@ -1,265 +1,265 @@
//
// 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, gTestSmallImages, gTestMaxImages;
extern clCommandQueueWrapper queue;
extern clContextWrapper context;
typedef struct image_kernel_data
{
cl_int width;
cl_int height;
cl_int arraySize;
cl_int channelType;
cl_int channelOrder;
cl_int expectedChannelType;
cl_int expectedChannelOrder;
};
static const char *methodTestKernelPattern =
"typedef struct {\n"
" int width;\n"
" int height;\n"
" int arraySize;\n"
" int channelType;\n"
" int channelOrder;\n"
" int expectedChannelType;\n"
" int expectedChannelOrder;\n"
" } image_kernel_data;\n"
"__kernel void sample_kernel( read_only image2d_array_t input, __global image_kernel_data *outData )\n"
"{\n"
" outData->width = get_image_width( input );\n"
" outData->height = get_image_height( input );\n"
" outData->arraySize = get_image_array_size( input );\n"
" outData->channelType = get_image_channel_data_type( input );\n"
" outData->channelOrder = get_image_channel_order( input );\n"
"\n"
" outData->expectedChannelType = %s;\n"
" outData->expectedChannelOrder = %s;\n"
"}";
int test_get_2Dimage_array_info_single( cl_device_id device, image_descriptor *imageInfo, MTdata d )
{
int error;
clProgramWrapper program;
clKernelWrapper kernel;
clMemWrapper image, outDataBuffer;
char programSrc[ 10240 ];
image_kernel_data outKernelData;
// Generate some data to test against
BufferOwningPtr<char> imageValues;
generate_random_image_data( imageInfo, imageValues, d );
// Construct testing source
if( gDebugTrace )
log_info( " - Creating 2D image array %d by %d by %d...\n", (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->arraySize );
image = create_image_2d_array( context, (cl_mem_flags)(CL_MEM_READ_ONLY), imageInfo->format, imageInfo->width, imageInfo->height, imageInfo->arraySize, 0, 0, NULL, &error );
if( image == NULL )
{
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 ) );
return -1;
}
char channelTypeConstantString[256] = {0};
char channelOrderConstantString[256] = {0};
const char* channelTypeName = GetChannelTypeName( imageInfo->format->image_channel_data_type );
const char* channelOrderName = GetChannelOrderName( imageInfo->format->image_channel_order );
if(channelTypeName && strlen(channelTypeName))
sprintf(channelTypeConstantString, "CLK_%s", &channelTypeName[3]); // replace CL_* with CLK_*
if(channelOrderName && strlen(channelOrderName))
sprintf(channelOrderConstantString, "CLK_%s", &channelOrderName[3]); // replace CL_* with CLK_*
// Create a program to run against
sprintf( programSrc, methodTestKernelPattern,
channelTypeConstantString, channelOrderConstantString);
//log_info("-----------------------------------\n%s\n", programSrc);
error = clFinish(queue);
if (error)
print_error(error, "clFinish failed.\n");
const char *ptr = programSrc;
error = create_single_kernel_helper( context, &program, &kernel, 1, &ptr, "sample_kernel" );
test_error( error, "Unable to create kernel to test against" );
// Create an output buffer
outDataBuffer = clCreateBuffer( context, (cl_mem_flags)(CL_MEM_READ_WRITE), sizeof( outKernelData ), NULL, &error );
test_error( error, "Unable to create output buffer" );
// Set up arguments and run
error = clSetKernelArg( kernel, 0, sizeof( image ), &image );
test_error( error, "Unable to set kernel argument" );
error = clSetKernelArg( kernel, 1, sizeof( outDataBuffer ), &outDataBuffer );
test_error( error, "Unable to set kernel argument" );
size_t threads[1] = { 1 }, localThreads[1] = { 1 };
error = clEnqueueNDRangeKernel( queue, kernel, 1, NULL, threads, localThreads, 0, NULL, NULL );
test_error( error, "Unable to run kernel" );
error = clEnqueueReadBuffer( queue, outDataBuffer, CL_TRUE, 0, sizeof( outKernelData ), &outKernelData, 0, NULL, NULL );
test_error( error, "Unable to read data buffer" );
// Verify the results now
if( outKernelData.width != (cl_int)imageInfo->width )
{
log_error( "ERROR: Returned width did not validate (expected %d, got %d)\n", (int)imageInfo->width, (int)outKernelData.width );
// return -1;
}
if( outKernelData.height != (cl_int)imageInfo->height )
{
log_error( "ERROR: Returned height did not validate (expected %d, got %d)\n", (int)imageInfo->height, (int)outKernelData.height );
// return -1;
}
if( outKernelData.arraySize != (cl_int)imageInfo->arraySize )
{
log_error( "ERROR: Returned array size did not validate (expected %d, got %d)\n", (int)imageInfo->arraySize, (int)outKernelData.arraySize );
// return -1;
}
if( outKernelData.channelType != (cl_int)outKernelData.expectedChannelType )
{
log_error( "ERROR: Returned channel type did not validate (expected %s (%d), got %d)\n", GetChannelTypeName( imageInfo->format->image_channel_data_type ),
(int)outKernelData.expectedChannelType, (int)outKernelData.channelType );
// return -1;
}
if( outKernelData.channelOrder != (cl_int)outKernelData.expectedChannelOrder )
{
log_error( "ERROR: Returned channel order did not validate (expected %s (%d), got %d)\n", GetChannelOrderName( imageInfo->format->image_channel_order ),
(int)outKernelData.expectedChannelOrder, (int)outKernelData.channelOrder );
// return -1;
}
error = clFinish(queue);
if (error)
print_error(error, "clFinish failed.");
return 0;
}
int test_get_image_info_2D_array( cl_device_id device, cl_image_format *format )
{
size_t maxWidth, maxHeight, maxArraySize;
cl_ulong maxAllocSize, memSize;
image_descriptor imageInfo;
RandomSeed seed( gRandomSeed );
size_t pixelSize;
imageInfo.type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
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_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 3D size from device" );
if( gTestSmallImages )
{
for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
{
imageInfo.rowPitch = imageInfo.width * pixelSize;
for( imageInfo.height = 1; imageInfo.height < 9; imageInfo.height++ )
{
imageInfo.slicePitch = imageInfo.rowPitch * imageInfo.height;
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_get_2Dimage_array_info_single( device, &imageInfo, 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;
imageInfo.slicePitch = imageInfo.height * imageInfo.rowPitch;
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_get_2Dimage_array_info_single( device, &imageInfo, 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.arraySize = (size_t)random_log_in_range( 16, (int)maxArraySize / 32, seed );
imageInfo.rowPitch = imageInfo.width * pixelSize;
imageInfo.slicePitch = imageInfo.rowPitch * imageInfo.height;
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_t extraHeight = (int)random_log_in_range( 0, 8, seed );
imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + extraHeight);
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_get_2Dimage_array_info_single( device, &imageInfo, seed );
if( ret )
return -1;
}
}
return 0;
}
//
// 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, gTestSmallImages, gTestMaxImages;
extern clCommandQueueWrapper queue;
extern clContextWrapper context;
typedef struct image_kernel_data
{
cl_int width;
cl_int height;
cl_int arraySize;
cl_int channelType;
cl_int channelOrder;
cl_int expectedChannelType;
cl_int expectedChannelOrder;
};
static const char *methodTestKernelPattern =
"typedef struct {\n"
" int width;\n"
" int height;\n"
" int arraySize;\n"
" int channelType;\n"
" int channelOrder;\n"
" int expectedChannelType;\n"
" int expectedChannelOrder;\n"
" } image_kernel_data;\n"
"__kernel void sample_kernel( read_only image2d_array_t input, __global image_kernel_data *outData )\n"
"{\n"
" outData->width = get_image_width( input );\n"
" outData->height = get_image_height( input );\n"
" outData->arraySize = get_image_array_size( input );\n"
" outData->channelType = get_image_channel_data_type( input );\n"
" outData->channelOrder = get_image_channel_order( input );\n"
"\n"
" outData->expectedChannelType = %s;\n"
" outData->expectedChannelOrder = %s;\n"
"}";
int test_get_2Dimage_array_info_single( cl_device_id device, image_descriptor *imageInfo, MTdata d )
{
int error;
clProgramWrapper program;
clKernelWrapper kernel;
clMemWrapper image, outDataBuffer;
char programSrc[ 10240 ];
image_kernel_data outKernelData;
// Generate some data to test against
BufferOwningPtr<char> imageValues;
generate_random_image_data( imageInfo, imageValues, d );
// Construct testing source
if( gDebugTrace )
log_info( " - Creating 2D image array %d by %d by %d...\n", (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->arraySize );
image = create_image_2d_array( context, (cl_mem_flags)(CL_MEM_READ_ONLY), imageInfo->format, imageInfo->width, imageInfo->height, imageInfo->arraySize, 0, 0, NULL, &error );
if( image == NULL )
{
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 ) );
return -1;
}
char channelTypeConstantString[256] = {0};
char channelOrderConstantString[256] = {0};
const char* channelTypeName = GetChannelTypeName( imageInfo->format->image_channel_data_type );
const char* channelOrderName = GetChannelOrderName( imageInfo->format->image_channel_order );
if(channelTypeName && strlen(channelTypeName))
sprintf(channelTypeConstantString, "CLK_%s", &channelTypeName[3]); // replace CL_* with CLK_*
if(channelOrderName && strlen(channelOrderName))
sprintf(channelOrderConstantString, "CLK_%s", &channelOrderName[3]); // replace CL_* with CLK_*
// Create a program to run against
sprintf( programSrc, methodTestKernelPattern,
channelTypeConstantString, channelOrderConstantString);
//log_info("-----------------------------------\n%s\n", programSrc);
error = clFinish(queue);
if (error)
print_error(error, "clFinish failed.\n");
const char *ptr = programSrc;
error = create_single_kernel_helper( context, &program, &kernel, 1, &ptr, "sample_kernel" );
test_error( error, "Unable to create kernel to test against" );
// Create an output buffer
outDataBuffer = clCreateBuffer( context, (cl_mem_flags)(CL_MEM_READ_WRITE), sizeof( outKernelData ), NULL, &error );
test_error( error, "Unable to create output buffer" );
// Set up arguments and run
error = clSetKernelArg( kernel, 0, sizeof( image ), &image );
test_error( error, "Unable to set kernel argument" );
error = clSetKernelArg( kernel, 1, sizeof( outDataBuffer ), &outDataBuffer );
test_error( error, "Unable to set kernel argument" );
size_t threads[1] = { 1 }, localThreads[1] = { 1 };
error = clEnqueueNDRangeKernel( queue, kernel, 1, NULL, threads, localThreads, 0, NULL, NULL );
test_error( error, "Unable to run kernel" );
error = clEnqueueReadBuffer( queue, outDataBuffer, CL_TRUE, 0, sizeof( outKernelData ), &outKernelData, 0, NULL, NULL );
test_error( error, "Unable to read data buffer" );
// Verify the results now
if( outKernelData.width != (cl_int)imageInfo->width )
{
log_error( "ERROR: Returned width did not validate (expected %d, got %d)\n", (int)imageInfo->width, (int)outKernelData.width );
// return -1;
}
if( outKernelData.height != (cl_int)imageInfo->height )
{
log_error( "ERROR: Returned height did not validate (expected %d, got %d)\n", (int)imageInfo->height, (int)outKernelData.height );
// return -1;
}
if( outKernelData.arraySize != (cl_int)imageInfo->arraySize )
{
log_error( "ERROR: Returned array size did not validate (expected %d, got %d)\n", (int)imageInfo->arraySize, (int)outKernelData.arraySize );
// return -1;
}
if( outKernelData.channelType != (cl_int)outKernelData.expectedChannelType )
{
log_error( "ERROR: Returned channel type did not validate (expected %s (%d), got %d)\n", GetChannelTypeName( imageInfo->format->image_channel_data_type ),
(int)outKernelData.expectedChannelType, (int)outKernelData.channelType );
// return -1;
}
if( outKernelData.channelOrder != (cl_int)outKernelData.expectedChannelOrder )
{
log_error( "ERROR: Returned channel order did not validate (expected %s (%d), got %d)\n", GetChannelOrderName( imageInfo->format->image_channel_order ),
(int)outKernelData.expectedChannelOrder, (int)outKernelData.channelOrder );
// return -1;
}
error = clFinish(queue);
if (error)
print_error(error, "clFinish failed.");
return 0;
}
int test_get_image_info_2D_array( cl_device_id device, cl_image_format *format )
{
size_t maxWidth, maxHeight, maxArraySize;
cl_ulong maxAllocSize, memSize;
image_descriptor imageInfo;
RandomSeed seed( gRandomSeed );
size_t pixelSize;
imageInfo.type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
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_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 3D size from device" );
if( gTestSmallImages )
{
for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
{
imageInfo.rowPitch = imageInfo.width * pixelSize;
for( imageInfo.height = 1; imageInfo.height < 9; imageInfo.height++ )
{
imageInfo.slicePitch = imageInfo.rowPitch * imageInfo.height;
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_get_2Dimage_array_info_single( device, &imageInfo, 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;
imageInfo.slicePitch = imageInfo.height * imageInfo.rowPitch;
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_get_2Dimage_array_info_single( device, &imageInfo, 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.arraySize = (size_t)random_log_in_range( 16, (int)maxArraySize / 32, seed );
imageInfo.rowPitch = imageInfo.width * pixelSize;
imageInfo.slicePitch = imageInfo.rowPitch * imageInfo.height;
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_t extraHeight = (int)random_log_in_range( 0, 8, seed );
imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + extraHeight);
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_get_2Dimage_array_info_single( device, &imageInfo, seed );
if( ret )
return -1;
}
}
return 0;
}

View File

@@ -1,127 +1,127 @@
//
// 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, gTestSmallImages, gTestMaxImages;
extern int test_get_image_info_single( cl_device_id device, image_descriptor *imageInfo, MTdata d );
int test_get_image_info_3D( cl_device_id device, cl_image_format *format )
{
size_t maxWidth, maxHeight, maxDepth;
cl_ulong maxAllocSize, memSize;
image_descriptor imageInfo;
RandomSeed seed( gRandomSeed );
size_t pixelSize;
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( gTestSmallImages )
{
for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
{
imageInfo.rowPitch = imageInfo.width * pixelSize;
for( imageInfo.height = 1; imageInfo.height < 9; imageInfo.height++ )
{
imageInfo.slicePitch = imageInfo.rowPitch * imageInfo.height;
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_get_image_info_single( device, &imageInfo, 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;
imageInfo.slicePitch = imageInfo.height * imageInfo.rowPitch;
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_get_image_info_single( device, &imageInfo, 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;
imageInfo.slicePitch = imageInfo.rowPitch * imageInfo.height;
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_t extraHeight = (int)random_log_in_range( 0, 8, seed );
imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + extraHeight);
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_get_image_info_single( device, &imageInfo, seed );
if( ret )
return -1;
}
}
return 0;
}
//
// 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, gTestSmallImages, gTestMaxImages;
extern int test_get_image_info_single( cl_device_id device, image_descriptor *imageInfo, MTdata d );
int test_get_image_info_3D( cl_device_id device, cl_image_format *format )
{
size_t maxWidth, maxHeight, maxDepth;
cl_ulong maxAllocSize, memSize;
image_descriptor imageInfo;
RandomSeed seed( gRandomSeed );
size_t pixelSize;
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( gTestSmallImages )
{
for( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
{
imageInfo.rowPitch = imageInfo.width * pixelSize;
for( imageInfo.height = 1; imageInfo.height < 9; imageInfo.height++ )
{
imageInfo.slicePitch = imageInfo.rowPitch * imageInfo.height;
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_get_image_info_single( device, &imageInfo, 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;
imageInfo.slicePitch = imageInfo.height * imageInfo.rowPitch;
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_get_image_info_single( device, &imageInfo, 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;
imageInfo.slicePitch = imageInfo.rowPitch * imageInfo.height;
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_t extraHeight = (int)random_log_in_range( 0, 8, seed );
imageInfo.slicePitch = imageInfo.rowPitch * (imageInfo.height + extraHeight);
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_get_image_info_single( device, &imageInfo, seed );
if( ret )
return -1;
}
}
return 0;
}

View File

@@ -1,208 +1,208 @@
//
// 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 cl_filter_mode gFilterModeToUse;
extern cl_addressing_mode gAddressModeToUse;
extern int gTypesToTest;
extern int gNormalizedModeToUse;
extern cl_channel_type gChannelTypeToUse;
extern bool gDebugTrace;
extern int test_get_image_info_1D( cl_device_id device, cl_image_format *format );
extern int test_get_image_info_2D( cl_device_id device, cl_image_format *format );
extern int test_get_image_info_3D( cl_device_id device, cl_image_format *format );
extern int test_get_image_info_1D_array( cl_device_id device, cl_image_format *format );
extern int test_get_image_info_2D_array( cl_device_id device, cl_image_format *format );
static const char *str_1d_image = "1D";
static const char *str_2d_image = "2D";
static const char *str_3d_image = "3D";
static const char *str_1d_image_array = "1D array";
static const char *str_2d_image_array = "2D array";
static const char *convert_image_type_to_string(cl_mem_object_type imageType)
{
const char *p;
switch (imageType)
{
case CL_MEM_OBJECT_IMAGE1D:
p = str_1d_image;
break;
case CL_MEM_OBJECT_IMAGE2D:
p = str_2d_image;
break;
case CL_MEM_OBJECT_IMAGE3D:
p = str_3d_image;
break;
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
p = str_1d_image_array;
break;
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
p = str_2d_image_array;
break;
}
return p;
}
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;
}
// 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 imageType, cl_image_format * &outFormatList, unsigned int &outFormatCount, cl_mem_flags flags )
{
extern clContextWrapper context;
int error = clGetSupportedImageFormats( context, (cl_mem_flags)flags,
imageType, 0, NULL, &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,
imageType, outFormatCount, outFormatList, NULL );
test_error( error, "Unable to get list of supported image formats" );
return 0;
}
int test_image_type( cl_device_id device, cl_mem_object_type imageType, cl_mem_flags flags )
{
log_info( "Running %s %s-only tests...\n", convert_image_type_to_string(imageType), flags == CL_MEM_READ_ONLY ? "read" : "write" );
int ret = 0;
// Grab the list of supported image formats for integer reads
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 );
filter_formats( formatList, filterFlags, numFormats, 0 );
// Run the format list
for( unsigned int i = 0; i < numFormats; i++ )
{
int test_return = 0;
if( filterFlags[i] )
{
log_info( "NOT RUNNING: " );
print_header( &formatList[ i ], false );
continue;
}
print_header( &formatList[ i ], false );
gTestCount++;
switch (imageType) {
case CL_MEM_OBJECT_IMAGE1D:
test_return = test_get_image_info_1D( device, &formatList[ i ] );
break;
case CL_MEM_OBJECT_IMAGE2D:
test_return = test_get_image_info_2D( device, &formatList[ i ] );
break;
case CL_MEM_OBJECT_IMAGE3D:
test_return = test_get_image_info_3D( device, &formatList[ i ] );
break;
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
test_return = test_get_image_info_1D_array( device, &formatList[ i ] );
break;
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
test_return = test_get_image_info_2D_array( device, &formatList[ i ] );
break;
}
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, cl_mem_object_type imageType )
{
int ret = 0;
ret += test_image_type( device, imageType, CL_MEM_READ_ONLY );
ret += test_image_type( device, imageType, CL_MEM_WRITE_ONLY );
return ret;
}
//
// 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 cl_filter_mode gFilterModeToUse;
extern cl_addressing_mode gAddressModeToUse;
extern int gTypesToTest;
extern int gNormalizedModeToUse;
extern cl_channel_type gChannelTypeToUse;
extern bool gDebugTrace;
extern int test_get_image_info_1D( cl_device_id device, cl_image_format *format );
extern int test_get_image_info_2D( cl_device_id device, cl_image_format *format );
extern int test_get_image_info_3D( cl_device_id device, cl_image_format *format );
extern int test_get_image_info_1D_array( cl_device_id device, cl_image_format *format );
extern int test_get_image_info_2D_array( cl_device_id device, cl_image_format *format );
static const char *str_1d_image = "1D";
static const char *str_2d_image = "2D";
static const char *str_3d_image = "3D";
static const char *str_1d_image_array = "1D array";
static const char *str_2d_image_array = "2D array";
static const char *convert_image_type_to_string(cl_mem_object_type imageType)
{
const char *p;
switch (imageType)
{
case CL_MEM_OBJECT_IMAGE1D:
p = str_1d_image;
break;
case CL_MEM_OBJECT_IMAGE2D:
p = str_2d_image;
break;
case CL_MEM_OBJECT_IMAGE3D:
p = str_3d_image;
break;
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
p = str_1d_image_array;
break;
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
p = str_2d_image_array;
break;
}
return p;
}
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;
}
// 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 imageType, cl_image_format * &outFormatList, unsigned int &outFormatCount, cl_mem_flags flags )
{
extern clContextWrapper context;
int error = clGetSupportedImageFormats( context, (cl_mem_flags)flags,
imageType, 0, NULL, &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,
imageType, outFormatCount, outFormatList, NULL );
test_error( error, "Unable to get list of supported image formats" );
return 0;
}
int test_image_type( cl_device_id device, cl_mem_object_type imageType, cl_mem_flags flags )
{
log_info( "Running %s %s-only tests...\n", convert_image_type_to_string(imageType), flags == CL_MEM_READ_ONLY ? "read" : "write" );
int ret = 0;
// Grab the list of supported image formats for integer reads
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 );
filter_formats( formatList, filterFlags, numFormats, 0 );
// Run the format list
for( unsigned int i = 0; i < numFormats; i++ )
{
int test_return = 0;
if( filterFlags[i] )
{
log_info( "NOT RUNNING: " );
print_header( &formatList[ i ], false );
continue;
}
print_header( &formatList[ i ], false );
gTestCount++;
switch (imageType) {
case CL_MEM_OBJECT_IMAGE1D:
test_return = test_get_image_info_1D( device, &formatList[ i ] );
break;
case CL_MEM_OBJECT_IMAGE2D:
test_return = test_get_image_info_2D( device, &formatList[ i ] );
break;
case CL_MEM_OBJECT_IMAGE3D:
test_return = test_get_image_info_3D( device, &formatList[ i ] );
break;
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
test_return = test_get_image_info_1D_array( device, &formatList[ i ] );
break;
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
test_return = test_get_image_info_2D_array( device, &formatList[ i ] );
break;
}
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, cl_mem_object_type imageType )
{
int ret = 0;
ret += test_image_type( device, imageType, CL_MEM_READ_ONLY );
ret += test_image_type( device, imageType, CL_MEM_WRITE_ONLY );
return ret;
}