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_OTHER_FUNCS_HPP
17 #define TEST_CONFORMANCE_CLCPP_MATH_FUNCS_OTHER_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(other, erfc, std::erfc, true, 16.0f, 16.0f, 0.001f, -1000.0f, 1000.0f)
26 MATH_FUNCS_DEFINE_UNARY_FUNC(other, erf, std::erf, true, 16.0f, 16.0f, 0.001f, -1000.0f, 1000.0f)
27 MATH_FUNCS_DEFINE_UNARY_FUNC(other, fabs, std::fabs, true, 0.0f, 0.0f, 0.001f, -1000.0f, 1000.0f)
28 MATH_FUNCS_DEFINE_UNARY_FUNC(other, tgamma, std::tgamma, true, 16.0f, 16.0f, 0.001f, -1000.0f, 1000.0f)
29
30 // group_name, func_name, reference_func, use_ulp, ulp, ulp_for_embedded, max_delta, min1, max1, min2, max2
31 MATH_FUNCS_DEFINE_BINARY_FUNC(other, hypot, std::hypot, true, 4.0f, 4.0f, 0.001f, -1000.0f, 1000.0f, -1000.0f, 1000.0f)
32
33 // group_name, func_name, reference_func, use_ulp, ulp, ulp_for_embedded, max_delta, min1, max1, min2, max2, min3, max3
34 MATH_FUNCS_DEFINE_TERNARY_FUNC(other, mad, reference::mad, false, 0.0f, 0.0f, 0.1f, -10.0f, 10.0f, -10.0f, 10.0f, -10.0f, 10.0f)
35
36 // other functions
AUTO_TEST_CASE(test_other_funcs)37 AUTO_TEST_CASE(test_other_funcs)
38 (cl_device_id device, cl_context context, cl_command_queue queue, int n_elems)
39 {
40 int error = CL_SUCCESS;
41 int last_error = CL_SUCCESS;
42
43 // Check for EMBEDDED_PROFILE
44 bool is_embedded_profile = false;
45 char profile[128];
46 last_error = clGetDeviceInfo(device, CL_DEVICE_PROFILE, sizeof(profile), (void *)&profile, NULL);
47 RETURN_ON_CL_ERROR(last_error, "clGetDeviceInfo")
48 if (std::strcmp(profile, "EMBEDDED_PROFILE") == 0)
49 is_embedded_profile = true;
50
51 // gentype erf(gentype x);
52 // gentype erfc(gentype x);
53 TEST_UNARY_FUNC_MACRO((other_func_erfc(is_embedded_profile)))
54 TEST_UNARY_FUNC_MACRO((other_func_erf(is_embedded_profile)))
55
56 // gentype fabs(gentype x);
57 TEST_UNARY_FUNC_MACRO((other_func_fabs(is_embedded_profile)))
58
59 // gentype tgamma(gentype x);
60 TEST_UNARY_FUNC_MACRO((other_func_tgamma(is_embedded_profile)))
61
62 // gentype hypot(gentype x, gentype y);
63 TEST_BINARY_FUNC_MACRO((other_func_hypot(is_embedded_profile)))
64
65 // gentype mad(gentype a, gentype b, gentype c);
66 TEST_TERNARY_FUNC_MACRO((other_func_mad(is_embedded_profile)))
67
68 if(error != CL_SUCCESS)
69 {
70 return -1;
71 }
72 return error;
73 }
74
75 #endif // TEST_CONFORMANCE_CLCPP_MATH_FUNCS_OTHER_FUNCS_HPP
76