xref: /aosp_15_r20/external/OpenCL-CTS/test_conformance/commonfns/main.cpp (revision 6467f958c7de8070b317fc65bcb0f6472e388d82)
1 //
2 // Copyright (c) 2023 The Khronos Group Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //    http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #include <stdio.h>
18 #include <string.h>
19 #include "procs.h"
20 #include "test_base.h"
21 #include "harness/kernelHelpers.h"
22 
23 std::map<size_t, std::string> BaseFunctionTest::type2name;
24 cl_half_rounding_mode BaseFunctionTest::halfRoundingMode = CL_HALF_RTE;
25 
26 int g_arrVecSizes[kVectorSizeCount + kStrangeVectorSizeCount];
27 int g_arrStrangeVectorSizes[kStrangeVectorSizeCount] = {3};
28 
initVecSizes()29 static void initVecSizes() {
30     int i;
31     for(i = 0; i < kVectorSizeCount; ++i) {
32         g_arrVecSizes[i] = (1<<i);
33     }
34     for(; i < kVectorSizeCount + kStrangeVectorSizeCount; ++i) {
35         g_arrVecSizes[i] = g_arrStrangeVectorSizes[i-kVectorSizeCount];
36     }
37 }
38 
39 test_definition test_list[] = {
40     ADD_TEST(clamp),      ADD_TEST(degrees),     ADD_TEST(fmax),
41     ADD_TEST(fmaxf),      ADD_TEST(fmin),        ADD_TEST(fminf),
42     ADD_TEST(max),        ADD_TEST(maxf),        ADD_TEST(min),
43     ADD_TEST(minf),       ADD_TEST(mix),         ADD_TEST(mixf),
44     ADD_TEST(radians),    ADD_TEST(step),        ADD_TEST(stepf),
45     ADD_TEST(smoothstep), ADD_TEST(smoothstepf), ADD_TEST(sign),
46 };
47 
48 const int test_num = ARRAY_SIZE( test_list );
49 
InitCL(cl_device_id device)50 test_status InitCL(cl_device_id device)
51 {
52     if (is_extension_available(device, "cl_khr_fp16"))
53     {
54         const cl_device_fp_config fpConfigHalf =
55             get_default_rounding_mode(device, CL_DEVICE_HALF_FP_CONFIG);
56         if ((fpConfigHalf & CL_FP_ROUND_TO_NEAREST) != 0)
57         {
58             BaseFunctionTest::halfRoundingMode = CL_HALF_RTE;
59         }
60         else if ((fpConfigHalf & CL_FP_ROUND_TO_ZERO) != 0)
61         {
62             BaseFunctionTest::halfRoundingMode = CL_HALF_RTZ;
63         }
64         else
65         {
66             log_error("Error while acquiring half rounding mode");
67             return TEST_FAIL;
68         }
69     }
70 
71     return TEST_PASS;
72 }
73 
main(int argc,const char * argv[])74 int main(int argc, const char *argv[])
75 {
76     initVecSizes();
77 
78     BaseFunctionTest::type2name[sizeof(half)] = "half";
79     BaseFunctionTest::type2name[sizeof(float)] = "float";
80     BaseFunctionTest::type2name[sizeof(double)] = "double";
81 
82     return runTestHarnessWithCheck(argc, argv, test_num, test_list, false, 0,
83                                    InitCL);
84 }
85