// // 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 "harness/compat.h" #include #include #include #include #include #include "testBase.h" #include "harness/errorHelpers.h" #define TEST_PRIME_INT ((1<<16)+1) #define TEST_PRIME_UINT ((1U<<16)+1U) #define TEST_PRIME_LONG ((1LL<<32)+1LL) #define TEST_PRIME_ULONG ((1ULL<<32)+1ULL) #define TEST_PRIME_SHORT ((1S<<8)+1S) #define TEST_PRIME_FLOAT (float)3.40282346638528860e+38 #define TEST_PRIME_HALF 119.f #define TEST_BOOL true #define TEST_PRIME_CHAR 0x77 #ifndef TestStruct typedef struct{ int a; float b; } TestStruct; #endif //--- the code for the kernel executables static const char *buffer_read_int_kernel_code[] = { "__kernel void test_buffer_read_int(__global int *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = ((1<<16)+1);\n" "}\n", "__kernel void test_buffer_read_int2(__global int2 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = ((1<<16)+1);\n" "}\n", "__kernel void test_buffer_read_int4(__global int4 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = ((1<<16)+1);\n" "}\n", "__kernel void test_buffer_read_int8(__global int8 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = ((1<<16)+1);\n" "}\n", "__kernel void test_buffer_read_int16(__global int16 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = ((1<<16)+1);\n" "}\n" }; static const char *int_kernel_name[] = { "test_buffer_read_int", "test_buffer_read_int2", "test_buffer_read_int4", "test_buffer_read_int8", "test_buffer_read_int16" }; static const char *buffer_read_uint_kernel_code[] = { "__kernel void test_buffer_read_uint(__global uint *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = ((1U<<16)+1U);\n" "}\n", "__kernel void test_buffer_read_uint2(__global uint2 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = ((1U<<16)+1U);\n" "}\n", "__kernel void test_buffer_read_uint4(__global uint4 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = ((1U<<16)+1U);\n" "}\n", "__kernel void test_buffer_read_uint8(__global uint8 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = ((1U<<16)+1U);\n" "}\n", "__kernel void test_buffer_read_uint16(__global uint16 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = ((1U<<16)+1U);\n" "}\n" }; static const char *uint_kernel_name[] = { "test_buffer_read_uint", "test_buffer_read_uint2", "test_buffer_read_uint4", "test_buffer_read_uint8", "test_buffer_read_uint16" }; static const char *buffer_read_long_kernel_code[] = { "__kernel void test_buffer_read_long(__global long *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = ((1L<<32)+1L);\n" "}\n", "__kernel void test_buffer_read_long2(__global long2 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = ((1L<<32)+1L);\n" "}\n", "__kernel void test_buffer_read_long4(__global long4 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = ((1L<<32)+1L);\n" "}\n", "__kernel void test_buffer_read_long8(__global long8 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = ((1L<<32)+1L);\n" "}\n", "__kernel void test_buffer_read_long16(__global long16 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = ((1L<<32)+1L);\n" "}\n" }; static const char *long_kernel_name[] = { "test_buffer_read_long", "test_buffer_read_long2", "test_buffer_read_long4", "test_buffer_read_long8", "test_buffer_read_long16" }; static const char *buffer_read_ulong_kernel_code[] = { "__kernel void test_buffer_read_ulong(__global ulong *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = ((1UL<<32)+1UL);\n" "}\n", "__kernel void test_buffer_read_ulong2(__global ulong2 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = ((1UL<<32)+1UL);\n" "}\n", "__kernel void test_buffer_read_ulong4(__global ulong4 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = ((1UL<<32)+1UL);\n" "}\n", "__kernel void test_buffer_read_ulong8(__global ulong8 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = ((1UL<<32)+1UL);\n" "}\n", "__kernel void test_buffer_read_ulong16(__global ulong16 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = ((1UL<<32)+1UL);\n" "}\n" }; static const char *ulong_kernel_name[] = { "test_buffer_read_ulong", "test_buffer_read_ulong2", "test_buffer_read_ulong4", "test_buffer_read_ulong8", "test_buffer_read_ulong16" }; static const char *buffer_read_short_kernel_code[] = { "__kernel void test_buffer_read_short(__global short *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = (short)((1<<8)+1);\n" "}\n", "__kernel void test_buffer_read_short2(__global short2 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = (short)((1<<8)+1);\n" "}\n", "__kernel void test_buffer_read_short4(__global short4 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = (short)((1<<8)+1);\n" "}\n", "__kernel void test_buffer_read_short8(__global short8 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = (short)((1<<8)+1);\n" "}\n", "__kernel void test_buffer_read_short16(__global short16 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = (short)((1<<8)+1);\n" "}\n" }; static const char *short_kernel_name[] = { "test_buffer_read_short", "test_buffer_read_short2", "test_buffer_read_short4", "test_buffer_read_short8", "test_buffer_read_short16" }; static const char *buffer_read_ushort_kernel_code[] = { "__kernel void test_buffer_read_ushort(__global ushort *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = (ushort)((1<<8)+1);\n" "}\n", "__kernel void test_buffer_read_ushort2(__global ushort2 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = (ushort)((1<<8)+1);\n" "}\n", "__kernel void test_buffer_read_ushort4(__global ushort4 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = (ushort)((1<<8)+1);\n" "}\n", "__kernel void test_buffer_read_ushort8(__global ushort8 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = (ushort)((1<<8)+1);\n" "}\n", "__kernel void test_buffer_read_ushort16(__global ushort16 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = (ushort)((1<<8)+1);\n" "}\n" }; static const char *ushort_kernel_name[] = { "test_buffer_read_ushort", "test_buffer_read_ushort2", "test_buffer_read_ushort4", "test_buffer_read_ushort8", "test_buffer_read_ushort16" }; static const char *buffer_read_float_kernel_code[] = { "__kernel void test_buffer_read_float(__global float *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = (float)3.40282346638528860e+38;\n" "}\n", "__kernel void test_buffer_read_float2(__global float2 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = (float)3.40282346638528860e+38;\n" "}\n", "__kernel void test_buffer_read_float4(__global float4 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = (float)3.40282346638528860e+38;\n" "}\n", "__kernel void test_buffer_read_float8(__global float8 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = (float)3.40282346638528860e+38;\n" "}\n", "__kernel void test_buffer_read_float16(__global float16 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = (float)3.40282346638528860e+38;\n" "}\n" }; static const char *float_kernel_name[] = { "test_buffer_read_float", "test_buffer_read_float2", "test_buffer_read_float4", "test_buffer_read_float8", "test_buffer_read_float16" }; static const char *buffer_read_char_kernel_code[] = { "__kernel void test_buffer_read_char(__global char *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = (char)'w';\n" "}\n", "__kernel void test_buffer_read_char2(__global char2 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = (char)'w';\n" "}\n", "__kernel void test_buffer_read_char4(__global char4 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = (char)'w';\n" "}\n", "__kernel void test_buffer_read_char8(__global char8 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = (char)'w';\n" "}\n", "__kernel void test_buffer_read_char16(__global char16 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = (char)'w';\n" "}\n" }; static const char *char_kernel_name[] = { "test_buffer_read_char", "test_buffer_read_char2", "test_buffer_read_char4", "test_buffer_read_char8", "test_buffer_read_char16" }; static const char *buffer_read_uchar_kernel_code[] = { "__kernel void test_buffer_read_uchar(__global uchar *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = 'w';\n" "}\n", "__kernel void test_buffer_read_uchar2(__global uchar2 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = (uchar)'w';\n" "}\n", "__kernel void test_buffer_read_uchar4(__global uchar4 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = (uchar)'w';\n" "}\n", "__kernel void test_buffer_read_uchar8(__global uchar8 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = (uchar)'w';\n" "}\n", "__kernel void test_buffer_read_uchar16(__global uchar16 *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid] = (uchar)'w';\n" "}\n" }; static const char *uchar_kernel_name[] = { "test_buffer_read_uchar", "test_buffer_read_uchar2", "test_buffer_read_uchar4", "test_buffer_read_uchar8", "test_buffer_read_uchar16" }; static const char *buffer_read_struct_kernel_code[] = { "typedef struct{\n" "int a;\n" "float b;\n" "} TestStruct;\n" "__kernel void test_buffer_read_struct(__global TestStruct *dst)\n" "{\n" " int tid = get_global_id(0);\n" "\n" " dst[tid].a = ((1<<16)+1);\n" " dst[tid].b = (float)3.40282346638528860e+38;\n" "}\n" }; static const char *struct_kernel_name[] = { "test_buffer_read_struct" }; //--- the verify functions static int verify_read_int(void *ptr, int n) { int i; int *outptr = (int *)ptr; for (i=0; i 0 ? TEST_FAIL : TEST_PASS; } #define DECLARE_LOCK_TEST(type, realType) \ REGISTER_TEST(buffer_map_read_##type) \ { \ return test_buffer_map_read(device, context, queue, num_elements, \ sizeof(realType), (char *)#type, 5, \ buffer_read_##type##_kernel_code, \ type##_kernel_name, verify_read_##type); \ } DECLARE_LOCK_TEST(int, cl_int) DECLARE_LOCK_TEST(uint, cl_uint) DECLARE_LOCK_TEST(long, cl_long) DECLARE_LOCK_TEST(ulong, cl_ulong) DECLARE_LOCK_TEST(short, cl_short) DECLARE_LOCK_TEST(ushort, cl_ushort) DECLARE_LOCK_TEST(char, cl_char) DECLARE_LOCK_TEST(uchar, cl_uchar) DECLARE_LOCK_TEST(float, cl_float) #undef DECLARE_LOCK_TEST #define DECLARE_LOCK_TEST(type, realType) \ REGISTER_TEST(immutable_buffer_map_##type) \ { \ return test_immutable_buffer_map(device, context, queue, num_elements, \ sizeof(realType), #type, 5); \ } DECLARE_LOCK_TEST(int, cl_int) DECLARE_LOCK_TEST(uint, cl_uint) DECLARE_LOCK_TEST(long, cl_long) DECLARE_LOCK_TEST(ulong, cl_ulong) DECLARE_LOCK_TEST(short, cl_short) DECLARE_LOCK_TEST(ushort, cl_ushort) DECLARE_LOCK_TEST(char, cl_char) DECLARE_LOCK_TEST(uchar, cl_uchar) DECLARE_LOCK_TEST(float, cl_float) #undef DECLARE_LOCK_TEST REGISTER_TEST(buffer_map_read_struct) { int (*foo)(void *,int); foo = verify_read_struct; return test_buffer_map_read(device, context, queue, num_elements, sizeof(TestStruct), (char *)"struct", 1, buffer_read_struct_kernel_code, struct_kernel_name, foo); } // end test_buffer_map_struct_read()