Skip to content

Commit

Permalink
Added cl_khr_fp16 extension support for test_fpmath from basic (Khron…
Browse files Browse the repository at this point in the history
…osGroup#1718)

* Added half and double support for fpmath test from basic (issue KhronosGroup#142, basic)

* Cosmetic corrections due to code review

* Removed unnecessary casting

* Added corrections due to code review

* Tuning range of input generation to avoid hitting infinity

* Moved string helpers procedures due to request from test_commonfns PR KhronosGroup#1695
  • Loading branch information
shajder authored Jun 20, 2023
1 parent 44b2578 commit 0e229b8
Show file tree
Hide file tree
Showing 7 changed files with 427 additions and 211 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion test_conformance/basic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ set(MODULE_NAME BASIC)

set(${MODULE_NAME}_SOURCES
main.cpp
test_fpmath_float.cpp
test_fpmath.cpp
test_intmath.cpp
test_hiloeo.cpp test_local.cpp test_pointercast.cpp
test_if.cpp test_loop.cpp
Expand Down
37 changes: 32 additions & 5 deletions test_conformance/basic/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// 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.
Expand All @@ -22,14 +22,15 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <CL/cl_half.h>

#include "harness/testHarness.h"
#include "procs.h"

test_definition test_list[] = {
ADD_TEST(hostptr),
ADD_TEST(fpmath_float),
ADD_TEST(fpmath_float2),
ADD_TEST(fpmath_float4),
ADD_TEST(fpmath),
ADD_TEST(intmath_int),
ADD_TEST(intmath_int2),
ADD_TEST(intmath_int4),
Expand Down Expand Up @@ -164,9 +165,35 @@ test_definition test_list[] = {
};

const int test_num = ARRAY_SIZE( test_list );
cl_half_rounding_mode halfRoundingMode = CL_HALF_RTE;

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)
{
halfRoundingMode = CL_HALF_RTE;
}
else if ((fpConfigHalf & CL_FP_ROUND_TO_ZERO) != 0)
{
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[])
{
return runTestHarness(argc, argv, test_num, test_list, false, 0);
return runTestHarnessWithCheck(argc, argv, test_num, test_list, false, 0,
InitCL);
}

10 changes: 5 additions & 5 deletions test_conformance/basic/procs.h
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,6 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//

#include "harness/kernelHelpers.h"
#include "harness/testHarness.h"
#include "harness/errorHelpers.h"
Expand All @@ -21,9 +22,8 @@
#include "harness/rounding_mode.h"

extern int test_hostptr(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
extern int test_fpmath_float(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
extern int test_fpmath_float2(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
extern int test_fpmath_float4(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
extern int test_fpmath(cl_device_id deviceID, cl_context context,
cl_command_queue queue, int num_elements);
extern int test_intmath_int(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
extern int test_intmath_int2(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
extern int test_intmath_int4(cl_device_id deviceID, cl_context context, cl_command_queue queue, int num_elements);
Expand Down
7 changes: 3 additions & 4 deletions test_conformance/basic/test_astype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
// limitations under the License.
//
#include "harness/compat.h"
#include "harness/conversions.h"
#include "harness/stringHelpers.h"
#include "harness/typeWrappers.h"

#include <limits.h>
#include <stdio.h>
Expand All @@ -22,11 +25,7 @@
#include <sys/stat.h>
#include <vector>

#include "harness/conversions.h"
#include "harness/typeWrappers.h"

#include "procs.h"
#include "utils.h"

// clang-format off

Expand Down
Loading

0 comments on commit 0e229b8

Please sign in to comment.