mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-23 07:39:01 +00:00
Initial open source release of OpenCL 2.2 CTS.
This commit is contained in:
12
test_conformance/clcpp/relational_funcs/CMakeLists.txt
Normal file
12
test_conformance/clcpp/relational_funcs/CMakeLists.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
set(MODULE_NAME CPP_RELATIONAL_FUNCS)
|
||||
|
||||
set(${MODULE_NAME}_SOURCES
|
||||
main.cpp
|
||||
../../../test_common/harness/errorHelpers.c
|
||||
../../../test_common/harness/testHarness.c
|
||||
../../../test_common/harness/kernelHelpers.c
|
||||
../../../test_common/harness/msvc9.c
|
||||
../../../test_common/harness/parseParameters.cpp
|
||||
)
|
||||
|
||||
include(../../CMakeCommon.txt)
|
||||
112
test_conformance/clcpp/relational_funcs/common.hpp
Normal file
112
test_conformance/clcpp/relational_funcs/common.hpp
Normal file
@@ -0,0 +1,112 @@
|
||||
//
|
||||
// Copyright (c) 2017 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.
|
||||
//
|
||||
#ifndef TEST_CONFORMANCE_CLCPP_RELATIONAL_FUNCS_COMMON_HPP
|
||||
#define TEST_CONFORMANCE_CLCPP_RELATIONAL_FUNCS_COMMON_HPP
|
||||
|
||||
#include "../common.hpp"
|
||||
#include "../funcs_test_utils.hpp"
|
||||
|
||||
#include <type_traits>
|
||||
#include <cmath>
|
||||
|
||||
template<class IN1, class IN2, class IN3, class OUT1, class F>
|
||||
OUT1 perform_function(const IN1& in1, const IN2& in2, const IN3& in3, F func, typename std::enable_if<is_vector_type<OUT1>::value>::type* = 0)
|
||||
{
|
||||
OUT1 result;
|
||||
for(size_t i = 0; i < vector_size<OUT1>::value; i++)
|
||||
{
|
||||
result.s[i] = func(in1.s[i], in2.s[i], in3.s[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<class IN1, class IN2, class IN3, class OUT1, class F>
|
||||
OUT1 perform_function(const IN1& in1, const IN2& in2, const IN3& in3, F func, typename std::enable_if<!is_vector_type<OUT1>::value>::type* = 0)
|
||||
{
|
||||
OUT1 result = func(in1, in2, in3);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
template<class IN1, class IN2, class OUT1, class F>
|
||||
OUT1 perform_function(const IN1& in1, const IN2& in2, F func, typename std::enable_if<is_vector_type<OUT1>::value>::type* = 0)
|
||||
{
|
||||
OUT1 result;
|
||||
for(size_t i = 0; i < vector_size<OUT1>::value; i++)
|
||||
{
|
||||
result.s[i] = func(in1.s[i], in2.s[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<class IN1, class IN2, class OUT1, class F>
|
||||
OUT1 perform_function(const IN1& in1, const IN2& in2, F func, typename std::enable_if<!is_vector_type<OUT1>::value>::type* = 0)
|
||||
{
|
||||
OUT1 result = func(in1, in2);
|
||||
return result;
|
||||
}
|
||||
|
||||
template<class IN1, class OUT1, class F>
|
||||
OUT1 perform_function(const IN1& in1, F func, typename std::enable_if<is_vector_type<OUT1>::value>::type* = 0)
|
||||
{
|
||||
OUT1 result;
|
||||
for(size_t i = 0; i < vector_size<OUT1>::value; i++)
|
||||
{
|
||||
result.s[i] = func(in1.s[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<class IN1, class OUT1, class F>
|
||||
OUT1 perform_function(const IN1& in1, F func, typename std::enable_if<!is_vector_type<OUT1>::value>::type* = 0)
|
||||
{
|
||||
OUT1 result = func(in1);
|
||||
return result;
|
||||
}
|
||||
|
||||
template<class IN1>
|
||||
cl_int perform_all_function(const IN1& in1, typename std::enable_if<is_vector_type<IN1>::value>::type* = 0)
|
||||
{
|
||||
cl_int result = 1;
|
||||
for(size_t i = 0; i < vector_size<IN1>::value; i++)
|
||||
{
|
||||
result = (in1.s[i] != 0) ? result : cl_int(0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
cl_int perform_all_function(const cl_int& in1, typename std::enable_if<!is_vector_type<cl_int>::value>::type* = 0)
|
||||
{
|
||||
return (in1 != 0) ? cl_int(1) : cl_int(0);
|
||||
}
|
||||
|
||||
template<class IN1>
|
||||
cl_int perform_any_function(const IN1& in1, typename std::enable_if<is_vector_type<IN1>::value>::type* = 0)
|
||||
{
|
||||
cl_int result = 0;
|
||||
for(size_t i = 0; i < vector_size<IN1>::value; i++)
|
||||
{
|
||||
result = (in1.s[i] != 0) ? cl_int(1) : result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
cl_int perform_any_function(const cl_int& in1, typename std::enable_if<!is_vector_type<cl_int>::value>::type* = 0)
|
||||
{
|
||||
return (in1 != 0) ? cl_int(1) : cl_int(0);
|
||||
}
|
||||
|
||||
#endif // TEST_CONFORMANCE_CLCPP_RELATIONAL_FUNCS_COMMON_HPP
|
||||
150
test_conformance/clcpp/relational_funcs/comparison_funcs.hpp
Normal file
150
test_conformance/clcpp/relational_funcs/comparison_funcs.hpp
Normal file
@@ -0,0 +1,150 @@
|
||||
//
|
||||
// Copyright (c) 2017 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.
|
||||
//
|
||||
#ifndef TEST_CONFORMANCE_CLCPP_RELATIONAL_FUNCS_COMPARISON_FUNCS_HPP
|
||||
#define TEST_CONFORMANCE_CLCPP_RELATIONAL_FUNCS_COMPARISON_FUNCS_HPP
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
// This marco creates a class wrapper for comparision function we want to test.
|
||||
#define DEF_COMPARISION_FUNC(CLASS_NAME, FUNC_NAME, HOST_FUNC_EXPRESSION) \
|
||||
template <cl_int N /* Vector size */> \
|
||||
struct CLASS_NAME : public binary_func< \
|
||||
typename make_vector_type<cl_float, N>::type, /* create cl_floatN type */ \
|
||||
typename make_vector_type<cl_float, N>::type, /* create cl_floatN type */ \
|
||||
typename make_vector_type<cl_int, N>::type /* create cl_intN type */ \
|
||||
> \
|
||||
{ \
|
||||
typedef typename make_vector_type<cl_float, N>::type input_type; \
|
||||
typedef typename make_vector_type<cl_int, N>::type result_type; \
|
||||
\
|
||||
std::string str() \
|
||||
{ \
|
||||
return #FUNC_NAME; \
|
||||
} \
|
||||
\
|
||||
std::string headers() \
|
||||
{ \
|
||||
return "#include <opencl_relational>\n"; \
|
||||
} \
|
||||
\
|
||||
result_type operator()(const input_type& x, const input_type& y) \
|
||||
{ \
|
||||
typedef typename scalar_type<input_type>::type SCALAR; \
|
||||
return perform_function<input_type, input_type, result_type>( \
|
||||
x, y, \
|
||||
[](const SCALAR& a, const SCALAR& b) \
|
||||
{ \
|
||||
if(HOST_FUNC_EXPRESSION) \
|
||||
{ \
|
||||
return cl_int(1); \
|
||||
} \
|
||||
return cl_int(0); \
|
||||
} \
|
||||
); \
|
||||
} \
|
||||
\
|
||||
bool is_out_bool() \
|
||||
{ \
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
input_type min1() \
|
||||
{ \
|
||||
return detail::def_limit<input_type>(-10000.0f); \
|
||||
} \
|
||||
\
|
||||
input_type max1() \
|
||||
{ \
|
||||
return detail::def_limit<input_type>(10000.0f); \
|
||||
} \
|
||||
\
|
||||
input_type min2() \
|
||||
{ \
|
||||
return detail::def_limit<input_type>(-10000.0f); \
|
||||
} \
|
||||
\
|
||||
input_type max2() \
|
||||
{ \
|
||||
return detail::def_limit<input_type>(10000.0f); \
|
||||
} \
|
||||
\
|
||||
std::vector<input_type> in1_special_cases() \
|
||||
{ \
|
||||
typedef typename scalar_type<input_type>::type SCALAR; \
|
||||
return { \
|
||||
detail::make_value<input_type>(std::numeric_limits<SCALAR>::infinity()), \
|
||||
detail::make_value<input_type>(-std::numeric_limits<SCALAR>::infinity()), \
|
||||
detail::make_value<input_type>(std::numeric_limits<SCALAR>::quiet_NaN()), \
|
||||
detail::make_value<input_type>(0.0f), \
|
||||
detail::make_value<input_type>(-0.0f) \
|
||||
}; \
|
||||
} \
|
||||
\
|
||||
std::vector<input_type> in2_special_cases() \
|
||||
{ \
|
||||
typedef typename scalar_type<input_type>::type SCALAR; \
|
||||
return { \
|
||||
detail::make_value<input_type>(std::numeric_limits<SCALAR>::infinity()), \
|
||||
detail::make_value<input_type>(-std::numeric_limits<SCALAR>::infinity()), \
|
||||
detail::make_value<input_type>(std::numeric_limits<SCALAR>::quiet_NaN()), \
|
||||
detail::make_value<input_type>(0.0f), \
|
||||
detail::make_value<input_type>(-0.0f) \
|
||||
}; \
|
||||
} \
|
||||
};
|
||||
|
||||
DEF_COMPARISION_FUNC(comparison_func_isequal, isequal, (a == b))
|
||||
DEF_COMPARISION_FUNC(comparison_func_isnotequal, isnotequal, !(a == b))
|
||||
DEF_COMPARISION_FUNC(comparison_func_isgreater, isgreater, (std::isgreater)(a, b))
|
||||
DEF_COMPARISION_FUNC(comparison_func_isgreaterequal, isgreaterequal, ((std::isgreater)(a, b) || a == b))
|
||||
DEF_COMPARISION_FUNC(comparison_func_isless, isless, (std::isless)(a, b))
|
||||
DEF_COMPARISION_FUNC(comparison_func_islessequal, islessequal, ((std::isless)(a, b) || a == b))
|
||||
DEF_COMPARISION_FUNC(comparison_func_islessgreater, islessgreater, ((a < b) || (a > b)))
|
||||
|
||||
#undef DEF_COMPARISION_FUNC
|
||||
|
||||
AUTO_TEST_CASE(test_relational_comparison_funcs)
|
||||
(cl_device_id device, cl_context context, cl_command_queue queue, int n_elems)
|
||||
{
|
||||
int error = CL_SUCCESS;
|
||||
int last_error = CL_SUCCESS;
|
||||
|
||||
// Helper macro, so we don't have to repreat the same code.
|
||||
#define TEST_BINARY_REL_FUNC_MACRO(CLASS_NAME) \
|
||||
TEST_BINARY_FUNC_MACRO(CLASS_NAME<1>()) \
|
||||
TEST_BINARY_FUNC_MACRO(CLASS_NAME<2>()) \
|
||||
TEST_BINARY_FUNC_MACRO(CLASS_NAME<4>()) \
|
||||
TEST_BINARY_FUNC_MACRO(CLASS_NAME<8>()) \
|
||||
TEST_BINARY_FUNC_MACRO(CLASS_NAME<16>())
|
||||
|
||||
TEST_BINARY_REL_FUNC_MACRO(comparison_func_isequal)
|
||||
TEST_BINARY_REL_FUNC_MACRO(comparison_func_isnotequal)
|
||||
TEST_BINARY_REL_FUNC_MACRO(comparison_func_isgreater)
|
||||
TEST_BINARY_REL_FUNC_MACRO(comparison_func_isgreaterequal)
|
||||
TEST_BINARY_REL_FUNC_MACRO(comparison_func_isless)
|
||||
TEST_BINARY_REL_FUNC_MACRO(comparison_func_islessequal)
|
||||
TEST_BINARY_REL_FUNC_MACRO(comparison_func_islessgreater)
|
||||
|
||||
#undef TEST_BINARY_REL_FUNC_MACRO
|
||||
|
||||
if(error != CL_SUCCESS)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
#endif // TEST_CONFORMANCE_CLCPP_RELATIONAL_FUNCS_COMPARISON_FUNCS_HPP
|
||||
31
test_conformance/clcpp/relational_funcs/main.cpp
Normal file
31
test_conformance/clcpp/relational_funcs/main.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// Copyright (c) 2017 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 "../common.hpp"
|
||||
|
||||
#include "comparison_funcs.hpp"
|
||||
#include "select_funcs.hpp"
|
||||
#include "test_funcs.hpp"
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
// Get list to all test functions
|
||||
std::vector<basefn> testfn_list = autotest::test_suite::get_test_functions();
|
||||
// Get names of all test functions
|
||||
std::vector<std::string> testfn_names = autotest::test_suite::get_test_names();
|
||||
// Create a vector of pointers to the names test functions
|
||||
std::vector<const char *> testfn_names_c_str = autotest::get_strings_ptrs(testfn_names);
|
||||
return runTestHarness(argc, argv, testfn_list.size(), testfn_list.data(), testfn_names_c_str.data(), false, false, 0);
|
||||
}
|
||||
158
test_conformance/clcpp/relational_funcs/select_funcs.hpp
Normal file
158
test_conformance/clcpp/relational_funcs/select_funcs.hpp
Normal file
@@ -0,0 +1,158 @@
|
||||
//
|
||||
// Copyright (c) 2017 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.
|
||||
//
|
||||
#ifndef TEST_CONFORMANCE_CLCPP_RELATIONAL_FUNCS_SELECT_FUNCS_HPP
|
||||
#define TEST_CONFORMANCE_CLCPP_RELATIONAL_FUNCS_SELECT_FUNCS_HPP
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
template <class IN1, cl_int N /* Vector size */>
|
||||
struct select_func_select : public ternary_func<
|
||||
typename make_vector_type<IN1, N>::type, /* create IN1N type */
|
||||
typename make_vector_type<IN1, N>::type, /* create IN1N type */
|
||||
typename make_vector_type<cl_int, N>::type, /* create cl_intN type */
|
||||
typename make_vector_type<IN1, N>::type /* create IN1N type */
|
||||
>
|
||||
{
|
||||
typedef typename make_vector_type<IN1, N>::type input1_type;
|
||||
typedef typename make_vector_type<IN1, N>::type input2_type;
|
||||
typedef typename make_vector_type<cl_int, N>::type input3_type;
|
||||
typedef typename make_vector_type<IN1, N>::type result_type;
|
||||
|
||||
std::string str()
|
||||
{
|
||||
return "select";
|
||||
}
|
||||
|
||||
std::string headers()
|
||||
{
|
||||
return "#include <opencl_relational>\n";
|
||||
}
|
||||
|
||||
result_type operator()(const input1_type& x, const input2_type& y, const input3_type& z)
|
||||
{
|
||||
typedef typename scalar_type<input1_type>::type SCALAR1;
|
||||
typedef typename scalar_type<input2_type>::type SCALAR2;
|
||||
typedef typename scalar_type<input3_type>::type SCALAR3;
|
||||
|
||||
return perform_function<input1_type, input2_type, input3_type, result_type>(
|
||||
x, y, z,
|
||||
[](const SCALAR1& a, const SCALAR2& b, const SCALAR3& c)
|
||||
{
|
||||
return (c != 0) ? b : a;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
bool is_in3_bool()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<input3_type> in3_special_cases()
|
||||
{
|
||||
return {
|
||||
detail::make_value<input3_type>(0),
|
||||
detail::make_value<input3_type>(1),
|
||||
detail::make_value<input3_type>(12),
|
||||
detail::make_value<input3_type>(-12)
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
template <class IN1, cl_int N /* Vector size */>
|
||||
struct select_func_bitselect : public ternary_func<
|
||||
typename make_vector_type<IN1, N>::type, /* create IN1N type */
|
||||
typename make_vector_type<IN1, N>::type, /* create IN1N type */
|
||||
typename make_vector_type<IN1, N>::type, /* create cl_intN type */
|
||||
typename make_vector_type<IN1, N>::type /* create IN1N type */
|
||||
>
|
||||
{
|
||||
typedef typename make_vector_type<IN1, N>::type input1_type;
|
||||
typedef typename make_vector_type<IN1, N>::type input2_type;
|
||||
typedef typename make_vector_type<IN1, N>::type input3_type;
|
||||
typedef typename make_vector_type<IN1, N>::type result_type;
|
||||
|
||||
std::string str()
|
||||
{
|
||||
return "bitselect";
|
||||
}
|
||||
|
||||
std::string headers()
|
||||
{
|
||||
return "#include <opencl_relational>\n";
|
||||
}
|
||||
|
||||
result_type operator()(const input1_type& x, const input2_type& y, const input3_type& z)
|
||||
{
|
||||
static_assert(
|
||||
std::is_integral<IN1>::value,
|
||||
"bitselect test is implemented only for integers."
|
||||
);
|
||||
static_assert(
|
||||
std::is_unsigned<IN1>::value,
|
||||
"IN1 type should be unsigned, bitwise operations on signed int may cause problems."
|
||||
);
|
||||
typedef typename scalar_type<input1_type>::type SCALAR1;
|
||||
typedef typename scalar_type<input2_type>::type SCALAR2;
|
||||
typedef typename scalar_type<input3_type>::type SCALAR3;
|
||||
|
||||
return perform_function<input1_type, input2_type, input3_type, result_type>(
|
||||
x, y, z,
|
||||
[](const SCALAR1& a, const SCALAR2& b, const SCALAR3& c)
|
||||
{
|
||||
return (~c & a) | (c & b);
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
AUTO_TEST_CASE(test_relational_select_funcs)
|
||||
(cl_device_id device, cl_context context, cl_command_queue queue, int n_elems)
|
||||
{
|
||||
int error = CL_SUCCESS;
|
||||
int last_error = CL_SUCCESS;
|
||||
|
||||
// Tests for select(gentype a, gentype b, booln c) are not run in USE_OPENCLC_KERNELS
|
||||
// mode, because this functions in OpenCL C requires different reference functions on host
|
||||
// compared to their equivalent in OpenCL C++.
|
||||
// (In OpenCL C the result of select(), when gentype is vector type, is based on the most
|
||||
// significant bits of c components)
|
||||
#ifndef USE_OPENCLC_KERNELS
|
||||
// gentype select(gentype a, gentype b, booln c)
|
||||
TEST_TERNARY_FUNC_MACRO((select_func_select<cl_uint, 1>()))
|
||||
TEST_TERNARY_FUNC_MACRO((select_func_select<cl_float, 2>()))
|
||||
TEST_TERNARY_FUNC_MACRO((select_func_select<cl_short, 4>()))
|
||||
TEST_TERNARY_FUNC_MACRO((select_func_select<cl_uint, 8>()))
|
||||
TEST_TERNARY_FUNC_MACRO((select_func_select<cl_uint, 16>()))
|
||||
#else
|
||||
log_info("WARNING:\n\tTests for select(gentype a, gentype b, booln c) are not run in USE_OPENCLC_KERNELS mode\n");
|
||||
#endif
|
||||
|
||||
// gentype bitselect(gentype a, gentype b, gentype c)
|
||||
TEST_TERNARY_FUNC_MACRO((select_func_bitselect<cl_uint, 1>()))
|
||||
TEST_TERNARY_FUNC_MACRO((select_func_bitselect<cl_ushort, 2>()))
|
||||
TEST_TERNARY_FUNC_MACRO((select_func_bitselect<cl_uchar, 4>()))
|
||||
TEST_TERNARY_FUNC_MACRO((select_func_bitselect<cl_ushort, 8>()))
|
||||
TEST_TERNARY_FUNC_MACRO((select_func_bitselect<cl_uint, 16>()))
|
||||
|
||||
if(error != CL_SUCCESS)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
#endif // TEST_CONFORMANCE_CLCPP_RELATIONAL_FUNCS_SELECT_FUNCS_HPP
|
||||
336
test_conformance/clcpp/relational_funcs/test_funcs.hpp
Normal file
336
test_conformance/clcpp/relational_funcs/test_funcs.hpp
Normal file
@@ -0,0 +1,336 @@
|
||||
//
|
||||
// Copyright (c) 2017 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.
|
||||
//
|
||||
#ifndef TEST_CONFORMANCE_CLCPP_RELATIONAL_FUNCS_TEST_FUNCS_HPP
|
||||
#define TEST_CONFORMANCE_CLCPP_RELATIONAL_FUNCS_TEST_FUNCS_HPP
|
||||
|
||||
#include "common.hpp"
|
||||
|
||||
// This marco creates a class wrapper for unary test function we want to test.
|
||||
#define DEF_UNARY_TEST_FUNC(CLASS_NAME, FUNC_NAME, HOST_FUNC_EXPRESSION) \
|
||||
template <cl_int N /* Vector size */> \
|
||||
struct CLASS_NAME : public unary_func< \
|
||||
typename make_vector_type<cl_float, N>::type, /* create cl_floatN type */ \
|
||||
typename make_vector_type<cl_int, N>::type /* create cl_intN type */ \
|
||||
> \
|
||||
{ \
|
||||
typedef typename make_vector_type<cl_float, N>::type input_type; \
|
||||
typedef typename make_vector_type<cl_int, N>::type result_type; \
|
||||
\
|
||||
std::string str() \
|
||||
{ \
|
||||
return #FUNC_NAME; \
|
||||
} \
|
||||
\
|
||||
std::string headers() \
|
||||
{ \
|
||||
return "#include <opencl_relational>\n"; \
|
||||
} \
|
||||
\
|
||||
result_type operator()(const input_type& x) \
|
||||
{ \
|
||||
typedef typename scalar_type<input_type>::type SCALAR; \
|
||||
return perform_function<input_type, result_type>( \
|
||||
x, \
|
||||
[](const SCALAR& a) \
|
||||
{ \
|
||||
if(HOST_FUNC_EXPRESSION) \
|
||||
{ \
|
||||
return cl_int(1); \
|
||||
} \
|
||||
return cl_int(0); \
|
||||
} \
|
||||
); \
|
||||
} \
|
||||
\
|
||||
bool is_out_bool() \
|
||||
{ \
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
input_type min1() \
|
||||
{ \
|
||||
return detail::def_limit<input_type>(-10000.0f); \
|
||||
} \
|
||||
\
|
||||
input_type max1() \
|
||||
{ \
|
||||
return detail::def_limit<input_type>(10000.0f); \
|
||||
} \
|
||||
\
|
||||
std::vector<input_type> in1_special_cases() \
|
||||
{ \
|
||||
typedef typename scalar_type<input_type>::type SCALAR; \
|
||||
return { \
|
||||
detail::make_value<input_type>(std::numeric_limits<SCALAR>::infinity()), \
|
||||
detail::make_value<input_type>(-std::numeric_limits<SCALAR>::infinity()), \
|
||||
detail::make_value<input_type>(std::numeric_limits<SCALAR>::quiet_NaN()), \
|
||||
detail::make_value<input_type>(std::numeric_limits<SCALAR>::signaling_NaN()), \
|
||||
detail::make_value<input_type>(std::numeric_limits<SCALAR>::denorm_min()), \
|
||||
detail::make_value<input_type>(0.0f), \
|
||||
detail::make_value<input_type>(-0.0f) \
|
||||
}; \
|
||||
} \
|
||||
};
|
||||
|
||||
// This marco creates a class wrapper for binary test function we want to test.
|
||||
#define DEF_BINARY_TEST_FUNC(CLASS_NAME, FUNC_NAME, HOST_FUNC_EXPRESSION) \
|
||||
template <cl_int N /* Vector size */> \
|
||||
struct CLASS_NAME : public binary_func< \
|
||||
typename make_vector_type<cl_float, N>::type, /* create cl_floatN type */ \
|
||||
typename make_vector_type<cl_float, N>::type, /* create cl_floatN type */ \
|
||||
typename make_vector_type<cl_int, N>::type /* create cl_intN type */ \
|
||||
> \
|
||||
{ \
|
||||
typedef typename make_vector_type<cl_float, N>::type input_type; \
|
||||
typedef typename make_vector_type<cl_int, N>::type result_type; \
|
||||
\
|
||||
std::string str() \
|
||||
{ \
|
||||
return #FUNC_NAME; \
|
||||
} \
|
||||
\
|
||||
std::string headers() \
|
||||
{ \
|
||||
return "#include <opencl_relational>\n"; \
|
||||
} \
|
||||
\
|
||||
result_type operator()(const input_type& x, const input_type& y) \
|
||||
{ \
|
||||
typedef typename scalar_type<input_type>::type SCALAR; \
|
||||
return perform_function<input_type, input_type, result_type>( \
|
||||
x, y, \
|
||||
[](const SCALAR& a, const SCALAR& b) \
|
||||
{ \
|
||||
if(HOST_FUNC_EXPRESSION) \
|
||||
{ \
|
||||
return cl_int(1); \
|
||||
} \
|
||||
return cl_int(0); \
|
||||
} \
|
||||
); \
|
||||
} \
|
||||
\
|
||||
bool is_out_bool() \
|
||||
{ \
|
||||
return true; \
|
||||
} \
|
||||
\
|
||||
input_type min1() \
|
||||
{ \
|
||||
return detail::def_limit<input_type>(-10000.0f); \
|
||||
} \
|
||||
\
|
||||
input_type max1() \
|
||||
{ \
|
||||
return detail::def_limit<input_type>(10000.0f); \
|
||||
} \
|
||||
\
|
||||
input_type min2() \
|
||||
{ \
|
||||
return detail::def_limit<input_type>(-10000.0f); \
|
||||
} \
|
||||
\
|
||||
input_type max2() \
|
||||
{ \
|
||||
return detail::def_limit<input_type>(10000.0f); \
|
||||
} \
|
||||
\
|
||||
std::vector<input_type> in1_special_cases() \
|
||||
{ \
|
||||
typedef typename scalar_type<input_type>::type SCALAR; \
|
||||
return { \
|
||||
detail::make_value<input_type>(std::numeric_limits<SCALAR>::infinity()), \
|
||||
detail::make_value<input_type>(-std::numeric_limits<SCALAR>::infinity()), \
|
||||
detail::make_value<input_type>(std::numeric_limits<SCALAR>::quiet_NaN()), \
|
||||
detail::make_value<input_type>(std::numeric_limits<SCALAR>::signaling_NaN()), \
|
||||
detail::make_value<input_type>(std::numeric_limits<SCALAR>::denorm_min()), \
|
||||
detail::make_value<input_type>(0.0f), \
|
||||
detail::make_value<input_type>(-0.0f) \
|
||||
}; \
|
||||
} \
|
||||
\
|
||||
std::vector<input_type> in2_special_cases() \
|
||||
{ \
|
||||
typedef typename scalar_type<input_type>::type SCALAR; \
|
||||
return { \
|
||||
detail::make_value<input_type>(std::numeric_limits<SCALAR>::infinity()), \
|
||||
detail::make_value<input_type>(-std::numeric_limits<SCALAR>::infinity()), \
|
||||
detail::make_value<input_type>(std::numeric_limits<SCALAR>::quiet_NaN()), \
|
||||
detail::make_value<input_type>(std::numeric_limits<SCALAR>::signaling_NaN()), \
|
||||
detail::make_value<input_type>(std::numeric_limits<SCALAR>::denorm_min()), \
|
||||
detail::make_value<input_type>(0.0f), \
|
||||
detail::make_value<input_type>(-0.0f) \
|
||||
}; \
|
||||
} \
|
||||
};
|
||||
|
||||
DEF_UNARY_TEST_FUNC(test_func_isfinite, isfinite, (std::isfinite)(a))
|
||||
DEF_UNARY_TEST_FUNC(test_func_isinf, isinf, (std::isinf)(a))
|
||||
DEF_UNARY_TEST_FUNC(test_func_isnan, isnan, (std::isnan)(a))
|
||||
DEF_UNARY_TEST_FUNC(test_func_isnormal, isnormal, (std::isnormal)(a))
|
||||
DEF_UNARY_TEST_FUNC(test_func_signbit, signbit , (std::signbit)(a))
|
||||
|
||||
DEF_BINARY_TEST_FUNC(test_func_isordered, isordered, !(std::isunordered)(a, b))
|
||||
DEF_BINARY_TEST_FUNC(test_func_isunordered, isunordered, (std::isunordered)(a, b))
|
||||
|
||||
#undef DEF_UNARY_TEST_FUNC
|
||||
#undef DEF_BINARY_TEST_FUNC
|
||||
|
||||
template <cl_int N /* Vector size */>
|
||||
struct test_func_all : public unary_func<
|
||||
typename make_vector_type<cl_int, N>::type, /* create cl_intN type */
|
||||
cl_int /* create cl_intN type */
|
||||
>
|
||||
{
|
||||
typedef typename make_vector_type<cl_int, N>::type input_type;
|
||||
typedef cl_int result_type;
|
||||
|
||||
std::string str()
|
||||
{
|
||||
return "all";
|
||||
}
|
||||
|
||||
std::string headers()
|
||||
{
|
||||
return "#include <opencl_relational>\n";
|
||||
}
|
||||
|
||||
result_type operator()(const input_type& x)
|
||||
{
|
||||
return perform_all_function(x);
|
||||
}
|
||||
|
||||
bool is_out_bool()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool is_in1_bool()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<input_type> in1_special_cases()
|
||||
{
|
||||
return {
|
||||
detail::make_value<input_type>(0),
|
||||
detail::make_value<input_type>(1),
|
||||
detail::make_value<input_type>(12),
|
||||
detail::make_value<input_type>(-12)
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
template <cl_int N /* Vector size */>
|
||||
struct test_func_any : public unary_func<
|
||||
typename make_vector_type<cl_int, N>::type, /* create cl_intN type */
|
||||
cl_int /* create cl_intN type */
|
||||
>
|
||||
{
|
||||
typedef typename make_vector_type<cl_int, N>::type input_type;
|
||||
typedef cl_int result_type;
|
||||
|
||||
std::string str()
|
||||
{
|
||||
return "any";
|
||||
}
|
||||
|
||||
std::string headers()
|
||||
{
|
||||
return "#include <opencl_relational>\n";
|
||||
}
|
||||
|
||||
result_type operator()(const input_type& x)
|
||||
{
|
||||
return perform_any_function(x);
|
||||
}
|
||||
|
||||
bool is_out_bool()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool is_in1_bool()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<input_type> in1_special_cases()
|
||||
{
|
||||
return {
|
||||
detail::make_value<input_type>(0),
|
||||
detail::make_value<input_type>(1),
|
||||
detail::make_value<input_type>(12),
|
||||
detail::make_value<input_type>(-12)
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
AUTO_TEST_CASE(test_relational_test_funcs)
|
||||
(cl_device_id device, cl_context context, cl_command_queue queue, int n_elems)
|
||||
{
|
||||
int error = CL_SUCCESS;
|
||||
int last_error = CL_SUCCESS;
|
||||
|
||||
// Helper macro, so we don't have to repreat the same code.
|
||||
#define TEST_UNARY_REL_FUNC_MACRO(CLASS_NAME) \
|
||||
TEST_UNARY_FUNC_MACRO(CLASS_NAME<1>()) \
|
||||
TEST_UNARY_FUNC_MACRO(CLASS_NAME<2>()) \
|
||||
TEST_UNARY_FUNC_MACRO(CLASS_NAME<4>()) \
|
||||
TEST_UNARY_FUNC_MACRO(CLASS_NAME<8>()) \
|
||||
TEST_UNARY_FUNC_MACRO(CLASS_NAME<16>())
|
||||
|
||||
TEST_UNARY_REL_FUNC_MACRO(test_func_isfinite)
|
||||
TEST_UNARY_REL_FUNC_MACRO(test_func_isinf)
|
||||
TEST_UNARY_REL_FUNC_MACRO(test_func_isnan)
|
||||
TEST_UNARY_REL_FUNC_MACRO(test_func_isnormal)
|
||||
TEST_UNARY_REL_FUNC_MACRO(test_func_signbit)
|
||||
|
||||
// Tests for all(booln x) and any(booln x) are not run in USE_OPENCLC_KERNELS mode,
|
||||
// because those functions in OpenCL C require different reference functions on host
|
||||
// compared to their equivalents from OpenCL C++.
|
||||
// (In OpenCL C those functions returns true/false based on the most significant bits
|
||||
// in any/all component/s of x)
|
||||
#ifndef USE_OPENCLC_KERNELS
|
||||
TEST_UNARY_REL_FUNC_MACRO(test_func_all)
|
||||
TEST_UNARY_REL_FUNC_MACRO(test_func_any)
|
||||
#else
|
||||
log_info("WARNING:\n\tTests for bool all(booln x) are not run in USE_OPENCLC_KERNELS mode\n");
|
||||
log_info("WARNING:\n\tTests for bool any(booln x) are not run in USE_OPENCLC_KERNELS mode\n");
|
||||
#endif
|
||||
|
||||
#undef TEST_UNARY_REL_FUNC_MACRO
|
||||
|
||||
#define TEST_BINARY_REL_FUNC_MACRO(CLASS_NAME) \
|
||||
TEST_BINARY_FUNC_MACRO(CLASS_NAME<1>()) \
|
||||
TEST_BINARY_FUNC_MACRO(CLASS_NAME<2>()) \
|
||||
TEST_BINARY_FUNC_MACRO(CLASS_NAME<4>()) \
|
||||
TEST_BINARY_FUNC_MACRO(CLASS_NAME<8>()) \
|
||||
TEST_BINARY_FUNC_MACRO(CLASS_NAME<16>())
|
||||
|
||||
TEST_BINARY_REL_FUNC_MACRO(test_func_isordered)
|
||||
TEST_BINARY_REL_FUNC_MACRO(test_func_isunordered)
|
||||
|
||||
#undef TEST_BINARY_REL_FUNC_MACRO
|
||||
|
||||
if(error != CL_SUCCESS)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
#endif // TEST_CONFORMANCE_CLCPP_RELATIONAL_FUNCS_TEST_FUNCS_HPP
|
||||
Reference in New Issue
Block a user