diff --git a/test_conformance/compatibility/test_common/gl/setup.h b/test_conformance/compatibility/test_common/gl/setup.h deleted file mode 100644 index 6ee810bb..00000000 --- a/test_conformance/compatibility/test_common/gl/setup.h +++ /dev/null @@ -1,48 +0,0 @@ -// -// Copyright (c) 2017 The Khronos Group Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -#ifndef _setup_h -#define _setup_h - -#include -#include -#include -#include "gl_headers.h" -#ifdef __APPLE__ -#include -#else -#include -#endif - - -// Note: the idea here is to have every platform define their own setup.cpp file that implements a GLEnvironment -// subclass internally, then return it as a definition for GLEnvironment::Create - -class GLEnvironment -{ - public: - GLEnvironment() {} - virtual ~GLEnvironment() {} - - virtual int Init( int *argc, char **argv, int use_opengl_32 ) = 0; - virtual cl_context CreateCLContext( void ) = 0; - virtual int SupportsCLGLInterop( cl_device_type device_type) = 0; - - static GLEnvironment * Instance( void ); - - -}; - -#endif // _setup_h diff --git a/test_conformance/compatibility/test_common/gl/setup_osx.cpp b/test_conformance/compatibility/test_common/gl/setup_osx.cpp deleted file mode 100644 index 8abddeda..00000000 --- a/test_conformance/compatibility/test_common/gl/setup_osx.cpp +++ /dev/null @@ -1,156 +0,0 @@ -// -// Copyright (c) 2017 The Khronos Group Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -#include "setup.h" -#include "harness/errorHelpers.h" -#include - -class OSXGLEnvironment : public GLEnvironment -{ - public: - OSXGLEnvironment() - { - mCGLContext = NULL; - } - - virtual int Init( int *argc, char **argv, int use_opengl_32 ) - { - if (!use_opengl_32) { - - // Create a GLUT window to render into - glutInit( argc, argv ); - glutInitWindowSize( 512, 512 ); - glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); - glutCreateWindow( "OpenCL <-> OpenGL Test" ); - } - - else { - - CGLPixelFormatAttribute attribs[] = { - kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute)kCGLOGLPVersion_3_2_Core, - kCGLPFAAllowOfflineRenderers, - kCGLPFANoRecovery, - kCGLPFAAccelerated, - kCGLPFADoubleBuffer, - (CGLPixelFormatAttribute)0 - }; - - CGLError err; - CGLPixelFormatObj pix; - GLint npix; - err = CGLChoosePixelFormat (attribs, &pix, &npix); - if(err != kCGLNoError) - { - log_error("Failed to choose pixel format\n"); - return -1; - } - err = CGLCreateContext(pix, NULL, &mCGLContext); - if(err != kCGLNoError) - { - log_error("Failed to create GL context\n"); - return -1; - } - CGLSetCurrentContext(mCGLContext); - } - - return 0; - } - - virtual cl_context CreateCLContext( void ) - { - int error; - - if( mCGLContext == NULL ) - mCGLContext = CGLGetCurrentContext(); - - CGLShareGroupObj share_group = CGLGetShareGroup(mCGLContext); - cl_context_properties properties[] = { CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, (cl_context_properties)share_group, 0 }; - cl_context context = clCreateContext(properties, 0, 0, 0, 0, &error); - if (error) { - print_error(error, "clCreateContext failed"); - return NULL; - } - - // Verify that all devices in the context support the required extension - cl_device_id devices[64]; - size_t size_out; - error = clGetContextInfo(context, CL_CONTEXT_DEVICES, sizeof(devices), devices, &size_out); - if (error) { - print_error(error, "clGetContextInfo failed"); - return NULL; - } - - char extensions[8192]; - for (int i=0; i<(int)(size_out/sizeof(cl_device_id)); i++) { - error = clGetDeviceInfo(devices[i], CL_DEVICE_EXTENSIONS, sizeof(extensions), extensions, NULL); - if (error) { - print_error(error, "clGetDeviceInfo failed"); - return NULL; - } - - if (strstr(extensions, "cl_APPLE_gl_sharing") == NULL) { - log_error("Device %d does not supporte required extension cl_APPLE_gl_sharing.\n", i); - return NULL; - } - } - return context; - } - - virtual int SupportsCLGLInterop( cl_device_type device_type ) - { - int found_valid_device = 0; - cl_device_id devices[64]; - cl_uint num_of_devices; - int error; - error = clGetDeviceIDs(NULL, device_type, 64, devices, &num_of_devices); - if (error) { - print_error(error, "clGetDeviceIDs failed"); - return -1; - } - - char extensions[8192]; - for (int i=0; i<(int)num_of_devices; i++) { - error = clGetDeviceInfo(devices[i], CL_DEVICE_EXTENSIONS, sizeof(extensions), extensions, NULL); - if (error) { - print_error(error, "clGetDeviceInfo failed"); - return -1; - } - - if (strstr(extensions, "cl_APPLE_gl_sharing") == NULL) { - log_info("Device %d of %d does not support required extension cl_APPLE_gl_sharing.\n", i, num_of_devices); - } else { - log_info("Device %d of %d does support required extension cl_APPLE_gl_sharing.\n", i, num_of_devices); - found_valid_device = 1; - } - } - return found_valid_device; - } - - virtual ~OSXGLEnvironment() - { - CGLDestroyContext( mCGLContext ); - } - - CGLContextObj mCGLContext; - -}; - -GLEnvironment * GLEnvironment::Instance( void ) -{ - static OSXGLEnvironment * env = NULL; - if( env == NULL ) - env = new OSXGLEnvironment(); - return env; -} diff --git a/test_conformance/compatibility/test_common/gl/setup_x11.cpp b/test_conformance/compatibility/test_common/gl/setup_x11.cpp deleted file mode 100644 index c21e99f4..00000000 --- a/test_conformance/compatibility/test_common/gl/setup_x11.cpp +++ /dev/null @@ -1,122 +0,0 @@ -// -// Copyright (c) 2017 The Khronos Group Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -#define GL_GLEXT_PROTOTYPES - -#include "setup.h" -#include "testBase.h" -#include "harness/errorHelpers.h" - -#include -#include -#include -#include -#include -#include - -class X11GLEnvironment : public GLEnvironment -{ -private: - cl_device_id m_devices[64]; - cl_uint m_device_count; - -public: - X11GLEnvironment() - { - m_device_count = 0; - } - virtual int Init( int *argc, char **argv, int use_opencl_32 ) - { - // Create a GLUT window to render into - glutInit( argc, argv ); - glutInitWindowSize( 512, 512 ); - glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); - glutCreateWindow( "OpenCL <-> OpenGL Test" ); - glewInit(); - return 0; - } - - virtual cl_context CreateCLContext( void ) - { - GLXContext context = glXGetCurrentContext(); - Display *dpy = glXGetCurrentDisplay(); - - cl_context_properties properties[] = { - CL_GL_CONTEXT_KHR, (cl_context_properties) context, - CL_GLX_DISPLAY_KHR, (cl_context_properties) dpy, - 0 - }; - cl_int status; - - if (!context || !dpy) { - print_error(CL_INVALID_CONTEXT, "No GL context bound"); - return 0; - } - - return clCreateContext(properties, 1, m_devices, NULL, NULL, &status); - } - - virtual int SupportsCLGLInterop( cl_device_type device_type ) - { - int found_valid_device = 0; - cl_platform_id platform; - cl_device_id devices[64]; - cl_uint num_of_devices; - int error; - error = clGetPlatformIDs(1, &platform, NULL); - if (error) { - print_error(error, "clGetPlatformIDs failed"); - return -1; - } - error = clGetDeviceIDs(platform, device_type, 64, devices, &num_of_devices); - // If this platform doesn't have any of the requested device_type (namely GPUs) then return 0 - if (error == CL_DEVICE_NOT_FOUND) - return 0; - if (error) { - print_error(error, "clGetDeviceIDs failed"); - return -1; - } - - char extensions[8192]; - for (int i=0; i<(int)num_of_devices; i++) { - error = clGetDeviceInfo(devices[i], CL_DEVICE_EXTENSIONS, sizeof(extensions), extensions, NULL); - if (error) { - print_error(error, "clGetDeviceInfo failed"); - return -1; - } - - if (strstr(extensions, "cl_khr_gl_sharing ") == NULL) { - log_info("Device %d of %d does not support required extension cl_khr_gl_sharing.\n", i+1, num_of_devices); - } else { - log_info("Device %d of %d supports required extension cl_khr_gl_sharing.\n", i+1, num_of_devices); - found_valid_device = 1; - m_devices[m_device_count++] = devices[i]; - } - } - return found_valid_device; - } - - virtual ~X11GLEnvironment() - { - } -}; - -GLEnvironment * GLEnvironment::Instance( void ) -{ - static X11GLEnvironment * env = NULL; - if( env == NULL ) - env = new X11GLEnvironment(); - return env; -} diff --git a/test_conformance/compatibility/test_common/harness/ThreadPool.h b/test_conformance/compatibility/test_common/harness/ThreadPool.h deleted file mode 100644 index 7c392306..00000000 --- a/test_conformance/compatibility/test_common/harness/ThreadPool.h +++ /dev/null @@ -1,76 +0,0 @@ -// -// Copyright (c) 2017 The Khronos Group Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -#ifndef THREAD_POOL_H -#define THREAD_POOL_H - -#if defined( __APPLE__ ) - #include -#else - #include -#endif - -#if defined(__cplusplus) - extern "C" { -#endif - -// -// An atomic add operator -cl_int ThreadPool_AtomicAdd( volatile cl_int *a, cl_int b ); // returns old value - -// Your function prototype -// -// A function pointer to the function you want to execute in a multithreaded context. No -// synchronization primitives are provided, other than the atomic add above. You may not -// call ThreadPool_Do from your function. ThreadPool_AtomicAdd() and GetThreadCount() should -// work, however. -// -// job ids and thread ids are 0 based. If number of jobs or threads was 8, they will numbered be 0 through 7. -// Note that while every job will be run, it is not guaranteed that every thread will wake up before -// the work is done. -typedef cl_int (*TPFuncPtr)( cl_uint /*job_id*/, cl_uint /* thread_id */, void *userInfo ); - -// returns first non-zero result from func_ptr, or CL_SUCCESS if all are zero. -// Some workitems may not run if a non-zero result is returned from func_ptr(). -// This function may not be called from a TPFuncPtr. -cl_int ThreadPool_Do( TPFuncPtr func_ptr, - cl_uint count, - void *userInfo ); - -// Returns the number of worker threads that underlie the threadpool. The value passed -// as the TPFuncPtrs thread_id will be between 0 and this value less one, inclusive. -// This is safe to call from a TPFuncPtr. -cl_uint GetThreadCount( void ); - -// SetThreadCount() may be used to artifically set the number of worker threads -// If the value is 0 (the default) the number of threads will be determined based on -// the number of CPU cores. If it is a unicore machine, then 2 will be used, so -// that we still get some testing for thread safety. -// -// If count < 2 or the CL_TEST_SINGLE_THREADED environment variable is set then the -// code will run single threaded, but will report an error to indicate that the test -// is invalid. This option is intended for debugging purposes only. It is suggested -// as a convention that test apps set the thread count to 1 in response to the -m flag. -// -// SetThreadCount() must be called before the first call to GetThreadCount() or ThreadPool_Do(), -// otherwise the behavior is indefined. It may not be called from a TPFuncPtr. -void SetThreadCount( int count ); - -#ifdef __cplusplus - } /* extern "C" */ -#endif - - -#endif /* THREAD_POOL_H */ diff --git a/test_conformance/compatibility/test_common/harness/conversions.c b/test_conformance/compatibility/test_common/harness/conversions.c deleted file mode 100644 index 72fd8cb3..00000000 --- a/test_conformance/compatibility/test_common/harness/conversions.c +++ /dev/null @@ -1,1198 +0,0 @@ -// -// Copyright (c) 2017 The Khronos Group Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -#include "conversions.h" -#include -#include -#include -#include "mt19937.h" -#include "compat.h" - -#if defined( __SSE__ ) || defined (_MSC_VER) - #include -#endif -#if defined( __SSE2__ ) || defined (_MSC_VER) - #include -#endif - -void print_type_to_string(ExplicitType type, void *data, char* string) { - switch (type) { - case kBool: - if (*(char*)data) - sprintf(string, "true"); - else - sprintf(string, "false"); - return; - case kChar: - sprintf(string, "%d", (int)*((cl_char*)data)); - return; - case kUChar: - case kUnsignedChar: - sprintf(string, "%u", (int)*((cl_uchar*)data)); - return; - case kShort: - sprintf(string, "%d", (int)*((cl_short*)data)); - return; - case kUShort: - case kUnsignedShort: - sprintf(string, "%u", (int)*((cl_ushort*)data)); - return; - case kInt: - sprintf(string, "%d", *((cl_int*)data)); - return; - case kUInt: - case kUnsignedInt: - sprintf(string, "%u", *((cl_uint*)data)); - return; - case kLong: - sprintf(string, "%lld", *((cl_long*)data)); - return; - case kULong: - case kUnsignedLong: - sprintf(string, "%llu", *((cl_ulong*)data)); - return; - case kFloat: - sprintf(string, "%f", *((cl_float*)data)); - return; - case kHalf: - sprintf(string, "half"); - return; - case kDouble: - sprintf(string, "%g", *((cl_double*)data)); - return; - default: - sprintf(string, "INVALID"); - return; - } - -} - -size_t get_explicit_type_size( ExplicitType type ) -{ - /* Quick method to avoid branching: make sure the following array matches the Enum order */ - static size_t sExplicitTypeSizes[] = { - sizeof( cl_bool ), - sizeof( cl_char ), - sizeof( cl_uchar ), - sizeof( cl_uchar ), - sizeof( cl_short ), - sizeof( cl_ushort ), - sizeof( cl_ushort ), - sizeof( cl_int ), - sizeof( cl_uint ), - sizeof( cl_uint ), - sizeof( cl_long ), - sizeof( cl_ulong ), - sizeof( cl_ulong ), - sizeof( cl_float ), - sizeof( cl_half ), - sizeof( cl_double ) - }; - - return sExplicitTypeSizes[ type ]; -} - -const char * get_explicit_type_name( ExplicitType type ) -{ - /* Quick method to avoid branching: make sure the following array matches the Enum order */ - static const char *sExplicitTypeNames[] = { "bool", "char", "uchar", "unsigned char", "short", "ushort", "unsigned short", "int", - "uint", "unsigned int", "long", "ulong", "unsigned long", "float", "half", "double" }; - - return sExplicitTypeNames[ type ]; -} - -static long lrintf_clamped( float f ); -static long lrintf_clamped( float f ) -{ - static const float magic[2] = { MAKE_HEX_FLOAT( 0x1.0p23f, 0x1, 23), - MAKE_HEX_FLOAT( 0x1.0p23f, 0x1, 23) }; - - if( f >= -(float) LONG_MIN ) - return LONG_MAX; - - if( f <= (float) LONG_MIN ) - return LONG_MIN; - - // Round fractional values to integer in round towards nearest mode - if( fabsf(f) < MAKE_HEX_FLOAT( 0x1.0p23f, 0x1, 23 ) ) - { - volatile float x = f; - float magicVal = magic[ f < 0 ]; - -#if defined( __SSE__ ) || defined (_WIN32) - // Defeat x87 based arithmetic, which cant do FTZ, and will round this incorrectly - __m128 v = _mm_set_ss( x ); - __m128 m = _mm_set_ss( magicVal ); - v = _mm_add_ss( v, m ); - v = _mm_sub_ss( v, m ); - _mm_store_ss( (float*) &x, v ); -#else - x += magicVal; - x -= magicVal; -#endif - f = x; - } - - return (long) f; -} - -static long lrint_clamped( double f ); -static long lrint_clamped( double f ) -{ - static const double magic[2] = { MAKE_HEX_DOUBLE(0x1.0p52, 0x1LL, 52), MAKE_HEX_DOUBLE(-0x1.0p52, -0x1LL, 52) }; - - if( sizeof( long ) > 4 ) - { - if( f >= -(double) LONG_MIN ) - return LONG_MAX; - } - else - { - if( f >= LONG_MAX ) - return LONG_MAX; - } - - if( f <= (double) LONG_MIN ) - return LONG_MIN; - - // Round fractional values to integer in round towards nearest mode - if( fabs(f) < MAKE_HEX_DOUBLE(0x1.0p52, 0x1LL, 52) ) - { - volatile double x = f; - double magicVal = magic[ f < 0 ]; -#if defined( __SSE2__ ) || (defined (_MSC_VER)) - // Defeat x87 based arithmetic, which cant do FTZ, and will round this incorrectly - __m128d v = _mm_set_sd( x ); - __m128d m = _mm_set_sd( magicVal ); - v = _mm_add_sd( v, m ); - v = _mm_sub_sd( v, m ); - _mm_store_sd( (double*) &x, v ); -#else - x += magicVal; - x -= magicVal; -#endif - f = x; - } - - return (long) f; -} - - -typedef cl_long Long; -typedef cl_ulong ULong; - -static ULong sUpperLimits[ kNumExplicitTypes ] = - { - 0, - 127, 255, 255, - 32767, 65535, 65535, - 0x7fffffffLL, 0xffffffffLL, 0xffffffffLL, - 0x7fffffffffffffffLL, 0xffffffffffffffffLL, 0xffffffffffffffffLL, - 0, 0 }; // Last two values aren't stored here - -static Long sLowerLimits[ kNumExplicitTypes ] = - { - -1, - -128, 0, 0, - -32768, 0, 0, - 0xffffffff80000000LL, 0, 0, - 0x8000000000000000LL, 0, 0, - 0, 0 }; // Last two values aren't stored here - -#define BOOL_CASE(inType) \ - case kBool: \ - boolPtr = (bool *)outRaw; \ - *boolPtr = ( *inType##Ptr ) != 0 ? true : false; \ - break; - -#define SIMPLE_CAST_CASE(inType,outEnum,outType) \ - case outEnum: \ - outType##Ptr = (outType *)outRaw; \ - *outType##Ptr = (outType)(*inType##Ptr); \ - break; - -// Sadly, the ULong downcasting cases need a separate #define to get rid of signed/unsigned comparison warnings -#define DOWN_CAST_CASE(inType,outEnum,outType,sat) \ - case outEnum: \ - outType##Ptr = (outType *)outRaw; \ - if( sat ) \ - { \ - if( ( sLowerLimits[outEnum] < 0 && *inType##Ptr > (Long)sUpperLimits[outEnum] ) || ( sLowerLimits[outEnum] == 0 && (ULong)*inType##Ptr > sUpperLimits[outEnum] ) )\ - *outType##Ptr = (outType)sUpperLimits[outEnum];\ - else if( *inType##Ptr < sLowerLimits[outEnum] )\ - *outType##Ptr = (outType)sLowerLimits[outEnum]; \ - else \ - *outType##Ptr = (outType)*inType##Ptr; \ - } else { \ - *outType##Ptr = (outType)( *inType##Ptr & ( 0xffffffffffffffffLL >> ( 64 - ( sizeof( outType ) * 8 ) ) ) ); \ - } \ - break; - -#define U_DOWN_CAST_CASE(inType,outEnum,outType,sat) \ - case outEnum: \ - outType##Ptr = (outType *)outRaw; \ - if( sat ) \ - { \ - if( (ULong)*inType##Ptr > sUpperLimits[outEnum] )\ - *outType##Ptr = (outType)sUpperLimits[outEnum];\ - else \ - *outType##Ptr = (outType)*inType##Ptr; \ - } else { \ - *outType##Ptr = (outType)( *inType##Ptr & ( 0xffffffffffffffffLL >> ( 64 - ( sizeof( outType ) * 8 ) ) ) ); \ - } \ - break; - -#define TO_FLOAT_CASE(inType) \ - case kFloat: \ - floatPtr = (float *)outRaw; \ - *floatPtr = (float)(*inType##Ptr); \ - break; -#define TO_DOUBLE_CASE(inType) \ - case kDouble: \ - doublePtr = (double *)outRaw; \ - *doublePtr = (double)(*inType##Ptr); \ - break; - - -/* Note: we use lrintf here to force the rounding instead of whatever the processor's current rounding mode is */ -#define FLOAT_ROUND_TO_NEAREST_CASE(outEnum,outType) \ - case outEnum: \ - outType##Ptr = (outType *)outRaw; \ - *outType##Ptr = (outType)lrintf_clamped( *floatPtr ); \ - break; - -#define FLOAT_ROUND_CASE(outEnum,outType,rounding,sat) \ - case outEnum: \ - { \ - outType##Ptr = (outType *)outRaw; \ - /* Get the tens digit */ \ - Long wholeValue = (Long)*floatPtr;\ - float largeRemainder = ( *floatPtr - (float)wholeValue ) * 10.f; \ - /* What do we do based on that? */ \ - if( rounding == kRoundToEven ) \ - { \ - if( wholeValue & 1LL ) /*between 1 and 1.99 */ \ - wholeValue += 1LL; /* round up to even */ \ - } \ - else if( rounding == kRoundToZero ) \ - { \ - /* Nothing to do, round-to-zero is what C casting does */ \ - } \ - else if( rounding == kRoundToPosInf ) \ - { \ - /* Only positive numbers are wrong */ \ - if( largeRemainder != 0.f && wholeValue >= 0 ) \ - wholeValue++; \ - } \ - else if( rounding == kRoundToNegInf ) \ - { \ - /* Only negative numbers are off */ \ - if( largeRemainder != 0.f && wholeValue < 0 ) \ - wholeValue--; \ - } \ - else \ - { /* Default is round-to-nearest */ \ - wholeValue = (Long)lrintf_clamped( *floatPtr ); \ - } \ - /* Now apply saturation rules */ \ - if( sat ) \ - { \ - if( ( sLowerLimits[outEnum] < 0 && wholeValue > (Long)sUpperLimits[outEnum] ) || ( sLowerLimits[outEnum] == 0 && (ULong)wholeValue > sUpperLimits[outEnum] ) )\ - *outType##Ptr = (outType)sUpperLimits[outEnum];\ - else if( wholeValue < sLowerLimits[outEnum] )\ - *outType##Ptr = (outType)sLowerLimits[outEnum]; \ - else \ - *outType##Ptr = (outType)wholeValue; \ - } else { \ - *outType##Ptr = (outType)( wholeValue & ( 0xffffffffffffffffLL >> ( 64 - ( sizeof( outType ) * 8 ) ) ) ); \ - } \ - } \ - break; - -#define DOUBLE_ROUND_CASE(outEnum,outType,rounding,sat) \ - case outEnum: \ - { \ - outType##Ptr = (outType *)outRaw; \ - /* Get the tens digit */ \ - Long wholeValue = (Long)*doublePtr;\ - double largeRemainder = ( *doublePtr - (double)wholeValue ) * 10.0; \ - /* What do we do based on that? */ \ - if( rounding == kRoundToEven ) \ - { \ - if( wholeValue & 1LL ) /*between 1 and 1.99 */ \ - wholeValue += 1LL; /* round up to even */ \ - } \ - else if( rounding == kRoundToZero ) \ - { \ - /* Nothing to do, round-to-zero is what C casting does */ \ - } \ - else if( rounding == kRoundToPosInf ) \ - { \ - /* Only positive numbers are wrong */ \ - if( largeRemainder != 0.0 && wholeValue >= 0 ) \ - wholeValue++; \ - } \ - else if( rounding == kRoundToNegInf ) \ - { \ - /* Only negative numbers are off */ \ - if( largeRemainder != 0.0 && wholeValue < 0 ) \ - wholeValue--; \ - } \ - else \ - { /* Default is round-to-nearest */ \ - wholeValue = (Long)lrint_clamped( *doublePtr ); \ - } \ - /* Now apply saturation rules */ \ - if( sat ) \ - { \ - if( ( sLowerLimits[outEnum] < 0 && wholeValue > (Long)sUpperLimits[outEnum] ) || ( sLowerLimits[outEnum] == 0 && (ULong)wholeValue > sUpperLimits[outEnum] ) )\ - *outType##Ptr = (outType)sUpperLimits[outEnum];\ - else if( wholeValue < sLowerLimits[outEnum] )\ - *outType##Ptr = (outType)sLowerLimits[outEnum]; \ - else \ - *outType##Ptr = (outType)wholeValue; \ - } else { \ - *outType##Ptr = (outType)( wholeValue & ( 0xffffffffffffffffLL >> ( 64 - ( sizeof( outType ) * 8 ) ) ) ); \ - } \ - } \ - break; - -typedef unsigned char uchar; -typedef unsigned short ushort; -typedef unsigned int uint; -typedef unsigned long ulong; - -void convert_explicit_value( void *inRaw, void *outRaw, ExplicitType inType, bool saturate, RoundingType roundType, ExplicitType outType ) -{ - bool *boolPtr; - char *charPtr; - uchar *ucharPtr; - short *shortPtr; - ushort *ushortPtr; - int *intPtr; - uint *uintPtr; - Long *LongPtr; - ULong *ULongPtr; - float *floatPtr; - double *doublePtr; - - - switch( inType ) - { - case kBool: - boolPtr = (bool *)inRaw; - switch( outType ) - { - case kBool: - memcpy( outRaw, inRaw, get_explicit_type_size( inType ) ); - break; - - case kChar: - case kUChar: - case kUnsignedChar: - case kShort: - case kUShort: - case kUnsignedShort: - case kInt: - case kUInt: - case kUnsignedInt: - case kLong: - case kULong: - case kUnsignedLong: - memset( outRaw, *boolPtr ? 0xff : 0, get_explicit_type_size( outType ) ); - break; - - case kFloat: - floatPtr = (float *)outRaw; - *floatPtr = ( *boolPtr ) ? -1.f : 0.f; - break; - case kDouble: - doublePtr = (double *)outRaw; - *doublePtr = ( *boolPtr ) ? -1.0 : 0.0; - break; - default: - log_error( "ERROR: Invalid type given to convert_explicit_value!!\n" ); - break; - } - break; - - case kChar: - charPtr = (char *)inRaw; - switch( outType ) - { - BOOL_CASE(char) - - case kChar: - memcpy( outRaw, inRaw, get_explicit_type_size( inType ) ); - break; - - DOWN_CAST_CASE(char,kUChar,uchar,saturate) - SIMPLE_CAST_CASE(char,kUnsignedChar,uchar) - SIMPLE_CAST_CASE(char,kShort,short) - SIMPLE_CAST_CASE(char,kUShort,ushort) - SIMPLE_CAST_CASE(char,kUnsignedShort,ushort) - SIMPLE_CAST_CASE(char,kInt,int) - SIMPLE_CAST_CASE(char,kUInt,uint) - SIMPLE_CAST_CASE(char,kUnsignedInt,uint) - SIMPLE_CAST_CASE(char,kLong,Long) - SIMPLE_CAST_CASE(char,kULong,ULong) - SIMPLE_CAST_CASE(char,kUnsignedLong,ULong) - - TO_FLOAT_CASE(char) - TO_DOUBLE_CASE(char) - - default: - log_error( "ERROR: Invalid type given to convert_explicit_value!!\n" ); - break; - } - break; - - case kUChar: - ucharPtr = (uchar *)inRaw; - switch( outType ) - { - BOOL_CASE(uchar) - - case kUChar: - case kUnsignedChar: - memcpy( outRaw, inRaw, get_explicit_type_size( inType ) ); - break; - - DOWN_CAST_CASE(uchar,kChar,char,saturate) - SIMPLE_CAST_CASE(uchar,kShort,short) - SIMPLE_CAST_CASE(uchar,kUShort,ushort) - SIMPLE_CAST_CASE(uchar,kUnsignedShort,ushort) - SIMPLE_CAST_CASE(uchar,kInt,int) - SIMPLE_CAST_CASE(uchar,kUInt,uint) - SIMPLE_CAST_CASE(uchar,kUnsignedInt,uint) - SIMPLE_CAST_CASE(uchar,kLong,Long) - SIMPLE_CAST_CASE(uchar,kULong,ULong) - SIMPLE_CAST_CASE(uchar,kUnsignedLong,ULong) - - TO_FLOAT_CASE(uchar) - TO_DOUBLE_CASE(uchar) - - default: - log_error( "ERROR: Invalid type given to convert_explicit_value!!\n" ); - break; - } - break; - - case kUnsignedChar: - ucharPtr = (uchar *)inRaw; - switch( outType ) - { - BOOL_CASE(uchar) - - case kUChar: - case kUnsignedChar: - memcpy( outRaw, inRaw, get_explicit_type_size( inType ) ); - break; - - DOWN_CAST_CASE(uchar,kChar,char,saturate) - SIMPLE_CAST_CASE(uchar,kShort,short) - SIMPLE_CAST_CASE(uchar,kUShort,ushort) - SIMPLE_CAST_CASE(uchar,kUnsignedShort,ushort) - SIMPLE_CAST_CASE(uchar,kInt,int) - SIMPLE_CAST_CASE(uchar,kUInt,uint) - SIMPLE_CAST_CASE(uchar,kUnsignedInt,uint) - SIMPLE_CAST_CASE(uchar,kLong,Long) - SIMPLE_CAST_CASE(uchar,kULong,ULong) - SIMPLE_CAST_CASE(uchar,kUnsignedLong,ULong) - - TO_FLOAT_CASE(uchar) - TO_DOUBLE_CASE(uchar) - - default: - log_error( "ERROR: Invalid type given to convert_explicit_value!!\n" ); - break; - } - break; - - case kShort: - shortPtr = (short *)inRaw; - switch( outType ) - { - BOOL_CASE(short) - - case kShort: - memcpy( outRaw, inRaw, get_explicit_type_size( inType ) ); - break; - - DOWN_CAST_CASE(short,kChar,char,saturate) - DOWN_CAST_CASE(short,kUChar,uchar,saturate) - DOWN_CAST_CASE(short,kUnsignedChar,uchar,saturate) - DOWN_CAST_CASE(short,kUShort,ushort,saturate) - DOWN_CAST_CASE(short,kUnsignedShort,ushort,saturate) - SIMPLE_CAST_CASE(short,kInt,int) - SIMPLE_CAST_CASE(short,kUInt,uint) - SIMPLE_CAST_CASE(short,kUnsignedInt,uint) - SIMPLE_CAST_CASE(short,kLong,Long) - SIMPLE_CAST_CASE(short,kULong,ULong) - SIMPLE_CAST_CASE(short,kUnsignedLong,ULong) - - TO_FLOAT_CASE(short) - TO_DOUBLE_CASE(short) - - default: - log_error( "ERROR: Invalid type given to convert_explicit_value!!\n" ); - break; - } - break; - - case kUShort: - ushortPtr = (ushort *)inRaw; - switch( outType ) - { - BOOL_CASE(ushort) - - case kUShort: - case kUnsignedShort: - memcpy( outRaw, inRaw, get_explicit_type_size( inType ) ); - break; - - DOWN_CAST_CASE(ushort,kChar,char,saturate) - DOWN_CAST_CASE(ushort,kUChar,uchar,saturate) - DOWN_CAST_CASE(ushort,kUnsignedChar,uchar,saturate) - DOWN_CAST_CASE(ushort,kShort,short,saturate) - SIMPLE_CAST_CASE(ushort,kInt,int) - SIMPLE_CAST_CASE(ushort,kUInt,uint) - SIMPLE_CAST_CASE(ushort,kUnsignedInt,uint) - SIMPLE_CAST_CASE(ushort,kLong,Long) - SIMPLE_CAST_CASE(ushort,kULong,ULong) - SIMPLE_CAST_CASE(ushort,kUnsignedLong,ULong) - - TO_FLOAT_CASE(ushort) - TO_DOUBLE_CASE(ushort) - - default: - log_error( "ERROR: Invalid type given to convert_explicit_value!!\n" ); - break; - } - break; - - case kUnsignedShort: - ushortPtr = (ushort *)inRaw; - switch( outType ) - { - BOOL_CASE(ushort) - - case kUShort: - case kUnsignedShort: - memcpy( outRaw, inRaw, get_explicit_type_size( inType ) ); - break; - - DOWN_CAST_CASE(ushort,kChar,char,saturate) - DOWN_CAST_CASE(ushort,kUChar,uchar,saturate) - DOWN_CAST_CASE(ushort,kUnsignedChar,uchar,saturate) - DOWN_CAST_CASE(ushort,kShort,short,saturate) - SIMPLE_CAST_CASE(ushort,kInt,int) - SIMPLE_CAST_CASE(ushort,kUInt,uint) - SIMPLE_CAST_CASE(ushort,kUnsignedInt,uint) - SIMPLE_CAST_CASE(ushort,kLong,Long) - SIMPLE_CAST_CASE(ushort,kULong,ULong) - SIMPLE_CAST_CASE(ushort,kUnsignedLong,ULong) - - TO_FLOAT_CASE(ushort) - TO_DOUBLE_CASE(ushort) - - default: - log_error( "ERROR: Invalid type given to convert_explicit_value!!\n" ); - break; - } - break; - - case kInt: - intPtr = (int *)inRaw; - switch( outType ) - { - BOOL_CASE(int) - - case kInt: - memcpy( outRaw, inRaw, get_explicit_type_size( inType ) ); - break; - - DOWN_CAST_CASE(int,kChar,char,saturate) - DOWN_CAST_CASE(int,kUChar,uchar,saturate) - DOWN_CAST_CASE(int,kUnsignedChar,uchar,saturate) - DOWN_CAST_CASE(int,kShort,short,saturate) - DOWN_CAST_CASE(int,kUShort,ushort,saturate) - DOWN_CAST_CASE(int,kUnsignedShort,ushort,saturate) - DOWN_CAST_CASE(int,kUInt,uint,saturate) - DOWN_CAST_CASE(int,kUnsignedInt,uint,saturate) - SIMPLE_CAST_CASE(int,kLong,Long) - SIMPLE_CAST_CASE(int,kULong,ULong) - SIMPLE_CAST_CASE(int,kUnsignedLong,ULong) - - TO_FLOAT_CASE(int) - TO_DOUBLE_CASE(int) - - default: - log_error( "ERROR: Invalid type given to convert_explicit_value!!\n" ); - break; - } - break; - - case kUInt: - uintPtr = (uint *)inRaw; - switch( outType ) - { - BOOL_CASE(uint) - - case kUInt: - case kUnsignedInt: - memcpy( outRaw, inRaw, get_explicit_type_size( inType ) ); - break; - - DOWN_CAST_CASE(uint,kChar,char,saturate) - DOWN_CAST_CASE(uint,kUChar,uchar,saturate) - DOWN_CAST_CASE(uint,kUnsignedChar,uchar,saturate) - DOWN_CAST_CASE(uint,kShort,short,saturate) - DOWN_CAST_CASE(uint,kUShort,ushort,saturate) - DOWN_CAST_CASE(uint,kUnsignedShort,ushort,saturate) - DOWN_CAST_CASE(uint,kInt,int,saturate) - SIMPLE_CAST_CASE(uint,kLong,Long) - SIMPLE_CAST_CASE(uint,kULong,ULong) - SIMPLE_CAST_CASE(uint,kUnsignedLong,ULong) - - TO_FLOAT_CASE(uint) - TO_DOUBLE_CASE(uint) - - default: - log_error( "ERROR: Invalid type given to convert_explicit_value!!\n" ); - break; - } - break; - - case kUnsignedInt: - uintPtr = (uint *)inRaw; - switch( outType ) - { - BOOL_CASE(uint) - - case kUInt: - case kUnsignedInt: - memcpy( outRaw, inRaw, get_explicit_type_size( inType ) ); - break; - - DOWN_CAST_CASE(uint,kChar,char,saturate) - DOWN_CAST_CASE(uint,kUChar,uchar,saturate) - DOWN_CAST_CASE(uint,kUnsignedChar,uchar,saturate) - DOWN_CAST_CASE(uint,kShort,short,saturate) - DOWN_CAST_CASE(uint,kUShort,ushort,saturate) - DOWN_CAST_CASE(uint,kUnsignedShort,ushort,saturate) - DOWN_CAST_CASE(uint,kInt,int,saturate) - SIMPLE_CAST_CASE(uint,kLong,Long) - SIMPLE_CAST_CASE(uint,kULong,ULong) - SIMPLE_CAST_CASE(uint,kUnsignedLong,ULong) - - TO_FLOAT_CASE(uint) - TO_DOUBLE_CASE(uint) - - default: - log_error( "ERROR: Invalid type given to convert_explicit_value!!\n" ); - break; - } - break; - - case kLong: - LongPtr = (Long *)inRaw; - switch( outType ) - { - BOOL_CASE(Long) - - case kLong: - memcpy( outRaw, inRaw, get_explicit_type_size( inType ) ); - break; - - DOWN_CAST_CASE(Long,kChar,char,saturate) - DOWN_CAST_CASE(Long,kUChar,uchar,saturate) - DOWN_CAST_CASE(Long,kUnsignedChar,uchar,saturate) - DOWN_CAST_CASE(Long,kShort,short,saturate) - DOWN_CAST_CASE(Long,kUShort,ushort,saturate) - DOWN_CAST_CASE(Long,kUnsignedShort,ushort,saturate) - DOWN_CAST_CASE(Long,kInt,int,saturate) - DOWN_CAST_CASE(Long,kUInt,uint,saturate) - DOWN_CAST_CASE(Long,kUnsignedInt,uint,saturate) - DOWN_CAST_CASE(Long,kULong,ULong,saturate) - DOWN_CAST_CASE(Long,kUnsignedLong,ULong,saturate) - - TO_FLOAT_CASE(Long) - TO_DOUBLE_CASE(Long) - - default: - log_error( "ERROR: Invalid type given to convert_explicit_value!!\n" ); - break; - } - break; - - case kULong: - ULongPtr = (ULong *)inRaw; - switch( outType ) - { - BOOL_CASE(ULong) - - case kUnsignedLong: - case kULong: - memcpy( outRaw, inRaw, get_explicit_type_size( inType ) ); - break; - - U_DOWN_CAST_CASE(ULong,kChar,char,saturate) - U_DOWN_CAST_CASE(ULong,kUChar,uchar,saturate) - U_DOWN_CAST_CASE(ULong,kUnsignedChar,uchar,saturate) - U_DOWN_CAST_CASE(ULong,kShort,short,saturate) - U_DOWN_CAST_CASE(ULong,kUShort,ushort,saturate) - U_DOWN_CAST_CASE(ULong,kUnsignedShort,ushort,saturate) - U_DOWN_CAST_CASE(ULong,kInt,int,saturate) - U_DOWN_CAST_CASE(ULong,kUInt,uint,saturate) - U_DOWN_CAST_CASE(ULong,kUnsignedInt,uint,saturate) - U_DOWN_CAST_CASE(ULong,kLong,Long,saturate) - - TO_FLOAT_CASE(ULong) - TO_DOUBLE_CASE(ULong) - - default: - log_error( "ERROR: Invalid type given to convert_explicit_value!!\n" ); - break; - } - break; - - case kUnsignedLong: - ULongPtr = (ULong *)inRaw; - switch( outType ) - { - BOOL_CASE(ULong) - - case kULong: - case kUnsignedLong: - memcpy( outRaw, inRaw, get_explicit_type_size( inType ) ); - break; - - U_DOWN_CAST_CASE(ULong,kChar,char,saturate) - U_DOWN_CAST_CASE(ULong,kUChar,uchar,saturate) - U_DOWN_CAST_CASE(ULong,kUnsignedChar,uchar,saturate) - U_DOWN_CAST_CASE(ULong,kShort,short,saturate) - U_DOWN_CAST_CASE(ULong,kUShort,ushort,saturate) - U_DOWN_CAST_CASE(ULong,kUnsignedShort,ushort,saturate) - U_DOWN_CAST_CASE(ULong,kInt,int,saturate) - U_DOWN_CAST_CASE(ULong,kUInt,uint,saturate) - U_DOWN_CAST_CASE(ULong,kUnsignedInt,uint,saturate) - U_DOWN_CAST_CASE(ULong,kLong,Long,saturate) - - TO_FLOAT_CASE(ULong) - TO_DOUBLE_CASE(ULong) - - default: - log_error( "ERROR: Invalid type given to convert_explicit_value!!\n" ); - break; - } - break; - - case kFloat: - floatPtr = (float *)inRaw; - switch( outType ) - { - BOOL_CASE(float) - - FLOAT_ROUND_CASE(kChar,char,roundType,saturate) - FLOAT_ROUND_CASE(kUChar,uchar,roundType,saturate) - FLOAT_ROUND_CASE(kUnsignedChar,uchar,roundType,saturate) - FLOAT_ROUND_CASE(kShort,short,roundType,saturate) - FLOAT_ROUND_CASE(kUShort,ushort,roundType,saturate) - FLOAT_ROUND_CASE(kUnsignedShort,ushort,roundType,saturate) - FLOAT_ROUND_CASE(kInt,int,roundType,saturate) - FLOAT_ROUND_CASE(kUInt,uint,roundType,saturate) - FLOAT_ROUND_CASE(kUnsignedInt,uint,roundType,saturate) - FLOAT_ROUND_CASE(kLong,Long,roundType,saturate) - FLOAT_ROUND_CASE(kULong,ULong,roundType,saturate) - FLOAT_ROUND_CASE(kUnsignedLong,ULong,roundType,saturate) - - case kFloat: - memcpy( outRaw, inRaw, get_explicit_type_size( inType ) ); - break; - - TO_DOUBLE_CASE(float); - - default: - log_error( "ERROR: Invalid type given to convert_explicit_value!!\n" ); - break; - } - break; - - case kDouble: - doublePtr = (double *)inRaw; - switch( outType ) - { - BOOL_CASE(double) - - DOUBLE_ROUND_CASE(kChar,char,roundType,saturate) - DOUBLE_ROUND_CASE(kUChar,uchar,roundType,saturate) - DOUBLE_ROUND_CASE(kUnsignedChar,uchar,roundType,saturate) - DOUBLE_ROUND_CASE(kShort,short,roundType,saturate) - DOUBLE_ROUND_CASE(kUShort,ushort,roundType,saturate) - DOUBLE_ROUND_CASE(kUnsignedShort,ushort,roundType,saturate) - DOUBLE_ROUND_CASE(kInt,int,roundType,saturate) - DOUBLE_ROUND_CASE(kUInt,uint,roundType,saturate) - DOUBLE_ROUND_CASE(kUnsignedInt,uint,roundType,saturate) - DOUBLE_ROUND_CASE(kLong,Long,roundType,saturate) - DOUBLE_ROUND_CASE(kULong,ULong,roundType,saturate) - DOUBLE_ROUND_CASE(kUnsignedLong,ULong,roundType,saturate) - - TO_FLOAT_CASE(double); - - case kDouble: - memcpy( outRaw, inRaw, get_explicit_type_size( inType ) ); - break; - - default: - log_error( "ERROR: Invalid type given to convert_explicit_value!!\n" ); - break; - } - break; - - default: - log_error( "ERROR: Invalid type given to convert_explicit_value!!\n" ); - break; - } -} - -void generate_random_data( ExplicitType type, size_t count, MTdata d, void *outData ) -{ - bool *boolPtr; - cl_char *charPtr; - cl_uchar *ucharPtr; - cl_short *shortPtr; - cl_ushort *ushortPtr; - cl_int *intPtr; - cl_uint *uintPtr; - cl_long *longPtr; - cl_ulong *ulongPtr; - cl_float *floatPtr; - cl_double *doublePtr; - cl_ushort *halfPtr; - size_t i; - cl_uint bits = genrand_int32(d); - cl_uint bitsLeft = 32; - - switch( type ) - { - case kBool: - boolPtr = (bool *)outData; - for( i = 0; i < count; i++ ) - { - if( 0 == bitsLeft) - { - bits = genrand_int32(d); - bitsLeft = 32; - } - boolPtr[i] = ( bits & 1 ) ? true : false; - bits >>= 1; bitsLeft -= 1; - } - break; - - case kChar: - charPtr = (cl_char *)outData; - for( i = 0; i < count; i++ ) - { - if( 0 == bitsLeft) - { - bits = genrand_int32(d); - bitsLeft = 32; - } - charPtr[i] = (cl_char)( (cl_int)(bits & 255 ) - 127 ); - bits >>= 8; bitsLeft -= 8; - } - break; - - case kUChar: - case kUnsignedChar: - ucharPtr = (cl_uchar *)outData; - for( i = 0; i < count; i++ ) - { - if( 0 == bitsLeft) - { - bits = genrand_int32(d); - bitsLeft = 32; - } - ucharPtr[i] = (cl_uchar)( bits & 255 ); - bits >>= 8; bitsLeft -= 8; - } - break; - - case kShort: - shortPtr = (cl_short *)outData; - for( i = 0; i < count; i++ ) - { - if( 0 == bitsLeft) - { - bits = genrand_int32(d); - bitsLeft = 32; - } - shortPtr[i] = (cl_short)( (cl_int)( bits & 65535 ) - 32767 ); - bits >>= 16; bitsLeft -= 16; - } - break; - - case kUShort: - case kUnsignedShort: - ushortPtr = (cl_ushort *)outData; - for( i = 0; i < count; i++ ) - { - if( 0 == bitsLeft) - { - bits = genrand_int32(d); - bitsLeft = 32; - } - ushortPtr[i] = (cl_ushort)( (cl_int)( bits & 65535 ) ); - bits >>= 16; bitsLeft -= 16; - } - break; - - case kInt: - intPtr = (cl_int *)outData; - for( i = 0; i < count; i++ ) - { - intPtr[i] = (cl_int)genrand_int32(d); - } - break; - - case kUInt: - case kUnsignedInt: - uintPtr = (cl_uint *)outData; - for( i = 0; i < count; i++ ) - { - uintPtr[i] = (unsigned int)genrand_int32(d); - } - break; - - case kLong: - longPtr = (cl_long *)outData; - for( i = 0; i < count; i++ ) - { - longPtr[i] = (cl_long)genrand_int32(d) | ( (cl_long)genrand_int32(d) << 32 ); - } - break; - - case kULong: - case kUnsignedLong: - ulongPtr = (cl_ulong *)outData; - for( i = 0; i < count; i++ ) - { - ulongPtr[i] = (cl_ulong)genrand_int32(d) | ( (cl_ulong)genrand_int32(d) << 32 ); - } - break; - - case kFloat: - floatPtr = (cl_float *)outData; - for( i = 0; i < count; i++ ) - { - // [ -(double) 0x7fffffff, (double) 0x7fffffff ] - double t = genrand_real1(d); - floatPtr[i] = (float) ((1.0 - t) * -(double) 0x7fffffff + t * (double) 0x7fffffff); - } - break; - - case kDouble: - doublePtr = (cl_double *)outData; - for( i = 0; i < count; i++ ) - { - cl_long u = (cl_long)genrand_int32(d) | ( (cl_long)genrand_int32(d) << 32 ); - double t = (double) u; - t *= MAKE_HEX_DOUBLE( 0x1.0p-32, 0x1, -32 ); // scale [-2**63, 2**63] to [-2**31, 2**31] - doublePtr[i] = t; - } - break; - - case kHalf: - halfPtr = (ushort *)outData; - for( i = 0; i < count; i++ ) - { - if( 0 == bitsLeft) - { - bits = genrand_int32(d); - bitsLeft = 32; - } - halfPtr[i] = bits & 65535; /* Kindly generates random bits for us */ - bits >>= 16; bitsLeft -= 16; - } - break; - - default: - log_error( "ERROR: Invalid type passed in to generate_random_data!\n" ); - break; - } -} - -void * create_random_data( ExplicitType type, MTdata d, size_t count ) -{ - void *data = malloc( get_explicit_type_size( type ) * count ); - generate_random_data( type, count, d, data ); - return data; -} - -cl_long read_upscale_signed( void *inRaw, ExplicitType inType ) -{ - switch( inType ) - { - case kChar: - return (cl_long)( *( (cl_char *)inRaw ) ); - case kUChar: - case kUnsignedChar: - return (cl_long)( *( (cl_uchar *)inRaw ) ); - case kShort: - return (cl_long)( *( (cl_short *)inRaw ) ); - case kUShort: - case kUnsignedShort: - return (cl_long)( *( (cl_ushort *)inRaw ) ); - case kInt: - return (cl_long)( *( (cl_int *)inRaw ) ); - case kUInt: - case kUnsignedInt: - return (cl_long)( *( (cl_uint *)inRaw ) ); - case kLong: - return (cl_long)( *( (cl_long *)inRaw ) ); - case kULong: - case kUnsignedLong: - return (cl_long)( *( (cl_ulong *)inRaw ) ); - default: - return 0; - } -} - -cl_ulong read_upscale_unsigned( void *inRaw, ExplicitType inType ) -{ - switch( inType ) - { - case kChar: - return (cl_ulong)( *( (cl_char *)inRaw ) ); - case kUChar: - case kUnsignedChar: - return (cl_ulong)( *( (cl_uchar *)inRaw ) ); - case kShort: - return (cl_ulong)( *( (cl_short *)inRaw ) ); - case kUShort: - case kUnsignedShort: - return (cl_ulong)( *( (cl_ushort *)inRaw ) ); - case kInt: - return (cl_ulong)( *( (cl_int *)inRaw ) ); - case kUInt: - case kUnsignedInt: - return (cl_ulong)( *( (cl_uint *)inRaw ) ); - case kLong: - return (cl_ulong)( *( (cl_long *)inRaw ) ); - case kULong: - case kUnsignedLong: - return (cl_ulong)( *( (cl_ulong *)inRaw ) ); - default: - return 0; - } -} - -float read_as_float( void *inRaw, ExplicitType inType ) -{ - switch( inType ) - { - case kChar: - return (float)( *( (cl_char *)inRaw ) ); - case kUChar: - case kUnsignedChar: - return (float)( *( (cl_char *)inRaw ) ); - case kShort: - return (float)( *( (cl_short *)inRaw ) ); - case kUShort: - case kUnsignedShort: - return (float)( *( (cl_ushort *)inRaw ) ); - case kInt: - return (float)( *( (cl_int *)inRaw ) ); - case kUInt: - case kUnsignedInt: - return (float)( *( (cl_uint *)inRaw ) ); - case kLong: - return (float)( *( (cl_long *)inRaw ) ); - case kULong: - case kUnsignedLong: - return (float)( *( (cl_ulong *)inRaw ) ); - case kFloat: - return *( (float *)inRaw ); - case kDouble: - return (float) *( (double*)inRaw ); - default: - return 0; - } -} - -float get_random_float(float low, float high, MTdata d) -{ - float t = (float)((double)genrand_int32(d) / (double)0xFFFFFFFF); - return (1.0f - t) * low + t * high; -} - -double get_random_double(double low, double high, MTdata d) -{ - cl_ulong u = (cl_ulong) genrand_int32(d) | ((cl_ulong) genrand_int32(d) << 32 ); - double t = (double) u * MAKE_HEX_DOUBLE( 0x1.0p-64, 0x1, -64); - return (1.0f - t) * low + t * high; -} - -float any_float( MTdata d ) -{ - union - { - float f; - cl_uint u; - }u; - - u.u = genrand_int32(d); - return u.f; -} - - -double any_double( MTdata d ) -{ - union - { - double f; - cl_ulong u; - }u; - - u.u = (cl_ulong) genrand_int32(d) | ((cl_ulong) genrand_int32(d) << 32); - return u.f; -} - -int random_in_range( int minV, int maxV, MTdata d ) -{ - cl_ulong r = ((cl_ulong) genrand_int32(d) ) * (maxV - minV + 1); - return (cl_uint)(r >> 32) + minV; -} - -size_t get_random_size_t(size_t low, size_t high, MTdata d) -{ - enum { N = sizeof(size_t)/sizeof(int) }; - - union { - int word[N]; - size_t size; - } u; - - for (unsigned i=0; i != N; ++i) { - u.word[i] = genrand_int32(d); - } - - assert(low <= high && "Invalid random number range specified"); - size_t range = high - low; - - return (range) ? low + ((u.size - low) % range) : low; -} - - diff --git a/test_conformance/compatibility/test_common/harness/conversions.h b/test_conformance/compatibility/test_common/harness/conversions.h deleted file mode 100644 index aa3cb6b4..00000000 --- a/test_conformance/compatibility/test_common/harness/conversions.h +++ /dev/null @@ -1,126 +0,0 @@ -// -// Copyright (c) 2017 The Khronos Group Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -#ifndef _conversions_h -#define _conversions_h - -#include "compat.h" - -#include "errorHelpers.h" -#include "mt19937.h" -#include -#include -#include -#include - -#if defined(__cplusplus) -extern "C" { -#endif - -/* Note: the next three all have to match in size and order!! */ - -enum ExplicitTypes -{ - kBool = 0, - kChar, - kUChar, - kUnsignedChar, - kShort, - kUShort, - kUnsignedShort, - kInt, - kUInt, - kUnsignedInt, - kLong, - kULong, - kUnsignedLong, - kFloat, - kHalf, - kDouble, - kNumExplicitTypes -}; - -typedef enum ExplicitTypes ExplicitType; - -enum RoundingTypes -{ - kRoundToEven = 0, - kRoundToZero, - kRoundToPosInf, - kRoundToNegInf, - kRoundToNearest, - - kNumRoundingTypes, - - kDefaultRoundingType = kRoundToNearest -}; - -typedef enum RoundingTypes RoundingType; - -extern void print_type_to_string(ExplicitType type, void *data, char* string); -extern size_t get_explicit_type_size( ExplicitType type ); -extern const char * get_explicit_type_name( ExplicitType type ); -extern void convert_explicit_value( void *inRaw, void *outRaw, ExplicitType inType, bool saturate, RoundingType roundType, ExplicitType outType ); - -extern void generate_random_data( ExplicitType type, size_t count, MTdata d, void *outData ); -extern void * create_random_data( ExplicitType type, MTdata d, size_t count ); - -extern cl_long read_upscale_signed( void *inRaw, ExplicitType inType ); -extern cl_ulong read_upscale_unsigned( void *inRaw, ExplicitType inType ); -extern float read_as_float( void *inRaw, ExplicitType inType ); - -extern float get_random_float(float low, float high, MTdata d); -extern double get_random_double(double low, double high, MTdata d); -extern float any_float( MTdata d ); -extern double any_double( MTdata d ); - -extern int random_in_range( int minV, int maxV, MTdata d ); - -size_t get_random_size_t(size_t low, size_t high, MTdata d); - -// Note: though this takes a double, this is for use with single precision tests -static inline int IsFloatSubnormal( float x ) -{ -#if 2 == FLT_RADIX - // Do this in integer to avoid problems with FTZ behavior - union{ float d; uint32_t u;}u; - u.d = fabsf(x); - return (u.u-1) < 0x007fffffU; -#else - // rely on floating point hardware for non-radix2 non-IEEE-754 hardware -- will fail if you flush subnormals to zero - return fabs(x) < (double) FLT_MIN && x != 0.0; -#endif -} - -static inline int IsDoubleSubnormal( double x ) -{ -#if 2 == FLT_RADIX - // Do this in integer to avoid problems with FTZ behavior - union{ double d; uint64_t u;}u; - u.d = fabs( x); - return (u.u-1) < 0x000fffffffffffffULL; -#else - // rely on floating point hardware for non-radix2 non-IEEE-754 hardware -- will fail if you flush subnormals to zero - return fabs(x) < (double) DBL_MIN && x != 0.0; -#endif -} - -#if defined(__cplusplus) -} -#endif - -#endif // _conversions_h - - diff --git a/test_conformance/compatibility/test_common/harness/genericThread.cpp b/test_conformance/compatibility/test_common/harness/genericThread.cpp deleted file mode 100644 index 2b742fa3..00000000 --- a/test_conformance/compatibility/test_common/harness/genericThread.cpp +++ /dev/null @@ -1,53 +0,0 @@ -// -// Copyright (c) 2017 The Khronos Group Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -#include "genericThread.h" - -#if defined(_WIN32) -#include -#else // !_WIN32 -#include -#endif - -void * genericThread::IStaticReflector( void * data ) -{ - genericThread *t = (genericThread *)data; - return t->IRun(); -} - -bool genericThread::Start( void ) -{ -#if defined(_WIN32) - mHandle = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE) IStaticReflector, this, 0, NULL ); - return ( mHandle != NULL ); -#else // !_WIN32 - int error = pthread_create( (pthread_t*)&mHandle, NULL, IStaticReflector, (void *)this ); - return ( error == 0 ); -#endif // !_WIN32 -} - -void * genericThread::Join( void ) -{ -#if defined(_WIN32) - WaitForSingleObject( (HANDLE)mHandle, INFINITE ); - return NULL; -#else // !_WIN32 - void * retVal; - int error = pthread_join( (pthread_t)mHandle, &retVal ); - if( error != 0 ) - retVal = NULL; - return retVal; -#endif // !_WIN32 -} diff --git a/test_conformance/compatibility/test_common/harness/genericThread.h b/test_conformance/compatibility/test_common/harness/genericThread.h deleted file mode 100644 index 168b7407..00000000 --- a/test_conformance/compatibility/test_common/harness/genericThread.h +++ /dev/null @@ -1,42 +0,0 @@ -// -// Copyright (c) 2017 The Khronos Group Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -#ifndef _genericThread_h -#define _genericThread_h - -#include - -class genericThread -{ - public: - - virtual ~genericThread() {} - - bool Start( void ); - void * Join( void ); - - protected: - - virtual void * IRun( void ) = 0; - - private: - - void* mHandle; - - static void * IStaticReflector( void * data ); -}; - -#endif // _genericThread_h - diff --git a/test_conformance/compatibility/test_common/harness/mingw_compat.c b/test_conformance/compatibility/test_common/harness/mingw_compat.c deleted file mode 100644 index 54c44635..00000000 --- a/test_conformance/compatibility/test_common/harness/mingw_compat.c +++ /dev/null @@ -1,59 +0,0 @@ -// -// Copyright (c) 2017 The Khronos Group Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -#if defined(__MINGW32__) - -#include "mingw_compat.h" -#include -#include - -//This function is unavailable on various mingw compilers, -//especially 64 bit so implementing it here -const char *basename_dot="."; -char* -basename(char *path) -{ - char *p = path, *b = NULL; - int len = strlen(path); - - if (path == NULL) { - return (char*)basename_dot; - } - - // Not absolute path on windows - if (path[1] != ':') { - return path; - } - - // Trim trailing path seperators - if (path[len - 1] == '\\' || - path[len - 1] == '/' ) { - len--; - path[len] = '\0'; - } - - while (len) { - while((*p != '\\' || *p != '/') && len) { - p++; - len--; - } - p++; - b = p; - } - - return b; -} - -#endif \ No newline at end of file diff --git a/test_conformance/compatibility/test_common/harness/mingw_compat.h b/test_conformance/compatibility/test_common/harness/mingw_compat.h deleted file mode 100644 index ab28f398..00000000 --- a/test_conformance/compatibility/test_common/harness/mingw_compat.h +++ /dev/null @@ -1,31 +0,0 @@ -// -// Copyright (c) 2017 The Khronos Group Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -#ifndef MINGW_COMPAT_H -#define MINGW_COMPAT_H - -#if defined(__MINGW32__) -char *basename(char *path); -#include - -#if defined(__MINGW64__) -//mingw-w64 doesnot have __mingw_aligned_malloc, instead it has _aligned_malloc -#define __mingw_aligned_malloc _aligned_malloc -#define __mingw_aligned_free _aligned_free -#include -#endif //(__MINGW64__) - -#endif //(__MINGW32__) -#endif // MINGW_COMPAT_H diff --git a/test_conformance/compatibility/test_common/harness/mt19937.h b/test_conformance/compatibility/test_common/harness/mt19937.h deleted file mode 100644 index d05beed1..00000000 --- a/test_conformance/compatibility/test_common/harness/mt19937.h +++ /dev/null @@ -1,99 +0,0 @@ - -/* - * mt19937.h - * - * Mersenne Twister. - * - A C-program for MT19937, with initialization improved 2002/1/26. - Coded by Takuji Nishimura and Makoto Matsumoto. - - Before using, initialize the state by using init_genrand(seed) - or init_by_array(init_key, key_length). - - Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - 3. The names of its contributors may not be used to endorse or promote - products derived from this software without specific prior written - permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - - Any feedback is very welcome. - http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html - email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space) - */ - -#ifndef MT19937_H -#define MT19937_H 1 - -#if defined( __APPLE__ ) - #include -#else - #include -#endif - -#ifdef __cplusplus - extern "C" { -#endif - -/* - * Interfaces here have been modified from original sources so that they - * are safe to call reentrantly, so long as a different MTdata is used - * on each thread. - */ - -typedef struct _MTdata *MTdata; - -/* Create the random number generator with seed */ -MTdata init_genrand( cl_uint /*seed*/ ); - -/* release memory used by a MTdata private data */ -void free_mtdata( MTdata /*data*/ ); - -/* generates a random number on [0,0xffffffff]-interval */ -cl_uint genrand_int32( MTdata /*data*/); - -/* generates a random number on [0,0xffffffffffffffffULL]-interval */ -cl_ulong genrand_int64( MTdata /*data*/); - -/* generates a random number on [0,1]-real-interval */ -double genrand_real1( MTdata /*data*/); - -/* generates a random number on [0,1)-real-interval */ -double genrand_real2( MTdata /*data*/); - -/* generates a random number on (0,1)-real-interval */ -double genrand_real3( MTdata /*data*/); - -/* generates a random number on [0,1) with 53-bit resolution*/ -double genrand_res53( MTdata /*data*/ ); - - -#ifdef __cplusplus - } -#endif - -#endif /* MT19937_H */ diff --git a/test_conformance/compatibility/test_common/harness/ref_counting.h b/test_conformance/compatibility/test_common/harness/ref_counting.h deleted file mode 100644 index 1a2aceee..00000000 --- a/test_conformance/compatibility/test_common/harness/ref_counting.h +++ /dev/null @@ -1,49 +0,0 @@ -// -// Copyright (c) 2017 The Khronos Group Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -#ifndef _ref_counting_h -#define _ref_counting_h - -#define MARK_REF_COUNT_BASE( c, type, bigType ) \ - cl_uint c##_refCount; \ - error = clGet##type##Info( c, CL_##bigType##_REFERENCE_COUNT, sizeof( c##_refCount ), &c##_refCount, NULL ); \ - test_error( error, "Unable to check reference count for " #type ); - -#define TEST_REF_COUNT_BASE( c, type, bigType ) \ - cl_uint c##_refCount_new; \ - error = clGet##type##Info( c, CL_##bigType##_REFERENCE_COUNT, sizeof( c##_refCount_new ), &c##_refCount_new, NULL ); \ - test_error( error, "Unable to check reference count for " #type ); \ - if( c##_refCount != c##_refCount_new ) \ - { \ - log_error( "ERROR: Reference count for " #type " changed! (was %d, now %d)\n", c##_refCount, c##_refCount_new ); \ - return -1; \ - } - -#define MARK_REF_COUNT_CONTEXT( c ) MARK_REF_COUNT_BASE( c, Context, CONTEXT ) -#define TEST_REF_COUNT_CONTEXT( c ) TEST_REF_COUNT_BASE( c, Context, CONTEXT ) - -#define MARK_REF_COUNT_DEVICE( c ) MARK_REF_COUNT_BASE( c, Device, DEVICE ) -#define TEST_REF_COUNT_DEVICE( c ) TEST_REF_COUNT_BASE( c, Device, DEVICE ) - -#define MARK_REF_COUNT_QUEUE( c ) MARK_REF_COUNT_BASE( c, CommandQueue, QUEUE ) -#define TEST_REF_COUNT_QUEUE( c ) TEST_REF_COUNT_BASE( c, CommandQueue, QUEUE ) - -#define MARK_REF_COUNT_PROGRAM( c ) MARK_REF_COUNT_BASE( c, Program, PROGRAM ) -#define TEST_REF_COUNT_PROGRAM( c ) TEST_REF_COUNT_BASE( c, Program, PROGRAM ) - -#define MARK_REF_COUNT_MEM( c ) MARK_REF_COUNT_BASE( c, MemObject, MEM ) -#define TEST_REF_COUNT_MEM( c ) TEST_REF_COUNT_BASE( c, MemObject, MEM ) - -#endif // _ref_counting_h diff --git a/test_conformance/compatibility/test_common/harness/test_mt19937.c b/test_conformance/compatibility/test_common/harness/test_mt19937.c deleted file mode 100644 index c0498ea9..00000000 --- a/test_conformance/compatibility/test_common/harness/test_mt19937.c +++ /dev/null @@ -1,51 +0,0 @@ -// -// Copyright (c) 2017 The Khronos Group Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -#include "mt19937.h" -#include - -int main( void ) -{ - MTdata d = init_genrand(42); - int i; - const cl_uint reference[16] = { 0x5fe1dc66, 0x8b255210, 0x0380b0c8, 0xc87d2ce4, - 0x55c31f24, 0x8bcd21ab, 0x14d5fef5, 0x9416d2b6, - 0xdf875de9, 0x00517d76, 0xd861c944, 0xa7676404, - 0x5491aff4, 0x67616209, 0xc368b3fb, 0x929dfc92 }; - int errcount = 0; - - for( i = 0; i < 65536; i++ ) - { - cl_uint u = genrand_int32( d ); - if( 0 == (i & 4095) ) - { - if( u != reference[i>>12] ) - { - printf("ERROR: expected *0x%8.8x at %d. Got 0x%8.8x\n", reference[i>>12], i, u ); - errcount++; - } - } - } - - free_mtdata(d); - - if( errcount ) - printf("mt19937 test failed.\n"); - else - printf("mt19937 test passed.\n"); - - - return 0; -} \ No newline at end of file diff --git a/test_conformance/compatibility/test_common/harness/threadTesting.h b/test_conformance/compatibility/test_common/harness/threadTesting.h deleted file mode 100644 index 81a5757b..00000000 --- a/test_conformance/compatibility/test_common/harness/threadTesting.h +++ /dev/null @@ -1,32 +0,0 @@ -// -// Copyright (c) 2017 The Khronos Group Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -#ifndef _threadTesting_h -#define _threadTesting_h - -#ifdef __APPLE__ - #include -#else - #include -#endif - -#define TEST_NOT_IMPLEMENTED -99 - -typedef int (*basefn)(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements); -extern int test_threaded_function( basefn fnToTest, cl_device_id device, cl_context context, cl_command_queue queue, int numElements ); - -#endif // _threadTesting_h - - diff --git a/test_conformance/compatibility/test_common/harness/typeWrappers.cpp b/test_conformance/compatibility/test_common/harness/typeWrappers.cpp deleted file mode 100644 index d4e08fb9..00000000 --- a/test_conformance/compatibility/test_common/harness/typeWrappers.cpp +++ /dev/null @@ -1,481 +0,0 @@ -// -// Copyright (c) 2017 The Khronos Group Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// -#include "typeWrappers.h" -#include "kernelHelpers.h" -#include "errorHelpers.h" -#include -#include "clImageHelper.h" - -#define ROUND_SIZE_UP( _size, _align ) (((size_t)(_size) + (size_t)(_align) - 1) & -((size_t)(_align))) - -#if defined( __APPLE__ ) - #define kPageSize 4096 - #include - #include -#elif defined(__linux__) - #include - #define kPageSize (getpagesize()) -#endif - -clProtectedImage::clProtectedImage( cl_context context, cl_mem_flags mem_flags, const cl_image_format *fmt, size_t width, cl_int *errcode_ret ) -{ - cl_int err = Create( context, mem_flags, fmt, width ); - if( errcode_ret != NULL ) - *errcode_ret = err; -} - -cl_int clProtectedImage::Create( cl_context context, cl_mem_flags mem_flags, const cl_image_format *fmt, size_t width ) -{ - cl_int error; -#if defined( __APPLE__ ) - int protect_pages = 1; - cl_device_id devices[16]; - size_t number_of_devices; - error = clGetContextInfo(context, CL_CONTEXT_DEVICES, sizeof(devices), devices, &number_of_devices); - test_error(error, "clGetContextInfo for CL_CONTEXT_DEVICES failed"); - - number_of_devices /= sizeof(cl_device_id); - for (int i=0; i<(int)number_of_devices; i++) { - cl_device_type type; - error = clGetDeviceInfo(devices[i], CL_DEVICE_TYPE, sizeof(type), &type, NULL); - test_error(error, "clGetDeviceInfo for CL_DEVICE_TYPE failed"); - if (type == CL_DEVICE_TYPE_GPU) { - protect_pages = 0; - break; - } - } - - if (protect_pages) { - size_t pixelBytes = get_pixel_bytes(fmt); - size_t rowBytes = ROUND_SIZE_UP( width * pixelBytes, kPageSize ); - size_t rowStride = rowBytes + kPageSize; - - // create backing store - backingStoreSize = rowStride + 8 * rowStride; - backingStore = mmap(0, backingStoreSize, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, 0, 0); - - // add guard pages - size_t row; - char *p = (char*) backingStore; - char *imagePtr = (char*) backingStore + 4 * rowStride; - for( row = 0; row < 4; row++ ) - { - mprotect( p, rowStride, PROT_NONE ); p += rowStride; - } - p += rowBytes; - mprotect( p, kPageSize, PROT_NONE ); p += rowStride; - p -= rowBytes; - for( row = 0; row < 4; row++ ) - { - mprotect( p, rowStride, PROT_NONE ); p += rowStride; - } - - if( getenv( "CL_ALIGN_RIGHT" ) ) - { - static int spewEnv = 1; - if(spewEnv) - { - log_info( "***CL_ALIGN_RIGHT is set. Aligning images at right edge of page\n" ); - spewEnv = 0; - } - imagePtr += rowBytes - pixelBytes * width; - } - - image = create_image_1d( context, mem_flags | CL_MEM_USE_HOST_PTR, fmt, width, rowStride, imagePtr, NULL, &error ); - } else { - backingStore = NULL; - image = create_image_1d( context, mem_flags, fmt, width, 0, NULL, NULL, &error ); - - } -#else - - backingStore = NULL; - image = create_image_1d( context, mem_flags, fmt, width, 0, NULL, NULL, &error ); - -#endif - return error; -} - - -clProtectedImage::clProtectedImage( cl_context context, cl_mem_flags mem_flags, const cl_image_format *fmt, size_t width, size_t height, cl_int *errcode_ret ) -{ - cl_int err = Create( context, mem_flags, fmt, width, height ); - if( errcode_ret != NULL ) - *errcode_ret = err; -} - -cl_int clProtectedImage::Create( cl_context context, cl_mem_flags mem_flags, const cl_image_format *fmt, size_t width, size_t height ) -{ - cl_int error; -#if defined( __APPLE__ ) - int protect_pages = 1; - cl_device_id devices[16]; - size_t number_of_devices; - error = clGetContextInfo(context, CL_CONTEXT_DEVICES, sizeof(devices), devices, &number_of_devices); - test_error(error, "clGetContextInfo for CL_CONTEXT_DEVICES failed"); - - number_of_devices /= sizeof(cl_device_id); - for (int i=0; i<(int)number_of_devices; i++) { - cl_device_type type; - error = clGetDeviceInfo(devices[i], CL_DEVICE_TYPE, sizeof(type), &type, NULL); - test_error(error, "clGetDeviceInfo for CL_DEVICE_TYPE failed"); - if (type == CL_DEVICE_TYPE_GPU) { - protect_pages = 0; - break; - } - } - - if (protect_pages) { - size_t pixelBytes = get_pixel_bytes(fmt); - size_t rowBytes = ROUND_SIZE_UP( width * pixelBytes, kPageSize ); - size_t rowStride = rowBytes + kPageSize; - - // create backing store - backingStoreSize = height * rowStride + 8 * rowStride; - backingStore = mmap(0, backingStoreSize, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, 0, 0); - - // add guard pages - size_t row; - char *p = (char*) backingStore; - char *imagePtr = (char*) backingStore + 4 * rowStride; - for( row = 0; row < 4; row++ ) - { - mprotect( p, rowStride, PROT_NONE ); p += rowStride; - } - p += rowBytes; - for( row = 0; row < height; row++ ) - { - mprotect( p, kPageSize, PROT_NONE ); p += rowStride; - } - p -= rowBytes; - for( row = 0; row < 4; row++ ) - { - mprotect( p, rowStride, PROT_NONE ); p += rowStride; - } - - if( getenv( "CL_ALIGN_RIGHT" ) ) - { - static int spewEnv = 1; - if(spewEnv) - { - log_info( "***CL_ALIGN_RIGHT is set. Aligning images at right edge of page\n" ); - spewEnv = 0; - } - imagePtr += rowBytes - pixelBytes * width; - } - - image = create_image_2d( context, mem_flags | CL_MEM_USE_HOST_PTR, fmt, width, height, rowStride, imagePtr, &error ); - } else { - backingStore = NULL; - image = create_image_2d( context, mem_flags, fmt, width, height, 0, NULL, &error ); - - } -#else - - backingStore = NULL; - image = create_image_2d( context, mem_flags, fmt, width, height, 0, NULL, &error ); - -#endif - return error; -} - -clProtectedImage::clProtectedImage( cl_context context, cl_mem_flags mem_flags, const cl_image_format *fmt, size_t width, size_t height, size_t depth, cl_int *errcode_ret ) -{ - cl_int err = Create( context, mem_flags, fmt, width, height, depth ); - if( errcode_ret != NULL ) - *errcode_ret = err; -} - -cl_int clProtectedImage::Create( cl_context context, cl_mem_flags mem_flags, const cl_image_format *fmt, size_t width, size_t height, size_t depth ) -{ - cl_int error; - -#if defined( __APPLE__ ) - int protect_pages = 1; - cl_device_id devices[16]; - size_t number_of_devices; - error = clGetContextInfo(context, CL_CONTEXT_DEVICES, sizeof(devices), devices, &number_of_devices); - test_error(error, "clGetContextInfo for CL_CONTEXT_DEVICES failed"); - - number_of_devices /= sizeof(cl_device_id); - for (int i=0; i<(int)number_of_devices; i++) { - cl_device_type type; - error = clGetDeviceInfo(devices[i], CL_DEVICE_TYPE, sizeof(type), &type, NULL); - test_error(error, "clGetDeviceInfo for CL_DEVICE_TYPE failed"); - if (type == CL_DEVICE_TYPE_GPU) { - protect_pages = 0; - break; - } - } - - if (protect_pages) { - size_t pixelBytes = get_pixel_bytes(fmt); - size_t rowBytes = ROUND_SIZE_UP( width * pixelBytes, kPageSize ); - size_t rowStride = rowBytes + kPageSize; - - // create backing store - backingStoreSize = height * depth * rowStride + 8 * rowStride; - backingStore = mmap(0, backingStoreSize, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, 0, 0); - - // add guard pages - size_t row; - char *p = (char*) backingStore; - char *imagePtr = (char*) backingStore + 4 * rowStride; - for( row = 0; row < 4; row++ ) - { - mprotect( p, rowStride, PROT_NONE ); p += rowStride; - } - p += rowBytes; - for( row = 0; row < height*depth; row++ ) - { - mprotect( p, kPageSize, PROT_NONE ); p += rowStride; - } - p -= rowBytes; - for( row = 0; row < 4; row++ ) - { - mprotect( p, rowStride, PROT_NONE ); p += rowStride; - } - - if( getenv( "CL_ALIGN_RIGHT" ) ) - { - static int spewEnv = 1; - if(spewEnv) - { - log_info( "***CL_ALIGN_RIGHT is set. Aligning images at right edge of page\n" ); - spewEnv = 0; - } - imagePtr += rowBytes - pixelBytes * width; - } - - image = create_image_3d( context, mem_flags | CL_MEM_USE_HOST_PTR, fmt, width, height, depth, rowStride, height*rowStride, imagePtr, &error ); - } else { - backingStore = NULL; - image = create_image_3d( context, mem_flags, fmt, width, height, depth, 0, 0, NULL, &error ); - } -#else - - backingStore = NULL; - image = create_image_3d( context, mem_flags, fmt, width, height, depth, 0, 0, NULL, &error ); - -#endif - - return error; -} - - -clProtectedImage::clProtectedImage( cl_context context, cl_mem_object_type imageType, cl_mem_flags mem_flags, const cl_image_format *fmt, size_t width, size_t height, size_t depth, size_t arraySize, cl_int *errcode_ret ) -{ - cl_int err = Create( context, imageType, mem_flags, fmt, width, height, depth, arraySize ); - if( errcode_ret != NULL ) - *errcode_ret = err; -} - -cl_int clProtectedImage::Create( cl_context context, cl_mem_object_type imageType, cl_mem_flags mem_flags, const cl_image_format *fmt, size_t width, size_t height, size_t depth, size_t arraySize ) -{ - cl_int error; -#if defined( __APPLE__ ) - int protect_pages = 1; - cl_device_id devices[16]; - size_t number_of_devices; - error = clGetContextInfo(context, CL_CONTEXT_DEVICES, sizeof(devices), devices, &number_of_devices); - test_error(error, "clGetContextInfo for CL_CONTEXT_DEVICES failed"); - - number_of_devices /= sizeof(cl_device_id); - for (int i=0; i<(int)number_of_devices; i++) { - cl_device_type type; - error = clGetDeviceInfo(devices[i], CL_DEVICE_TYPE, sizeof(type), &type, NULL); - test_error(error, "clGetDeviceInfo for CL_DEVICE_TYPE failed"); - if (type == CL_DEVICE_TYPE_GPU) { - protect_pages = 0; - break; - } - } - - if (protect_pages) { - size_t pixelBytes = get_pixel_bytes(fmt); - size_t rowBytes = ROUND_SIZE_UP( width * pixelBytes, kPageSize ); - size_t rowStride = rowBytes + kPageSize; - - // create backing store - switch (imageType) - { - case CL_MEM_OBJECT_IMAGE1D: - backingStoreSize = rowStride + 8 * rowStride; - break; - case CL_MEM_OBJECT_IMAGE2D: - backingStoreSize = height * rowStride + 8 * rowStride; - break; - case CL_MEM_OBJECT_IMAGE3D: - backingStoreSize = height * depth * rowStride + 8 * rowStride; - break; - case CL_MEM_OBJECT_IMAGE1D_ARRAY: - backingStoreSize = arraySize * rowStride + 8 * rowStride; - break; - case CL_MEM_OBJECT_IMAGE2D_ARRAY: - backingStoreSize = height * arraySize * rowStride + 8 * rowStride; - break; - } - backingStore = mmap(0, backingStoreSize, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, 0, 0); - - // add guard pages - size_t row; - char *p = (char*) backingStore; - char *imagePtr = (char*) backingStore + 4 * rowStride; - for( row = 0; row < 4; row++ ) - { - mprotect( p, rowStride, PROT_NONE ); p += rowStride; - } - p += rowBytes; - size_t sz = (height > 0 ? height : 1) * (depth > 0 ? depth : 1) * (arraySize > 0 ? arraySize : 1); - for( row = 0; row < sz; row++ ) - { - mprotect( p, kPageSize, PROT_NONE ); p += rowStride; - } - p -= rowBytes; - for( row = 0; row < 4; row++ ) - { - mprotect( p, rowStride, PROT_NONE ); p += rowStride; - } - - if( getenv( "CL_ALIGN_RIGHT" ) ) - { - static int spewEnv = 1; - if(spewEnv) - { - log_info( "***CL_ALIGN_RIGHT is set. Aligning images at right edge of page\n" ); - spewEnv = 0; - } - imagePtr += rowBytes - pixelBytes * width; - } - - switch (imageType) - { - case CL_MEM_OBJECT_IMAGE1D: - image = create_image_1d( context, mem_flags | CL_MEM_USE_HOST_PTR, fmt, width, rowStride, imagePtr, NULL, &error ); - break; - case CL_MEM_OBJECT_IMAGE2D: - image = create_image_2d( context, mem_flags | CL_MEM_USE_HOST_PTR, fmt, width, height, rowStride, imagePtr, &error ); - break; - case CL_MEM_OBJECT_IMAGE3D: - image = create_image_3d( context, mem_flags | CL_MEM_USE_HOST_PTR, fmt, width, height, depth, rowStride, height*rowStride, imagePtr, &error ); - break; - case CL_MEM_OBJECT_IMAGE1D_ARRAY: - image = create_image_1d_array( context, mem_flags | CL_MEM_USE_HOST_PTR, fmt, width, arraySize, rowStride, rowStride, imagePtr, &error ); - break; - case CL_MEM_OBJECT_IMAGE2D_ARRAY: - image = create_image_2d_array( context, mem_flags | CL_MEM_USE_HOST_PTR, fmt, width, height, arraySize, rowStride, height*rowStride, imagePtr, &error ); - break; - } - } else { - backingStore = NULL; - switch (imageType) - { - case CL_MEM_OBJECT_IMAGE1D: - image = create_image_1d( context, mem_flags, fmt, width, 0, NULL, NULL, &error ); - break; - case CL_MEM_OBJECT_IMAGE2D: - image = create_image_2d( context, mem_flags, fmt, width, height, 0, NULL, &error ); - break; - case CL_MEM_OBJECT_IMAGE3D: - image = create_image_3d( context, mem_flags, fmt, width, height, depth, 0, 0, NULL, &error );; - break; - case CL_MEM_OBJECT_IMAGE1D_ARRAY: - image = create_image_1d_array( context, mem_flags, fmt, width, arraySize, 0, 0, NULL, &error ); - break; - case CL_MEM_OBJECT_IMAGE2D_ARRAY: - image = create_image_2d_array( context, mem_flags, fmt, width, height, arraySize, 0, 0, NULL, &error ); - break; - } - - } -#else - - backingStore = NULL; - switch (imageType) - { - case CL_MEM_OBJECT_IMAGE1D: - image = create_image_1d( context, mem_flags, fmt, width, 0, NULL, NULL, &error ); - break; - case CL_MEM_OBJECT_IMAGE2D: - image = create_image_2d( context, mem_flags, fmt, width, height, 0, NULL, &error ); - break; - case CL_MEM_OBJECT_IMAGE3D: - image = create_image_3d( context, mem_flags, fmt, width, height, depth, 0, 0, NULL, &error );; - break; - case CL_MEM_OBJECT_IMAGE1D_ARRAY: - image = create_image_1d_array( context, mem_flags, fmt, width, arraySize, 0, 0, NULL, &error ); - break; - case CL_MEM_OBJECT_IMAGE2D_ARRAY: - image = create_image_2d_array( context, mem_flags, fmt, width, height, arraySize, 0, 0, NULL, &error ); - break; - } -#endif - return error; -} - - - -/******* - * clProtectedArray implementation - *******/ -clProtectedArray::clProtectedArray() -{ - mBuffer = mValidBuffer = NULL; -} - -clProtectedArray::clProtectedArray( size_t sizeInBytes ) -{ - mBuffer = mValidBuffer = NULL; - Allocate( sizeInBytes ); -} - -clProtectedArray::~clProtectedArray() -{ - if( mBuffer != NULL ) { -#if defined( __APPLE__ ) - int error = munmap( mBuffer, mRealSize ); - if (error) log_error("WARNING: munmap failed in clProtectedArray.\n"); -#else - free( mBuffer ); -#endif - } -} - -void clProtectedArray::Allocate( size_t sizeInBytes ) -{ - -#if defined( __APPLE__ ) - - // Allocate enough space to: round up our actual allocation to an even number of pages - // and allocate two pages on either side - mRoundedSize = ROUND_SIZE_UP( sizeInBytes, kPageSize ); - mRealSize = mRoundedSize + kPageSize * 2; - - // Use mmap here to ensure we start on a page boundary, so the mprotect calls will work OK - mBuffer = (char *)mmap(0, mRealSize, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, 0, 0); - - mValidBuffer = mBuffer + kPageSize; - - // Protect guard area from access - mprotect( mValidBuffer - kPageSize, kPageSize, PROT_NONE ); - mprotect( mValidBuffer + mRoundedSize, kPageSize, PROT_NONE ); -#else - mRoundedSize = mRealSize = sizeInBytes; - mBuffer = mValidBuffer = (char *)calloc(1, mRealSize); -#endif -} - - diff --git a/test_conformance/compatibility/test_conformance/api/CMakeLists.txt b/test_conformance/compatibility/test_conformance/api/CMakeLists.txt index 4af76989..8dfa2f2e 100644 --- a/test_conformance/compatibility/test_conformance/api/CMakeLists.txt +++ b/test_conformance/compatibility/test_conformance/api/CMakeLists.txt @@ -25,8 +25,8 @@ set(${MODULE_NAME}_SOURCES ../../test_common/harness/threadTesting.c ../../test_common/harness/testHarness.c ../../test_common/harness/kernelHelpers.c - ../../test_common/harness/typeWrappers.cpp - ../../test_common/harness/conversions.c + ../../../../test_common/harness/typeWrappers.cpp + ../../../../test_common/harness/conversions.c ../../test_common/harness/mt19937.c ../../test_common/harness/msvc9.c ../../test_common/harness/imageHelpers.cpp diff --git a/test_conformance/compatibility/test_conformance/basic/CMakeLists.txt b/test_conformance/compatibility/test_conformance/basic/CMakeLists.txt index d6a5fe65..0893596e 100644 --- a/test_conformance/compatibility/test_conformance/basic/CMakeLists.txt +++ b/test_conformance/compatibility/test_conformance/basic/CMakeLists.txt @@ -54,10 +54,10 @@ set(${MODULE_NAME}_SOURCES ../../test_common/harness/threadTesting.c ../../test_common/harness/testHarness.c ../../test_common/harness/kernelHelpers.c - ../../test_common/harness/typeWrappers.cpp + ../../../../test_common/harness/typeWrappers.cpp ../../test_common/harness/imageHelpers.cpp ../../test_common/harness/mt19937.c - ../../test_common/harness/conversions.c + ../../../../test_common/harness/conversions.c ../../test_common/harness/rounding_mode.c ../../test_common/harness/msvc9.c )