aboutsummaryrefslogtreecommitdiff
path: root/test_conformance/commonfns/main.cpp
blob: 645d3f703cf2521109bd7dbf44f20d6180440842 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// 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
//
//    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 <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) {
        g_arrVecSizes[i] = (1<<i);
    }
    for(; i < kVectorSizeCount + kStrangeVectorSizeCount; ++i) {
        g_arrVecSizes[i] = g_arrStrangeVectorSizes[i-kVectorSizeCount];
    }
}

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(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();

    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);
}