mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-24 15:59:03 +00:00
Initial open source release of OpenCL 2.0 CTS.
This commit is contained in:
23
test_conformance/images/samplerlessReads/CMakeLists.txt
Normal file
23
test_conformance/images/samplerlessReads/CMakeLists.txt
Normal file
@@ -0,0 +1,23 @@
|
||||
set(MODULE_NAME SAMPLERLESS_READS)
|
||||
|
||||
set(${MODULE_NAME}_SOURCES
|
||||
main.cpp
|
||||
test_iterations.cpp
|
||||
test_loops.cpp
|
||||
test_read_1D.cpp
|
||||
test_read_3D.cpp
|
||||
test_read_1D_buffer.cpp
|
||||
test_read_1D_array.cpp
|
||||
test_read_2D_array.cpp
|
||||
../../../test_common/harness/errorHelpers.c
|
||||
../../../test_common/harness/threadTesting.c
|
||||
../../../test_common/harness/kernelHelpers.c
|
||||
../../../test_common/harness/imageHelpers.cpp
|
||||
../../../test_common/harness/mt19937.c
|
||||
../../../test_common/harness/conversions.c
|
||||
../../../test_common/harness/testHarness.c
|
||||
../../../test_common/harness/typeWrappers.cpp
|
||||
../../../test_common/harness/msvc9.c
|
||||
)
|
||||
|
||||
include(../../CMakeCommon.txt)
|
||||
19
test_conformance/images/samplerlessReads/Jamfile
Normal file
19
test_conformance/images/samplerlessReads/Jamfile
Normal file
@@ -0,0 +1,19 @@
|
||||
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
|
||||
;
|
||||
|
||||
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
|
||||
;
|
||||
|
||||
52
test_conformance/images/samplerlessReads/Makefile
Normal file
52
test_conformance/images/samplerlessReads/Makefile
Normal file
@@ -0,0 +1,52 @@
|
||||
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 \
|
||||
../../../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.
|
||||
317
test_conformance/images/samplerlessReads/main.cpp
Normal file
317
test_conformance/images/samplerlessReads/main.cpp
Normal file
@@ -0,0 +1,317 @@
|
||||
//
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#include "../../../test_common/harness/compat.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#if !defined(_WIN32)
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include "../testBase.h"
|
||||
#include "../../../test_common/harness/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 gTestReadWrite = false;
|
||||
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;
|
||||
static cl_device_id device;
|
||||
|
||||
#define MAX_ALLOWED_STD_DEVIATION_IN_MB 8.0
|
||||
|
||||
static void printUsage( const char *execName );
|
||||
|
||||
extern int test_image_set( cl_device_id device, cl_mem_object_type imageType );
|
||||
|
||||
int test_1D(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements)
|
||||
{
|
||||
return test_image_set( device, CL_MEM_OBJECT_IMAGE1D ) +
|
||||
test_image_set( device, CL_MEM_OBJECT_IMAGE1D_BUFFER );
|
||||
}
|
||||
int test_2D(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements)
|
||||
{
|
||||
return test_image_set( device, CL_MEM_OBJECT_IMAGE2D );
|
||||
}
|
||||
int test_3D(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements)
|
||||
{
|
||||
return test_image_set( device, CL_MEM_OBJECT_IMAGE3D );
|
||||
}
|
||||
int test_1DArray(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements)
|
||||
{
|
||||
return test_image_set( device, CL_MEM_OBJECT_IMAGE1D_ARRAY );
|
||||
}
|
||||
int test_2DArray(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements)
|
||||
{
|
||||
return test_image_set( device, CL_MEM_OBJECT_IMAGE2D_ARRAY );
|
||||
}
|
||||
|
||||
basefn basefn_list[] = {
|
||||
test_1D,
|
||||
test_2D,
|
||||
test_3D,
|
||||
test_1DArray,
|
||||
test_2DArray,
|
||||
};
|
||||
|
||||
const char *basefn_names[] = {
|
||||
"1D",
|
||||
"2D",
|
||||
"3D",
|
||||
"1DArray",
|
||||
"2DArray",
|
||||
};
|
||||
|
||||
ct_assert((sizeof(basefn_names) / sizeof(basefn_names[0])) == (sizeof(basefn_list) / sizeof(basefn_list[0])));
|
||||
|
||||
int num_fns = sizeof(basefn_names) / sizeof(char *);
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
cl_platform_id platform;
|
||||
cl_channel_type chanType;
|
||||
cl_channel_order chanOrder;
|
||||
bool randomize = false;
|
||||
|
||||
test_start();
|
||||
|
||||
//Check CL_DEVICE_TYPE environment variable
|
||||
checkDeviceTypeOverride( &gDeviceType );
|
||||
|
||||
const char ** argList = (const char **)calloc( argc, sizeof( char*) );
|
||||
|
||||
if( NULL == argList )
|
||||
{
|
||||
log_error( "Failed to allocate memory for argList array.\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
argList[0] = argv[0];
|
||||
size_t argCount = 1;
|
||||
|
||||
// Parse arguments
|
||||
for ( int i = 1; i < argc; i++ )
|
||||
{
|
||||
if ( strcmp( argv[i], "cpu" ) == 0 || strcmp( argv[i], "CL_DEVICE_TYPE_CPU" ) == 0 )
|
||||
gDeviceType = CL_DEVICE_TYPE_CPU;
|
||||
else if ( strcmp( argv[i], "gpu" ) == 0 || strcmp( argv[i], "CL_DEVICE_TYPE_GPU" ) == 0 )
|
||||
gDeviceType = CL_DEVICE_TYPE_GPU;
|
||||
else if ( strcmp( argv[i], "accelerator" ) == 0 || strcmp( argv[i], "CL_DEVICE_TYPE_ACCELERATOR" ) == 0 )
|
||||
gDeviceType = CL_DEVICE_TYPE_ACCELERATOR;
|
||||
else if ( strcmp( argv[i], "CL_DEVICE_TYPE_DEFAULT" ) == 0 )
|
||||
gDeviceType = CL_DEVICE_TYPE_DEFAULT;
|
||||
|
||||
else if ( strcmp( argv[i], "debug_trace" ) == 0 )
|
||||
gDebugTrace = true;
|
||||
else if ( strcmp( argv[i], "read_write" ) == 0 )
|
||||
gTestReadWrite = true;
|
||||
else if ( strcmp( argv[i], "small_images" ) == 0 )
|
||||
gTestSmallImages = true;
|
||||
else if ( strcmp( argv[i], "max_images" ) == 0 )
|
||||
gTestMaxImages = true;
|
||||
else if ( strcmp( argv[i], "use_pitches" ) == 0 )
|
||||
gEnablePitch = true;
|
||||
|
||||
else if ( strcmp( argv[i], "int" ) == 0 )
|
||||
gTypesToTest |= kTestInt;
|
||||
else if ( strcmp( argv[i], "uint" ) == 0 )
|
||||
gTypesToTest |= kTestUInt;
|
||||
else if ( strcmp( argv[i], "float" ) == 0 )
|
||||
gTypesToTest |= kTestFloat;
|
||||
|
||||
else if ( strcmp( argv[i], "randomize" ) == 0 )
|
||||
randomize = true;
|
||||
|
||||
else if ( strcmp( argv[i], "--help" ) == 0 || strcmp( argv[i], "-h" ) == 0 )
|
||||
{
|
||||
printUsage( argv[ 0 ] );
|
||||
return -1;
|
||||
}
|
||||
|
||||
else if ( ( chanType = get_channel_type_from_name( argv[i] ) ) != (cl_channel_type)-1 )
|
||||
gChannelTypeToUse = chanType;
|
||||
|
||||
else if ( ( chanOrder = get_channel_order_from_name( argv[i] ) ) != (cl_channel_order)-1 )
|
||||
gChannelOrderToUse = chanOrder;
|
||||
else
|
||||
{
|
||||
argList[argCount] = argv[i];
|
||||
argCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if ( gTypesToTest == 0 )
|
||||
gTypesToTest = kTestAllTypes;
|
||||
|
||||
// Seed the random # generators
|
||||
if ( randomize )
|
||||
{
|
||||
gRandomSeed = (cl_uint) time( NULL );
|
||||
gReSeed = 1;
|
||||
log_info( "Random seed: %u.\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 = clCreateCommandQueueWithProperties( context, device, 0, &error );
|
||||
if ( error != CL_SUCCESS )
|
||||
{
|
||||
print_error( error, "Unable to create testing command queue" );
|
||||
test_finish();
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( gTestSmallImages )
|
||||
log_info( "Note: Using small test images\n" );
|
||||
|
||||
// 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);
|
||||
|
||||
int ret = parseAndCallCommandLineTests( argCount, argList, NULL, num_fns, basefn_list, basefn_names, true, 0, 0 );
|
||||
|
||||
// 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 sub-tests.\n", gTestCount, gTestCount);
|
||||
else
|
||||
log_info("PASSED sub-test.\n");
|
||||
}
|
||||
else if (gTestFailure > 0) {
|
||||
if (gTestCount > 1)
|
||||
log_error("FAILED %d of %d sub-tests.\n", gTestFailure, gTestCount);
|
||||
else
|
||||
log_error("FAILED sub-test.\n");
|
||||
}
|
||||
|
||||
// Clean up
|
||||
free(argList);
|
||||
test_finish();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void printUsage( const char *execName )
|
||||
{
|
||||
const char *p = strrchr( execName, '/' );
|
||||
if ( p != NULL )
|
||||
execName = p + 1;
|
||||
|
||||
log_info( "Usage: %s [options] [test_names]\n", execName );
|
||||
log_info( "Options:\n" );
|
||||
log_info( "\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( "\tThe following modify the types of images tested:\n" );
|
||||
log_info( "\t\read_write - Runs the tests with read_write images which allow a kernel do both read and write to the same image \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" );
|
||||
log_info( "\n" );
|
||||
log_info( "Test names:\n" );
|
||||
for( int i = 0; i < num_fns; i++ )
|
||||
{
|
||||
log_info( "\t%s\n", basefn_names[i] );
|
||||
}
|
||||
}
|
||||
337
test_conformance/images/samplerlessReads/test_iterations.cpp
Normal file
337
test_conformance/images/samplerlessReads/test_iterations.cpp
Normal file
@@ -0,0 +1,337 @@
|
||||
//
|
||||
// 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;
|
||||
extern bool gTestReadWrite;
|
||||
|
||||
#define MAX_TRIES 1
|
||||
#define MAX_CLAMPED 1
|
||||
|
||||
const char *read2DKernelSourcePattern =
|
||||
"__kernel void sample_kernel( read_only %s 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"
|
||||
"}";
|
||||
|
||||
|
||||
const char *read_write2DKernelSourcePattern =
|
||||
"__kernel void sample_kernel( read_only %s read_only_image, read_write %s read_write_image, 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(read_only_image) + tidX;\n"
|
||||
" int2 coords = (int2)(tidX, tidY);\n"
|
||||
" %s clr = read_image%s( read_only_image, sampler, coords );\n"
|
||||
" write_image%s(read_write_image, coords, clr);\n"
|
||||
" atomic_work_item_fence(CLK_IMAGE_MEM_FENCE, memory_order_acq_rel, memory_scope_work_item);\n"
|
||||
" int4 test = (clr != read_image%s( read_write_image, 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 read_only_image, read_write_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_desc.num_mip_levels = 0;
|
||||
read_only_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 read_only image of size %d x %d pitch %d (%s)\n", (int)imageInfo->width, (int)imageInfo->height, (int)imageInfo->rowPitch, IGetErrorString( error ) );
|
||||
return error;
|
||||
}
|
||||
|
||||
if(gTestReadWrite)
|
||||
{
|
||||
read_write_image = clCreateImage(context,
|
||||
CL_MEM_READ_WRITE,
|
||||
imageInfo->format,
|
||||
&image_desc,
|
||||
NULL,
|
||||
&error );
|
||||
if ( error != CL_SUCCESS )
|
||||
{
|
||||
log_error( "ERROR: Unable to create 2D read_write 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
|
||||
cl_sampler_properties properties[] = {
|
||||
CL_SAMPLER_NORMALIZED_COORDS, CL_FALSE,
|
||||
CL_SAMPLER_ADDRESSING_MODE, CL_ADDRESS_NONE,
|
||||
CL_SAMPLER_FILTER_MODE, CL_FILTER_NEAREST,
|
||||
0 };
|
||||
actualSampler = clCreateSamplerWithProperties( context, properties, &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 ), &read_only_image );
|
||||
test_error( error, "Unable to set kernel arguments" );
|
||||
if(gTestReadWrite)
|
||||
{
|
||||
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &read_write_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(read_only_image);
|
||||
if(gTestReadWrite)
|
||||
{
|
||||
clReleaseMemObject(read_write_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 = { 0 };
|
||||
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" );
|
||||
|
||||
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 = (format->image_channel_order == CL_DEPTH) ? "float" : "float4";
|
||||
}
|
||||
|
||||
if(gTestReadWrite)
|
||||
{
|
||||
sprintf(programSrc,
|
||||
read_write2DKernelSourcePattern,
|
||||
(format->image_channel_order == CL_DEPTH) ? "image2d_depth_t" : "image2d_t",
|
||||
(format->image_channel_order == CL_DEPTH) ? "image2d_depth_t" : "image2d_t",
|
||||
dataType,
|
||||
readFormat,
|
||||
readFormat,
|
||||
readFormat);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(programSrc,
|
||||
read2DKernelSourcePattern,
|
||||
(format->image_channel_order == CL_DEPTH) ? "image2d_depth_t" : "image2d_t",
|
||||
dataType,
|
||||
readFormat,
|
||||
readFormat );
|
||||
}
|
||||
|
||||
ptr = programSrc;
|
||||
error = create_single_kernel_helper_with_build_options( context, &program, &kernel, 1, &ptr, "sample_kernel", "-cl-std=CL2.0" );
|
||||
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;
|
||||
}
|
||||
305
test_conformance/images/samplerlessReads/test_loops.cpp
Normal file
305
test_conformance/images/samplerlessReads/test_loops.cpp
Normal file
@@ -0,0 +1,305 @@
|
||||
//
|
||||
// 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 bool gTestReadWrite;
|
||||
|
||||
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 *str_1d_image_buffer = "1D image buffer";
|
||||
|
||||
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;
|
||||
case CL_MEM_OBJECT_IMAGE1D_BUFFER:
|
||||
p = str_1d_image_buffer;
|
||||
}
|
||||
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 );
|
||||
break;
|
||||
case CL_MEM_OBJECT_IMAGE1D_BUFFER:
|
||||
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;
|
||||
|
||||
// This flag is only for querying the list of supported formats
|
||||
// The flag for creating image will be set explicitly in test functions
|
||||
cl_mem_flags flags = (gTestReadWrite)? CL_MEM_KERNEL_READ_AND_WRITE : 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;
|
||||
}
|
||||
332
test_conformance/images/samplerlessReads/test_read_1D.cpp
Normal file
332
test_conformance/images/samplerlessReads/test_read_1D.cpp
Normal file
@@ -0,0 +1,332 @@
|
||||
//
|
||||
// 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;
|
||||
extern bool gTestReadWrite;
|
||||
|
||||
#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"
|
||||
"}";
|
||||
|
||||
const char *read_write1DKernelSourcePattern =
|
||||
"__kernel void sample_kernel( read_only image1d_t read_only_image, read_write image1d_t read_write_image, sampler_t sampler, __global int *results )\n"
|
||||
"{\n"
|
||||
" int tidX = get_global_id(0);\n"
|
||||
" int offset = tidX;\n"
|
||||
" %s clr = read_image%s( read_only_image, sampler, tidX );\n"
|
||||
" write_image%s(read_write_image, tidX, clr);\n"
|
||||
" atomic_work_item_fence(CLK_IMAGE_MEM_FENCE, memory_order_acq_rel, memory_scope_work_item);\n"
|
||||
" int4 test = (clr != read_image%s(read_write_image, 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 read_only_image, read_write_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_desc.num_mip_levels = 0;
|
||||
|
||||
read_only_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 read_only 1D image of size %d pitch %d (%s)\n", (int)imageInfo->width, (int)imageInfo->rowPitch, IGetErrorString( error ) );
|
||||
return error;
|
||||
}
|
||||
|
||||
if(gTestReadWrite)
|
||||
{
|
||||
read_write_image = clCreateImage(context,
|
||||
CL_MEM_READ_WRITE,
|
||||
imageInfo->format,
|
||||
&image_desc,
|
||||
NULL,
|
||||
&error );
|
||||
if ( error != CL_SUCCESS )
|
||||
{
|
||||
log_error( "ERROR: Unable to create read_write 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
|
||||
cl_sampler_properties properties[] = {
|
||||
CL_SAMPLER_NORMALIZED_COORDS, CL_FALSE,
|
||||
CL_SAMPLER_ADDRESSING_MODE, CL_ADDRESS_NONE,
|
||||
CL_SAMPLER_FILTER_MODE, CL_FILTER_NEAREST,
|
||||
0 };
|
||||
actualSampler = clCreateSamplerWithProperties( context, properties, &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 ), &read_only_image );
|
||||
test_error( error, "Unable to set kernel arguments" );
|
||||
if(gTestReadWrite)
|
||||
{
|
||||
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &read_write_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(read_only_image);
|
||||
if(gTestReadWrite)
|
||||
{
|
||||
clReleaseMemObject(read_write_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 = { 0 };
|
||||
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";
|
||||
}
|
||||
|
||||
if(gTestReadWrite)
|
||||
{
|
||||
sprintf( programSrc,
|
||||
read_write1DKernelSourcePattern,
|
||||
dataType,
|
||||
readFormat,
|
||||
readFormat,
|
||||
readFormat);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( programSrc,
|
||||
read1DKernelSourcePattern,
|
||||
dataType,
|
||||
readFormat,
|
||||
readFormat );
|
||||
}
|
||||
|
||||
|
||||
ptr = programSrc;
|
||||
error = create_single_kernel_helper_with_build_options( context, &program, &kernel, 1, &ptr, "sample_kernel", "-cl-std=CL2.0" );
|
||||
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;
|
||||
}
|
||||
336
test_conformance/images/samplerlessReads/test_read_1D_array.cpp
Normal file
336
test_conformance/images/samplerlessReads/test_read_1D_array.cpp
Normal file
@@ -0,0 +1,336 @@
|
||||
//
|
||||
// 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;
|
||||
extern bool gTestReadWrite;
|
||||
|
||||
#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"
|
||||
"}";
|
||||
|
||||
const char *read_write1DArrayKernelSourcePattern =
|
||||
"__kernel void sample_kernel( read_only image1d_array_t read_only_image, read_write image1d_array_t read_write_image, 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(read_only_image) + tidX;\n"
|
||||
" int2 coords = (int2)(tidX, tidY);\n"
|
||||
" %s clr = read_image%s( read_only_image, sampler, coords );\n"
|
||||
" write_image%s(read_write_image, coords, clr);\n"
|
||||
" atomic_work_item_fence(CLK_IMAGE_MEM_FENCE, memory_order_acq_rel, memory_scope_work_item);\n"
|
||||
" int4 test = (clr != read_image%s( read_write_image, 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 read_only_image, read_write_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_desc.num_mip_levels = 0;
|
||||
read_only_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 read_only 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(gTestReadWrite)
|
||||
{
|
||||
read_write_image = clCreateImage(context,
|
||||
CL_MEM_READ_WRITE,
|
||||
imageInfo->format,
|
||||
&image_desc,
|
||||
NULL,
|
||||
&error );
|
||||
if ( error != CL_SUCCESS )
|
||||
{
|
||||
log_error( "ERROR: Unable to create read_write 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
|
||||
cl_sampler_properties properties[] = {
|
||||
CL_SAMPLER_NORMALIZED_COORDS, CL_FALSE,
|
||||
CL_SAMPLER_ADDRESSING_MODE, CL_ADDRESS_NONE,
|
||||
CL_SAMPLER_FILTER_MODE, CL_FILTER_NEAREST,
|
||||
0 };
|
||||
actualSampler = clCreateSamplerWithProperties( context, properties, &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 ), &read_only_image );
|
||||
test_error( error, "Unable to set kernel arguments" );
|
||||
if(gTestReadWrite)
|
||||
{
|
||||
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &read_write_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 %lu.\n", ic );
|
||||
return -1;
|
||||
}
|
||||
|
||||
clReleaseSampler(actualSampler);
|
||||
clReleaseMemObject(results);
|
||||
if(gTestReadWrite)
|
||||
{
|
||||
clReleaseMemObject(read_write_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 = { 0 };
|
||||
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";
|
||||
}
|
||||
|
||||
if(gTestReadWrite)
|
||||
{
|
||||
sprintf( programSrc,
|
||||
read_write1DArrayKernelSourcePattern,
|
||||
dataType,
|
||||
readFormat,
|
||||
readFormat,
|
||||
readFormat);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( programSrc,
|
||||
read1DArrayKernelSourcePattern,
|
||||
dataType,
|
||||
readFormat,
|
||||
readFormat );
|
||||
}
|
||||
|
||||
|
||||
ptr = programSrc;
|
||||
error = create_single_kernel_helper_with_build_options( context, &program, &kernel, 1, &ptr, "sample_kernel", "-cl-std=CL2.0" );
|
||||
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;
|
||||
}
|
||||
324
test_conformance/images/samplerlessReads/test_read_1D_buffer.cpp
Normal file
324
test_conformance/images/samplerlessReads/test_read_1D_buffer.cpp
Normal file
@@ -0,0 +1,324 @@
|
||||
//
|
||||
// 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.mem_object = imageBuffer;
|
||||
image[0] = clCreateImage( context, CL_MEM_READ_ONLY, imageInfo->format,
|
||||
&image_desc, NULL, &error );
|
||||
if ( error != CL_SUCCESS )
|
||||
{
|
||||
log_error( "ERROR: Unable to create IMAGE1D_BUFFER of size %d pitch %d (%s)\n", (int)imageInfo->width, (int)imageInfo->rowPitch, IGetErrorString( error ) );
|
||||
return error;
|
||||
}
|
||||
|
||||
cl_mem ret = NULL;
|
||||
error = clGetMemObjectInfo(image[0], CL_MEM_ASSOCIATED_MEMOBJECT, sizeof(ret), &ret, NULL);
|
||||
if ( error != CL_SUCCESS )
|
||||
{
|
||||
log_error( "ERROR: Unable to query CL_MEM_ASSOCIATED_MEMOBJECT\n", IGetErrorString( error ) );
|
||||
return error;
|
||||
}
|
||||
|
||||
if (ret != imageBuffer) {
|
||||
log_error("ERROR: clGetImageInfo for CL_IMAGE_BUFFER returned wrong value\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
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
|
||||
cl_sampler_properties properties[] = {
|
||||
CL_SAMPLER_NORMALIZED_COORDS, CL_FALSE,
|
||||
CL_SAMPLER_ADDRESSING_MODE, CL_ADDRESS_NONE,
|
||||
CL_SAMPLER_FILTER_MODE, CL_FILTER_NEAREST,
|
||||
0 };
|
||||
actualSampler = clCreateSamplerWithProperties( context, properties, &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 = { 0 };
|
||||
size_t pixelSize;
|
||||
|
||||
if (format->image_channel_order == CL_RGB || format->image_channel_order == CL_RGBx)
|
||||
{
|
||||
switch (format->image_channel_data_type)
|
||||
{
|
||||
case CL_UNORM_INT8:
|
||||
case CL_UNORM_INT16:
|
||||
case CL_SNORM_INT8:
|
||||
case CL_SNORM_INT16:
|
||||
case CL_HALF_FLOAT:
|
||||
case CL_FLOAT:
|
||||
case CL_SIGNED_INT8:
|
||||
case CL_SIGNED_INT16:
|
||||
case CL_SIGNED_INT32:
|
||||
case CL_UNSIGNED_INT8:
|
||||
case CL_UNSIGNED_INT16:
|
||||
case CL_UNSIGNED_INT32:
|
||||
case CL_UNORM_INT_101010:
|
||||
log_info( "Skipping image format: %s %s\n", GetChannelOrderName( format->image_channel_order ),
|
||||
GetChannelTypeName( format->image_channel_data_type ));
|
||||
return 0;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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_with_build_options( context, &program, &kernel, 1, &ptr, "sample_kernel", "-cl-std=CL2.0" );
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
334
test_conformance/images/samplerlessReads/test_read_2D_array.cpp
Normal file
334
test_conformance/images/samplerlessReads/test_read_2D_array.cpp
Normal file
@@ -0,0 +1,334 @@
|
||||
//
|
||||
// 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;
|
||||
extern bool gTestReadWrite;
|
||||
|
||||
const char *read2DArrayKernelSourcePattern =
|
||||
"__kernel void sample_kernel( read_only %s 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"
|
||||
"}";
|
||||
|
||||
const char *read_write2DArrayKernelSourcePattern =
|
||||
"__kernel void sample_kernel( read_only %s read_only_image, read_write %s read_write_image, 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(read_only_image)*get_image_height(read_only_image) + tidY*get_image_width(read_only_image) + tidX;\n"
|
||||
" int4 coords = (int4)( tidX, tidY, tidZ, 0 );\n"
|
||||
" %s clr = read_image%s( read_only_image, sampler, coords );\n"
|
||||
" write_image%s(read_write_image, coords, clr);\n"
|
||||
" atomic_work_item_fence(CLK_IMAGE_MEM_FENCE, memory_order_acq_rel, memory_scope_work_item);\n"
|
||||
" int4 test = (clr != read_image%s( read_write_image, 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 read_only_image, read_write_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_desc.num_mip_levels = 0;
|
||||
read_only_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 read_only 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;
|
||||
}
|
||||
|
||||
if(gTestReadWrite)
|
||||
{
|
||||
read_write_image = clCreateImage(context,
|
||||
CL_MEM_READ_WRITE,
|
||||
imageInfo->format,
|
||||
&image_desc,
|
||||
NULL,
|
||||
&error );
|
||||
if ( error != CL_SUCCESS )
|
||||
{
|
||||
log_error( "ERROR: Unable to create read_write 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
|
||||
cl_sampler_properties properties[] = {
|
||||
CL_SAMPLER_NORMALIZED_COORDS, CL_FALSE,
|
||||
CL_SAMPLER_ADDRESSING_MODE, CL_ADDRESS_NONE,
|
||||
CL_SAMPLER_FILTER_MODE, CL_FILTER_NEAREST,
|
||||
0 };
|
||||
actualSampler = clCreateSamplerWithProperties( context, properties, &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 ), &read_only_image );
|
||||
test_error( error, "Unable to set kernel arguments" );
|
||||
if(gTestReadWrite)
|
||||
{
|
||||
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &read_write_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(read_only_image);
|
||||
if(gTestReadWrite)
|
||||
{
|
||||
clReleaseMemObject(read_write_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 = { 0 };
|
||||
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 = (format->image_channel_order == CL_DEPTH) ? "float" : "float4";
|
||||
}
|
||||
|
||||
// Construct the source
|
||||
if(gTestReadWrite)
|
||||
{
|
||||
sprintf( programSrc, read_write2DArrayKernelSourcePattern,
|
||||
(format->image_channel_order == CL_DEPTH) ? "image2d_array_depth_t" : "image2d_array_t",
|
||||
(format->image_channel_order == CL_DEPTH) ? "image2d_array_depth_t" : "image2d_array_t",
|
||||
dataType,
|
||||
readFormat,
|
||||
readFormat,
|
||||
readFormat);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( programSrc, read2DArrayKernelSourcePattern,
|
||||
(format->image_channel_order == CL_DEPTH) ? "image2d_array_depth_t" : "image2d_array_t",
|
||||
dataType,
|
||||
readFormat,
|
||||
readFormat );
|
||||
}
|
||||
|
||||
|
||||
ptr = programSrc;
|
||||
error = create_single_kernel_helper_with_build_options( context, &program, &kernel, 1, &ptr, "sample_kernel", "-cl-std=CL2.0" );
|
||||
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;
|
||||
}
|
||||
337
test_conformance/images/samplerlessReads/test_read_3D.cpp
Normal file
337
test_conformance/images/samplerlessReads/test_read_3D.cpp
Normal file
@@ -0,0 +1,337 @@
|
||||
//
|
||||
// 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;
|
||||
extern bool gTestReadWrite;
|
||||
|
||||
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"
|
||||
"}";
|
||||
|
||||
const char *read_write3DKernelSourcePattern =
|
||||
"__kernel void sample_kernel( read_only image3d_t read_only_image, read_write image3d_t read_write_image, 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(read_only_image)*get_image_height(read_only_image) + tidY*get_image_width(read_only_image) + tidX;\n"
|
||||
" int4 coords = (int4)( tidX, tidY, tidZ, 0 );\n"
|
||||
" %s clr = read_image%s( read_only_image, sampler, coords );\n"
|
||||
" write_image%s(read_write_image, coords, clr);\n"
|
||||
" atomic_work_item_fence(CLK_IMAGE_MEM_FENCE, memory_order_acq_rel, memory_scope_work_item);\n"
|
||||
" int4 test = (clr != read_image%s( read_write_image, 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 read_only_image, read_write_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_desc.num_mip_levels = 0;
|
||||
read_only_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 read_only 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;
|
||||
}
|
||||
|
||||
if(gTestReadWrite)
|
||||
{
|
||||
read_write_image = clCreateImage(context,
|
||||
CL_MEM_READ_WRITE,
|
||||
imageInfo->format,
|
||||
&image_desc,
|
||||
NULL,
|
||||
&error);
|
||||
if ( error != CL_SUCCESS )
|
||||
{
|
||||
log_error( "ERROR: Unable to create read_write 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
|
||||
cl_sampler_properties properties[] = {
|
||||
CL_SAMPLER_NORMALIZED_COORDS, CL_FALSE,
|
||||
CL_SAMPLER_ADDRESSING_MODE, CL_ADDRESS_NONE,
|
||||
CL_SAMPLER_FILTER_MODE, CL_FILTER_NEAREST,
|
||||
0 };
|
||||
actualSampler = clCreateSamplerWithProperties( context, properties, &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 ), &read_only_image );
|
||||
test_error( error, "Unable to set kernel arguments" );
|
||||
if(gTestReadWrite)
|
||||
{
|
||||
error = clSetKernelArg( kernel, idx++, sizeof( cl_mem ), &read_write_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 %lu.\n", ic );
|
||||
return -1;
|
||||
}
|
||||
|
||||
clReleaseSampler(actualSampler);
|
||||
clReleaseMemObject(results);
|
||||
clReleaseMemObject(read_only_image);
|
||||
if(gTestReadWrite)
|
||||
{
|
||||
clReleaseMemObject(read_write_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 = { 0 };
|
||||
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
|
||||
if(gTestReadWrite)
|
||||
{
|
||||
sprintf( programSrc,
|
||||
read_write3DKernelSourcePattern,
|
||||
dataType,
|
||||
readFormat,
|
||||
readFormat,
|
||||
readFormat);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( programSrc,
|
||||
read3DKernelSourcePattern,
|
||||
dataType,
|
||||
readFormat,
|
||||
readFormat );
|
||||
}
|
||||
|
||||
|
||||
ptr = programSrc;
|
||||
error = create_single_kernel_helper_with_build_options( context, &program, &kernel, 1, &ptr, "sample_kernel", "-cl-std=CL2.0" );
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user