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,20 +1,20 @@
project
: requirements
# <toolset>gcc:<cflags>-xc++
# <toolset>msvc:<cflags>"/TP"
;
exe test_samplerless_reads
: main.cpp
test_iterations.cpp
test_loops.cpp
test_read_3D.cpp
/images//image_helpers
;
install dist
: test_samplerless_reads
: <variant>debug:<location>$(DIST)/debug/tests/test_conformance/images/samplerlessReads
<variant>release:<location>$(DIST)/release/tests/test_conformance/images/samplerlessReads
;
project
: requirements
# <toolset>gcc:<cflags>-xc++
# <toolset>msvc:<cflags>"/TP"
;
exe test_samplerless_reads
: main.cpp
test_iterations.cpp
test_loops.cpp
test_read_3D.cpp
/images//image_helpers
;
install dist
: test_samplerless_reads
: <variant>debug:<location>$(DIST)/debug/tests/test_conformance/images/samplerlessReads
<variant>release:<location>$(DIST)/release/tests/test_conformance/images/samplerlessReads
;

View File

@@ -1,53 +1,53 @@
ifdef BUILD_WITH_ATF
ATF = -framework ATF
USE_ATF = -DUSE_ATF
endif
SRCS = main.cpp \
test_iterations.cpp \
test_loops.cpp \
test_read_1D.cpp \
test_read_1D_buffer.cpp \
test_read_1D_array.cpp \
test_read_2D_array.cpp \
test_read_3D.cpp \
../image_helpers.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_samplerless_reads
INCLUDE = -I../../test_common/harness
COMPILERFLAGS = -c -Wall -g -Wshorten-64-to-32 -Os
CC = c++
CXX = c++
CFLAGS = $(COMPILERFLAGS) ${RC_CFLAGS} ${USE_ATF} $(DEFINES:%=-D%) $(INCLUDE)
CXXFLAGS = $(COMPILERFLAGS) ${RC_CFLAGS} ${USE_ATF} $(DEFINES:%=-D%) $(INCLUDE)
LIBRARIES = -framework OpenCL -framework OpenGL -framework GLUT -framework AppKit ${ATF}
OBJECTS := ${SOURCES:.c=.o}
OBJECTS := ${OBJECTS:.cpp=.o}
TARGETOBJECT =
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) $(RC_CFLAGS) $(OBJECTS) -o $@ $(LIBPATH) $(LIBRARIES)
clean:
rm -f $(TARGET) $(OBJECTS)
.DEFAULT:
@echo The target \"$@\" does not exist in Makefile.
ifdef BUILD_WITH_ATF
ATF = -framework ATF
USE_ATF = -DUSE_ATF
endif
SRCS = main.cpp \
test_iterations.cpp \
test_loops.cpp \
test_read_1D.cpp \
test_read_1D_buffer.cpp \
test_read_1D_array.cpp \
test_read_2D_array.cpp \
test_read_3D.cpp \
../image_helpers.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_samplerless_reads
INCLUDE = -I../../test_common/harness
COMPILERFLAGS = -c -Wall -g -Wshorten-64-to-32 -Os
CC = c++
CXX = c++
CFLAGS = $(COMPILERFLAGS) ${RC_CFLAGS} ${USE_ATF} $(DEFINES:%=-D%) $(INCLUDE)
CXXFLAGS = $(COMPILERFLAGS) ${RC_CFLAGS} ${USE_ATF} $(DEFINES:%=-D%) $(INCLUDE)
LIBRARIES = -framework OpenCL -framework OpenGL -framework GLUT -framework AppKit ${ATF}
OBJECTS := ${SOURCES:.c=.o}
OBJECTS := ${OBJECTS:.cpp=.o}
TARGETOBJECT =
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) $(RC_CFLAGS) $(OBJECTS) -o $@ $(LIBPATH) $(LIBRARIES)
clean:
rm -f $(TARGET) $(OBJECTS)
.DEFAULT:
@echo The target \"$@\" does not exist in Makefile.

View File

@@ -1,296 +1,296 @@
//
// 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"
#include "../../../test_common/harness/fpcontrol.h"
#if defined(__PPC__)
// Global varaiable used to hold the FPU control register state. The FPSCR register can not
// be used because not all Power implementations retain or observed the NI (non-IEEE
// mode) bit.
__thread fpu_control_t fpu_control = 0;
#endif
bool gDebugTrace = false;
bool gTestMaxImages = false, gTestSmallImages = false, gTestRounding = false;
int gTypesToTest = 0;
cl_channel_type gChannelTypeToUse = (cl_channel_type)-1;
cl_channel_order gChannelOrderToUse = (cl_channel_order)-1;
bool gEnablePitch = false;
cl_device_type gDeviceType = CL_DEVICE_TYPE_DEFAULT;
cl_command_queue queue;
cl_context context;
#define MAX_ALLOWED_STD_DEVIATION_IN_MB 8.0
void printUsage( const char *execName )
{
const char *p = strrchr( execName, '/' );
if ( p != NULL )
execName = p + 1;
log_info( "Usage: %s [options]\n", execName );
log_info( "Where:\n" );
log_info( "\n" );
log_info( "\tThe following flags specify the types to test. They can be combined; if none are specified, all are tested:\n" );
log_info( "\t\tint - Test integer I/O (read_imagei)\n" );
log_info( "\t\tuint - Test unsigned integer I/O (read_imageui)\n" );
log_info( "\t\tfloat - Test float I/O (read_imagef)\n" );
log_info( "\n" );
log_info( "You may also use appropriate CL_ channel type and ordering constants.\n" );
log_info( "\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( "\tThe following modify the types of images tested:\n" );
log_info( "\t\tsmall_images - Runs every format through a loop of widths 1-13 and heights 1-9, instead of random sizes\n" );
log_info( "\t\tmax_images - Runs every format through a set of size combinations with the max values, max values - 1, and max values / 128\n" );
log_info( "\n" );
log_info( "\tdebug_trace - Enables additional debug info logging\n" );
log_info( "\tuse_pitches - Enables row and slice pitches\n" );
}
extern int test_image_set( cl_device_id device, cl_mem_object_type imageType );
int main(int argc, const char *argv[])
{
cl_platform_id platform;
cl_device_id device;
cl_channel_type chanType;
cl_channel_order chanOrder;
char str[ 128 ];
int testMethods = 0;
bool randomize = false;
test_start();
//Check CL_DEVICE_TYPE environment variable
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, "use_pitches" ) == 0 )
gEnablePitch = true;
else if ( strcmp( str, "int" ) == 0 )
gTypesToTest |= kTestInt;
else if ( strcmp( str, "uint" ) == 0 )
gTypesToTest |= kTestUInt;
else if ( strcmp( str, "float" ) == 0 )
gTypesToTest |= kTestFloat;
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 if ( ( chanOrder = get_channel_order_from_name( str ) ) != (cl_channel_order)-1 )
gChannelOrderToUse = chanOrder;
else
{
log_error( "ERROR: Unknown argument %d: %s. Exiting....\n", i, str );
return -1;
}
}
if (testMethods == 0)
testMethods = k1D | k2D | k3D | k1DArray | k2DArray;
if ( gTypesToTest == 0 )
gTypesToTest = kTestAllTypes;
// Seed the random # generators
if ( randomize )
{
gRandomSeed = (unsigned) (((int64_t) clock() * 1103515245 + 12345) >> 8);
gReSeed = 1;
log_info( "Random seed: %d\n", gRandomSeed );
}
int error;
// Get our platform
error = clGetPlatformIDs(1, &platform, NULL);
if ( error )
{
print_error( error, "Unable to get platform" );
test_finish();
return -1;
}
// Get our device
error = clGetDeviceIDs(platform, gDeviceType, 1, &device, NULL );
if ( error )
{
print_error( error, "Unable to get specified device" );
test_finish();
return -1;
}
// Get the device type so we know if it is a GPU even if default is passed in.
error = clGetDeviceInfo(device, CL_DEVICE_TYPE, sizeof(gDeviceType), &gDeviceType, NULL);
if ( error )
{
print_error( error, "Unable to get device type" );
test_finish();
return -1;
}
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" );
// On most platforms which support denorm, default is FTZ off. However,
// on some hardware where the reference is computed, default might be flush denorms to zero e.g. arm.
// This creates issues in result verification. Since spec allows the implementation to either flush or
// not flush denorms to zero, an implementation may choose not to flush i.e. return denorm result whereas
// reference result may be zero (flushed denorm). Hence we need to disable denorm flushing on host side
// where reference is being computed to make sure we get non-flushed reference result. If implementation
// returns flushed result, we correctly take care of that in verification code.
FPU_mode_type oldMode;
DisableFTZ(&oldMode);
// 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 );
// Restore FP state before leaving
RestoreFPState(&oldMode);
error = clFinish(queue);
if (error)
print_error(error, "clFinish failed.");
clReleaseContext(context);
clReleaseCommandQueue(queue);
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");
}
// Clean up
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"
#include "../../../test_common/harness/fpcontrol.h"
#if defined(__PPC__)
// Global varaiable used to hold the FPU control register state. The FPSCR register can not
// be used because not all Power implementations retain or observed the NI (non-IEEE
// mode) bit.
__thread fpu_control_t fpu_control = 0;
#endif
bool gDebugTrace = false;
bool gTestMaxImages = false, gTestSmallImages = false, gTestRounding = false;
int gTypesToTest = 0;
cl_channel_type gChannelTypeToUse = (cl_channel_type)-1;
cl_channel_order gChannelOrderToUse = (cl_channel_order)-1;
bool gEnablePitch = false;
cl_device_type gDeviceType = CL_DEVICE_TYPE_DEFAULT;
cl_command_queue queue;
cl_context context;
#define MAX_ALLOWED_STD_DEVIATION_IN_MB 8.0
void printUsage( const char *execName )
{
const char *p = strrchr( execName, '/' );
if ( p != NULL )
execName = p + 1;
log_info( "Usage: %s [options]\n", execName );
log_info( "Where:\n" );
log_info( "\n" );
log_info( "\tThe following flags specify the types to test. They can be combined; if none are specified, all are tested:\n" );
log_info( "\t\tint - Test integer I/O (read_imagei)\n" );
log_info( "\t\tuint - Test unsigned integer I/O (read_imageui)\n" );
log_info( "\t\tfloat - Test float I/O (read_imagef)\n" );
log_info( "\n" );
log_info( "You may also use appropriate CL_ channel type and ordering constants.\n" );
log_info( "\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( "\tThe following modify the types of images tested:\n" );
log_info( "\t\tsmall_images - Runs every format through a loop of widths 1-13 and heights 1-9, instead of random sizes\n" );
log_info( "\t\tmax_images - Runs every format through a set of size combinations with the max values, max values - 1, and max values / 128\n" );
log_info( "\n" );
log_info( "\tdebug_trace - Enables additional debug info logging\n" );
log_info( "\tuse_pitches - Enables row and slice pitches\n" );
}
extern int test_image_set( cl_device_id device, cl_mem_object_type imageType );
int main(int argc, const char *argv[])
{
cl_platform_id platform;
cl_device_id device;
cl_channel_type chanType;
cl_channel_order chanOrder;
char str[ 128 ];
int testMethods = 0;
bool randomize = false;
test_start();
//Check CL_DEVICE_TYPE environment variable
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, "use_pitches" ) == 0 )
gEnablePitch = true;
else if ( strcmp( str, "int" ) == 0 )
gTypesToTest |= kTestInt;
else if ( strcmp( str, "uint" ) == 0 )
gTypesToTest |= kTestUInt;
else if ( strcmp( str, "float" ) == 0 )
gTypesToTest |= kTestFloat;
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 if ( ( chanOrder = get_channel_order_from_name( str ) ) != (cl_channel_order)-1 )
gChannelOrderToUse = chanOrder;
else
{
log_error( "ERROR: Unknown argument %d: %s. Exiting....\n", i, str );
return -1;
}
}
if (testMethods == 0)
testMethods = k1D | k2D | k3D | k1DArray | k2DArray;
if ( gTypesToTest == 0 )
gTypesToTest = kTestAllTypes;
// Seed the random # generators
if ( randomize )
{
gRandomSeed = (unsigned) (((int64_t) clock() * 1103515245 + 12345) >> 8);
gReSeed = 1;
log_info( "Random seed: %d\n", gRandomSeed );
}
int error;
// Get our platform
error = clGetPlatformIDs(1, &platform, NULL);
if ( error )
{
print_error( error, "Unable to get platform" );
test_finish();
return -1;
}
// Get our device
error = clGetDeviceIDs(platform, gDeviceType, 1, &device, NULL );
if ( error )
{
print_error( error, "Unable to get specified device" );
test_finish();
return -1;
}
// Get the device type so we know if it is a GPU even if default is passed in.
error = clGetDeviceInfo(device, CL_DEVICE_TYPE, sizeof(gDeviceType), &gDeviceType, NULL);
if ( error )
{
print_error( error, "Unable to get device type" );
test_finish();
return -1;
}
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" );
// On most platforms which support denorm, default is FTZ off. However,
// on some hardware where the reference is computed, default might be flush denorms to zero e.g. arm.
// This creates issues in result verification. Since spec allows the implementation to either flush or
// not flush denorms to zero, an implementation may choose not to flush i.e. return denorm result whereas
// reference result may be zero (flushed denorm). Hence we need to disable denorm flushing on host side
// where reference is being computed to make sure we get non-flushed reference result. If implementation
// returns flushed result, we correctly take care of that in verification code.
FPU_mode_type oldMode;
DisableFTZ(&oldMode);
// 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 );
// Restore FP state before leaving
RestoreFPState(&oldMode);
error = clFinish(queue);
if (error)
print_error(error, "clFinish failed.");
clReleaseContext(context);
clReleaseCommandQueue(queue);
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");
}
// Clean up
test_finish();
if (gTestFailure > 0)
return gTestFailure;
return ret;
}

View File

@@ -1,266 +1,266 @@
//
// 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"
#include <float.h>
#if defined( __APPLE__ )
#include <signal.h>
#include <sys/signal.h>
#include <setjmp.h>
#endif
#define MAX_ERR 0.005f
#define MAX_HALF_LINEAR_ERR 0.3f
extern cl_command_queue queue;
extern cl_context context;
extern bool gDebugTrace, gTestSmallImages, gEnablePitch, gTestMaxImages, gTestRounding;
extern cl_device_type gDeviceType;
#define MAX_TRIES 1
#define MAX_CLAMPED 1
const char *read2DKernelSourcePattern =
"__kernel void sample_kernel( read_only image2d_t input, sampler_t sampler, __global int *results )\n"
"{\n"
" int tidX = get_global_id(0), tidY = get_global_id(1);\n"
" int offset = tidY*get_image_width(input) + tidX;\n"
" int2 coords = (int2)(tidX, tidY);\n"
" %s clr = read_image%s( input, coords );\n"
" int4 test = (clr != read_image%s( input, sampler, coords ));\n"
" if ( test.x || test.y || test.z || test.w )\n"
" results[offset] = -1;\n"
" else\n"
" results[offset] = 0;\n"
"}";
int test_read_image_2D( cl_device_id device, cl_context context, cl_command_queue queue, cl_kernel kernel,
image_descriptor *imageInfo, image_sampler_data *imageSampler,
ExplicitType outputType, MTdata d )
{
int error;
size_t threads[2];
cl_sampler actualSampler;
// generate_random_image_data allocates with malloc, so we use a MallocDataBuffer here
BufferOwningPtr<char> imageValues;
generate_random_image_data( imageInfo, imageValues, d );
if ( gDebugTrace )
log_info( " - Creating image %d by %d...\n", (int)imageInfo->width, (int)imageInfo->height );
// Construct testing sources
cl_mem image;
cl_image_desc image_desc;
memset(&image_desc, 0x0, sizeof(cl_image_desc));
image_desc.image_type = CL_MEM_OBJECT_IMAGE2D;
image_desc.image_width = imageInfo->width;
image_desc.image_height = imageInfo->height;
image_desc.image_row_pitch = ( gEnablePitch ? imageInfo->rowPitch : 0 );
image = clCreateImage( context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, imageInfo->format,
&image_desc, imageValues, &error );
if ( error != CL_SUCCESS )
{
log_error( "ERROR: Unable to create 2D image of size %d x %d pitch %d (%s)\n", (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->rowPitch, IGetErrorString( error ) );
return error;
}
if ( gDebugTrace )
log_info( " - Creating kernel arguments...\n" );
// Create sampler to use
actualSampler = clCreateSampler( context, false, CL_ADDRESS_NONE, CL_FILTER_NEAREST, &error );
test_error( error, "Unable to create image sampler" );
// Create results buffer
cl_mem results = clCreateBuffer( context, 0, imageInfo->width * imageInfo->height * sizeof(cl_int), NULL, &error);
test_error( error, "Unable to create results buffer" );
size_t resultValuesSize = imageInfo->width * imageInfo->height * sizeof(cl_int);
BufferOwningPtr<int> resultValues(malloc( resultValuesSize ));
memset( resultValues, 0xff, resultValuesSize );
clEnqueueWriteBuffer( queue, results, CL_TRUE, 0, resultValuesSize, resultValues, 0, NULL, NULL );
// Set arguments
int idx = 0;
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &image );
test_error( error, "Unable to set kernel arguments" );
error = clSetKernelArg( kernel, idx++, sizeof( cl_sampler ), &actualSampler );
test_error( error, "Unable to set kernel arguments" );
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &results );
test_error( error, "Unable to set kernel arguments" );
// Run the kernel
threads[0] = (size_t)imageInfo->width;
threads[1] = (size_t)imageInfo->height;
error = clEnqueueNDRangeKernel( queue, kernel, 2, NULL, threads, NULL, 0, NULL, NULL );
test_error( error, "Unable to run kernel" );
if ( gDebugTrace )
log_info( " reading results, %ld kbytes\n", (unsigned long)( imageInfo->width * imageInfo->height * sizeof(cl_int) / 1024 ) );
error = clEnqueueReadBuffer( queue, results, CL_TRUE, 0, resultValuesSize, resultValues, 0, NULL, NULL );
test_error( error, "Unable to read results from kernel" );
if ( gDebugTrace )
log_info( " results read\n" );
// Check for non-zero comps
bool allZeroes = true;
for ( size_t ic = 0; ic < imageInfo->width * imageInfo->height; ++ic )
{
if ( resultValues[ic] ) {
allZeroes = false;
break;
}
}
if ( !allZeroes )
{
log_error( " Sampler-less reads differ from reads with sampler.\n" );
return -1;
}
clReleaseSampler(actualSampler);
clReleaseMemObject(results);
clReleaseMemObject(image);
return 0;
}
int test_read_image_set_2D( cl_device_id device, cl_image_format *format, image_sampler_data *imageSampler,
ExplicitType outputType )
{
char programSrc[10240];
const char *ptr;
const char *readFormat;
const char *dataType;
clProgramWrapper program;
clKernelWrapper kernel;
RandomSeed seed( gRandomSeed );
int error;
// Get our operating params
size_t maxWidth, maxHeight;
cl_ulong maxAllocSize, memSize;
image_descriptor imageInfo;
size_t pixelSize;
imageInfo.format = format;
imageInfo.depth = imageInfo.arraySize = imageInfo.slicePitch = 0;
imageInfo.type = CL_MEM_OBJECT_IMAGE2D;
pixelSize = get_pixel_size( imageInfo.format );
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" );
// Determine types
if ( outputType == kInt )
{
readFormat = "i";
dataType = "int4";
}
else if ( outputType == kUInt )
{
readFormat = "ui";
dataType = "uint4";
}
else // kFloat
{
readFormat = "f";
dataType = "float4";
}
sprintf( programSrc, read2DKernelSourcePattern, dataType,
readFormat,
readFormat );
ptr = programSrc;
error = create_single_kernel_helper( context, &program, &kernel, 1, &ptr, "sample_kernel" );
test_error( error, "Unable to create testing kernel" );
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 retCode = test_read_image_2D( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
}
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 ] );
int retCode = test_read_image_2D( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
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;
if ( gEnablePitch )
{
size_t extraWidth = (int)random_log_in_range( 0, 64, seed );
imageInfo.rowPitch += extraWidth * pixelSize;
}
size = (size_t)imageInfo.rowPitch * (size_t)imageInfo.height * 4;
} while ( size > maxAllocSize || ( size * 3 ) > memSize );
if ( gDebugTrace )
log_info( " at size %d,%d (row pitch %d) out of %d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.rowPitch, (int)maxWidth, (int)maxHeight );
int retCode = test_read_image_2D( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
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"
#include <float.h>
#if defined( __APPLE__ )
#include <signal.h>
#include <sys/signal.h>
#include <setjmp.h>
#endif
#define MAX_ERR 0.005f
#define MAX_HALF_LINEAR_ERR 0.3f
extern cl_command_queue queue;
extern cl_context context;
extern bool gDebugTrace, gTestSmallImages, gEnablePitch, gTestMaxImages, gTestRounding;
extern cl_device_type gDeviceType;
#define MAX_TRIES 1
#define MAX_CLAMPED 1
const char *read2DKernelSourcePattern =
"__kernel void sample_kernel( read_only image2d_t input, sampler_t sampler, __global int *results )\n"
"{\n"
" int tidX = get_global_id(0), tidY = get_global_id(1);\n"
" int offset = tidY*get_image_width(input) + tidX;\n"
" int2 coords = (int2)(tidX, tidY);\n"
" %s clr = read_image%s( input, coords );\n"
" int4 test = (clr != read_image%s( input, sampler, coords ));\n"
" if ( test.x || test.y || test.z || test.w )\n"
" results[offset] = -1;\n"
" else\n"
" results[offset] = 0;\n"
"}";
int test_read_image_2D( cl_device_id device, cl_context context, cl_command_queue queue, cl_kernel kernel,
image_descriptor *imageInfo, image_sampler_data *imageSampler,
ExplicitType outputType, MTdata d )
{
int error;
size_t threads[2];
cl_sampler actualSampler;
// generate_random_image_data allocates with malloc, so we use a MallocDataBuffer here
BufferOwningPtr<char> imageValues;
generate_random_image_data( imageInfo, imageValues, d );
if ( gDebugTrace )
log_info( " - Creating image %d by %d...\n", (int)imageInfo->width, (int)imageInfo->height );
// Construct testing sources
cl_mem image;
cl_image_desc image_desc;
memset(&image_desc, 0x0, sizeof(cl_image_desc));
image_desc.image_type = CL_MEM_OBJECT_IMAGE2D;
image_desc.image_width = imageInfo->width;
image_desc.image_height = imageInfo->height;
image_desc.image_row_pitch = ( gEnablePitch ? imageInfo->rowPitch : 0 );
image = clCreateImage( context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, imageInfo->format,
&image_desc, imageValues, &error );
if ( error != CL_SUCCESS )
{
log_error( "ERROR: Unable to create 2D image of size %d x %d pitch %d (%s)\n", (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->rowPitch, IGetErrorString( error ) );
return error;
}
if ( gDebugTrace )
log_info( " - Creating kernel arguments...\n" );
// Create sampler to use
actualSampler = clCreateSampler( context, false, CL_ADDRESS_NONE, CL_FILTER_NEAREST, &error );
test_error( error, "Unable to create image sampler" );
// Create results buffer
cl_mem results = clCreateBuffer( context, 0, imageInfo->width * imageInfo->height * sizeof(cl_int), NULL, &error);
test_error( error, "Unable to create results buffer" );
size_t resultValuesSize = imageInfo->width * imageInfo->height * sizeof(cl_int);
BufferOwningPtr<int> resultValues(malloc( resultValuesSize ));
memset( resultValues, 0xff, resultValuesSize );
clEnqueueWriteBuffer( queue, results, CL_TRUE, 0, resultValuesSize, resultValues, 0, NULL, NULL );
// Set arguments
int idx = 0;
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &image );
test_error( error, "Unable to set kernel arguments" );
error = clSetKernelArg( kernel, idx++, sizeof( cl_sampler ), &actualSampler );
test_error( error, "Unable to set kernel arguments" );
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &results );
test_error( error, "Unable to set kernel arguments" );
// Run the kernel
threads[0] = (size_t)imageInfo->width;
threads[1] = (size_t)imageInfo->height;
error = clEnqueueNDRangeKernel( queue, kernel, 2, NULL, threads, NULL, 0, NULL, NULL );
test_error( error, "Unable to run kernel" );
if ( gDebugTrace )
log_info( " reading results, %ld kbytes\n", (unsigned long)( imageInfo->width * imageInfo->height * sizeof(cl_int) / 1024 ) );
error = clEnqueueReadBuffer( queue, results, CL_TRUE, 0, resultValuesSize, resultValues, 0, NULL, NULL );
test_error( error, "Unable to read results from kernel" );
if ( gDebugTrace )
log_info( " results read\n" );
// Check for non-zero comps
bool allZeroes = true;
for ( size_t ic = 0; ic < imageInfo->width * imageInfo->height; ++ic )
{
if ( resultValues[ic] ) {
allZeroes = false;
break;
}
}
if ( !allZeroes )
{
log_error( " Sampler-less reads differ from reads with sampler.\n" );
return -1;
}
clReleaseSampler(actualSampler);
clReleaseMemObject(results);
clReleaseMemObject(image);
return 0;
}
int test_read_image_set_2D( cl_device_id device, cl_image_format *format, image_sampler_data *imageSampler,
ExplicitType outputType )
{
char programSrc[10240];
const char *ptr;
const char *readFormat;
const char *dataType;
clProgramWrapper program;
clKernelWrapper kernel;
RandomSeed seed( gRandomSeed );
int error;
// Get our operating params
size_t maxWidth, maxHeight;
cl_ulong maxAllocSize, memSize;
image_descriptor imageInfo;
size_t pixelSize;
imageInfo.format = format;
imageInfo.depth = imageInfo.arraySize = imageInfo.slicePitch = 0;
imageInfo.type = CL_MEM_OBJECT_IMAGE2D;
pixelSize = get_pixel_size( imageInfo.format );
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" );
// Determine types
if ( outputType == kInt )
{
readFormat = "i";
dataType = "int4";
}
else if ( outputType == kUInt )
{
readFormat = "ui";
dataType = "uint4";
}
else // kFloat
{
readFormat = "f";
dataType = "float4";
}
sprintf( programSrc, read2DKernelSourcePattern, dataType,
readFormat,
readFormat );
ptr = programSrc;
error = create_single_kernel_helper( context, &program, &kernel, 1, &ptr, "sample_kernel" );
test_error( error, "Unable to create testing kernel" );
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 retCode = test_read_image_2D( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
}
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 ] );
int retCode = test_read_image_2D( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
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;
if ( gEnablePitch )
{
size_t extraWidth = (int)random_log_in_range( 0, 64, seed );
imageInfo.rowPitch += extraWidth * pixelSize;
}
size = (size_t)imageInfo.rowPitch * (size_t)imageInfo.height * 4;
} while ( size > maxAllocSize || ( size * 3 ) > memSize );
if ( gDebugTrace )
log_info( " at size %d,%d (row pitch %d) out of %d,%d\n", (int)imageInfo.width, (int)imageInfo.height, (int)imageInfo.rowPitch, (int)maxWidth, (int)maxHeight );
int retCode = test_read_image_2D( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
return 0;
}

View File

@@ -1,296 +1,296 @@
//
// 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_context context;
extern int gTypesToTest;
extern cl_channel_type gChannelTypeToUse;
extern cl_channel_order gChannelOrderToUse;
extern bool gDebugTrace;
extern int test_read_image_set_1D( cl_device_id device, cl_image_format *format, image_sampler_data *imageSampler, ExplicitType outputType );
extern int test_read_image_set_1D_buffer( cl_device_id device, cl_image_format *format, image_sampler_data *imageSampler, ExplicitType outputType );
extern int test_read_image_set_2D( cl_device_id device, cl_image_format *format, image_sampler_data *imageSampler, ExplicitType outputType );
extern int test_read_image_set_3D( cl_device_id device, cl_image_format *format, image_sampler_data *imageSampler, ExplicitType outputType );
extern int test_read_image_set_1D_array( cl_device_id device, cl_image_format *format, image_sampler_data *imageSampler, ExplicitType outputType );
extern int test_read_image_set_2D_array( cl_device_id device, cl_image_format *format, image_sampler_data *imageSampler, ExplicitType outputType );
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 the channel type via the command line?
if ( gChannelTypeToUse != (cl_channel_type)-1 && gChannelTypeToUse != formatList[ j ].image_channel_data_type )
{
filterFlags[ j ] = true;
continue;
}
// Have we already discarded the channel order via the command line?
if ( gChannelOrderToUse != (cl_channel_order)-1 && gChannelOrderToUse != formatList[ j ].image_channel_order )
{
filterFlags[ j ] = true;
continue;
}
// Is given format standard channel order and type given by spec. We don't want to test it if this is vendor extension
if( !IsChannelOrderSupported( formatList[ j ].image_channel_order ) || !IsChannelTypeSupported( formatList[ j ].image_channel_data_type ) )
{
filterFlags[ j ] = true;
continue;
}
// We don't filter by channel type
if( !channelDataTypesToFilter )
{
numSupported++;
continue;
}
// Is the format supported?
int i;
for ( i = 0; channelDataTypesToFilter[ i ] != (cl_channel_type)-1; i++ )
{
if ( formatList[ j ].image_channel_data_type == channelDataTypesToFilter[ i ] )
{
numSupported++;
break;
}
}
if ( channelDataTypesToFilter[ i ] == (cl_channel_type)-1 )
{
// Format is NOT supported, so mark it as such
filterFlags[ j ] = true;
}
}
return numSupported;
}
int get_format_list( cl_device_id device, cl_mem_object_type imageType, cl_image_format * &outFormatList, unsigned int &outFormatCount, cl_mem_flags flags )
{
int error;
cl_image_format tempList[ 128 ];
error = clGetSupportedImageFormats( context, flags,
imageType, 128, tempList, &outFormatCount );
test_error( error, "Unable to get count of supported image formats" );
outFormatList = new cl_image_format[ outFormatCount ];
error = clGetSupportedImageFormats( context, flags,
imageType, outFormatCount, outFormatList, NULL );
test_error( error, "Unable to get list of supported image formats" );
return 0;
}
int test_read_image_type( cl_device_id device, cl_image_format *format,
image_sampler_data *imageSampler, ExplicitType outputType, cl_mem_object_type imageType )
{
int ret = 0;
imageSampler->addressing_mode = CL_ADDRESS_NONE;
print_read_header( format, imageSampler, false );
gTestCount++;
switch (imageType)
{
case CL_MEM_OBJECT_IMAGE1D:
ret = test_read_image_set_1D( device, format, imageSampler, outputType );
ret += test_read_image_set_1D_buffer( device, format, imageSampler, outputType );
break;
case CL_MEM_OBJECT_IMAGE2D:
ret = test_read_image_set_2D( device, format, imageSampler, outputType );
break;
case CL_MEM_OBJECT_IMAGE3D:
ret = test_read_image_set_3D( device, format, imageSampler, outputType );
break;
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
ret = test_read_image_set_1D_array( device, format, imageSampler, outputType );
break;
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
ret = test_read_image_set_2D_array( device, format, imageSampler, outputType );
break;
}
if ( ret != 0 )
{
gTestFailure++;
log_error( "FAILED: " );
print_read_header( format, imageSampler, true );
log_info( "\n" );
}
return ret;
}
int test_read_image_formats( cl_device_id device, cl_image_format *formatList, bool *filterFlags, unsigned int numFormats,
image_sampler_data *imageSampler, ExplicitType outputType, cl_mem_object_type imageType )
{
int ret = 0;
imageSampler->normalized_coords = false;
log_info( "read_image (%s coords, %s results) *****************************\n",
"integer", get_explicit_type_name( outputType ) );
for ( unsigned int i = 0; i < numFormats; i++ )
{
if ( filterFlags[i] )
continue;
cl_image_format &imageFormat = formatList[ i ];
ret |= test_read_image_type( device, &imageFormat, imageSampler, outputType, imageType );
}
return ret;
}
int test_image_set( cl_device_id device, cl_mem_object_type imageType )
{
int ret = 0;
static int printedFormatList = -1;
// Grab the list of supported image formats
cl_image_format *formatList;
bool *filterFlags;
unsigned int numFormats;
cl_mem_flags flags = CL_MEM_READ_ONLY;
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 );
// First time through, we'll go ahead and print the formats supported, regardless of type
if ( printedFormatList != (int)imageType )
{
log_info( "---- Supported %s read formats for this device ---- \n", convert_image_type_to_string(imageType) );
for ( unsigned int f = 0; f < numFormats; f++ )
log_info( " %-7s %-24s %d\n", GetChannelOrderName( formatList[ f ].image_channel_order ),
GetChannelTypeName( formatList[ f ].image_channel_data_type ),
(int)get_format_channel_count( &formatList[ f ] ) );
log_info( "------------------------------------------- \n" );
printedFormatList = imageType;
}
image_sampler_data imageSampler;
/////// float tests ///////
if ( gTypesToTest & kTestFloat )
{
cl_channel_type floatFormats[] = { CL_UNORM_SHORT_565, CL_UNORM_SHORT_555, CL_UNORM_INT_101010,
#ifdef OBSOLETE_FORAMT
CL_UNORM_SHORT_565_REV, CL_UNORM_SHORT_555_REV, CL_UNORM_INT_8888, CL_UNORM_INT_8888_REV, CL_UNORM_INT_101010_REV,
#endif
#ifdef CL_SFIXED14_APPLE
CL_SFIXED14_APPLE,
#endif
CL_UNORM_INT8, CL_SNORM_INT8,
CL_UNORM_INT16, CL_SNORM_INT16, CL_FLOAT, CL_HALF_FLOAT, (cl_channel_type)-1 };
if ( filter_formats( formatList, filterFlags, numFormats, floatFormats ) == 0 )
{
log_info( "No formats supported for float type\n" );
}
else
{
imageSampler.filter_mode = CL_FILTER_NEAREST;
ret += test_read_image_formats( device, formatList, filterFlags, numFormats, &imageSampler, kFloat, imageType );
}
}
/////// int tests ///////
if ( gTypesToTest & kTestInt )
{
cl_channel_type intFormats[] = { CL_SIGNED_INT8, CL_SIGNED_INT16, CL_SIGNED_INT32, (cl_channel_type)-1 };
if ( filter_formats( formatList, filterFlags, numFormats, intFormats ) == 0 )
{
log_info( "No formats supported for integer type\n" );
}
else
{
// Only filter mode we support on int is nearest
imageSampler.filter_mode = CL_FILTER_NEAREST;
ret += test_read_image_formats( device, formatList, filterFlags, numFormats, &imageSampler, kInt, imageType );
}
}
/////// uint tests ///////
if ( gTypesToTest & kTestUInt )
{
cl_channel_type uintFormats[] = { CL_UNSIGNED_INT8, CL_UNSIGNED_INT16, CL_UNSIGNED_INT32, (cl_channel_type)-1 };
if ( filter_formats( formatList, filterFlags, numFormats, uintFormats ) == 0 )
{
log_info( "No formats supported for unsigned int type\n" );
}
else
{
// Only filter mode we support on uint is nearest
imageSampler.filter_mode = CL_FILTER_NEAREST;
ret += test_read_image_formats( device, formatList, filterFlags, numFormats, &imageSampler, kUInt, imageType );
}
}
delete[] filterFlags;
delete[] formatList;
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_context context;
extern int gTypesToTest;
extern cl_channel_type gChannelTypeToUse;
extern cl_channel_order gChannelOrderToUse;
extern bool gDebugTrace;
extern int test_read_image_set_1D( cl_device_id device, cl_image_format *format, image_sampler_data *imageSampler, ExplicitType outputType );
extern int test_read_image_set_1D_buffer( cl_device_id device, cl_image_format *format, image_sampler_data *imageSampler, ExplicitType outputType );
extern int test_read_image_set_2D( cl_device_id device, cl_image_format *format, image_sampler_data *imageSampler, ExplicitType outputType );
extern int test_read_image_set_3D( cl_device_id device, cl_image_format *format, image_sampler_data *imageSampler, ExplicitType outputType );
extern int test_read_image_set_1D_array( cl_device_id device, cl_image_format *format, image_sampler_data *imageSampler, ExplicitType outputType );
extern int test_read_image_set_2D_array( cl_device_id device, cl_image_format *format, image_sampler_data *imageSampler, ExplicitType outputType );
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 the channel type via the command line?
if ( gChannelTypeToUse != (cl_channel_type)-1 && gChannelTypeToUse != formatList[ j ].image_channel_data_type )
{
filterFlags[ j ] = true;
continue;
}
// Have we already discarded the channel order via the command line?
if ( gChannelOrderToUse != (cl_channel_order)-1 && gChannelOrderToUse != formatList[ j ].image_channel_order )
{
filterFlags[ j ] = true;
continue;
}
// Is given format standard channel order and type given by spec. We don't want to test it if this is vendor extension
if( !IsChannelOrderSupported( formatList[ j ].image_channel_order ) || !IsChannelTypeSupported( formatList[ j ].image_channel_data_type ) )
{
filterFlags[ j ] = true;
continue;
}
// We don't filter by channel type
if( !channelDataTypesToFilter )
{
numSupported++;
continue;
}
// Is the format supported?
int i;
for ( i = 0; channelDataTypesToFilter[ i ] != (cl_channel_type)-1; i++ )
{
if ( formatList[ j ].image_channel_data_type == channelDataTypesToFilter[ i ] )
{
numSupported++;
break;
}
}
if ( channelDataTypesToFilter[ i ] == (cl_channel_type)-1 )
{
// Format is NOT supported, so mark it as such
filterFlags[ j ] = true;
}
}
return numSupported;
}
int get_format_list( cl_device_id device, cl_mem_object_type imageType, cl_image_format * &outFormatList, unsigned int &outFormatCount, cl_mem_flags flags )
{
int error;
cl_image_format tempList[ 128 ];
error = clGetSupportedImageFormats( context, flags,
imageType, 128, tempList, &outFormatCount );
test_error( error, "Unable to get count of supported image formats" );
outFormatList = new cl_image_format[ outFormatCount ];
error = clGetSupportedImageFormats( context, flags,
imageType, outFormatCount, outFormatList, NULL );
test_error( error, "Unable to get list of supported image formats" );
return 0;
}
int test_read_image_type( cl_device_id device, cl_image_format *format,
image_sampler_data *imageSampler, ExplicitType outputType, cl_mem_object_type imageType )
{
int ret = 0;
imageSampler->addressing_mode = CL_ADDRESS_NONE;
print_read_header( format, imageSampler, false );
gTestCount++;
switch (imageType)
{
case CL_MEM_OBJECT_IMAGE1D:
ret = test_read_image_set_1D( device, format, imageSampler, outputType );
ret += test_read_image_set_1D_buffer( device, format, imageSampler, outputType );
break;
case CL_MEM_OBJECT_IMAGE2D:
ret = test_read_image_set_2D( device, format, imageSampler, outputType );
break;
case CL_MEM_OBJECT_IMAGE3D:
ret = test_read_image_set_3D( device, format, imageSampler, outputType );
break;
case CL_MEM_OBJECT_IMAGE1D_ARRAY:
ret = test_read_image_set_1D_array( device, format, imageSampler, outputType );
break;
case CL_MEM_OBJECT_IMAGE2D_ARRAY:
ret = test_read_image_set_2D_array( device, format, imageSampler, outputType );
break;
}
if ( ret != 0 )
{
gTestFailure++;
log_error( "FAILED: " );
print_read_header( format, imageSampler, true );
log_info( "\n" );
}
return ret;
}
int test_read_image_formats( cl_device_id device, cl_image_format *formatList, bool *filterFlags, unsigned int numFormats,
image_sampler_data *imageSampler, ExplicitType outputType, cl_mem_object_type imageType )
{
int ret = 0;
imageSampler->normalized_coords = false;
log_info( "read_image (%s coords, %s results) *****************************\n",
"integer", get_explicit_type_name( outputType ) );
for ( unsigned int i = 0; i < numFormats; i++ )
{
if ( filterFlags[i] )
continue;
cl_image_format &imageFormat = formatList[ i ];
ret |= test_read_image_type( device, &imageFormat, imageSampler, outputType, imageType );
}
return ret;
}
int test_image_set( cl_device_id device, cl_mem_object_type imageType )
{
int ret = 0;
static int printedFormatList = -1;
// Grab the list of supported image formats
cl_image_format *formatList;
bool *filterFlags;
unsigned int numFormats;
cl_mem_flags flags = CL_MEM_READ_ONLY;
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 );
// First time through, we'll go ahead and print the formats supported, regardless of type
if ( printedFormatList != (int)imageType )
{
log_info( "---- Supported %s read formats for this device ---- \n", convert_image_type_to_string(imageType) );
for ( unsigned int f = 0; f < numFormats; f++ )
log_info( " %-7s %-24s %d\n", GetChannelOrderName( formatList[ f ].image_channel_order ),
GetChannelTypeName( formatList[ f ].image_channel_data_type ),
(int)get_format_channel_count( &formatList[ f ] ) );
log_info( "------------------------------------------- \n" );
printedFormatList = imageType;
}
image_sampler_data imageSampler;
/////// float tests ///////
if ( gTypesToTest & kTestFloat )
{
cl_channel_type floatFormats[] = { CL_UNORM_SHORT_565, CL_UNORM_SHORT_555, CL_UNORM_INT_101010,
#ifdef OBSOLETE_FORAMT
CL_UNORM_SHORT_565_REV, CL_UNORM_SHORT_555_REV, CL_UNORM_INT_8888, CL_UNORM_INT_8888_REV, CL_UNORM_INT_101010_REV,
#endif
#ifdef CL_SFIXED14_APPLE
CL_SFIXED14_APPLE,
#endif
CL_UNORM_INT8, CL_SNORM_INT8,
CL_UNORM_INT16, CL_SNORM_INT16, CL_FLOAT, CL_HALF_FLOAT, (cl_channel_type)-1 };
if ( filter_formats( formatList, filterFlags, numFormats, floatFormats ) == 0 )
{
log_info( "No formats supported for float type\n" );
}
else
{
imageSampler.filter_mode = CL_FILTER_NEAREST;
ret += test_read_image_formats( device, formatList, filterFlags, numFormats, &imageSampler, kFloat, imageType );
}
}
/////// int tests ///////
if ( gTypesToTest & kTestInt )
{
cl_channel_type intFormats[] = { CL_SIGNED_INT8, CL_SIGNED_INT16, CL_SIGNED_INT32, (cl_channel_type)-1 };
if ( filter_formats( formatList, filterFlags, numFormats, intFormats ) == 0 )
{
log_info( "No formats supported for integer type\n" );
}
else
{
// Only filter mode we support on int is nearest
imageSampler.filter_mode = CL_FILTER_NEAREST;
ret += test_read_image_formats( device, formatList, filterFlags, numFormats, &imageSampler, kInt, imageType );
}
}
/////// uint tests ///////
if ( gTypesToTest & kTestUInt )
{
cl_channel_type uintFormats[] = { CL_UNSIGNED_INT8, CL_UNSIGNED_INT16, CL_UNSIGNED_INT32, (cl_channel_type)-1 };
if ( filter_formats( formatList, filterFlags, numFormats, uintFormats ) == 0 )
{
log_info( "No formats supported for unsigned int type\n" );
}
else
{
// Only filter mode we support on uint is nearest
imageSampler.filter_mode = CL_FILTER_NEAREST;
ret += test_read_image_formats( device, formatList, filterFlags, numFormats, &imageSampler, kUInt, imageType );
}
}
delete[] filterFlags;
delete[] formatList;
return ret;
}

View File

@@ -1,259 +1,263 @@
//
// 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"
#include <float.h>
#if defined( __APPLE__ )
#include <signal.h>
#include <sys/signal.h>
#include <setjmp.h>
#endif
#define MAX_ERR 0.005f
#define MAX_HALF_LINEAR_ERR 0.3f
extern cl_command_queue queue;
extern cl_context context;
extern bool gDebugTrace, gTestSmallImages, gEnablePitch, gTestMaxImages, gTestRounding;
extern cl_device_type gDeviceType;
#define MAX_TRIES 1
#define MAX_CLAMPED 1
const char *read1DKernelSourcePattern =
"__kernel void sample_kernel( read_only image1d_t input, sampler_t sampler, __global int *results )\n"
"{\n"
" int tidX = get_global_id(0);\n"
" int offset = tidX;\n"
" %s clr = read_image%s( input, tidX );\n"
" int4 test = (clr != read_image%s( input, sampler, tidX ));\n"
" if ( test.x || test.y || test.z || test.w )\n"
" results[offset] = -1;\n"
" else\n"
" results[offset] = 0;\n"
"}";
int test_read_image_1D( cl_device_id device, cl_context context, cl_command_queue queue, cl_kernel kernel,
image_descriptor *imageInfo, image_sampler_data *imageSampler,
ExplicitType outputType, MTdata d )
{
int error;
size_t threads[2];
cl_sampler actualSampler;
// generate_random_image_data allocates with malloc, so we use a MallocDataBuffer here
BufferOwningPtr<char> imageValues;
generate_random_image_data( imageInfo, imageValues, d );
if ( gDebugTrace )
log_info( " - Creating image %d by %d...\n", (int)imageInfo->width, (int)imageInfo->height );
// Construct testing sources
cl_mem image;
cl_image_desc image_desc;
memset(&image_desc, 0x0, sizeof(cl_image_desc));
image_desc.image_type = CL_MEM_OBJECT_IMAGE1D;
image_desc.image_width = imageInfo->width;
image_desc.image_row_pitch = ( gEnablePitch ? imageInfo->rowPitch : 0 );
image = clCreateImage( context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, imageInfo->format,
&image_desc, imageValues, &error );
if ( error != CL_SUCCESS )
{
log_error( "ERROR: Unable to create 1D image of size %d pitch %d (%s)\n", (int)imageInfo->width, (int)imageInfo->rowPitch, IGetErrorString( error ) );
return error;
}
if ( gDebugTrace )
log_info( " - Creating kernel arguments...\n" );
// Create sampler to use
actualSampler = clCreateSampler( context, false, CL_ADDRESS_NONE, CL_FILTER_NEAREST, &error );
test_error( error, "Unable to create image sampler" );
// Create results buffer
cl_mem results = clCreateBuffer( context, 0, imageInfo->width * sizeof(cl_int), NULL, &error);
test_error( error, "Unable to create results buffer" );
size_t resultValuesSize = imageInfo->width * sizeof(cl_int);
BufferOwningPtr<int> resultValues(malloc( resultValuesSize ));
memset( resultValues, 0xff, resultValuesSize );
clEnqueueWriteBuffer( queue, results, CL_TRUE, 0, resultValuesSize, resultValues, 0, NULL, NULL );
// Set arguments
int idx = 0;
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &image );
test_error( error, "Unable to set kernel arguments" );
error = clSetKernelArg( kernel, idx++, sizeof( cl_sampler ), &actualSampler );
test_error( error, "Unable to set kernel arguments" );
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &results );
test_error( error, "Unable to set kernel arguments" );
// Run the kernel
threads[0] = (size_t)imageInfo->width;
error = clEnqueueNDRangeKernel( queue, kernel, 1, NULL, threads, NULL, 0, NULL, NULL );
test_error( error, "Unable to run kernel" );
if ( gDebugTrace )
log_info( " reading results, %ld kbytes\n", (unsigned long)( imageInfo->width * sizeof(cl_int) / 1024 ) );
error = clEnqueueReadBuffer( queue, results, CL_TRUE, 0, resultValuesSize, resultValues, 0, NULL, NULL );
test_error( error, "Unable to read results from kernel" );
if ( gDebugTrace )
log_info( " results read\n" );
// Check for non-zero comps
bool allZeroes = true;
for ( size_t ic = 0; ic < imageInfo->width; ++ic )
{
if ( resultValues[ic] ) {
allZeroes = false;
break;
}
}
if ( !allZeroes )
{
log_error( " Sampler-less reads differ from reads with sampler.\n" );
return -1;
}
clReleaseSampler(actualSampler);
clReleaseMemObject(results);
clReleaseMemObject(image);
return 0;
}
int test_read_image_set_1D( cl_device_id device, cl_image_format *format, image_sampler_data *imageSampler,
ExplicitType outputType )
{
char programSrc[10240];
const char *ptr;
const char *readFormat;
const char *dataType;
clProgramWrapper program;
clKernelWrapper kernel;
RandomSeed seed( gRandomSeed );
int error;
// Get our operating params
size_t maxWidth;
cl_ulong maxAllocSize, memSize;
image_descriptor imageInfo;
size_t pixelSize;
imageInfo.format = format;
imageInfo.height = imageInfo.depth = imageInfo.arraySize = imageInfo.slicePitch = 0;
imageInfo.type = CL_MEM_OBJECT_IMAGE1D;
pixelSize = get_pixel_size( imageInfo.format );
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" );
// Determine types
if ( outputType == kInt )
{
readFormat = "i";
dataType = "int4";
}
else if ( outputType == kUInt )
{
readFormat = "ui";
dataType = "uint4";
}
else // kFloat
{
readFormat = "f";
dataType = "float4";
}
sprintf( programSrc, read1DKernelSourcePattern, dataType,
readFormat,
readFormat );
ptr = programSrc;
error = create_single_kernel_helper( context, &program, &kernel, 1, &ptr, "sample_kernel" );
test_error( error, "Unable to create testing kernel" );
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 retCode = test_read_image_1D( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
}
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 ] );
int retCode = test_read_image_1D( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
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;
if ( gEnablePitch )
{
size_t extraWidth = (int)random_log_in_range( 0, 64, seed );
imageInfo.rowPitch += extraWidth * pixelSize;
}
size = (size_t)imageInfo.rowPitch * 4;
} while ( size > maxAllocSize || ( size * 3 ) > memSize );
if ( gDebugTrace )
log_info( " at size %d (row pitch %d) out of %d\n", (int)imageInfo.width, (int)imageInfo.rowPitch, (int)maxWidth );
int retCode = test_read_image_1D( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
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"
#include <float.h>
#if defined( __APPLE__ )
#include <signal.h>
#include <sys/signal.h>
#include <setjmp.h>
#endif
#define MAX_ERR 0.005f
#define MAX_HALF_LINEAR_ERR 0.3f
extern cl_command_queue queue;
extern cl_context context;
extern bool gDebugTrace, gTestSmallImages, gEnablePitch, gTestMaxImages, gTestRounding;
extern cl_device_type gDeviceType;
#define MAX_TRIES 1
#define MAX_CLAMPED 1
const char *read1DKernelSourcePattern =
"__kernel void sample_kernel( read_only image1d_t input, sampler_t sampler, __global int *results )\n"
"{\n"
" int tidX = get_global_id(0);\n"
" int offset = tidX;\n"
" %s clr = read_image%s( input, tidX );\n"
" int4 test = (clr != read_image%s( input, sampler, tidX ));\n"
" if ( test.x || test.y || test.z || test.w )\n"
" results[offset] = -1;\n"
" else\n"
" results[offset] = 0;\n"
"}";
int test_read_image_1D( cl_device_id device, cl_context context, cl_command_queue queue, cl_kernel kernel,
image_descriptor *imageInfo, image_sampler_data *imageSampler,
ExplicitType outputType, MTdata d )
{
int error;
size_t threads[2];
cl_sampler actualSampler;
// generate_random_image_data allocates with malloc, so we use a MallocDataBuffer here
BufferOwningPtr<char> imageValues;
generate_random_image_data( imageInfo, imageValues, d );
if ( gDebugTrace )
log_info( " - Creating image %d by %d...\n", (int)imageInfo->width, (int)imageInfo->height );
// Construct testing sources
cl_mem image;
cl_image_desc image_desc;
memset(&image_desc, 0x0, sizeof(cl_image_desc));
image_desc.image_type = CL_MEM_OBJECT_IMAGE1D;
image_desc.image_width = imageInfo->width;
image_desc.image_row_pitch = ( gEnablePitch ? imageInfo->rowPitch : 0 );
image = clCreateImage( context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, imageInfo->format,
&image_desc, imageValues, &error );
if ( error != CL_SUCCESS )
{
log_error( "ERROR: Unable to create 1D image of size %d pitch %d (%s)\n", (int)imageInfo->width, (int)imageInfo->rowPitch, IGetErrorString( error ) );
return error;
}
if ( gDebugTrace )
log_info( " - Creating kernel arguments...\n" );
// Create sampler to use
actualSampler = clCreateSampler( context, false, CL_ADDRESS_NONE, CL_FILTER_NEAREST, &error );
test_error( error, "Unable to create image sampler" );
// Create results buffer
cl_mem results = clCreateBuffer( context, 0, imageInfo->width * sizeof(cl_int), NULL, &error);
test_error( error, "Unable to create results buffer" );
size_t resultValuesSize = imageInfo->width * sizeof(cl_int);
BufferOwningPtr<int> resultValues(malloc( resultValuesSize ));
memset( resultValues, 0xff, resultValuesSize );
clEnqueueWriteBuffer( queue, results, CL_TRUE, 0, resultValuesSize, resultValues, 0, NULL, NULL );
// Set arguments
int idx = 0;
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &image );
test_error( error, "Unable to set kernel arguments" );
error = clSetKernelArg( kernel, idx++, sizeof( cl_sampler ), &actualSampler );
test_error( error, "Unable to set kernel arguments" );
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &results );
test_error( error, "Unable to set kernel arguments" );
// Run the kernel
threads[0] = (size_t)imageInfo->width;
error = clEnqueueNDRangeKernel( queue, kernel, 1, NULL, threads, NULL, 0, NULL, NULL );
test_error( error, "Unable to run kernel" );
if ( gDebugTrace )
log_info( " reading results, %ld kbytes\n", (unsigned long)( imageInfo->width * sizeof(cl_int) / 1024 ) );
error = clEnqueueReadBuffer( queue, results, CL_TRUE, 0, resultValuesSize, resultValues, 0, NULL, NULL );
test_error( error, "Unable to read results from kernel" );
if ( gDebugTrace )
log_info( " results read\n" );
// Check for non-zero comps
bool allZeroes = true;
for ( size_t ic = 0; ic < imageInfo->width; ++ic )
{
if ( resultValues[ic] ) {
allZeroes = false;
break;
}
}
if ( !allZeroes )
{
log_error( " Sampler-less reads differ from reads with sampler.\n" );
return -1;
}
clReleaseSampler(actualSampler);
clReleaseMemObject(results);
clReleaseMemObject(image);
return 0;
}
int test_read_image_set_1D( cl_device_id device, cl_image_format *format, image_sampler_data *imageSampler,
ExplicitType outputType )
{
char programSrc[10240];
const char *ptr;
const char *readFormat;
const char *dataType;
clProgramWrapper program;
clKernelWrapper kernel;
RandomSeed seed( gRandomSeed );
int error;
// Get our operating params
size_t maxWidth;
cl_ulong maxAllocSize, memSize;
image_descriptor imageInfo;
size_t pixelSize;
imageInfo.format = format;
imageInfo.height = imageInfo.depth = imageInfo.arraySize = imageInfo.slicePitch = 0;
imageInfo.type = CL_MEM_OBJECT_IMAGE1D;
pixelSize = get_pixel_size( imageInfo.format );
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 (memSize > (cl_ulong)SIZE_MAX) {
memSize = (cl_ulong)SIZE_MAX;
}
// Determine types
if ( outputType == kInt )
{
readFormat = "i";
dataType = "int4";
}
else if ( outputType == kUInt )
{
readFormat = "ui";
dataType = "uint4";
}
else // kFloat
{
readFormat = "f";
dataType = "float4";
}
sprintf( programSrc, read1DKernelSourcePattern, dataType,
readFormat,
readFormat );
ptr = programSrc;
error = create_single_kernel_helper( context, &program, &kernel, 1, &ptr, "sample_kernel" );
test_error( error, "Unable to create testing kernel" );
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 retCode = test_read_image_1D( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
}
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 ] );
int retCode = test_read_image_1D( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
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;
if ( gEnablePitch )
{
size_t extraWidth = (int)random_log_in_range( 0, 64, seed );
imageInfo.rowPitch += extraWidth * pixelSize;
}
size = (size_t)imageInfo.rowPitch * 4;
} while ( size > maxAllocSize || ( size * 3 ) > memSize );
if ( gDebugTrace )
log_info( " at size %d (row pitch %d) out of %d\n", (int)imageInfo.width, (int)imageInfo.rowPitch, (int)maxWidth );
int retCode = test_read_image_1D( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
return 0;
}

View File

@@ -1,272 +1,276 @@
//
// 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"
#include <float.h>
#if defined( __APPLE__ )
#include <signal.h>
#include <sys/signal.h>
#include <setjmp.h>
#endif
#define MAX_ERR 0.005f
#define MAX_HALF_LINEAR_ERR 0.3f
extern cl_command_queue queue;
extern cl_context context;
extern bool gDebugTrace, gTestSmallImages, gEnablePitch, gTestMaxImages, gTestRounding;
extern cl_device_type gDeviceType;
#define MAX_TRIES 1
#define MAX_CLAMPED 1
const char *read1DArrayKernelSourcePattern =
"__kernel void sample_kernel( read_only image1d_array_t input, sampler_t sampler, __global int *results )\n"
"{\n"
" int tidX = get_global_id(0), tidY = get_global_id(1);\n"
" int offset = tidY*get_image_width(input) + tidX;\n"
" int2 coords = (int2)(tidX, tidY);\n"
" %s clr = read_image%s( input, coords );\n"
" int4 test = (clr != read_image%s( input, sampler, coords ));\n"
" if ( test.x || test.y || test.z || test.w )\n"
" results[offset] = -1;\n"
" else\n"
" results[offset] = 0;\n"
"}";
int test_read_image_1D_array( cl_device_id device, cl_context context, cl_command_queue queue, cl_kernel kernel,
image_descriptor *imageInfo, image_sampler_data *imageSampler,
ExplicitType outputType, MTdata d )
{
int error;
size_t threads[2];
cl_sampler actualSampler;
// generate_random_image_data allocates with malloc, so we use a MallocDataBuffer here
BufferOwningPtr<char> imageValues;
generate_random_image_data( imageInfo, imageValues, d );
if ( gDebugTrace )
log_info( " - Creating image %d by %d...\n", (int)imageInfo->width, (int)imageInfo->arraySize );
// Construct testing sources
cl_mem image;
cl_image_desc image_desc;
memset(&image_desc, 0x0, sizeof(cl_image_desc));
image_desc.image_type = CL_MEM_OBJECT_IMAGE1D_ARRAY;
image_desc.image_width = imageInfo->width;
image_desc.image_height = imageInfo->height;
image_desc.image_array_size = imageInfo->arraySize;
image_desc.image_row_pitch = ( gEnablePitch ? imageInfo->rowPitch : 0 );
image_desc.image_slice_pitch = 0;
image = clCreateImage( context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, imageInfo->format,
&image_desc, imageValues, &error );
if ( error != CL_SUCCESS )
{
log_error( "ERROR: Unable to create 1D image array of size %d x %d pitch %d (%s)\n", (int)imageInfo->width, (int)imageInfo->arraySize, (int)imageInfo->rowPitch, IGetErrorString( error ) );
return error;
}
if ( gDebugTrace )
log_info( " - Creating kernel arguments...\n" );
// Create sampler to use
actualSampler = clCreateSampler( context, false, CL_ADDRESS_NONE, CL_FILTER_NEAREST, &error );
test_error( error, "Unable to create image sampler" );
// Create results buffer
cl_mem results = clCreateBuffer( context, 0, imageInfo->width * imageInfo->arraySize * sizeof(cl_int), NULL, &error);
test_error( error, "Unable to create results buffer" );
size_t resultValuesSize = imageInfo->width * imageInfo->arraySize * sizeof(cl_int);
BufferOwningPtr<int> resultValues(malloc( resultValuesSize ));
memset( resultValues, 0xff, resultValuesSize );
clEnqueueWriteBuffer( queue, results, CL_TRUE, 0, resultValuesSize, resultValues, 0, NULL, NULL );
// Set arguments
int idx = 0;
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &image );
test_error( error, "Unable to set kernel arguments" );
error = clSetKernelArg( kernel, idx++, sizeof( cl_sampler ), &actualSampler );
test_error( error, "Unable to set kernel arguments" );
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &results );
test_error( error, "Unable to set kernel arguments" );
// Run the kernel
threads[0] = (size_t)imageInfo->width;
threads[1] = (size_t)imageInfo->arraySize;
error = clEnqueueNDRangeKernel( queue, kernel, 2, NULL, threads, NULL, 0, NULL, NULL );
test_error( error, "Unable to run kernel" );
if ( gDebugTrace )
log_info( " reading results, %ld kbytes\n", (unsigned long)( imageInfo->width * imageInfo->arraySize * sizeof(cl_int) / 1024 ) );
error = clEnqueueReadBuffer( queue, results, CL_TRUE, 0, resultValuesSize, resultValues, 0, NULL, NULL );
test_error( error, "Unable to read results from kernel" );
if ( gDebugTrace )
log_info( " results read\n" );
// Check for non-zero comps
bool allZeroes = true;
size_t ic;
for ( ic = 0; ic < imageInfo->width * imageInfo->arraySize; ++ic )
{
if ( resultValues[ic] ) {
allZeroes = false;
break;
}
}
if ( !allZeroes )
{
log_error( " Sampler-less reads differ from reads with sampler at index %d.\n", ic );
return -1;
}
clReleaseSampler(actualSampler);
clReleaseMemObject(results);
clReleaseMemObject(image);
return 0;
}
int test_read_image_set_1D_array( cl_device_id device, cl_image_format *format, image_sampler_data *imageSampler,
ExplicitType outputType )
{
char programSrc[10240];
const char *ptr;
const char *readFormat;
const char *dataType;
clProgramWrapper program;
clKernelWrapper kernel;
RandomSeed seed( gRandomSeed );
int error;
// Get our operating params
size_t maxWidth, maxArraySize;
cl_ulong maxAllocSize, memSize;
image_descriptor imageInfo;
size_t pixelSize;
imageInfo.format = format;
imageInfo.height = imageInfo.depth = 0;
imageInfo.type = CL_MEM_OBJECT_IMAGE1D_ARRAY;
pixelSize = get_pixel_size( imageInfo.format );
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" );
// Determine types
if ( outputType == kInt )
{
readFormat = "i";
dataType = "int4";
}
else if ( outputType == kUInt )
{
readFormat = "ui";
dataType = "uint4";
}
else // kFloat
{
readFormat = "f";
dataType = "float4";
}
sprintf( programSrc, read1DArrayKernelSourcePattern, dataType,
readFormat,
readFormat );
ptr = programSrc;
error = create_single_kernel_helper( context, &program, &kernel, 1, &ptr, "sample_kernel" );
test_error( error, "Unable to create testing kernel" );
if ( gTestSmallImages )
{
for ( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
{
imageInfo.rowPitch = imageInfo.width * pixelSize;
imageInfo.slicePitch = imageInfo.rowPitch;
for ( imageInfo.arraySize = 2; imageInfo.arraySize < 9; imageInfo.arraySize++ )
{
if ( gDebugTrace )
log_info( " at size %d,%d\n", (int)imageInfo.width, (int)imageInfo.arraySize );
int retCode = test_read_image_1D_array( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
}
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 ] );
int retCode = test_read_image_1D_array( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
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;
if ( gEnablePitch )
{
size_t extraWidth = (int)random_log_in_range( 0, 64, seed );
imageInfo.rowPitch += extraWidth * pixelSize;
}
imageInfo.slicePitch = imageInfo.rowPitch;
size = (size_t)imageInfo.rowPitch * (size_t)imageInfo.arraySize * 4;
} while ( size > maxAllocSize || ( size * 3 ) > memSize );
if ( gDebugTrace )
log_info( " at size %d,%d (row pitch %d) out of %d,%d\n", (int)imageInfo.width, (int)imageInfo.arraySize, (int)imageInfo.rowPitch, (int)maxWidth, (int)maxArraySize );
int retCode = test_read_image_1D_array( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
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"
#include <float.h>
#if defined( __APPLE__ )
#include <signal.h>
#include <sys/signal.h>
#include <setjmp.h>
#endif
#define MAX_ERR 0.005f
#define MAX_HALF_LINEAR_ERR 0.3f
extern cl_command_queue queue;
extern cl_context context;
extern bool gDebugTrace, gTestSmallImages, gEnablePitch, gTestMaxImages, gTestRounding;
extern cl_device_type gDeviceType;
#define MAX_TRIES 1
#define MAX_CLAMPED 1
const char *read1DArrayKernelSourcePattern =
"__kernel void sample_kernel( read_only image1d_array_t input, sampler_t sampler, __global int *results )\n"
"{\n"
" int tidX = get_global_id(0), tidY = get_global_id(1);\n"
" int offset = tidY*get_image_width(input) + tidX;\n"
" int2 coords = (int2)(tidX, tidY);\n"
" %s clr = read_image%s( input, coords );\n"
" int4 test = (clr != read_image%s( input, sampler, coords ));\n"
" if ( test.x || test.y || test.z || test.w )\n"
" results[offset] = -1;\n"
" else\n"
" results[offset] = 0;\n"
"}";
int test_read_image_1D_array( cl_device_id device, cl_context context, cl_command_queue queue, cl_kernel kernel,
image_descriptor *imageInfo, image_sampler_data *imageSampler,
ExplicitType outputType, MTdata d )
{
int error;
size_t threads[2];
cl_sampler actualSampler;
// generate_random_image_data allocates with malloc, so we use a MallocDataBuffer here
BufferOwningPtr<char> imageValues;
generate_random_image_data( imageInfo, imageValues, d );
if ( gDebugTrace )
log_info( " - Creating image %d by %d...\n", (int)imageInfo->width, (int)imageInfo->arraySize );
// Construct testing sources
cl_mem image;
cl_image_desc image_desc;
memset(&image_desc, 0x0, sizeof(cl_image_desc));
image_desc.image_type = CL_MEM_OBJECT_IMAGE1D_ARRAY;
image_desc.image_width = imageInfo->width;
image_desc.image_height = imageInfo->height;
image_desc.image_array_size = imageInfo->arraySize;
image_desc.image_row_pitch = ( gEnablePitch ? imageInfo->rowPitch : 0 );
image_desc.image_slice_pitch = 0;
image = clCreateImage( context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, imageInfo->format,
&image_desc, imageValues, &error );
if ( error != CL_SUCCESS )
{
log_error( "ERROR: Unable to create 1D image array of size %d x %d pitch %d (%s)\n", (int)imageInfo->width, (int)imageInfo->arraySize, (int)imageInfo->rowPitch, IGetErrorString( error ) );
return error;
}
if ( gDebugTrace )
log_info( " - Creating kernel arguments...\n" );
// Create sampler to use
actualSampler = clCreateSampler( context, false, CL_ADDRESS_NONE, CL_FILTER_NEAREST, &error );
test_error( error, "Unable to create image sampler" );
// Create results buffer
cl_mem results = clCreateBuffer( context, 0, imageInfo->width * imageInfo->arraySize * sizeof(cl_int), NULL, &error);
test_error( error, "Unable to create results buffer" );
size_t resultValuesSize = imageInfo->width * imageInfo->arraySize * sizeof(cl_int);
BufferOwningPtr<int> resultValues(malloc( resultValuesSize ));
memset( resultValues, 0xff, resultValuesSize );
clEnqueueWriteBuffer( queue, results, CL_TRUE, 0, resultValuesSize, resultValues, 0, NULL, NULL );
// Set arguments
int idx = 0;
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &image );
test_error( error, "Unable to set kernel arguments" );
error = clSetKernelArg( kernel, idx++, sizeof( cl_sampler ), &actualSampler );
test_error( error, "Unable to set kernel arguments" );
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &results );
test_error( error, "Unable to set kernel arguments" );
// Run the kernel
threads[0] = (size_t)imageInfo->width;
threads[1] = (size_t)imageInfo->arraySize;
error = clEnqueueNDRangeKernel( queue, kernel, 2, NULL, threads, NULL, 0, NULL, NULL );
test_error( error, "Unable to run kernel" );
if ( gDebugTrace )
log_info( " reading results, %ld kbytes\n", (unsigned long)( imageInfo->width * imageInfo->arraySize * sizeof(cl_int) / 1024 ) );
error = clEnqueueReadBuffer( queue, results, CL_TRUE, 0, resultValuesSize, resultValues, 0, NULL, NULL );
test_error( error, "Unable to read results from kernel" );
if ( gDebugTrace )
log_info( " results read\n" );
// Check for non-zero comps
bool allZeroes = true;
size_t ic;
for ( ic = 0; ic < imageInfo->width * imageInfo->arraySize; ++ic )
{
if ( resultValues[ic] ) {
allZeroes = false;
break;
}
}
if ( !allZeroes )
{
log_error( " Sampler-less reads differ from reads with sampler at index %d.\n", ic );
return -1;
}
clReleaseSampler(actualSampler);
clReleaseMemObject(results);
clReleaseMemObject(image);
return 0;
}
int test_read_image_set_1D_array( cl_device_id device, cl_image_format *format, image_sampler_data *imageSampler,
ExplicitType outputType )
{
char programSrc[10240];
const char *ptr;
const char *readFormat;
const char *dataType;
clProgramWrapper program;
clKernelWrapper kernel;
RandomSeed seed( gRandomSeed );
int error;
// Get our operating params
size_t maxWidth, maxArraySize;
cl_ulong maxAllocSize, memSize;
image_descriptor imageInfo;
size_t pixelSize;
imageInfo.format = format;
imageInfo.height = imageInfo.depth = 0;
imageInfo.type = CL_MEM_OBJECT_IMAGE1D_ARRAY;
pixelSize = get_pixel_size( imageInfo.format );
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 (memSize > (cl_ulong)SIZE_MAX) {
memSize = (cl_ulong)SIZE_MAX;
}
// Determine types
if ( outputType == kInt )
{
readFormat = "i";
dataType = "int4";
}
else if ( outputType == kUInt )
{
readFormat = "ui";
dataType = "uint4";
}
else // kFloat
{
readFormat = "f";
dataType = "float4";
}
sprintf( programSrc, read1DArrayKernelSourcePattern, dataType,
readFormat,
readFormat );
ptr = programSrc;
error = create_single_kernel_helper( context, &program, &kernel, 1, &ptr, "sample_kernel" );
test_error( error, "Unable to create testing kernel" );
if ( gTestSmallImages )
{
for ( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
{
imageInfo.rowPitch = imageInfo.width * pixelSize;
imageInfo.slicePitch = imageInfo.rowPitch;
for ( imageInfo.arraySize = 2; imageInfo.arraySize < 9; imageInfo.arraySize++ )
{
if ( gDebugTrace )
log_info( " at size %d,%d\n", (int)imageInfo.width, (int)imageInfo.arraySize );
int retCode = test_read_image_1D_array( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
}
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 ] );
int retCode = test_read_image_1D_array( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
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;
if ( gEnablePitch )
{
size_t extraWidth = (int)random_log_in_range( 0, 64, seed );
imageInfo.rowPitch += extraWidth * pixelSize;
}
imageInfo.slicePitch = imageInfo.rowPitch;
size = (size_t)imageInfo.rowPitch * (size_t)imageInfo.arraySize * 4;
} while ( size > maxAllocSize || ( size * 3 ) > memSize );
if ( gDebugTrace )
log_info( " at size %d,%d (row pitch %d) out of %d,%d\n", (int)imageInfo.width, (int)imageInfo.arraySize, (int)imageInfo.rowPitch, (int)maxWidth, (int)maxArraySize );
int retCode = test_read_image_1D_array( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
return 0;
}

View File

@@ -1,276 +1,281 @@
//
// Copyright (c) 2017 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "../testBase.h"
#include <float.h>
#if defined( __APPLE__ )
#include <signal.h>
#include <sys/signal.h>
#include <setjmp.h>
#endif
#define MAX_ERR 0.005f
#define MAX_HALF_LINEAR_ERR 0.3f
extern cl_command_queue queue;
extern cl_context context;
extern bool gDebugTrace, gTestSmallImages, gTestMaxImages, gTestRounding;
extern cl_device_type gDeviceType;
#define MAX_TRIES 1
#define MAX_CLAMPED 1
const char *read1DBufferKernelSourcePattern =
"__kernel void sample_kernel( read_only image1d_buffer_t inputA, read_only image1d_t inputB, sampler_t sampler, __global int *results )\n"
"{\n"
" int tidX = get_global_id(0);\n"
" int offset = tidX;\n"
" %s clr = read_image%s( inputA, tidX );\n"
" int4 test = (clr != read_image%s( inputB, sampler, tidX ));\n"
" if ( test.x || test.y || test.z || test.w )\n"
" results[offset] = -1;\n"
" else\n"
" results[offset] = 0;\n"
"}";
int test_read_image_1D_buffer( cl_device_id device, cl_context context, cl_command_queue queue, cl_kernel kernel,
image_descriptor *imageInfo, image_sampler_data *imageSampler,
ExplicitType outputType, MTdata d )
{
int error;
size_t threads[2];
cl_sampler actualSampler;
BufferOwningPtr<char> imageValues;
generate_random_image_data( imageInfo, imageValues, d );
if ( gDebugTrace )
log_info( " - Creating 1D image from buffer %d ...\n", (int)imageInfo->width );
// Construct testing sources
cl_mem image[2];
cl_image_desc image_desc;
cl_mem imageBuffer = clCreateBuffer( context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, imageInfo->rowPitch, imageValues, &error);
if ( error != CL_SUCCESS )
{
log_error( "ERROR: Unable to create buffer of size %d bytes (%s)\n", (int)imageInfo->rowPitch, IGetErrorString( error ) );
return error;
}
memset(&image_desc, 0x0, sizeof(cl_image_desc));
image_desc.image_type = CL_MEM_OBJECT_IMAGE1D_BUFFER;
image_desc.image_width = imageInfo->width;
image_desc.buffer = imageBuffer;
image[0] = clCreateImage( context, CL_MEM_READ_ONLY, imageInfo->format,
&image_desc, NULL, &error );
if ( error != CL_SUCCESS )
{
log_error( "ERROR: Unable to IMAGE1D_BUFFER of size %d pitch %d (%s)\n", (int)imageInfo->width, (int)imageInfo->rowPitch, IGetErrorString( error ) );
return error;
}
memset(&image_desc, 0x0, sizeof(cl_image_desc));
image_desc.image_type = CL_MEM_OBJECT_IMAGE1D;
image_desc.image_width = imageInfo->width;
image[1] = clCreateImage( context, CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR, imageInfo->format, &image_desc, imageValues, &error );
if ( error != CL_SUCCESS )
{
log_error( "ERROR: Unable to create IMAGE1D of size %d pitch %d (%s)\n", (int)imageInfo->width, (int)imageInfo->rowPitch, IGetErrorString( error ) );
return error;
}
if ( gDebugTrace )
log_info( " - Creating kernel arguments...\n" );
// Create sampler to use
actualSampler = clCreateSampler( context, false, CL_ADDRESS_NONE, CL_FILTER_NEAREST, &error );
test_error( error, "Unable to create image sampler" );
// Create results buffer
cl_mem results = clCreateBuffer( context, 0, imageInfo->width * sizeof(cl_int), NULL, &error);
test_error( error, "Unable to create results buffer" );
size_t resultValuesSize = imageInfo->width * sizeof(cl_int);
BufferOwningPtr<int> resultValues(malloc( resultValuesSize ));
memset( resultValues, 0xff, resultValuesSize );
clEnqueueWriteBuffer( queue, results, CL_TRUE, 0, resultValuesSize, resultValues, 0, NULL, NULL );
// Set arguments
int idx = 0;
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &image[0] );
test_error( error, "Unable to set kernel arguments" );
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &image[1] );
test_error( error, "Unable to set kernel arguments" );
error = clSetKernelArg( kernel, idx++, sizeof( cl_sampler ), &actualSampler );
test_error( error, "Unable to set kernel arguments" );
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &results );
test_error( error, "Unable to set kernel arguments" );
// Run the kernel
threads[0] = (size_t)imageInfo->width;
error = clEnqueueNDRangeKernel( queue, kernel, 1, NULL, threads, NULL, 0, NULL, NULL );
test_error( error, "Unable to run kernel" );
if ( gDebugTrace )
log_info( " reading results, %ld kbytes\n", (unsigned long)( imageInfo->width * sizeof(cl_int) / 1024 ) );
error = clEnqueueReadBuffer( queue, results, CL_TRUE, 0, resultValuesSize, resultValues, 0, NULL, NULL );
test_error( error, "Unable to read results from kernel" );
if ( gDebugTrace )
log_info( " results read\n" );
// Check for non-zero comps
bool allZeroes = true;
for ( size_t ic = 0; ic < imageInfo->width; ++ic )
{
if ( resultValues[ic] ) {
allZeroes = false;
break;
}
}
if ( !allZeroes )
{
log_error( " Sampler-less reads differ from reads with sampler.\n" );
return -1;
}
clReleaseSampler(actualSampler);
clReleaseMemObject(results);
clReleaseMemObject(image[0]);
clReleaseMemObject(image[1]);
clReleaseMemObject(imageBuffer);
return 0;
}
int test_read_image_set_1D_buffer( cl_device_id device, cl_image_format *format, image_sampler_data *imageSampler,
ExplicitType outputType )
{
char programSrc[10240];
const char *ptr;
const char *readFormat;
const char *dataType;
clProgramWrapper program;
clKernelWrapper kernel;
RandomSeed seed( gRandomSeed );
int error;
// Get our operating params
size_t maxWidth, maxWidth1D;
cl_ulong maxAllocSize, memSize;
image_descriptor imageInfo;
size_t pixelSize;
imageInfo.format = format;
imageInfo.height = imageInfo.depth = imageInfo.arraySize = imageInfo.slicePitch = 0;
imageInfo.type = CL_MEM_OBJECT_IMAGE1D;
pixelSize = get_pixel_size( imageInfo.format );
error = clGetDeviceInfo( device, CL_DEVICE_IMAGE_MAX_BUFFER_SIZE, sizeof( maxWidth ), &maxWidth, NULL );
error |= clGetDeviceInfo( device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof( maxAllocSize ), &maxAllocSize, NULL );
error |= clGetDeviceInfo( device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof( memSize ), &memSize, NULL );
error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE2D_MAX_WIDTH, sizeof( maxWidth ), &maxWidth1D, NULL );
test_error( error, "Unable to get max image 1D buffer size from device" );
// note: image_buffer test uses image1D for results validation.
// So the test can't use the biggest possible size for image_buffer if it's bigger than the max image1D size
maxWidth = (maxWidth > maxWidth1D) ? maxWidth1D : maxWidth;
// Determine types
if ( outputType == kInt )
{
readFormat = "i";
dataType = "int4";
}
else if ( outputType == kUInt )
{
readFormat = "ui";
dataType = "uint4";
}
else // kFloat
{
readFormat = "f";
dataType = "float4";
}
sprintf( programSrc, read1DBufferKernelSourcePattern, dataType,
readFormat,
readFormat );
ptr = programSrc;
error = create_single_kernel_helper( context, &program, &kernel, 1, &ptr, "sample_kernel" );
test_error( error, "Unable to create testing kernel" );
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 retCode = test_read_image_1D_buffer( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
}
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 ] );
int retCode = test_read_image_1D_buffer( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
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 = (size_t)imageInfo.rowPitch * 4;
} while ( size > maxAllocSize || ( size * 3 ) > memSize );
if ( gDebugTrace )
log_info( " at size %d (row pitch %d) out of %d\n", (int)imageInfo.width, (int)imageInfo.rowPitch, (int)maxWidth );
int retCode = test_read_image_1D_buffer( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
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"
#include <float.h>
#if defined( __APPLE__ )
#include <signal.h>
#include <sys/signal.h>
#include <setjmp.h>
#endif
#define MAX_ERR 0.005f
#define MAX_HALF_LINEAR_ERR 0.3f
extern cl_command_queue queue;
extern cl_context context;
extern bool gDebugTrace, gTestSmallImages, gTestMaxImages, gTestRounding;
extern cl_device_type gDeviceType;
#define MAX_TRIES 1
#define MAX_CLAMPED 1
const char *read1DBufferKernelSourcePattern =
"__kernel void sample_kernel( read_only image1d_buffer_t inputA, read_only image1d_t inputB, sampler_t sampler, __global int *results )\n"
"{\n"
" int tidX = get_global_id(0);\n"
" int offset = tidX;\n"
" %s clr = read_image%s( inputA, tidX );\n"
" int4 test = (clr != read_image%s( inputB, sampler, tidX ));\n"
" if ( test.x || test.y || test.z || test.w )\n"
" results[offset] = -1;\n"
" else\n"
" results[offset] = 0;\n"
"}";
int test_read_image_1D_buffer( cl_device_id device, cl_context context, cl_command_queue queue, cl_kernel kernel,
image_descriptor *imageInfo, image_sampler_data *imageSampler,
ExplicitType outputType, MTdata d )
{
int error;
size_t threads[2];
cl_sampler actualSampler;
BufferOwningPtr<char> imageValues;
generate_random_image_data( imageInfo, imageValues, d );
if ( gDebugTrace )
log_info( " - Creating 1D image from buffer %d ...\n", (int)imageInfo->width );
// Construct testing sources
cl_mem image[2];
cl_image_desc image_desc;
cl_mem imageBuffer = clCreateBuffer( context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, imageInfo->rowPitch, imageValues, &error);
if ( error != CL_SUCCESS )
{
log_error( "ERROR: Unable to create buffer of size %d bytes (%s)\n", (int)imageInfo->rowPitch, IGetErrorString( error ) );
return error;
}
memset(&image_desc, 0x0, sizeof(cl_image_desc));
image_desc.image_type = CL_MEM_OBJECT_IMAGE1D_BUFFER;
image_desc.image_width = imageInfo->width;
image_desc.buffer = imageBuffer;
image[0] = clCreateImage( context, CL_MEM_READ_ONLY, imageInfo->format,
&image_desc, NULL, &error );
if ( error != CL_SUCCESS )
{
log_error( "ERROR: Unable to IMAGE1D_BUFFER of size %d pitch %d (%s)\n", (int)imageInfo->width, (int)imageInfo->rowPitch, IGetErrorString( error ) );
return error;
}
memset(&image_desc, 0x0, sizeof(cl_image_desc));
image_desc.image_type = CL_MEM_OBJECT_IMAGE1D;
image_desc.image_width = imageInfo->width;
image[1] = clCreateImage( context, CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR, imageInfo->format, &image_desc, imageValues, &error );
if ( error != CL_SUCCESS )
{
log_error( "ERROR: Unable to create IMAGE1D of size %d pitch %d (%s)\n", (int)imageInfo->width, (int)imageInfo->rowPitch, IGetErrorString( error ) );
return error;
}
if ( gDebugTrace )
log_info( " - Creating kernel arguments...\n" );
// Create sampler to use
actualSampler = clCreateSampler( context, false, CL_ADDRESS_NONE, CL_FILTER_NEAREST, &error );
test_error( error, "Unable to create image sampler" );
// Create results buffer
cl_mem results = clCreateBuffer( context, 0, imageInfo->width * sizeof(cl_int), NULL, &error);
test_error( error, "Unable to create results buffer" );
size_t resultValuesSize = imageInfo->width * sizeof(cl_int);
BufferOwningPtr<int> resultValues(malloc( resultValuesSize ));
memset( resultValues, 0xff, resultValuesSize );
clEnqueueWriteBuffer( queue, results, CL_TRUE, 0, resultValuesSize, resultValues, 0, NULL, NULL );
// Set arguments
int idx = 0;
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &image[0] );
test_error( error, "Unable to set kernel arguments" );
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &image[1] );
test_error( error, "Unable to set kernel arguments" );
error = clSetKernelArg( kernel, idx++, sizeof( cl_sampler ), &actualSampler );
test_error( error, "Unable to set kernel arguments" );
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &results );
test_error( error, "Unable to set kernel arguments" );
// Run the kernel
threads[0] = (size_t)imageInfo->width;
error = clEnqueueNDRangeKernel( queue, kernel, 1, NULL, threads, NULL, 0, NULL, NULL );
test_error( error, "Unable to run kernel" );
if ( gDebugTrace )
log_info( " reading results, %ld kbytes\n", (unsigned long)( imageInfo->width * sizeof(cl_int) / 1024 ) );
error = clEnqueueReadBuffer( queue, results, CL_TRUE, 0, resultValuesSize, resultValues, 0, NULL, NULL );
test_error( error, "Unable to read results from kernel" );
if ( gDebugTrace )
log_info( " results read\n" );
// Check for non-zero comps
bool allZeroes = true;
for ( size_t ic = 0; ic < imageInfo->width; ++ic )
{
if ( resultValues[ic] ) {
allZeroes = false;
break;
}
}
if ( !allZeroes )
{
log_error( " Sampler-less reads differ from reads with sampler.\n" );
return -1;
}
clReleaseSampler(actualSampler);
clReleaseMemObject(results);
clReleaseMemObject(image[0]);
clReleaseMemObject(image[1]);
clReleaseMemObject(imageBuffer);
return 0;
}
int test_read_image_set_1D_buffer( cl_device_id device, cl_image_format *format, image_sampler_data *imageSampler,
ExplicitType outputType )
{
char programSrc[10240];
const char *ptr;
const char *readFormat;
const char *dataType;
clProgramWrapper program;
clKernelWrapper kernel;
RandomSeed seed( gRandomSeed );
int error;
// Get our operating params
size_t maxWidth, maxWidth1D;
cl_ulong maxAllocSize, memSize;
image_descriptor imageInfo;
size_t pixelSize;
imageInfo.format = format;
imageInfo.height = imageInfo.depth = imageInfo.arraySize = imageInfo.slicePitch = 0;
imageInfo.type = CL_MEM_OBJECT_IMAGE1D;
pixelSize = get_pixel_size( imageInfo.format );
error = clGetDeviceInfo( device, CL_DEVICE_IMAGE_MAX_BUFFER_SIZE, sizeof( maxWidth ), &maxWidth, NULL );
error |= clGetDeviceInfo( device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof( maxAllocSize ), &maxAllocSize, NULL );
error |= clGetDeviceInfo( device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof( memSize ), &memSize, NULL );
error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE2D_MAX_WIDTH, sizeof( maxWidth ), &maxWidth1D, NULL );
test_error( error, "Unable to get max image 1D buffer size from device" );
if (memSize > (cl_ulong)SIZE_MAX) {
memSize = (cl_ulong)SIZE_MAX;
}
// note: image_buffer test uses image1D for results validation.
// So the test can't use the biggest possible size for image_buffer if it's bigger than the max image1D size
maxWidth = (maxWidth > maxWidth1D) ? maxWidth1D : maxWidth;
// Determine types
if ( outputType == kInt )
{
readFormat = "i";
dataType = "int4";
}
else if ( outputType == kUInt )
{
readFormat = "ui";
dataType = "uint4";
}
else // kFloat
{
readFormat = "f";
dataType = "float4";
}
sprintf( programSrc, read1DBufferKernelSourcePattern, dataType,
readFormat,
readFormat );
ptr = programSrc;
error = create_single_kernel_helper( context, &program, &kernel, 1, &ptr, "sample_kernel" );
test_error( error, "Unable to create testing kernel" );
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 retCode = test_read_image_1D_buffer( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
}
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 ] );
int retCode = test_read_image_1D_buffer( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
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 = (size_t)imageInfo.rowPitch * 4;
} while ( size > maxAllocSize || ( size * 3 ) > memSize );
if ( gDebugTrace )
log_info( " at size %d (row pitch %d) out of %d\n", (int)imageInfo.width, (int)imageInfo.rowPitch, (int)maxWidth );
int retCode = test_read_image_1D_buffer( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
return 0;
}

View File

@@ -1,267 +1,271 @@
//
// 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"
#include <float.h>
#define MAX_ERR 0.005f
#define MAX_HALF_LINEAR_ERR 0.3f
extern cl_command_queue queue;
extern cl_context context;
extern bool gDebugTrace, gTestSmallImages, gEnablePitch, gTestMaxImages, gTestRounding;
extern cl_device_type gDeviceType;
const char *read2DArrayKernelSourcePattern =
"__kernel void sample_kernel( read_only image2d_array_t input, sampler_t sampler, __global int *results )\n"
"{\n"
" int tidX = get_global_id(0), tidY = get_global_id(1), tidZ = get_global_id(2);\n"
" int offset = tidZ*get_image_width(input)*get_image_height(input) + tidY*get_image_width(input) + tidX;\n"
" int4 coords = (int4)( tidX, tidY, tidZ, 0 );\n"
" %s clr = read_image%s( input, coords );\n"
" int4 test = (clr != read_image%s( input, sampler, coords ));\n"
" if ( test.x || test.y || test.z || test.w )\n"
" results[offset] = -1;\n"
" else\n"
" results[offset] = 0;\n"
"}";
int test_read_image_2D_array( cl_device_id device, cl_context context, cl_command_queue queue, cl_kernel kernel,
image_descriptor *imageInfo, image_sampler_data *imageSampler,
ExplicitType outputType, MTdata d )
{
int error;
size_t threads[3];
cl_sampler actualSampler;
BufferOwningPtr<char> imageValues;
generate_random_image_data( imageInfo, imageValues, d );
// Don't use clEnqueueWriteImage; just use copy host ptr to get the data in
cl_image_desc image_desc;
cl_mem image;
memset(&image_desc, 0x0, sizeof(cl_image_desc));
image_desc.image_type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
image_desc.image_width = imageInfo->width;
image_desc.image_height = imageInfo->height;
image_desc.image_array_size = imageInfo->arraySize;
image_desc.image_row_pitch = ( gEnablePitch ? imageInfo->rowPitch : 0 );
image_desc.image_slice_pitch = ( gEnablePitch ? imageInfo->slicePitch : 0 );
image = clCreateImage( context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, imageInfo->format,
&image_desc, imageValues, &error );
if ( error != CL_SUCCESS )
{
log_error( "ERROR: Unable to create 2D image array of size %d x %d x %d (pitch %d, %d ) (%s)", (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->arraySize, (int)imageInfo->rowPitch, (int)imageInfo->slicePitch, IGetErrorString( error ) );
return error;
}
// Create sampler to use
actualSampler = clCreateSampler( context, false, CL_ADDRESS_NONE, CL_FILTER_NEAREST, &error );
test_error( error, "Unable to create image sampler" );
// Create results buffer
cl_mem results = clCreateBuffer( context, 0, imageInfo->width * imageInfo->height * imageInfo->arraySize * sizeof(cl_int), NULL, &error);
test_error( error, "Unable to create results buffer" );
size_t resultValuesSize = imageInfo->width * imageInfo->height * imageInfo->arraySize * sizeof(cl_int);
BufferOwningPtr<int> resultValues(malloc( resultValuesSize ));
memset( resultValues, 0xff, resultValuesSize );
clEnqueueWriteBuffer( queue, results, CL_TRUE, 0, resultValuesSize, resultValues, 0, NULL, NULL );
// Set arguments
int idx = 0;
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &image );
test_error( error, "Unable to set kernel arguments" );
error = clSetKernelArg( kernel, idx++, sizeof( cl_sampler ), &actualSampler );
test_error( error, "Unable to set kernel arguments" );
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &results );
test_error( error, "Unable to set kernel arguments" );
// Figure out thread dimensions
threads[0] = (size_t)imageInfo->width;
threads[1] = (size_t)imageInfo->height;
threads[2] = (size_t)imageInfo->arraySize;
// Run the kernel
error = clEnqueueNDRangeKernel( queue, kernel, 3, NULL, threads, NULL, 0, NULL, NULL );
test_error( error, "Unable to run kernel" );
// Get results
error = clEnqueueReadBuffer( queue, results, CL_TRUE, 0, resultValuesSize, resultValues, 0, NULL, NULL );
test_error( error, "Unable to read results from kernel" );
if ( gDebugTrace )
log_info( " results read\n" );
// Check for non-zero comps
bool allZeroes = true;
for ( size_t ic = 0; ic < imageInfo->width * imageInfo->height * imageInfo->arraySize; ++ic )
{
if ( resultValues[ic] ) {
allZeroes = false;
break;
}
}
if ( !allZeroes )
{
log_error( " Sampler-less reads differ from reads with sampler.\n" );
return -1;
}
clReleaseSampler(actualSampler);
clReleaseMemObject(results);
clReleaseMemObject(image);
return 0;
}
int test_read_image_set_2D_array( cl_device_id device, cl_image_format *format, image_sampler_data *imageSampler, ExplicitType outputType )
{
char programSrc[10240];
const char *ptr;
const char *readFormat;
const char *dataType;
RandomSeed seed( gRandomSeed );
int error;
clProgramWrapper program;
clKernelWrapper kernel;
// Get operating parameters
size_t maxWidth, maxHeight, maxArraySize;
cl_ulong maxAllocSize, memSize;
image_descriptor imageInfo;
size_t pixelSize;
imageInfo.format = format;
imageInfo.type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
pixelSize = get_pixel_size( imageInfo.format );
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 2D array size from device" );
// Determine types
if ( outputType == kInt )
{
readFormat = "i";
dataType = "int4";
}
else if ( outputType == kUInt )
{
readFormat = "ui";
dataType = "uint4";
}
else // kFloat
{
readFormat = "f";
dataType = "float4";
}
// Construct the source
sprintf( programSrc, read2DArrayKernelSourcePattern, dataType,
readFormat,
readFormat );
ptr = programSrc;
error = create_single_kernel_helper( context, &program, &kernel, 1, &ptr, "sample_kernel" );
test_error( error, "Unable to create testing kernel" );
// Run tests
if ( gTestSmallImages )
{
for ( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
{
imageInfo.rowPitch = imageInfo.width * get_pixel_size( imageInfo.format );
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 retCode = test_read_image_2D_array( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
}
}
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 ] );
int retCode = test_read_image_2D_array( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
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;
if ( gEnablePitch )
{
size_t extraWidth = (int)random_log_in_range( 0, 64, seed );
imageInfo.rowPitch += extraWidth * pixelSize;
size_t extraHeight = (int)random_log_in_range( 0, 64, 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 retCode = test_read_image_2D_array( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
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"
#include <float.h>
#define MAX_ERR 0.005f
#define MAX_HALF_LINEAR_ERR 0.3f
extern cl_command_queue queue;
extern cl_context context;
extern bool gDebugTrace, gTestSmallImages, gEnablePitch, gTestMaxImages, gTestRounding;
extern cl_device_type gDeviceType;
const char *read2DArrayKernelSourcePattern =
"__kernel void sample_kernel( read_only image2d_array_t input, sampler_t sampler, __global int *results )\n"
"{\n"
" int tidX = get_global_id(0), tidY = get_global_id(1), tidZ = get_global_id(2);\n"
" int offset = tidZ*get_image_width(input)*get_image_height(input) + tidY*get_image_width(input) + tidX;\n"
" int4 coords = (int4)( tidX, tidY, tidZ, 0 );\n"
" %s clr = read_image%s( input, coords );\n"
" int4 test = (clr != read_image%s( input, sampler, coords ));\n"
" if ( test.x || test.y || test.z || test.w )\n"
" results[offset] = -1;\n"
" else\n"
" results[offset] = 0;\n"
"}";
int test_read_image_2D_array( cl_device_id device, cl_context context, cl_command_queue queue, cl_kernel kernel,
image_descriptor *imageInfo, image_sampler_data *imageSampler,
ExplicitType outputType, MTdata d )
{
int error;
size_t threads[3];
cl_sampler actualSampler;
BufferOwningPtr<char> imageValues;
generate_random_image_data( imageInfo, imageValues, d );
// Don't use clEnqueueWriteImage; just use copy host ptr to get the data in
cl_image_desc image_desc;
cl_mem image;
memset(&image_desc, 0x0, sizeof(cl_image_desc));
image_desc.image_type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
image_desc.image_width = imageInfo->width;
image_desc.image_height = imageInfo->height;
image_desc.image_array_size = imageInfo->arraySize;
image_desc.image_row_pitch = ( gEnablePitch ? imageInfo->rowPitch : 0 );
image_desc.image_slice_pitch = ( gEnablePitch ? imageInfo->slicePitch : 0 );
image = clCreateImage( context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, imageInfo->format,
&image_desc, imageValues, &error );
if ( error != CL_SUCCESS )
{
log_error( "ERROR: Unable to create 2D image array of size %d x %d x %d (pitch %d, %d ) (%s)", (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->arraySize, (int)imageInfo->rowPitch, (int)imageInfo->slicePitch, IGetErrorString( error ) );
return error;
}
// Create sampler to use
actualSampler = clCreateSampler( context, false, CL_ADDRESS_NONE, CL_FILTER_NEAREST, &error );
test_error( error, "Unable to create image sampler" );
// Create results buffer
cl_mem results = clCreateBuffer( context, 0, imageInfo->width * imageInfo->height * imageInfo->arraySize * sizeof(cl_int), NULL, &error);
test_error( error, "Unable to create results buffer" );
size_t resultValuesSize = imageInfo->width * imageInfo->height * imageInfo->arraySize * sizeof(cl_int);
BufferOwningPtr<int> resultValues(malloc( resultValuesSize ));
memset( resultValues, 0xff, resultValuesSize );
clEnqueueWriteBuffer( queue, results, CL_TRUE, 0, resultValuesSize, resultValues, 0, NULL, NULL );
// Set arguments
int idx = 0;
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &image );
test_error( error, "Unable to set kernel arguments" );
error = clSetKernelArg( kernel, idx++, sizeof( cl_sampler ), &actualSampler );
test_error( error, "Unable to set kernel arguments" );
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &results );
test_error( error, "Unable to set kernel arguments" );
// Figure out thread dimensions
threads[0] = (size_t)imageInfo->width;
threads[1] = (size_t)imageInfo->height;
threads[2] = (size_t)imageInfo->arraySize;
// Run the kernel
error = clEnqueueNDRangeKernel( queue, kernel, 3, NULL, threads, NULL, 0, NULL, NULL );
test_error( error, "Unable to run kernel" );
// Get results
error = clEnqueueReadBuffer( queue, results, CL_TRUE, 0, resultValuesSize, resultValues, 0, NULL, NULL );
test_error( error, "Unable to read results from kernel" );
if ( gDebugTrace )
log_info( " results read\n" );
// Check for non-zero comps
bool allZeroes = true;
for ( size_t ic = 0; ic < imageInfo->width * imageInfo->height * imageInfo->arraySize; ++ic )
{
if ( resultValues[ic] ) {
allZeroes = false;
break;
}
}
if ( !allZeroes )
{
log_error( " Sampler-less reads differ from reads with sampler.\n" );
return -1;
}
clReleaseSampler(actualSampler);
clReleaseMemObject(results);
clReleaseMemObject(image);
return 0;
}
int test_read_image_set_2D_array( cl_device_id device, cl_image_format *format, image_sampler_data *imageSampler, ExplicitType outputType )
{
char programSrc[10240];
const char *ptr;
const char *readFormat;
const char *dataType;
RandomSeed seed( gRandomSeed );
int error;
clProgramWrapper program;
clKernelWrapper kernel;
// Get operating parameters
size_t maxWidth, maxHeight, maxArraySize;
cl_ulong maxAllocSize, memSize;
image_descriptor imageInfo;
size_t pixelSize;
imageInfo.format = format;
imageInfo.type = CL_MEM_OBJECT_IMAGE2D_ARRAY;
pixelSize = get_pixel_size( imageInfo.format );
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 2D array size from device" );
if (memSize > (cl_ulong)SIZE_MAX) {
memSize = (cl_ulong)SIZE_MAX;
}
// Determine types
if ( outputType == kInt )
{
readFormat = "i";
dataType = "int4";
}
else if ( outputType == kUInt )
{
readFormat = "ui";
dataType = "uint4";
}
else // kFloat
{
readFormat = "f";
dataType = "float4";
}
// Construct the source
sprintf( programSrc, read2DArrayKernelSourcePattern, dataType,
readFormat,
readFormat );
ptr = programSrc;
error = create_single_kernel_helper( context, &program, &kernel, 1, &ptr, "sample_kernel" );
test_error( error, "Unable to create testing kernel" );
// Run tests
if ( gTestSmallImages )
{
for ( imageInfo.width = 1; imageInfo.width < 13; imageInfo.width++ )
{
imageInfo.rowPitch = imageInfo.width * get_pixel_size( imageInfo.format );
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 retCode = test_read_image_2D_array( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
}
}
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 ] );
int retCode = test_read_image_2D_array( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
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;
if ( gEnablePitch )
{
size_t extraWidth = (int)random_log_in_range( 0, 64, seed );
imageInfo.rowPitch += extraWidth * pixelSize;
size_t extraHeight = (int)random_log_in_range( 0, 64, 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 retCode = test_read_image_2D_array( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
return 0;
}

View File

@@ -1,272 +1,276 @@
//
// 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"
#include <float.h>
#define MAX_ERR 0.005f
#define MAX_HALF_LINEAR_ERR 0.3f
extern cl_command_queue queue;
extern cl_context context;
extern bool gDebugTrace, gTestSmallImages, gEnablePitch, gTestMaxImages, gTestRounding;
extern cl_device_type gDeviceType;
const char *read3DKernelSourcePattern =
"__kernel void sample_kernel( read_only image3d_t input, sampler_t sampler, __global int *results )\n"
"{\n"
" int tidX = get_global_id(0), tidY = get_global_id(1), tidZ = get_global_id(2);\n"
" int offset = tidZ*get_image_width(input)*get_image_height(input) + tidY*get_image_width(input) + tidX;\n"
" int4 coords = (int4)( tidX, tidY, tidZ, 0 );\n"
" %s clr = read_image%s( input, coords );\n"
" int4 test = (clr != read_image%s( input, sampler, coords ));\n"
" if ( test.x || test.y || test.z || test.w )\n"
" results[offset] = -1;\n"
" else\n"
" results[offset] = 0;\n"
"}";
int test_read_image_3D( cl_device_id device, cl_context context, cl_command_queue queue, cl_kernel kernel,
image_descriptor *imageInfo, image_sampler_data *imageSampler,
ExplicitType outputType, MTdata d )
{
int error;
size_t threads[3];
cl_sampler actualSampler;
BufferOwningPtr<char> imageValues;
generate_random_image_data( imageInfo, imageValues, d );
// Don't use clEnqueueWriteImage; just use copy host ptr to get the data in
cl_image_desc image_desc;
cl_mem image;
memset(&image_desc, 0x0, sizeof(cl_image_desc));
image_desc.image_type = CL_MEM_OBJECT_IMAGE3D;
image_desc.image_width = imageInfo->width;
image_desc.image_height = imageInfo->height;
image_desc.image_depth = imageInfo->depth;
image_desc.image_row_pitch = ( gEnablePitch ? imageInfo->rowPitch : 0 );
image_desc.image_slice_pitch = ( gEnablePitch ? imageInfo->slicePitch : 0 );
image = clCreateImage( context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, imageInfo->format,
&image_desc, imageValues, &error );
if ( error != CL_SUCCESS )
{
log_error( "ERROR: Unable to create 3D image of size %d x %d x %d (pitch %d, %d ) (%s)", (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->depth, (int)imageInfo->rowPitch, (int)imageInfo->slicePitch, IGetErrorString( error ) );
return error;
}
// Create sampler to use
actualSampler = clCreateSampler( context, CL_FALSE, CL_ADDRESS_NONE, CL_FILTER_NEAREST, &error );
test_error( error, "Unable to create image sampler" );
// Create results buffer
cl_mem results = clCreateBuffer( context, 0, imageInfo->width * imageInfo->height * imageInfo->depth * sizeof(cl_int), NULL, &error);
test_error( error, "Unable to create results buffer" );
size_t resultValuesSize = imageInfo->width * imageInfo->height * imageInfo->depth * sizeof(cl_int);
BufferOwningPtr<int> resultValues(malloc( resultValuesSize ));
memset( resultValues, 0xff, resultValuesSize );
clEnqueueWriteBuffer( queue, results, CL_TRUE, 0, resultValuesSize, resultValues, 0, NULL, NULL );
// Set arguments
int idx = 0;
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &image );
test_error( error, "Unable to set kernel arguments" );
error = clSetKernelArg( kernel, idx++, sizeof( cl_sampler ), &actualSampler );
test_error( error, "Unable to set kernel arguments" );
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &results );
test_error( error, "Unable to set kernel arguments" );
// Figure out thread dimensions
threads[0] = (size_t)imageInfo->width;
threads[1] = (size_t)imageInfo->height;
threads[2] = (size_t)imageInfo->depth;
// Run the kernel
error = clEnqueueNDRangeKernel( queue, kernel, 3, NULL, threads, NULL, 0, NULL, NULL );
test_error( error, "Unable to run kernel" );
if ( gDebugTrace )
log_info( " reading results, %ld kbytes\n", (unsigned long)( imageInfo->width * imageInfo->height * imageInfo->depth * sizeof(cl_int) / 1024 ) );
// Get results
error = clEnqueueReadBuffer( queue, results, CL_TRUE, 0, resultValuesSize, resultValues, 0, NULL, NULL );
test_error( error, "Unable to read results from kernel" );
if ( gDebugTrace )
log_info( " results read\n" );
// Check for non-zero comps
bool allZeroes = true;
size_t ic;
for ( ic = 0; ic < imageInfo->width * imageInfo->height * imageInfo->depth; ++ic )
{
if ( resultValues[ic] ) {
allZeroes = false;
break;
}
}
if ( !allZeroes )
{
log_error( " Sampler-less reads differ from reads with sampler at index %d.\n", ic );
return -1;
}
clReleaseSampler(actualSampler);
clReleaseMemObject(results);
clReleaseMemObject(image);
return 0;
}
int test_read_image_set_3D( cl_device_id device, cl_image_format *format, image_sampler_data *imageSampler, ExplicitType outputType )
{
char programSrc[10240];
const char *ptr;
const char *readFormat;
const char *dataType;
RandomSeed seed( gRandomSeed );
int error;
clProgramWrapper program;
clKernelWrapper kernel;
// Get operating parameters
size_t maxWidth, maxHeight, maxDepth;
cl_ulong maxAllocSize, memSize;
image_descriptor imageInfo;
size_t pixelSize;
imageInfo.format = format;
imageInfo.arraySize = 0;
imageInfo.type = CL_MEM_OBJECT_IMAGE3D;
pixelSize = get_pixel_size( imageInfo.format );
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" );
// Determine types
if ( outputType == kInt )
{
readFormat = "i";
dataType = "int4";
}
else if ( outputType == kUInt )
{
readFormat = "ui";
dataType = "uint4";
}
else // kFloat
{
readFormat = "f";
dataType = "float4";
}
// Construct the source
sprintf( programSrc, read3DKernelSourcePattern, dataType,
readFormat,
readFormat );
ptr = programSrc;
error = create_single_kernel_helper( context, &program, &kernel, 1, &ptr, "sample_kernel" );
test_error( error, "Unable to create testing kernel" );
// Run tests
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 retCode = test_read_image_3D( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
}
}
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 ] );
int retCode = test_read_image_3D( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
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;
if ( gEnablePitch )
{
size_t extraWidth = (int)random_log_in_range( 0, 64, seed );
imageInfo.rowPitch += extraWidth * pixelSize;
size_t extraHeight = (int)random_log_in_range( 0, 64, 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 retCode = test_read_image_3D( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
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"
#include <float.h>
#define MAX_ERR 0.005f
#define MAX_HALF_LINEAR_ERR 0.3f
extern cl_command_queue queue;
extern cl_context context;
extern bool gDebugTrace, gTestSmallImages, gEnablePitch, gTestMaxImages, gTestRounding;
extern cl_device_type gDeviceType;
const char *read3DKernelSourcePattern =
"__kernel void sample_kernel( read_only image3d_t input, sampler_t sampler, __global int *results )\n"
"{\n"
" int tidX = get_global_id(0), tidY = get_global_id(1), tidZ = get_global_id(2);\n"
" int offset = tidZ*get_image_width(input)*get_image_height(input) + tidY*get_image_width(input) + tidX;\n"
" int4 coords = (int4)( tidX, tidY, tidZ, 0 );\n"
" %s clr = read_image%s( input, coords );\n"
" int4 test = (clr != read_image%s( input, sampler, coords ));\n"
" if ( test.x || test.y || test.z || test.w )\n"
" results[offset] = -1;\n"
" else\n"
" results[offset] = 0;\n"
"}";
int test_read_image_3D( cl_device_id device, cl_context context, cl_command_queue queue, cl_kernel kernel,
image_descriptor *imageInfo, image_sampler_data *imageSampler,
ExplicitType outputType, MTdata d )
{
int error;
size_t threads[3];
cl_sampler actualSampler;
BufferOwningPtr<char> imageValues;
generate_random_image_data( imageInfo, imageValues, d );
// Don't use clEnqueueWriteImage; just use copy host ptr to get the data in
cl_image_desc image_desc;
cl_mem image;
memset(&image_desc, 0x0, sizeof(cl_image_desc));
image_desc.image_type = CL_MEM_OBJECT_IMAGE3D;
image_desc.image_width = imageInfo->width;
image_desc.image_height = imageInfo->height;
image_desc.image_depth = imageInfo->depth;
image_desc.image_row_pitch = ( gEnablePitch ? imageInfo->rowPitch : 0 );
image_desc.image_slice_pitch = ( gEnablePitch ? imageInfo->slicePitch : 0 );
image = clCreateImage( context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, imageInfo->format,
&image_desc, imageValues, &error );
if ( error != CL_SUCCESS )
{
log_error( "ERROR: Unable to create 3D image of size %d x %d x %d (pitch %d, %d ) (%s)", (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->depth, (int)imageInfo->rowPitch, (int)imageInfo->slicePitch, IGetErrorString( error ) );
return error;
}
// Create sampler to use
actualSampler = clCreateSampler( context, CL_FALSE, CL_ADDRESS_NONE, CL_FILTER_NEAREST, &error );
test_error( error, "Unable to create image sampler" );
// Create results buffer
cl_mem results = clCreateBuffer( context, 0, imageInfo->width * imageInfo->height * imageInfo->depth * sizeof(cl_int), NULL, &error);
test_error( error, "Unable to create results buffer" );
size_t resultValuesSize = imageInfo->width * imageInfo->height * imageInfo->depth * sizeof(cl_int);
BufferOwningPtr<int> resultValues(malloc( resultValuesSize ));
memset( resultValues, 0xff, resultValuesSize );
clEnqueueWriteBuffer( queue, results, CL_TRUE, 0, resultValuesSize, resultValues, 0, NULL, NULL );
// Set arguments
int idx = 0;
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &image );
test_error( error, "Unable to set kernel arguments" );
error = clSetKernelArg( kernel, idx++, sizeof( cl_sampler ), &actualSampler );
test_error( error, "Unable to set kernel arguments" );
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &results );
test_error( error, "Unable to set kernel arguments" );
// Figure out thread dimensions
threads[0] = (size_t)imageInfo->width;
threads[1] = (size_t)imageInfo->height;
threads[2] = (size_t)imageInfo->depth;
// Run the kernel
error = clEnqueueNDRangeKernel( queue, kernel, 3, NULL, threads, NULL, 0, NULL, NULL );
test_error( error, "Unable to run kernel" );
if ( gDebugTrace )
log_info( " reading results, %ld kbytes\n", (unsigned long)( imageInfo->width * imageInfo->height * imageInfo->depth * sizeof(cl_int) / 1024 ) );
// Get results
error = clEnqueueReadBuffer( queue, results, CL_TRUE, 0, resultValuesSize, resultValues, 0, NULL, NULL );
test_error( error, "Unable to read results from kernel" );
if ( gDebugTrace )
log_info( " results read\n" );
// Check for non-zero comps
bool allZeroes = true;
size_t ic;
for ( ic = 0; ic < imageInfo->width * imageInfo->height * imageInfo->depth; ++ic )
{
if ( resultValues[ic] ) {
allZeroes = false;
break;
}
}
if ( !allZeroes )
{
log_error( " Sampler-less reads differ from reads with sampler at index %d.\n", ic );
return -1;
}
clReleaseSampler(actualSampler);
clReleaseMemObject(results);
clReleaseMemObject(image);
return 0;
}
int test_read_image_set_3D( cl_device_id device, cl_image_format *format, image_sampler_data *imageSampler, ExplicitType outputType )
{
char programSrc[10240];
const char *ptr;
const char *readFormat;
const char *dataType;
RandomSeed seed( gRandomSeed );
int error;
clProgramWrapper program;
clKernelWrapper kernel;
// Get operating parameters
size_t maxWidth, maxHeight, maxDepth;
cl_ulong maxAllocSize, memSize;
image_descriptor imageInfo;
size_t pixelSize;
imageInfo.format = format;
imageInfo.arraySize = 0;
imageInfo.type = CL_MEM_OBJECT_IMAGE3D;
pixelSize = get_pixel_size( imageInfo.format );
error = clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_WIDTH, sizeof( maxWidth ), &maxWidth, NULL );
error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_HEIGHT, sizeof( maxHeight ), &maxHeight, NULL );
error |= clGetDeviceInfo( device, CL_DEVICE_IMAGE3D_MAX_DEPTH, sizeof( maxDepth ), &maxDepth, NULL );
error |= clGetDeviceInfo( device, CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof( maxAllocSize ), &maxAllocSize, NULL );
error |= clGetDeviceInfo( device, CL_DEVICE_GLOBAL_MEM_SIZE, sizeof( memSize ), &memSize, NULL );
test_error( error, "Unable to get max image 3D size from device" );
if (memSize > (cl_ulong)SIZE_MAX) {
memSize = (cl_ulong)SIZE_MAX;
}
// Determine types
if ( outputType == kInt )
{
readFormat = "i";
dataType = "int4";
}
else if ( outputType == kUInt )
{
readFormat = "ui";
dataType = "uint4";
}
else // kFloat
{
readFormat = "f";
dataType = "float4";
}
// Construct the source
sprintf( programSrc, read3DKernelSourcePattern, dataType,
readFormat,
readFormat );
ptr = programSrc;
error = create_single_kernel_helper( context, &program, &kernel, 1, &ptr, "sample_kernel" );
test_error( error, "Unable to create testing kernel" );
// Run tests
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 retCode = test_read_image_3D( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
}
}
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 ] );
int retCode = test_read_image_3D( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
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;
if ( gEnablePitch )
{
size_t extraWidth = (int)random_log_in_range( 0, 64, seed );
imageInfo.rowPitch += extraWidth * pixelSize;
size_t extraHeight = (int)random_log_in_range( 0, 64, 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 retCode = test_read_image_3D( device, context, queue, kernel, &imageInfo, imageSampler, outputType, seed );
if ( retCode )
return retCode;
}
}
return 0;
}