Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added cl_half support for test_select #1617

Merged
merged 6 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 32 additions & 21 deletions test_conformance/select/test_select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ static cl_program makeSelectProgram(cl_kernel *kernel_ptr, const cl_context cont
if (srctype == kdouble)
strcpy( extension, "#pragma OPENCL EXTENSION cl_khr_fp64 : enable\n" );

if (srctype == khalf)
strcpy(extension, "#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n");

// create type name and testname
switch( vec_len )
{
Expand Down Expand Up @@ -315,12 +318,19 @@ static int doTest(cl_command_queue queue, cl_context context, Type stype, Type c
cl_program programs[VECTOR_SIZE_COUNT];
cl_kernel kernels[VECTOR_SIZE_COUNT];

if(stype == kdouble && ! is_extension_available( device, "cl_khr_fp64" ))
if (stype == kdouble && !is_extension_available(device, "cl_khr_fp64"))
{
log_info("Skipping double because cl_khr_fp64 extension is not supported.\n");
return 0;
}

if (stype == khalf && !is_extension_available(device, "cl_khr_fp16"))
{
log_info(
"Skipping half because cl_khr_fp16 extension is not supported.\n");
return 0;
}

if (gIsEmbedded)
{
if (( stype == klong || stype == kulong ) && ! is_extension_available( device, "cles_khr_int64" ))
Expand Down Expand Up @@ -506,6 +516,16 @@ int test_select_short_short(cl_device_id deviceID, cl_context context, cl_comman
{
return doTest(queue, context, kshort, kshort, deviceID);
}
int test_select_half_ushort(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements)
{
return doTest(queue, context, khalf, kushort, deviceID);
}
int test_select_half_short(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements)
{
return doTest(queue, context, khalf, kshort, deviceID);
}
int test_select_uint_uint(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements)
{
return doTest(queue, context, kuint, kuint, deviceID);
Expand Down Expand Up @@ -556,26 +576,17 @@ int test_select_double_long(cl_device_id deviceID, cl_context context, cl_comman
}

test_definition test_list[] = {
ADD_TEST( select_uchar_uchar ),
ADD_TEST( select_uchar_char ),
ADD_TEST( select_char_uchar ),
ADD_TEST( select_char_char ),
ADD_TEST( select_ushort_ushort ),
ADD_TEST( select_ushort_short ),
ADD_TEST( select_short_ushort ),
ADD_TEST( select_short_short ),
ADD_TEST( select_uint_uint ),
ADD_TEST( select_uint_int ),
ADD_TEST( select_int_uint ),
ADD_TEST( select_int_int ),
ADD_TEST( select_float_uint ),
ADD_TEST( select_float_int ),
ADD_TEST( select_ulong_ulong ),
ADD_TEST( select_ulong_long ),
ADD_TEST( select_long_ulong ),
ADD_TEST( select_long_long ),
ADD_TEST( select_double_ulong ),
ADD_TEST( select_double_long ),
ADD_TEST(select_uchar_uchar), ADD_TEST(select_uchar_char),
ADD_TEST(select_char_uchar), ADD_TEST(select_char_char),
ADD_TEST(select_ushort_ushort), ADD_TEST(select_ushort_short),
ADD_TEST(select_short_ushort), ADD_TEST(select_short_short),
ADD_TEST(select_half_ushort), ADD_TEST(select_half_short),
ADD_TEST(select_uint_uint), ADD_TEST(select_uint_int),
ADD_TEST(select_int_uint), ADD_TEST(select_int_int),
ADD_TEST(select_float_uint), ADD_TEST(select_float_int),
ADD_TEST(select_ulong_ulong), ADD_TEST(select_ulong_long),
ADD_TEST(select_long_ulong), ADD_TEST(select_long_long),
ADD_TEST(select_double_ulong), ADD_TEST(select_double_long),
};

const int test_num = ARRAY_SIZE( test_list );
Expand Down
18 changes: 10 additions & 8 deletions test_conformance/select/test_select.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,20 @@
#endif

// Defines the set of types we support (no support for double)
typedef enum {
typedef enum
{
kuchar = 0,
kchar = 1,
kushort = 2,
kshort = 3,
kuint = 4,
kint = 5,
kfloat = 6,
kulong = 7,
klong = 8,
kdouble = 9,
kTypeCount // always goes last
khalf = 4,
kuint = 5,
kint = 6,
kfloat = 7,
shajder marked this conversation as resolved.
Show resolved Hide resolved
kulong = 8,
klong = 9,
kdouble = 10,
kTypeCount // always goes last
} Type;


Expand Down
135 changes: 103 additions & 32 deletions test_conformance/select/util_select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "harness/compat.h"
#include "harness/errorHelpers.h"

#include <stdio.h>
Expand All @@ -25,29 +24,28 @@
//-----------------------------------------


const char *type_name[kTypeCount] = {
"uchar", "char",
"ushort", "short",
"uint", "int",
"float", "ulong", "long", "double" };
const char *type_name[kTypeCount] = { "uchar", "char", "ushort", "short",
"half", "uint", "int", "float",
"ulong", "long", "double" };

const size_t type_size[kTypeCount] = {
sizeof(cl_uchar), sizeof(cl_char),
sizeof(cl_ushort), sizeof(cl_short),
sizeof(cl_uint), sizeof(cl_int),
sizeof(cl_float), sizeof(cl_ulong), sizeof(cl_long), sizeof( cl_double ) };
sizeof(cl_uchar), sizeof(cl_char), sizeof(cl_ushort), sizeof(cl_short),
sizeof(cl_half), sizeof(cl_uint), sizeof(cl_int), sizeof(cl_float),
sizeof(cl_ulong), sizeof(cl_long), sizeof(cl_double)
};

const Type ctype[kTypeCount][2] = {
{ kuchar, kchar }, // uchar
{ kuchar, kchar }, // char
{ kushort, kshort}, // ushort
{ kushort, kshort}, // short
{ kuint, kint }, // uint
{ kuint, kint }, // int
{ kuint, kint }, // float
{ kulong, klong }, // ulong
{ kulong, klong }, // long
{ kulong, klong } // double
{ kuchar, kchar }, // uchar
{ kuchar, kchar }, // char
{ kushort, kshort }, // ushort
{ kushort, kshort }, // short
{ kushort, kshort }, // half
{ kuint, kint }, // uint
{ kuint, kint }, // int
{ kuint, kint }, // float
{ kulong, klong }, // ulong
{ kulong, klong }, // long
{ kulong, klong } // double
};


Expand Down Expand Up @@ -242,6 +240,28 @@ void refselect_1u64u(void *dest, void *src1, void *src2, void *cmp, size_t count
d[i] = m[i] ? y[i] : x[i];
}

void refselect_hhi(void *dest, void *src1, void *src2, void *cmp, size_t count)
{
size_t i;
cl_short *d, *x, *y, *m;
d = (cl_short *)dest;
shajder marked this conversation as resolved.
Show resolved Hide resolved
x = (cl_short *)src1;
y = (cl_short *)src2;
m = (cl_short *)cmp;
for (i = 0; i < count; ++i) d[i] = m[i] ? y[i] : x[i];
}

void refselect_hhu(void *dest, void *src1, void *src2, void *cmp, size_t count)
{
size_t i;
cl_ushort *d, *x, *y, *m;
d = (cl_ushort *)dest;
x = (cl_ushort *)src1;
y = (cl_ushort *)src2;
m = (cl_ushort *)cmp;
for (i = 0; i < count; ++i) d[i] = m[i] ? y[i] : x[i];
}

void refselect_ffi(void *dest, void *src1, void *src2, void *cmp, size_t count) {
size_t i;
cl_int *d, *x, *y;
Expand Down Expand Up @@ -476,6 +496,29 @@ void vrefselect_1u64u(void *dest, void *src1, void *src2, void *cmp, size_t coun
d[i] = (m[i] & 0x8000000000000000ULL) ? y[i] : x[i];
}

void vrefselect_hhi(void *dest, void *src1, void *src2, void *cmp, size_t count)
{
size_t i;
cl_ushort *d, *x, *y;
cl_short *m;
d = (cl_ushort *)dest;
x = (cl_ushort *)src1;
y = (cl_ushort *)src2;
m = (cl_short *)cmp;
for (i = 0; i < count; ++i) d[i] = (m[i] & 0x8000) ? y[i] : x[i];
}

void vrefselect_hhu(void *dest, void *src1, void *src2, void *cmp, size_t count)
{
size_t i;
cl_ushort *d, *x, *y, *m;
d = (cl_ushort *)dest;
x = (cl_ushort *)src1;
y = (cl_ushort *)src2;
m = (cl_ushort *)cmp;
for (i = 0; i < count; ++i) d[i] = (m[i] & 0x8000U) ? y[i] : x[i];
}

void vrefselect_ffi(void *dest, void *src1, void *src2, void *cmp, size_t count) {
size_t i;
cl_uint *d, *x, *y;
Expand Down Expand Up @@ -525,31 +568,33 @@ void vrefselect_ddu(void *dest, void *src1, void *src2, void *cmp, size_t count)
}

// Define refSelects
Select refSelects[kTypeCount][2] = {
{ refselect_1u8u, refselect_1u8 }, // cl_uchar
{ refselect_1i8u, refselect_1i8 }, // char
Select refSelects[kTypeCount][2] = {
{ refselect_1u8u, refselect_1u8 }, // cl_uchar
{ refselect_1i8u, refselect_1i8 }, // char
{ refselect_1u16u, refselect_1u16 }, // ushort
{ refselect_1i16u, refselect_1i16 }, // short
{ refselect_hhu, refselect_hhi }, // half
{ refselect_1u32u, refselect_1u32 }, // uint
{ refselect_1i32u, refselect_1i32 }, // int
{ refselect_ffu, refselect_ffi }, // float
{ refselect_ffu, refselect_ffi }, // float
{ refselect_1u64u, refselect_1u64 }, // ulong
{ refselect_1i64u, refselect_1i64 }, // long
{ refselect_ddu, refselect_ddi } // double
{ refselect_ddu, refselect_ddi } // double
};

// Define vrefSelects (vector refSelects)
Select vrefSelects[kTypeCount][2] = {
{ vrefselect_1u8u, vrefselect_1u8 }, // cl_uchar
{ vrefselect_1i8u, vrefselect_1i8 }, // char
Select vrefSelects[kTypeCount][2] = {
{ vrefselect_1u8u, vrefselect_1u8 }, // cl_uchar
{ vrefselect_1i8u, vrefselect_1i8 }, // char
{ vrefselect_1u16u, vrefselect_1u16 }, // ushort
{ vrefselect_1i16u, vrefselect_1i16 }, // short
{ vrefselect_hhu, vrefselect_hhi }, // half
{ vrefselect_1u32u, vrefselect_1u32 }, // uint
{ vrefselect_1i32u, vrefselect_1i32 }, // int
{ vrefselect_ffu, vrefselect_ffi }, // float
{ vrefselect_ffu, vrefselect_ffi }, // float
{ vrefselect_1u64u, vrefselect_1u64 }, // ulong
{ vrefselect_1i64u, vrefselect_1i64 }, // long
{ vrefselect_ddu, vrefselect_ddi } // double
{ vrefselect_ddu, vrefselect_ddi } // double
};


Expand Down Expand Up @@ -724,6 +769,30 @@ size_t check_long(void *test, void *correct, size_t count, size_t vector_size) {
return 0;
}

size_t check_half(void *test, void *correct, size_t count, size_t vector_size)
{
const cl_ushort *t = (const cl_ushort *)test;
shajder marked this conversation as resolved.
Show resolved Hide resolved
const cl_ushort *c = (const cl_ushort *)correct;
size_t i;

if (memcmp(t, c, count * sizeof(c[0])) != 0)
{
for (i = 0; i < count; i++) /* Allow nans to be binary different */
if ((t[i] != c[i])
&& !(isnan(((cl_half *)correct)[i])
&& isnan(((cl_half *)test)[i])))
{
log_error("\n(check_half) Error for vector size %ld found at "
"0x%8.8lx (of 0x%8.8lx): "
"*0x%4.4x vs 0x%4.4x\n",
vector_size, i, count, c[i], t[i]);
return i + 1;
}
}

return 0;
}

size_t check_float( void *test, void *correct, size_t count, size_t vector_size ) {
const cl_uint *t = (const cl_uint *) test;
const cl_uint *c = (const cl_uint *) correct;
Expand Down Expand Up @@ -770,5 +839,7 @@ size_t check_double( void *test, void *correct, size_t count, size_t vector_size
}

CheckResults checkResults[kTypeCount] = {
check_uchar, check_char, check_ushort, check_short, check_uint,
check_int, check_float, check_ulong, check_long, check_double };
check_uchar, check_char, check_ushort, check_short,
check_half, check_uint, check_int, check_float,
check_ulong, check_long, check_double
};