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_khr_fp16 extension support for test_explicit_s2v from basic #1713

Merged
merged 13 commits into from
Oct 17, 2023
24 changes: 10 additions & 14 deletions test_conformance/basic/test_explicit_s2v.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include <cmath>
#define isnan std::isnan
bashbaug marked this conversation as resolved.
Show resolved Hide resolved
#include "harness/compat.h"

#include <stdio.h>
Expand Down Expand Up @@ -98,16 +100,6 @@ const char * kernel_explicit_s2v_set[NUM_VEC_TYPES][NUM_VEC_TYPES][5] = {

// clang-format on

int IsFloatNaN(double x)
{
union {
cl_float d;
cl_uint u;
} u;
u.d = (cl_float)x;
return ((u.u & 0x7fffffffU) > 0x7F800000U);
}

bool IsHalfNaN(cl_half v)
{
// Extract FP16 exponent and mantissa
Expand Down Expand Up @@ -179,10 +171,14 @@ int test_explicit_s2v_function(cl_context context, cl_command_queue queue,
{
if( memcmp( convertedData, outPtr + destTypeSize * s, destTypeSize ) != 0 )
{
if ((srcType == kHalf) && (destType == kFloat)
&& IsHalfNaN(*reinterpret_cast<cl_half *>(inPtr))
&& IsFloatNaN(*reinterpret_cast<cl_float *>(
outPtr + destTypeSize * s)))
bool isSrcNaN = (((srcType == kHalf) && IsHalfNaN(*reinterpret_cast<cl_half *>(inPtr)))
|| ((srcType == kFloat) && isnan(*reinterpret_cast<cl_float *>(inPtr)))
|| ((srcType == kDouble) && isnan(*reinterpret_cast<cl_double *>(inPtr))));
bool isDestNaN = (((destType == kHalf) && IsHalfNaN(*reinterpret_cast<cl_half *>(outPtr + destTypeSize * s)))
|| ((destType == kFloat) && isnan(*reinterpret_cast<cl_float *>(outPtr + destTypeSize * s)))
|| ((destType == kDouble) && isnan(*reinterpret_cast<cl_double *>(outPtr + destTypeSize * s))));

if (isSrcNaN && isDestNaN)
{
continue;
}
Expand Down
Loading