• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (c) 2017 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 #ifndef TEST_CONFORMANCE_CLCPP_MATH_FUNCS_EXP_FUNCS_HPP
17 #define TEST_CONFORMANCE_CLCPP_MATH_FUNCS_EXP_FUNCS_HPP
18 
19 #include <type_traits>
20 #include <cmath>
21 
22 #include "common.hpp"
23 
24 // group_name, func_name, reference_func, use_ulp, ulp, ulp_for_embedded, max_delta, min1, max1
25 MATH_FUNCS_DEFINE_UNARY_FUNC(exponential, exp, std::exp, true, 3.0f, 4.0f, 0.001f, -1000.0f, 1000.0f)
26 MATH_FUNCS_DEFINE_UNARY_FUNC(exponential, expm1, std::expm1, true, 3.0f, 4.0f, 0.001f, -1000.0f, 1000.0f)
27 MATH_FUNCS_DEFINE_UNARY_FUNC(exponential, exp2, std::exp2, true, 3.0f, 4.0f, 0.001f, -1000.0f, 1000.0f)
28 MATH_FUNCS_DEFINE_UNARY_FUNC(exponential, exp10, reference::exp10, true, 3.0f, 4.0f, 0.001f, -1000.0f, 1000.0f)
29 
30 struct exponential_func_ldexp : public binary_func<cl_float, cl_int, cl_float>
31 {
exponential_func_ldexpexponential_func_ldexp32     exponential_func_ldexp(bool is_embedded) : m_is_embedded(is_embedded)
33     {
34 
35     }
36 
strexponential_func_ldexp37     std::string str()
38     {
39         return "ldexp";
40     }
41 
headersexponential_func_ldexp42     std::string headers()
43     {
44         return "#include <opencl_math>\n";
45     }
46 
47     /* Reference value type is cl_double */
operator ()exponential_func_ldexp48     cl_double operator()(const cl_float& x, const cl_int& y)
49     {
50         return (std::ldexp)(static_cast<cl_double>(x), y);
51     }
52 
min1exponential_func_ldexp53     cl_float min1()
54     {
55         return -1000.0f;
56     }
57 
max1exponential_func_ldexp58     cl_float max1()
59     {
60         return 1000.0f;
61     }
62 
min2exponential_func_ldexp63     cl_int min2()
64     {
65         return -8;
66     }
67 
max2exponential_func_ldexp68     cl_int max2()
69     {
70         return 8;
71     }
72 
in1_special_casesexponential_func_ldexp73     std::vector<cl_float> in1_special_cases()
74     {
75         return {
76             cl_float(0.0f),
77             cl_float(-0.0f),
78             cl_float(1.0f),
79             cl_float(-1.0f),
80             cl_float(2.0f),
81             cl_float(-2.0f),
82             std::numeric_limits<cl_float>::infinity(),
83             -std::numeric_limits<cl_float>::infinity(),
84             std::numeric_limits<cl_float>::quiet_NaN()
85         };
86     }
87 
use_ulpexponential_func_ldexp88     bool use_ulp()
89     {
90         return true;
91     }
92 
ulpexponential_func_ldexp93     float ulp()
94     {
95         if(m_is_embedded)
96         {
97             return 0.0f;
98         }
99         return 0.0f;
100     }
101 private:
102     bool m_is_embedded;
103 };
104 
105 // exponential functions
AUTO_TEST_CASE(test_exponential_funcs)106 AUTO_TEST_CASE(test_exponential_funcs)
107 (cl_device_id device, cl_context context, cl_command_queue queue, int n_elems)
108 {
109     int error = CL_SUCCESS;
110     int last_error = CL_SUCCESS;
111 
112     // Check for EMBEDDED_PROFILE
113     bool is_embedded_profile = false;
114     char profile[128];
115     last_error = clGetDeviceInfo(device, CL_DEVICE_PROFILE, sizeof(profile), (void *)&profile, NULL);
116     RETURN_ON_CL_ERROR(last_error, "clGetDeviceInfo")
117     if (std::strcmp(profile, "EMBEDDED_PROFILE") == 0)
118         is_embedded_profile = true;
119 
120     // auto exp(gentype x);
121     // auto expm1(gentype x);
122     // auto exp2(gentype x);
123     // auto exp10(gentype x);
124     TEST_UNARY_FUNC_MACRO((exponential_func_exp(is_embedded_profile)))
125     TEST_UNARY_FUNC_MACRO((exponential_func_expm1(is_embedded_profile)))
126     TEST_UNARY_FUNC_MACRO((exponential_func_exp2(is_embedded_profile)))
127     TEST_UNARY_FUNC_MACRO((exponential_func_exp10(is_embedded_profile)))
128 
129     // auto ldexp(gentype x, intn k);
130     TEST_BINARY_FUNC_MACRO((exponential_func_ldexp(is_embedded_profile)))
131 
132     if(error != CL_SUCCESS)
133     {
134         return -1;
135     }
136     return error;
137 }
138 
139 #endif // TEST_CONFORMANCE_CLCPP_MATH_FUNCS_EXP_FUNCS_HPP
140