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_commonfns #1695

Merged
merged 15 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
14 changes: 1 addition & 13 deletions test_conformance/commonfns/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,10 @@ set(MODULE_NAME COMMONFNS)
set(${MODULE_NAME}_SOURCES
main.cpp
test_clamp.cpp
test_degrees.cpp
test_max.cpp
test_maxf.cpp
test_min.cpp
test_minf.cpp
test_unary_fn.cpp
test_mix.cpp
test_radians.cpp
test_step.cpp
test_stepf.cpp
test_smoothstep.cpp
test_smoothstepf.cpp
test_sign.cpp
test_fmax.cpp
test_fmin.cpp
test_fmaxf.cpp
test_fminf.cpp
test_binary_fn.cpp
)

Expand Down
74 changes: 52 additions & 22 deletions test_conformance/commonfns/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// Copyright (c) 2017 The Khronos Group Inc.
//
// Copyright (c) 2023 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
Expand All @@ -13,15 +13,20 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include "harness/compat.h"

#include <stdio.h>
#include <string.h>
#include "procs.h"
#include "test_base.h"
#include "harness/kernelHelpers.h"

std::map<size_t, std::string> BaseFunctionTest::type2name;
cl_half_rounding_mode BaseFunctionTest::halfRoundingMode = CL_HALF_RTE;

int g_arrVecSizes[kVectorSizeCount + kStrangeVectorSizeCount];
int g_arrStrangeVectorSizes[kStrangeVectorSizeCount] = {3};

//--------------------------------------------------------------------------
static void initVecSizes() {
int i;
for(i = 0; i < kVectorSizeCount; ++i) {
Expand All @@ -32,32 +37,57 @@ static void initVecSizes() {
}
}


//--------------------------------------------------------------------------
test_definition test_list[] = {
ADD_TEST( clamp ),
ADD_TEST( degrees ),
ADD_TEST( fmax ),
ADD_TEST( fmaxf ),
ADD_TEST( fmin ),
ADD_TEST( fminf ),
ADD_TEST( max ),
ADD_TEST( maxf ),
ADD_TEST( min ),
ADD_TEST( minf ),
ADD_TEST( mix ),
ADD_TEST( radians ),
ADD_TEST( step ),
ADD_TEST( stepf ),
ADD_TEST( smoothstep ),
ADD_TEST( smoothstepf ),
ADD_TEST( sign ),
ADD_TEST(clamp), ADD_TEST(degrees), ADD_TEST(fmax),
ADD_TEST(fmaxf), ADD_TEST(fmin), ADD_TEST(fminf),
ADD_TEST(max), ADD_TEST(maxf), ADD_TEST(min),
ADD_TEST(minf), ADD_TEST(mix), ADD_TEST(mixf),
ADD_TEST(radians), ADD_TEST(step), ADD_TEST(stepf),
ADD_TEST(smoothstep), ADD_TEST(smoothstepf), ADD_TEST(sign),
};

const int test_num = ARRAY_SIZE( test_list );

//--------------------------------------------------------------------------
test_status InitCL(cl_device_id device)
{
if (is_extension_available(device, "cl_khr_fp16"))
{
const cl_device_fp_config fpConfigHalf =
get_default_rounding_mode(device, CL_DEVICE_HALF_FP_CONFIG);
if ((fpConfigHalf & CL_FP_ROUND_TO_NEAREST) != 0)
{
BaseFunctionTest::halfRoundingMode = CL_HALF_RTE;
}
else if ((fpConfigHalf & CL_FP_ROUND_TO_ZERO) != 0)
{
BaseFunctionTest::halfRoundingMode = CL_HALF_RTZ;
}
else
{
log_error("Error while acquiring half rounding mode");
return TEST_FAIL;
}
}

return TEST_PASS;
}

//--------------------------------------------------------------------------
int main(int argc, const char *argv[])
{
initVecSizes();
return runTestHarness(argc, argv, test_num, test_list, false, 0);

if (BaseFunctionTest::type2name.empty())
EwanC marked this conversation as resolved.
Show resolved Hide resolved
{
BaseFunctionTest::type2name[sizeof(half)] = "half";
BaseFunctionTest::type2name[sizeof(float)] = "float";
BaseFunctionTest::type2name[sizeof(double)] = "double";
}

return runTestHarnessWithCheck(argc, argv, test_num, test_list, false, 0,
InitCL);
}

//--------------------------------------------------------------------------
9 changes: 2 additions & 7 deletions test_conformance/commonfns/procs.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,13 @@ extern int test_maxf(cl_device_id device, cl_context context, cl_command_
extern int test_min(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements);
extern int test_minf(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements);
extern int test_mix(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements);
extern int test_mixf(cl_device_id device, cl_context context,
cl_command_queue queue, int num_elements);
extern int test_radians(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements);
extern int test_step(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements);
extern int test_stepf(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements);
extern int test_smoothstep(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements);
extern int test_smoothstepf(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements);
extern int test_sign(cl_device_id device, cl_context context, cl_command_queue queue, int num_elements);

typedef int (*binary_verify_float_fn)( float *x, float *y, float *out, int numElements, int vecSize );
typedef int (*binary_verify_double_fn)( double *x, double *y, double *out, int numElements, int vecSize );

extern int test_binary_fn( cl_device_id device, cl_context context, cl_command_queue queue, int n_elems,
const char *fnName, bool vectorSecondParam,
binary_verify_float_fn floatVerifyFn, binary_verify_double_fn doubleVerifyFn );


Loading