mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-21 14:59:02 +00:00
Initial open source release of OpenCL 2.2 CTS.
This commit is contained in:
308
test_conformance/clcpp/utils_test/binary.hpp
Normal file
308
test_conformance/clcpp/utils_test/binary.hpp
Normal file
@@ -0,0 +1,308 @@
|
||||
//
|
||||
// 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_UTILS_TEST_BINARY_HPP
|
||||
#define TEST_CONFORMANCE_CLCPP_UTILS_TEST_BINARY_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <cmath>
|
||||
|
||||
#include "../common.hpp"
|
||||
|
||||
#include "detail/base_func_type.hpp"
|
||||
#include "generate_inputs.hpp"
|
||||
#include "compare.hpp"
|
||||
|
||||
template<class IN1, class IN2, class OUT1>
|
||||
struct binary_func : public detail::base_func_type<OUT1>
|
||||
{
|
||||
typedef IN1 in1_type;
|
||||
typedef IN2 in2_type;
|
||||
typedef OUT1 out_type;
|
||||
|
||||
virtual ~binary_func() {};
|
||||
virtual std::string str() = 0;
|
||||
|
||||
std::string decl_str()
|
||||
{
|
||||
return type_name<OUT1>() + "(" + type_name<IN1>() + ", " + type_name<IN2>() + ")";
|
||||
}
|
||||
|
||||
bool is_in1_bool()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool is_in2_bool()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
IN1 min1()
|
||||
{
|
||||
return detail::get_min<IN1>();
|
||||
}
|
||||
|
||||
IN1 max1()
|
||||
{
|
||||
return detail::get_max<IN1>();
|
||||
}
|
||||
|
||||
IN2 min2()
|
||||
{
|
||||
return detail::get_min<IN2>();
|
||||
}
|
||||
|
||||
IN2 max2()
|
||||
{
|
||||
return detail::get_max<IN2>();
|
||||
}
|
||||
|
||||
std::vector<IN1> in1_special_cases()
|
||||
{
|
||||
return { };
|
||||
}
|
||||
|
||||
std::vector<IN2> in2_special_cases()
|
||||
{
|
||||
return { };
|
||||
}
|
||||
|
||||
template<class T>
|
||||
typename make_vector_type<cl_double, vector_size<T>::value>::type
|
||||
delta(const IN1& in1, const IN2& in2, const T& expected)
|
||||
{
|
||||
typedef
|
||||
typename make_vector_type<cl_double, vector_size<T>::value>::type
|
||||
delta_vector_type;
|
||||
// Take care of unused variable warning
|
||||
(void) in1;
|
||||
(void) in2;
|
||||
auto e = detail::make_value<delta_vector_type>(1e-3);
|
||||
return detail::multiply<delta_vector_type>(e, expected);
|
||||
}
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
// ------------- ONLY FOR OPENCL 22 CONFORMANCE TEST 22 DEVELOPMENT ------------------
|
||||
// -----------------------------------------------------------------------------------
|
||||
#if defined(DEVELOPMENT) && defined(USE_OPENCLC_KERNELS)
|
||||
template <class func_type, class in1_type, class in2_type, class out_type>
|
||||
std::string generate_kernel_binary(func_type func)
|
||||
{
|
||||
std::string in1_value = "input1[gid]";
|
||||
if(func.is_in1_bool())
|
||||
{
|
||||
std::string i = vector_size<in1_type>::value == 1 ? "" : std::to_string(vector_size<in1_type>::value);
|
||||
in1_value = "(input1[gid] != (int" + i + ")(0))";
|
||||
}
|
||||
std::string in2_value = "input2[gid]";
|
||||
if(func.is_in2_bool())
|
||||
{
|
||||
std::string i = vector_size<in2_type>::value == 1 ? "" : std::to_string(vector_size<in2_type>::value);
|
||||
in2_value = "(input2[gid] != (int" + i + ")(0))";
|
||||
}
|
||||
std::string function_call = func.str() + "(" + in1_value + ", " + in2_value + ")";
|
||||
if(func.is_out_bool())
|
||||
{
|
||||
std::string i = vector_size<out_type>::value == 1 ? "" : std::to_string(vector_size<out_type>::value);
|
||||
function_call = "convert_int" + i + "(" + func.str() + "(" + in1_value + ", " + in2_value + "))";
|
||||
}
|
||||
return
|
||||
"__kernel void " + func.get_kernel_name() + "(global " + type_name<in1_type>() + " *input1,\n"
|
||||
" global " + type_name<in2_type>() + " *input2,\n"
|
||||
" global " + type_name<out_type>() + " *output)\n"
|
||||
"{\n"
|
||||
" size_t gid = get_global_id(0);\n"
|
||||
" output[gid] = " + function_call + ";\n"
|
||||
"}\n";
|
||||
}
|
||||
#else
|
||||
template <class func_type, class in1_type, class in2_type, class out_type>
|
||||
std::string generate_kernel_binary(func_type func)
|
||||
{
|
||||
std::string headers = func.headers();
|
||||
std::string in1_value = "input1[gid]";
|
||||
if(func.is_in1_bool())
|
||||
{
|
||||
std::string i = vector_size<in1_type>::value == 1 ? "" : std::to_string(vector_size<in1_type>::value);
|
||||
in1_value = "(input1[gid] != (int" + i + ")(0))";
|
||||
}
|
||||
std::string in2_value = "input2[gid]";
|
||||
if(func.is_in2_bool())
|
||||
{
|
||||
std::string i = vector_size<in2_type>::value == 1 ? "" : std::to_string(vector_size<in2_type>::value);
|
||||
in2_value = "(input2[gid] != (int" + i + ")(0))";
|
||||
}
|
||||
std::string function_call = func.str() + "(" + in1_value + ", " + in2_value + ")";
|
||||
if(func.is_out_bool())
|
||||
{
|
||||
std::string i = vector_size<out_type>::value == 1 ? "" : std::to_string(vector_size<out_type>::value);
|
||||
function_call = "convert_cast<int" + i + ">(" + func.str() + "(" + in1_value + ", " + in2_value + "))";
|
||||
}
|
||||
if(func.is_out_bool() || func.is_in1_bool() || func.is_in2_bool())
|
||||
{
|
||||
if(headers.find("#include <opencl_convert>") == std::string::npos)
|
||||
{
|
||||
headers += "#include <opencl_convert>\n";
|
||||
}
|
||||
}
|
||||
return
|
||||
"" + func.defs() +
|
||||
"" + headers +
|
||||
"#include <opencl_memory>\n"
|
||||
"#include <opencl_work_item>\n"
|
||||
"using namespace cl;\n"
|
||||
"__kernel void " + func.get_kernel_name() + "(global_ptr<" + type_name<in1_type>() + "[]> input1,\n"
|
||||
" global_ptr<" + type_name<in2_type>() + "[]> input2,\n"
|
||||
" global_ptr<" + type_name<out_type>() + "[]> output)\n"
|
||||
"{\n"
|
||||
" size_t gid = get_global_id(0);\n"
|
||||
" output[gid] = " + function_call + ";\n"
|
||||
"}\n";
|
||||
}
|
||||
#endif
|
||||
|
||||
template<class INPUT1, class INPUT2, class OUTPUT, class binary_op>
|
||||
bool verify_binary(const std::vector<INPUT1> &in1,
|
||||
const std::vector<INPUT2> &in2,
|
||||
const std::vector<OUTPUT> &out,
|
||||
binary_op op)
|
||||
{
|
||||
for(size_t i = 0; i < in1.size(); i++)
|
||||
{
|
||||
auto expected = op(in1[i], in2[i]);
|
||||
if(!are_equal(expected, out[i], op.delta(in1[i], in2[i], expected), op))
|
||||
{
|
||||
print_error_msg(expected, out[i], i, op);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class binary_op>
|
||||
int test_binary_func(cl_device_id device, cl_context context, cl_command_queue queue, size_t count, binary_op op)
|
||||
{
|
||||
cl_mem buffers[3];
|
||||
cl_program program;
|
||||
cl_kernel kernel;
|
||||
size_t work_size[1];
|
||||
int err;
|
||||
|
||||
typedef typename binary_op::in1_type INPUT1;
|
||||
typedef typename binary_op::in2_type INPUT2;
|
||||
typedef typename binary_op::out_type OUTPUT;
|
||||
|
||||
// Don't run test for unsupported types
|
||||
if(!(type_supported<INPUT1>(device)
|
||||
&& type_supported<INPUT2>(device)
|
||||
&& type_supported<OUTPUT>(device)))
|
||||
{
|
||||
return CL_SUCCESS;
|
||||
}
|
||||
|
||||
std::string code_str = generate_kernel_binary<binary_op, INPUT1, INPUT2, OUTPUT>(op);
|
||||
std::string kernel_name = op.get_kernel_name();
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
// ------------- ONLY FOR OPENCL 22 CONFORMANCE TEST 22 DEVELOPMENT ------------------
|
||||
// -----------------------------------------------------------------------------------
|
||||
// Only OpenCL C++ to SPIR-V compilation
|
||||
#if defined(DEVELOPMENT) && defined(ONLY_SPIRV_COMPILATION)
|
||||
err = create_opencl_kernel(context, &program, &kernel, code_str, kernel_name);
|
||||
RETURN_ON_ERROR(err)
|
||||
return err;
|
||||
// Use OpenCL C kernels instead of OpenCL C++ kernels (test C++ host code)
|
||||
#elif defined(DEVELOPMENT) && defined(USE_OPENCLC_KERNELS)
|
||||
err = create_opencl_kernel(context, &program, &kernel, code_str, kernel_name, "-cl-std=CL2.0", false);
|
||||
RETURN_ON_ERROR(err)
|
||||
#else
|
||||
err = create_opencl_kernel(context, &program, &kernel, code_str, kernel_name);
|
||||
RETURN_ON_ERROR(err)
|
||||
#endif
|
||||
|
||||
std::vector<INPUT1> in1_spec_cases = op.in1_special_cases();
|
||||
std::vector<INPUT2> in2_spec_cases = op.in2_special_cases();
|
||||
prepare_special_cases(in1_spec_cases, in2_spec_cases);
|
||||
std::vector<INPUT1> input1 = generate_input<INPUT1>(count, op.min1(), op.max1(), in1_spec_cases);
|
||||
std::vector<INPUT2> input2 = generate_input<INPUT2>(count, op.min2(), op.max2(), in2_spec_cases);
|
||||
std::vector<OUTPUT> output = generate_output<OUTPUT>(count);
|
||||
|
||||
buffers[0] = clCreateBuffer(
|
||||
context, (cl_mem_flags)(CL_MEM_READ_WRITE), sizeof(INPUT1) * input1.size(), NULL, &err
|
||||
);
|
||||
RETURN_ON_CL_ERROR(err, "clCreateBuffer")
|
||||
|
||||
buffers[1] = clCreateBuffer(
|
||||
context, (cl_mem_flags)(CL_MEM_READ_WRITE), sizeof(INPUT2) * input2.size(), NULL, &err
|
||||
);
|
||||
RETURN_ON_CL_ERROR(err, "clCreateBuffer")
|
||||
|
||||
buffers[2] = clCreateBuffer(
|
||||
context, (cl_mem_flags)(CL_MEM_READ_WRITE), sizeof(OUTPUT) * output.size(), NULL, &err
|
||||
);
|
||||
RETURN_ON_CL_ERROR(err, "clCreateBuffer")
|
||||
|
||||
err = clEnqueueWriteBuffer(
|
||||
queue, buffers[0], CL_TRUE, 0, sizeof(INPUT1) * input1.size(),
|
||||
static_cast<void *>(input1.data()), 0, NULL, NULL
|
||||
);
|
||||
RETURN_ON_CL_ERROR(err, "clEnqueueWriteBuffer")
|
||||
|
||||
err = clEnqueueWriteBuffer(
|
||||
queue, buffers[1], CL_TRUE, 0, sizeof(INPUT2) * input2.size(),
|
||||
static_cast<void *>(input2.data()), 0, NULL, NULL
|
||||
);
|
||||
RETURN_ON_CL_ERROR(err, "clEnqueueWriteBuffer")
|
||||
|
||||
err = clSetKernelArg(kernel, 0, sizeof(buffers[0]), &buffers[0]);
|
||||
err |= clSetKernelArg(kernel, 1, sizeof(buffers[1]), &buffers[1]);
|
||||
err |= clSetKernelArg(kernel, 2, sizeof(buffers[2]), &buffers[2]);
|
||||
RETURN_ON_CL_ERROR(err, "clSetKernelArg");
|
||||
|
||||
work_size[0] = count;
|
||||
err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, work_size, NULL, 0, NULL, NULL);
|
||||
RETURN_ON_CL_ERROR(err, "clEnqueueNDRangeKernel");
|
||||
|
||||
err = clEnqueueReadBuffer(
|
||||
queue, buffers[2], CL_TRUE, 0, sizeof(OUTPUT) * output.size(),
|
||||
static_cast<void *>(output.data()), 0, NULL, NULL
|
||||
);
|
||||
RETURN_ON_CL_ERROR(err, "clEnqueueReadBuffer");
|
||||
|
||||
if (!verify_binary(input1, input2, output, op))
|
||||
{
|
||||
RETURN_ON_ERROR_MSG(-1,
|
||||
"test_%s %s(%s, %s) failed", op.str().c_str(),
|
||||
type_name<OUTPUT>().c_str(), type_name<INPUT1>().c_str(), type_name<INPUT2>().c_str()
|
||||
);
|
||||
}
|
||||
log_info(
|
||||
"test_%s %s(%s, %s) passed\n", op.str().c_str(),
|
||||
type_name<OUTPUT>().c_str(), type_name<INPUT1>().c_str(), type_name<INPUT2>().c_str()
|
||||
);
|
||||
|
||||
clReleaseMemObject(buffers[0]);
|
||||
clReleaseMemObject(buffers[1]);
|
||||
clReleaseMemObject(buffers[2]);
|
||||
clReleaseKernel(kernel);
|
||||
clReleaseProgram(program);
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif // TEST_CONFORMANCE_CLCPP_UTILS_TEST_BINARY_HPP
|
||||
161
test_conformance/clcpp/utils_test/compare.hpp
Normal file
161
test_conformance/clcpp/utils_test/compare.hpp
Normal file
@@ -0,0 +1,161 @@
|
||||
//
|
||||
// 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_UTILS_TEST_COMPARE_HPP
|
||||
#define TEST_CONFORMANCE_CLCPP_UTILS_TEST_COMPARE_HPP
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <algorithm>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "../common.hpp"
|
||||
|
||||
// Checks if x is equal to y.
|
||||
template<class type, class delta_type, class op_type>
|
||||
inline bool are_equal(const type& x,
|
||||
const type& y,
|
||||
const delta_type& delta,
|
||||
op_type op,
|
||||
typename std::enable_if<
|
||||
is_vector_type<type>::value
|
||||
&& std::is_integral<typename scalar_type<type>::type>::value
|
||||
>::type* = 0)
|
||||
{
|
||||
(void) delta;
|
||||
for(size_t i = 0; i < vector_size<type>::value; i++)
|
||||
{
|
||||
if(op.is_out_bool())
|
||||
{
|
||||
if(!((x.s[i] != 0) == (y.s[i] != 0)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if(!(x.s[i] == y.s[i]))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class type, class delta_type, class op_type>
|
||||
inline bool are_equal(const type& x,
|
||||
const type& y,
|
||||
const delta_type& delta,
|
||||
op_type op,
|
||||
typename std::enable_if<
|
||||
!is_vector_type<type>::value
|
||||
&& std::is_integral<type>::value
|
||||
>::type* = 0)
|
||||
{
|
||||
(void) delta;
|
||||
if(op.is_out_bool())
|
||||
{
|
||||
if(!((x != 0) == (y != 0)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return x == y;
|
||||
}
|
||||
|
||||
template<class type, class type1, class type2, class op_type>
|
||||
inline bool are_equal(const type& x,
|
||||
const type1& y,
|
||||
const type2& delta,
|
||||
op_type op,
|
||||
typename std::enable_if<
|
||||
!is_vector_type<type>::value
|
||||
&& std::is_floating_point<type>::value
|
||||
>::type* = 0)
|
||||
{
|
||||
// x - expected
|
||||
// y - result
|
||||
|
||||
// INFO:
|
||||
// Whe don't care about subnormal values in OpenCL C++ tests
|
||||
if(std::fpclassify(static_cast<type1>(x)) == FP_SUBNORMAL || std::fpclassify(y) == FP_SUBNORMAL)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// both are NaN
|
||||
if((std::isnan)(static_cast<type1>(x)) && (std::isnan)(y))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// one is NaN
|
||||
else if((std::isnan)(static_cast<type1>(x)) || (std::isnan)(y))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for perfect match, it also covers inf, -inf
|
||||
if(static_cast<type1>(x) != y)
|
||||
{
|
||||
// Check if values are close
|
||||
if(std::abs(static_cast<type1>(x) - y) > (std::max)(std::numeric_limits<type2>::epsilon(), std::abs(delta)))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// Check ulp
|
||||
if(op.use_ulp())
|
||||
{
|
||||
return !(std::abs(Ulp_Error(x, y)) > op.ulp());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class type, class type1, class type2, class op_type>
|
||||
inline bool are_equal(const type& x,
|
||||
const type1& y,
|
||||
const type2& delta,
|
||||
op_type op,
|
||||
typename std::enable_if<
|
||||
is_vector_type<type>::value
|
||||
&& std::is_floating_point<typename scalar_type<type>::type>::value
|
||||
>::type* = 0)
|
||||
{
|
||||
// x - expected
|
||||
// y - result
|
||||
for(size_t i = 0; i < vector_size<type>::value; i++)
|
||||
{
|
||||
if(!are_equal(x.s[i], y.s[i], delta.s[i], op))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class type, class type1, class func>
|
||||
inline void print_error_msg(const type& expected, const type1& result, size_t i, func op)
|
||||
{
|
||||
log_error(
|
||||
"ERROR: test_%s %s failed. Error at %lu: Expected: %s, got: %s\n",
|
||||
op.str().c_str(),
|
||||
op.decl_str().c_str(),
|
||||
i,
|
||||
format_value(expected).c_str(),
|
||||
format_value(result).c_str()
|
||||
);
|
||||
}
|
||||
|
||||
#endif // TEST_CONFORMANCE_CLCPP_UTILS_TEST_COMPARE_HPP
|
||||
112
test_conformance/clcpp/utils_test/detail/base_func_type.hpp
Normal file
112
test_conformance/clcpp/utils_test/detail/base_func_type.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_UTILS_TEST_DETAIL_BASE_FUNC_TYPE_HPP
|
||||
#define TEST_CONFORMANCE_CLCPP_UTILS_TEST_DETAIL_BASE_FUNC_TYPE_HPP
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <algorithm>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "../../common.hpp"
|
||||
|
||||
#include "vec_helpers.hpp"
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class OUT1>
|
||||
struct base_func_type
|
||||
{
|
||||
virtual ~base_func_type() {};
|
||||
|
||||
// Returns function name
|
||||
virtual std::string str() = 0;
|
||||
|
||||
// Returns name of the test kernel for that function
|
||||
virtual std::string get_kernel_name()
|
||||
{
|
||||
std::string kn = this->str();
|
||||
replace_all(kn, "::", "_");
|
||||
return "test_" + kn;
|
||||
}
|
||||
|
||||
// Returns required defines and pragmas.
|
||||
virtual std::string defs()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
// Returns required OpenCL C++ headers.
|
||||
virtual std::string headers()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
// Return true if OUT1 type in OpenCL kernel should be treated
|
||||
// as bool type; false otherwise.
|
||||
bool is_out_bool()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Max ULP error, that is error should be raised when
|
||||
// if Ulp_Error(result, expected) > ulp()
|
||||
float ulp()
|
||||
{
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
// Should we check ULP error when verifing if the result is
|
||||
// correct?
|
||||
//
|
||||
// (This effects how are_equal() function works,
|
||||
// it may not have effect if verify() method in derived
|
||||
// class does not use are_equal() function.)
|
||||
//
|
||||
// Only for FP numbers/vectors
|
||||
bool use_ulp()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Max error. Error should be raised if
|
||||
// abs(result - expected) > delta(.., expected)
|
||||
//
|
||||
// Default value: 0.001 * expected
|
||||
//
|
||||
// (This effects how are_equal() function works,
|
||||
// it may not have effect if verify() method in derived
|
||||
// class does not use are_equal() function.)
|
||||
//
|
||||
// Only for FP numbers/vectors
|
||||
template<class T>
|
||||
typename make_vector_type<cl_double, vector_size<T>::value>::type
|
||||
delta(const T& expected)
|
||||
{
|
||||
typedef
|
||||
typename make_vector_type<cl_double, vector_size<T>::value>::type
|
||||
delta_vector_type;
|
||||
auto e = detail::make_value<delta_vector_type>(1e-3);
|
||||
return detail::multiply<delta_vector_type>(e, expected);
|
||||
}
|
||||
};
|
||||
|
||||
} // detail namespace
|
||||
|
||||
#endif // TEST_CONFORMANCE_CLCPP_UTILS_TEST_DETAIL_BASE_FUNC_TYPE_HPP
|
||||
104
test_conformance/clcpp/utils_test/detail/vec_helpers.hpp
Normal file
104
test_conformance/clcpp/utils_test/detail/vec_helpers.hpp
Normal file
@@ -0,0 +1,104 @@
|
||||
//
|
||||
// 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_UTILS_TEST_DETAIL_VEC_HELPERS_HPP
|
||||
#define TEST_CONFORMANCE_CLCPP_UTILS_TEST_DETAIL_VEC_HELPERS_HPP
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <algorithm>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "../../common.hpp"
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class T>
|
||||
T make_value(typename scalar_type<T>::type x, typename std::enable_if<is_vector_type<T>::value>::type* = 0)
|
||||
{
|
||||
T value;
|
||||
for(size_t i = 0; i < vector_size<T>::value; i++)
|
||||
{
|
||||
value.s[i] = x;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T make_value(T x, typename std::enable_if<!is_vector_type<T>::value>::type* = 0)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
template<class result_type, class IN1, class IN2>
|
||||
result_type multiply(const IN1& x, const IN2& y, typename std::enable_if<is_vector_type<result_type>::value>::type* = 0)
|
||||
{
|
||||
static_assert(
|
||||
(vector_size<IN1>::value == vector_size<IN2>::value)
|
||||
&& (vector_size<IN2>::value == vector_size<result_type>::value),
|
||||
"Vector sizes must be the same."
|
||||
);
|
||||
typedef typename scalar_type<result_type>::type SCALAR;
|
||||
result_type value;
|
||||
for(size_t i = 0; i < vector_size<result_type>::value; i++)
|
||||
{
|
||||
value.s[i] = static_cast<SCALAR>(x.s[i]) * static_cast<SCALAR>(y.s[i]);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
template<class result_type, class IN1, class IN2>
|
||||
result_type multiply(const IN1& x, const IN2& y, typename std::enable_if<!is_vector_type<result_type>::value>::type* = 0)
|
||||
{
|
||||
static_assert(
|
||||
!is_vector_type<IN1>::value && !is_vector_type<IN2>::value,
|
||||
"IN1 and IN2 must be scalar types"
|
||||
);
|
||||
return static_cast<result_type>(x) * static_cast<result_type>(y);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T get_min()
|
||||
{
|
||||
typedef typename scalar_type<T>::type SCALAR;
|
||||
return make_value<T>((std::numeric_limits<SCALAR>::min)());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T get_max()
|
||||
{
|
||||
typedef typename scalar_type<T>::type SCALAR;
|
||||
return make_value<T>((std::numeric_limits<SCALAR>::max)());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T get_part_max(typename scalar_type<T>::type x)
|
||||
{
|
||||
typedef typename scalar_type<T>::type SCALAR;
|
||||
return make_value<T>((std::numeric_limits<SCALAR>::max)() / x);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T def_limit(typename scalar_type<T>::type x)
|
||||
{
|
||||
return make_value<T>(x);
|
||||
}
|
||||
|
||||
} // detail namespace
|
||||
|
||||
#endif // TEST_CONFORMANCE_CLCPP_UTILS_TEST_DETAIL_VEC_HELPERS_HPP
|
||||
331
test_conformance/clcpp/utils_test/generate_inputs.hpp
Normal file
331
test_conformance/clcpp/utils_test/generate_inputs.hpp
Normal file
@@ -0,0 +1,331 @@
|
||||
//
|
||||
// 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_UTILS_TEST_GENERATE_INPUTS_HPP
|
||||
#define TEST_CONFORMANCE_CLCPP_UTILS_TEST_GENERATE_INPUTS_HPP
|
||||
|
||||
#include <random>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
#include <algorithm>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "../common.hpp"
|
||||
|
||||
template <class type>
|
||||
std::vector<type> generate_input(size_t count,
|
||||
const type& min,
|
||||
const type& max,
|
||||
const std::vector<type> special_cases,
|
||||
typename std::enable_if<
|
||||
is_vector_type<type>::value
|
||||
&& std::is_integral<typename scalar_type<type>::type>::value
|
||||
// std::uniform_int_distribution<> does not work in VS2015 for cl_uchar and cl_char,
|
||||
// because VS2015 thinks that use cl_int, because VS2015 thinks cl_uchar cl_char are
|
||||
// not int types
|
||||
&& !(std::is_same<typename scalar_type<type>::type, cl_uchar>::value
|
||||
|| std::is_same<typename scalar_type<type>::type, cl_char>::value)
|
||||
>::type* = 0)
|
||||
{
|
||||
typedef typename scalar_type<type>::type SCALAR;
|
||||
const size_t vec_size = vector_size<type>::value;
|
||||
|
||||
std::vector<type> input(count);
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
std::vector<std::uniform_int_distribution<SCALAR>> dists(vec_size);
|
||||
for(size_t i = 0; i < vec_size; i++)
|
||||
{
|
||||
dists[i] = std::uniform_int_distribution<SCALAR>(min.s[i], max.s[i]);
|
||||
}
|
||||
for(auto& i : input)
|
||||
{
|
||||
for(size_t j = 0; j < vec_size; j++)
|
||||
{
|
||||
i.s[j] = dists[j](gen);
|
||||
}
|
||||
}
|
||||
|
||||
input.insert(input.begin(), special_cases.begin(), special_cases.end());
|
||||
input.resize(count);
|
||||
return input;
|
||||
}
|
||||
|
||||
template <class type>
|
||||
std::vector<type> generate_input(size_t count,
|
||||
const type& min,
|
||||
const type& max,
|
||||
const std::vector<type> special_cases,
|
||||
typename std::enable_if<
|
||||
is_vector_type<type>::value
|
||||
&& std::is_integral<typename scalar_type<type>::type>::value
|
||||
// std::uniform_int_distribution<> does not work in VS2015 for cl_uchar and cl_char,
|
||||
// because VS2015 thinks that use cl_int, because VS2015 thinks cl_uchar cl_char are
|
||||
// not int types
|
||||
&& (std::is_same<typename scalar_type<type>::type, cl_uchar>::value
|
||||
|| std::is_same<typename scalar_type<type>::type, cl_char>::value)
|
||||
>::type* = 0)
|
||||
{
|
||||
typedef typename scalar_type<type>::type SCALAR;
|
||||
const size_t vec_size = vector_size<type>::value;
|
||||
|
||||
std::vector<type> input(count);
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
std::vector<std::uniform_int_distribution<cl_int>> dists(vec_size);
|
||||
for(size_t i = 0; i < vec_size; i++)
|
||||
{
|
||||
dists[i] = std::uniform_int_distribution<cl_int>(
|
||||
static_cast<cl_int>(min.s[i]),
|
||||
static_cast<cl_int>(max.s[i])
|
||||
);
|
||||
}
|
||||
for(auto& i : input)
|
||||
{
|
||||
for(size_t j = 0; j < vec_size; j++)
|
||||
{
|
||||
i.s[j] = static_cast<SCALAR>(dists[j](gen));
|
||||
}
|
||||
}
|
||||
|
||||
input.insert(input.begin(), special_cases.begin(), special_cases.end());
|
||||
input.resize(count);
|
||||
return input;
|
||||
}
|
||||
|
||||
|
||||
template <class type>
|
||||
std::vector<type> generate_input(size_t count,
|
||||
const type& min,
|
||||
const type& max,
|
||||
const std::vector<type> special_cases,
|
||||
typename std::enable_if<
|
||||
!is_vector_type<type>::value
|
||||
&& std::is_integral<type>::value
|
||||
// std::uniform_int_distribution<> does not work in VS2015 for cl_uchar and cl_char,
|
||||
// because VS2015 thinks that use cl_int, because VS2015 thinks cl_uchar cl_char are
|
||||
// not int types
|
||||
&& !(std::is_same<type, cl_uchar>::value || std::is_same<type, cl_char>::value)
|
||||
>::type* = 0)
|
||||
{
|
||||
std::vector<type> input(count);
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
std::uniform_int_distribution<type> dis(min, max);
|
||||
for(auto& i : input)
|
||||
{
|
||||
i = dis(gen);
|
||||
}
|
||||
|
||||
input.insert(input.begin(), special_cases.begin(), special_cases.end());
|
||||
input.resize(count);
|
||||
return input;
|
||||
}
|
||||
|
||||
template <class type>
|
||||
std::vector<type> generate_input(size_t count,
|
||||
const type& min,
|
||||
const type& max,
|
||||
const std::vector<type> special_cases,
|
||||
typename std::enable_if<
|
||||
!is_vector_type<type>::value
|
||||
&& std::is_integral<type>::value
|
||||
// std::uniform_int_distribution<> does not work in VS2015 for cl_uchar and cl_char,
|
||||
// because VS2015 thinks that use cl_int, because VS2015 thinks cl_uchar cl_char are
|
||||
// not int types
|
||||
&& (std::is_same<type, cl_uchar>::value || std::is_same<type, cl_char>::value)
|
||||
>::type* = 0)
|
||||
{
|
||||
std::vector<type> input(count);
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
std::uniform_int_distribution<cl_int> dis(
|
||||
static_cast<cl_int>(min), static_cast<cl_int>(max)
|
||||
);
|
||||
for(auto& i : input)
|
||||
{
|
||||
i = static_cast<type>(dis(gen));
|
||||
}
|
||||
|
||||
input.insert(input.begin(), special_cases.begin(), special_cases.end());
|
||||
input.resize(count);
|
||||
return input;
|
||||
}
|
||||
|
||||
template <class type>
|
||||
std::vector<type> generate_input(size_t count,
|
||||
const type& min,
|
||||
const type& max,
|
||||
const std::vector<type> special_cases,
|
||||
typename std::enable_if<
|
||||
is_vector_type<type>::value
|
||||
&& std::is_floating_point<typename scalar_type<type>::type>::value
|
||||
>::type* = 0)
|
||||
{
|
||||
typedef typename scalar_type<type>::type SCALAR;
|
||||
const size_t vec_size = vector_size<type>::value;
|
||||
|
||||
std::vector<type> input(count);
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
std::vector<std::uniform_real_distribution<SCALAR>> dists(vec_size);
|
||||
for(size_t i = 0; i < vec_size; i++)
|
||||
{
|
||||
// Fatal error
|
||||
if(std::fpclassify(max.s[i]) == FP_SUBNORMAL || std::fpclassify(min.s[i]) == FP_SUBNORMAL)
|
||||
{
|
||||
log_error("ERROR: min and max value for input generation CAN NOT BE subnormal\n");
|
||||
}
|
||||
dists[i] = std::uniform_real_distribution<SCALAR>(min.s[i], max.s[i]);
|
||||
}
|
||||
for(auto& i : input)
|
||||
{
|
||||
for(size_t j = 0; j < vec_size; j++)
|
||||
{
|
||||
SCALAR x = dists[j](gen);
|
||||
while(std::fpclassify(x) == FP_SUBNORMAL)
|
||||
{
|
||||
x = dists[j](gen);
|
||||
}
|
||||
i.s[j] = x;
|
||||
}
|
||||
}
|
||||
|
||||
input.insert(input.begin(), special_cases.begin(), special_cases.end());
|
||||
input.resize(count);
|
||||
return input;
|
||||
}
|
||||
|
||||
template <class type>
|
||||
std::vector<type> generate_input(size_t count,
|
||||
const type& min,
|
||||
const type& max,
|
||||
const std::vector<type> special_cases,
|
||||
typename std::enable_if<
|
||||
!is_vector_type<type>::value
|
||||
&& std::is_floating_point<type>::value
|
||||
>::type* = 0)
|
||||
{
|
||||
// Fatal error
|
||||
if(std::fpclassify(max) == FP_SUBNORMAL || std::fpclassify(min) == FP_SUBNORMAL)
|
||||
{
|
||||
log_error("ERROR: min and max value for input generation CAN NOT BE subnormal\n");
|
||||
}
|
||||
std::vector<type> input(count);
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
std::uniform_real_distribution<type> dis(min, max);
|
||||
for(auto& i : input)
|
||||
{
|
||||
type x = dis(gen);
|
||||
while(std::fpclassify(x) == FP_SUBNORMAL)
|
||||
{
|
||||
x = dis(gen);
|
||||
}
|
||||
i = x;
|
||||
}
|
||||
|
||||
input.insert(input.begin(), special_cases.begin(), special_cases.end());
|
||||
input.resize(count);
|
||||
return input;
|
||||
}
|
||||
|
||||
template <class type>
|
||||
std::vector<type> generate_output(size_t count,
|
||||
typename scalar_type<type>::type svalue = typename scalar_type<type>::type(0),
|
||||
typename std::enable_if<is_vector_type<type>::value>::type* = 0)
|
||||
{
|
||||
type value;
|
||||
for(size_t i = 0; i < vector_size<type>::value; i++)
|
||||
value.s[i] = svalue;
|
||||
return std::vector<type>(count, value);
|
||||
}
|
||||
|
||||
template <class type>
|
||||
std::vector<type> generate_output(size_t count,
|
||||
type svalue = type(0),
|
||||
typename std::enable_if<!is_vector_type<type>::value>::type* = 0)
|
||||
{
|
||||
return std::vector<type>(count, svalue);
|
||||
}
|
||||
|
||||
template<class T, class K>
|
||||
void prepare_special_cases(std::vector<T>& in1_spec_cases, std::vector<K>& in2_spec_cases)
|
||||
{
|
||||
if(in1_spec_cases.empty() || in2_spec_cases.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
size_t new_size = in1_spec_cases.size() * in2_spec_cases.size();
|
||||
std::vector<T> new_in1(new_size);
|
||||
std::vector<K> new_in2(new_size);
|
||||
for(size_t i = 0; i < in1_spec_cases.size(); i++)
|
||||
{
|
||||
for(size_t j = 0; j < in2_spec_cases.size(); j++)
|
||||
{
|
||||
new_in1[(i * in2_spec_cases.size()) + j] = in1_spec_cases[i];
|
||||
new_in2[(i * in2_spec_cases.size()) + j] = in2_spec_cases[j];
|
||||
}
|
||||
}
|
||||
in1_spec_cases = new_in1;
|
||||
in2_spec_cases = new_in2;
|
||||
}
|
||||
|
||||
template<class T, class K, class M>
|
||||
void prepare_special_cases(std::vector<T>& in1_spec_cases,
|
||||
std::vector<K>& in2_spec_cases,
|
||||
std::vector<M>& in3_spec_cases)
|
||||
{
|
||||
if(in3_spec_cases.empty())
|
||||
{
|
||||
return prepare_special_cases(in1_spec_cases, in2_spec_cases);
|
||||
}
|
||||
else if (in2_spec_cases.empty())
|
||||
{
|
||||
return prepare_special_cases(in1_spec_cases, in3_spec_cases);
|
||||
}
|
||||
else if (in1_spec_cases.empty())
|
||||
{
|
||||
return prepare_special_cases(in2_spec_cases, in3_spec_cases);
|
||||
}
|
||||
|
||||
size_t new_size = in1_spec_cases.size() * in2_spec_cases.size() * in3_spec_cases.size();
|
||||
std::vector<T> new_in1(new_size);
|
||||
std::vector<K> new_in2(new_size);
|
||||
std::vector<M> new_in3(new_size);
|
||||
for(size_t i = 0; i < in1_spec_cases.size(); i++)
|
||||
{
|
||||
for(size_t j = 0; j < in2_spec_cases.size(); j++)
|
||||
{
|
||||
for(size_t k = 0; k < in3_spec_cases.size(); k++)
|
||||
{
|
||||
size_t idx =
|
||||
(i * in2_spec_cases.size() * in3_spec_cases.size())
|
||||
+ (j * in3_spec_cases.size())
|
||||
+ k;
|
||||
new_in1[idx] = in1_spec_cases[i];
|
||||
new_in2[idx] = in2_spec_cases[j];
|
||||
new_in3[idx] = in3_spec_cases[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
in1_spec_cases = new_in1;
|
||||
in2_spec_cases = new_in2;
|
||||
in3_spec_cases = new_in3;
|
||||
}
|
||||
|
||||
#endif // TEST_CONFORMANCE_CLCPP_UTILS_TEST_GENERATE_INPUTS_HPP
|
||||
368
test_conformance/clcpp/utils_test/ternary.hpp
Normal file
368
test_conformance/clcpp/utils_test/ternary.hpp
Normal file
@@ -0,0 +1,368 @@
|
||||
//
|
||||
// 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_UTILS_TEST_TERNARY_HPP
|
||||
#define TEST_CONFORMANCE_CLCPP_UTILS_TEST_TERNARY_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <cmath>
|
||||
|
||||
#include "../common.hpp"
|
||||
|
||||
#include "detail/base_func_type.hpp"
|
||||
#include "generate_inputs.hpp"
|
||||
#include "compare.hpp"
|
||||
|
||||
template<class IN1, class IN2, class IN3, class OUT1>
|
||||
struct ternary_func : public detail::base_func_type<OUT1>
|
||||
{
|
||||
typedef IN1 in1_type;
|
||||
typedef IN2 in2_type;
|
||||
typedef IN3 in3_type;
|
||||
typedef OUT1 out_type;
|
||||
|
||||
virtual ~ternary_func() {};
|
||||
virtual std::string str() = 0;
|
||||
|
||||
std::string decl_str()
|
||||
{
|
||||
return type_name<OUT1>() + "(" + type_name<IN1>() + ", " + type_name<IN2>()+ ", " + type_name<IN3>() + ")";
|
||||
}
|
||||
|
||||
bool is_in1_bool()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool is_in2_bool()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool is_in3_bool()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
IN1 min1()
|
||||
{
|
||||
return detail::get_min<IN1>();
|
||||
}
|
||||
|
||||
IN1 max1()
|
||||
{
|
||||
return detail::get_max<IN1>();
|
||||
}
|
||||
|
||||
IN2 min2()
|
||||
{
|
||||
return detail::get_min<IN2>();
|
||||
}
|
||||
|
||||
IN2 max2()
|
||||
{
|
||||
return detail::get_max<IN2>();
|
||||
}
|
||||
|
||||
IN3 min3()
|
||||
{
|
||||
return detail::get_min<IN3>();
|
||||
}
|
||||
|
||||
IN3 max3()
|
||||
{
|
||||
return detail::get_max<IN3>();
|
||||
}
|
||||
|
||||
std::vector<IN1> in1_special_cases()
|
||||
{
|
||||
return { };
|
||||
}
|
||||
|
||||
std::vector<IN2> in2_special_cases()
|
||||
{
|
||||
return { };
|
||||
}
|
||||
|
||||
std::vector<IN3> in3_special_cases()
|
||||
{
|
||||
return { };
|
||||
}
|
||||
|
||||
template<class T>
|
||||
typename make_vector_type<cl_double, vector_size<T>::value>::type
|
||||
delta(const IN1& in1, const IN2& in2, const IN3& in3, const T& expected)
|
||||
{
|
||||
typedef
|
||||
typename make_vector_type<cl_double, vector_size<T>::value>::type
|
||||
delta_vector_type;
|
||||
// Take care of unused variable warning
|
||||
(void) in1;
|
||||
(void) in2;
|
||||
(void) in3;
|
||||
auto e = detail::make_value<delta_vector_type>(1e-3);
|
||||
return detail::multiply<delta_vector_type>(e, expected);
|
||||
}
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
// ------------- ONLY FOR OPENCL 22 CONFORMANCE TEST 22 DEVELOPMENT ------------------
|
||||
// -----------------------------------------------------------------------------------
|
||||
#if defined(DEVELOPMENT) && defined(USE_OPENCLC_KERNELS)
|
||||
template <class func_type, class in1_type, class in2_type, class in3_type, class out_type>
|
||||
std::string generate_kernel_ternary(func_type func)
|
||||
{
|
||||
std::string in1_value = "input1[gid]";
|
||||
if(func.is_in1_bool())
|
||||
{
|
||||
std::string i = vector_size<in1_type>::value == 1 ? "" : std::to_string(vector_size<in1_type>::value);
|
||||
in1_value = "(input1[gid] != (int" + i + ")(0))";
|
||||
}
|
||||
std::string in2_value = "input2[gid]";
|
||||
if(func.is_in2_bool())
|
||||
{
|
||||
std::string i = vector_size<in2_type>::value == 1 ? "" : std::to_string(vector_size<in2_type>::value);
|
||||
in2_value = "(input2[gid] != (int" + i + ")(0))";
|
||||
}
|
||||
std::string in3_value = "input3[gid]";
|
||||
if(func.is_in3_bool())
|
||||
{
|
||||
std::string i = vector_size<in3_type>::value == 1 ? "" : std::to_string(vector_size<in3_type>::value);
|
||||
in3_value = "(input3[gid] != (int" + i + ")(0))";
|
||||
}
|
||||
std::string function_call = func.str() + "(" + in1_value + ", " + in2_value + ", " + in3_value + ")";
|
||||
if(func.is_out_bool())
|
||||
{
|
||||
std::string i = vector_size<out_type>::value == 1 ? "" : std::to_string(vector_size<out_type>::value);
|
||||
function_call = "convert_int" + i + "(" + func.str() + "(" + in1_value + ", " + in2_value + ", " + in3_value + "))";
|
||||
}
|
||||
return
|
||||
"__kernel void " + func.get_kernel_name() + "(global " + type_name<in1_type>() + " *input1,\n"
|
||||
" global " + type_name<in2_type>() + " *input2,\n"
|
||||
" global " + type_name<in3_type>() + " *input3,\n"
|
||||
" global " + type_name<out_type>() + " *output)\n"
|
||||
"{\n"
|
||||
" size_t gid = get_global_id(0);\n"
|
||||
" output[gid] = " + function_call + ";\n"
|
||||
"}\n";
|
||||
}
|
||||
#else
|
||||
template <class func_type, class in1_type, class in2_type, class in3_type, class out_type>
|
||||
std::string generate_kernel_ternary(func_type func)
|
||||
{
|
||||
std::string headers = func.headers();
|
||||
std::string in1_value = "input1[gid]";
|
||||
if(func.is_in1_bool())
|
||||
{
|
||||
std::string i = vector_size<in1_type>::value == 1 ? "" : std::to_string(vector_size<in1_type>::value);
|
||||
in1_value = "(input1[gid] != (int" + i + ")(0))";
|
||||
}
|
||||
std::string in2_value = "input2[gid]";
|
||||
if(func.is_in2_bool())
|
||||
{
|
||||
std::string i = vector_size<in2_type>::value == 1 ? "" : std::to_string(vector_size<in2_type>::value);
|
||||
in2_value = "(input2[gid] != (int" + i + ")(0))";
|
||||
}
|
||||
std::string in3_value = "input3[gid]";
|
||||
if(func.is_in3_bool())
|
||||
{
|
||||
std::string i = vector_size<in3_type>::value == 1 ? "" : std::to_string(vector_size<in3_type>::value);
|
||||
in3_value = "(input3[gid] != (int" + i + ")(0))";
|
||||
}
|
||||
std::string function_call = func.str() + "(" + in1_value + ", " + in2_value + ", " + in3_value + ")";
|
||||
if(func.is_out_bool())
|
||||
{
|
||||
std::string i = vector_size<out_type>::value == 1 ? "" : std::to_string(vector_size<out_type>::value);
|
||||
function_call = "convert_cast<int" + i + ">(" + func.str() + "(" + in1_value + ", " + in2_value + ", " + in3_value + "))";
|
||||
}
|
||||
if(func.is_out_bool() || func.is_in1_bool() || func.is_in2_bool() || func.is_in3_bool())
|
||||
{
|
||||
if(headers.find("#include <opencl_convert>") == std::string::npos)
|
||||
{
|
||||
headers += "#include <opencl_convert>\n";
|
||||
}
|
||||
}
|
||||
return
|
||||
"" + func.defs() +
|
||||
"" + headers +
|
||||
"#include <opencl_memory>\n"
|
||||
"#include <opencl_work_item>\n"
|
||||
"using namespace cl;\n"
|
||||
"__kernel void " + func.get_kernel_name() + "(global_ptr<" + type_name<in1_type>() + "[]> input1,\n"
|
||||
" global_ptr<" + type_name<in2_type>() + "[]> input2,\n"
|
||||
" global_ptr<" + type_name<in3_type>() + "[]> input3,\n"
|
||||
" global_ptr<" + type_name<out_type>() + "[]> output)\n"
|
||||
"{\n"
|
||||
" size_t gid = get_global_id(0);\n"
|
||||
" output[gid] = " + function_call + ";\n"
|
||||
"}\n";
|
||||
}
|
||||
#endif
|
||||
|
||||
template<class INPUT1, class INPUT2, class INPUT3, class OUTPUT, class ternary_op>
|
||||
bool verify_ternary(const std::vector<INPUT1> &in1,
|
||||
const std::vector<INPUT2> &in2,
|
||||
const std::vector<INPUT3> &in3,
|
||||
const std::vector<OUTPUT> &out,
|
||||
ternary_op op)
|
||||
{
|
||||
for(size_t i = 0; i < in1.size(); i++)
|
||||
{
|
||||
auto expected = op(in1[i], in2[i], in3[i]);
|
||||
if(!are_equal(expected, out[i], op.delta(in1[i], in2[i], in3[i], expected), op))
|
||||
{
|
||||
print_error_msg(expected, out[i], i, op);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class ternary_op>
|
||||
int test_ternary_func(cl_device_id device, cl_context context, cl_command_queue queue, size_t count, ternary_op op)
|
||||
{
|
||||
cl_mem buffers[4];
|
||||
cl_program program;
|
||||
cl_kernel kernel;
|
||||
size_t work_size[1];
|
||||
int err;
|
||||
|
||||
typedef typename ternary_op::in1_type INPUT1;
|
||||
typedef typename ternary_op::in2_type INPUT2;
|
||||
typedef typename ternary_op::in3_type INPUT3;
|
||||
typedef typename ternary_op::out_type OUTPUT;
|
||||
|
||||
// Don't run test for unsupported types
|
||||
if(!(type_supported<INPUT1>(device)
|
||||
&& type_supported<INPUT2>(device)
|
||||
&& type_supported<INPUT3>(device)
|
||||
&& type_supported<OUTPUT>(device)))
|
||||
{
|
||||
return CL_SUCCESS;
|
||||
}
|
||||
|
||||
std::string code_str = generate_kernel_ternary<ternary_op, INPUT1, INPUT2, INPUT3, OUTPUT>(op);
|
||||
std::string kernel_name = op.get_kernel_name();
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
// ------------- ONLY FOR OPENCL 22 CONFORMANCE TEST 22 DEVELOPMENT ------------------
|
||||
// -----------------------------------------------------------------------------------
|
||||
// Only OpenCL C++ to SPIR-V compilation
|
||||
#if defined(DEVELOPMENT) && defined(ONLY_SPIRV_COMPILATION)
|
||||
err = create_opencl_kernel(context, &program, &kernel, code_str, kernel_name);
|
||||
RETURN_ON_ERROR(err)
|
||||
return err;
|
||||
// Use OpenCL C kernels instead of OpenCL C++ kernels (test C++ host code)
|
||||
#elif defined(DEVELOPMENT) && defined(USE_OPENCLC_KERNELS)
|
||||
err = create_opencl_kernel(context, &program, &kernel, code_str, kernel_name, "-cl-std=CL2.0", false);
|
||||
RETURN_ON_ERROR(err)
|
||||
#else
|
||||
err = create_opencl_kernel(context, &program, &kernel, code_str, kernel_name);
|
||||
RETURN_ON_ERROR(err)
|
||||
#endif
|
||||
|
||||
std::vector<INPUT1> in1_spec_cases = op.in1_special_cases();
|
||||
std::vector<INPUT2> in2_spec_cases = op.in2_special_cases();
|
||||
std::vector<INPUT3> in3_spec_cases = op.in3_special_cases();
|
||||
prepare_special_cases(in1_spec_cases, in2_spec_cases, in3_spec_cases);
|
||||
std::vector<INPUT1> input1 = generate_input<INPUT1>(count, op.min1(), op.max1(), in1_spec_cases);
|
||||
std::vector<INPUT2> input2 = generate_input<INPUT2>(count, op.min2(), op.max2(), in2_spec_cases);
|
||||
std::vector<INPUT3> input3 = generate_input<INPUT3>(count, op.min3(), op.max3(), in3_spec_cases);
|
||||
std::vector<OUTPUT> output = generate_output<OUTPUT>(count);
|
||||
|
||||
buffers[0] = clCreateBuffer(
|
||||
context, (cl_mem_flags)(CL_MEM_READ_WRITE), sizeof(INPUT1) * input1.size(), NULL, &err
|
||||
);
|
||||
RETURN_ON_CL_ERROR(err, "clCreateBuffer")
|
||||
|
||||
buffers[1] = clCreateBuffer(
|
||||
context, (cl_mem_flags)(CL_MEM_READ_WRITE), sizeof(INPUT2) * input2.size(), NULL, &err
|
||||
);
|
||||
RETURN_ON_CL_ERROR(err, "clCreateBuffer")
|
||||
|
||||
buffers[2] = clCreateBuffer(
|
||||
context, (cl_mem_flags)(CL_MEM_READ_WRITE), sizeof(INPUT3) * input3.size(), NULL, &err
|
||||
);
|
||||
RETURN_ON_CL_ERROR(err, "clCreateBuffer")
|
||||
|
||||
buffers[3] = clCreateBuffer(
|
||||
context, (cl_mem_flags)(CL_MEM_READ_WRITE), sizeof(OUTPUT) * output.size(), NULL, &err
|
||||
);
|
||||
RETURN_ON_CL_ERROR(err, "clCreateBuffer")
|
||||
|
||||
err = clEnqueueWriteBuffer(
|
||||
queue, buffers[0], CL_TRUE, 0, sizeof(INPUT1) * input1.size(),
|
||||
static_cast<void *>(input1.data()), 0, NULL, NULL
|
||||
);
|
||||
RETURN_ON_CL_ERROR(err, "clEnqueueWriteBuffer");
|
||||
|
||||
err = clEnqueueWriteBuffer(
|
||||
queue, buffers[1], CL_TRUE, 0, sizeof(INPUT2) * input2.size(),
|
||||
static_cast<void *>(input2.data()), 0, NULL, NULL
|
||||
);
|
||||
RETURN_ON_CL_ERROR(err, "clEnqueueWriteBuffer");
|
||||
|
||||
err = clEnqueueWriteBuffer(
|
||||
queue, buffers[2], CL_TRUE, 0, sizeof(INPUT3) * input3.size(),
|
||||
static_cast<void *>(input3.data()), 0, NULL, NULL
|
||||
);
|
||||
RETURN_ON_CL_ERROR(err, "clEnqueueWriteBuffer");
|
||||
|
||||
err = clSetKernelArg(kernel, 0, sizeof(buffers[0]), &buffers[0]);
|
||||
err |= clSetKernelArg(kernel, 1, sizeof(buffers[1]), &buffers[1]);
|
||||
err |= clSetKernelArg(kernel, 2, sizeof(buffers[2]), &buffers[2]);
|
||||
err |= clSetKernelArg(kernel, 3, sizeof(buffers[3]), &buffers[3]);
|
||||
RETURN_ON_CL_ERROR(err, "clSetKernelArg");
|
||||
|
||||
work_size[0] = count;
|
||||
err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, work_size, NULL, 0, NULL, NULL);
|
||||
RETURN_ON_CL_ERROR(err, "clEnqueueNDRangeKernel");
|
||||
|
||||
err = clEnqueueReadBuffer(
|
||||
queue, buffers[3], CL_TRUE, 0, sizeof(OUTPUT) * output.size(),
|
||||
static_cast<void *>(output.data()), 0, NULL, NULL
|
||||
);
|
||||
RETURN_ON_CL_ERROR(err, "clEnqueueReadBuffer");
|
||||
|
||||
if (!verify_ternary(input1, input2, input3, output, op))
|
||||
{
|
||||
RETURN_ON_ERROR_MSG(-1,
|
||||
"test_%s %s(%s, %s, %s) failed", op.str().c_str(),
|
||||
type_name<OUTPUT>().c_str(),
|
||||
type_name<INPUT1>().c_str(),
|
||||
type_name<INPUT2>().c_str(),
|
||||
type_name<INPUT3>().c_str()
|
||||
);
|
||||
}
|
||||
log_info(
|
||||
"test_%s %s(%s, %s, %s) passed\n", op.str().c_str(),
|
||||
type_name<OUTPUT>().c_str(),
|
||||
type_name<INPUT1>().c_str(),
|
||||
type_name<INPUT2>().c_str(),
|
||||
type_name<INPUT3>().c_str()
|
||||
);
|
||||
|
||||
clReleaseMemObject(buffers[0]);
|
||||
clReleaseMemObject(buffers[1]);
|
||||
clReleaseMemObject(buffers[2]);
|
||||
clReleaseMemObject(buffers[3]);
|
||||
clReleaseKernel(kernel);
|
||||
clReleaseProgram(program);
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif // TEST_CONFORMANCE_CLCPP_UTILS_TEST_TERNARY_HPP
|
||||
261
test_conformance/clcpp/utils_test/unary.hpp
Normal file
261
test_conformance/clcpp/utils_test/unary.hpp
Normal file
@@ -0,0 +1,261 @@
|
||||
//
|
||||
// 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_UTILS_TEST_UNARY_HPP
|
||||
#define TEST_CONFORMANCE_CLCPP_UTILS_TEST_UNARY_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <cmath>
|
||||
|
||||
#include "../common.hpp"
|
||||
|
||||
#include "detail/base_func_type.hpp"
|
||||
#include "generate_inputs.hpp"
|
||||
#include "compare.hpp"
|
||||
|
||||
template<class IN1, class OUT1>
|
||||
struct unary_func : public detail::base_func_type<OUT1>
|
||||
{
|
||||
typedef IN1 in_type;
|
||||
typedef OUT1 out_type;
|
||||
|
||||
virtual ~unary_func() {};
|
||||
virtual std::string str() = 0;
|
||||
|
||||
// Return string with function type, for example: int(float).
|
||||
std::string decl_str()
|
||||
{
|
||||
return type_name<OUT1>() + "(" + type_name<IN1>() + ")";
|
||||
}
|
||||
|
||||
// Return true if IN1 type in OpenCL kernel should be treated
|
||||
// as bool type; false otherwise.
|
||||
bool is_in1_bool()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return min value that can be used as a first argument.
|
||||
IN1 min1()
|
||||
{
|
||||
return detail::get_min<IN1>();
|
||||
}
|
||||
|
||||
// Return max value that can be used as a first argument.
|
||||
IN1 max1()
|
||||
{
|
||||
return detail::get_max<IN1>();
|
||||
}
|
||||
|
||||
// This returns a list of special cases input values we want to
|
||||
// test.
|
||||
std::vector<IN1> in_special_cases()
|
||||
{
|
||||
return { };
|
||||
}
|
||||
|
||||
// Max error. Error should be raised if
|
||||
// abs(result - expected) > delta(.., expected)
|
||||
//
|
||||
// Default value: 0.001 * expected
|
||||
//
|
||||
// (This effects how are_equal() function works,
|
||||
// it may not have effect if verify() method in derived
|
||||
// class does not use are_equal() function.)
|
||||
//
|
||||
// Only for FP numbers/vectors
|
||||
template<class T>
|
||||
typename make_vector_type<cl_double, vector_size<T>::value>::type
|
||||
delta(const IN1& in1, const T& expected)
|
||||
{
|
||||
typedef
|
||||
typename make_vector_type<cl_double, vector_size<T>::value>::type
|
||||
delta_vector_type;
|
||||
// Take care of unused variable warning
|
||||
(void) in1;
|
||||
auto e = detail::make_value<delta_vector_type>(1e-3);
|
||||
return detail::multiply<delta_vector_type>(e, expected);
|
||||
}
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
// ------------- ONLY FOR OPENCL 22 CONFORMANCE TEST 22 DEVELOPMENT ------------------
|
||||
// -----------------------------------------------------------------------------------
|
||||
#if defined(DEVELOPMENT) && defined(USE_OPENCLC_KERNELS)
|
||||
template <class func_type, class in_type, class out_type>
|
||||
std::string generate_kernel_unary(func_type func)
|
||||
{
|
||||
std::string in1_value = "input[gid]";
|
||||
// Convert uintN to boolN values
|
||||
if(func.is_in1_bool())
|
||||
{
|
||||
std::string i = vector_size<in_type>::value == 1 ? "" : std::to_string(vector_size<in_type>::value);
|
||||
in1_value = "(input[gid] != (int" + i + ")(0))";
|
||||
}
|
||||
std::string function_call = func.str() + "(" + in1_value + ");";
|
||||
// Convert boolN result of funtion func_type to uintN
|
||||
if(func.is_out_bool())
|
||||
{
|
||||
std::string i = vector_size<out_type>::value == 1 ? "" : std::to_string(vector_size<out_type>::value);
|
||||
function_call = "convert_int" + i + "(" + func.str() + "(" + in1_value + "))";
|
||||
}
|
||||
return
|
||||
"__kernel void " + func.get_kernel_name() + "(global " + type_name<in_type>() + " *input, global " + type_name<out_type>() + " *output)\n"
|
||||
"{\n"
|
||||
" size_t gid = get_global_id(0);\n"
|
||||
" output[gid] = " + function_call + ";\n"
|
||||
"}\n";
|
||||
}
|
||||
#else
|
||||
template <class func_type, class in_type, class out_type>
|
||||
std::string generate_kernel_unary(func_type func)
|
||||
{
|
||||
std::string headers = func.headers();
|
||||
std::string in1_value = "input[gid]";
|
||||
if(func.is_in1_bool())
|
||||
{
|
||||
std::string i = vector_size<in_type>::value == 1 ? "" : std::to_string(vector_size<in_type>::value);
|
||||
in1_value = "(input[gid] != (int" + i + ")(0))";
|
||||
}
|
||||
std::string function_call = func.str() + "(" + in1_value + ")";
|
||||
if(func.is_out_bool())
|
||||
{
|
||||
std::string i = vector_size<out_type>::value == 1 ? "" : std::to_string(vector_size<out_type>::value);
|
||||
function_call = "convert_cast<int" + i + ">(" + func.str() + "(" + in1_value + "))";
|
||||
}
|
||||
if(func.is_out_bool() || func.is_in1_bool())
|
||||
{
|
||||
if(headers.find("#include <opencl_convert>") == std::string::npos)
|
||||
{
|
||||
headers += "#include <opencl_convert>\n";
|
||||
}
|
||||
}
|
||||
return
|
||||
"" + func.defs() +
|
||||
"" + headers +
|
||||
"#include <opencl_memory>\n"
|
||||
"#include <opencl_work_item>\n"
|
||||
"using namespace cl;\n"
|
||||
"__kernel void " + func.get_kernel_name() + "(global_ptr<" + type_name<in_type>() + "[]> input,"
|
||||
"global_ptr<" + type_name<out_type>() + "[]> output)\n"
|
||||
"{\n"
|
||||
" size_t gid = get_global_id(0);\n"
|
||||
" output[gid] = " + function_call + ";\n"
|
||||
"}\n";
|
||||
}
|
||||
#endif
|
||||
|
||||
template<class INPUT, class OUTPUT, class unary_op>
|
||||
bool verify_unary(const std::vector<INPUT> &in, const std::vector<OUTPUT> &out, unary_op op)
|
||||
{
|
||||
for(size_t i = 0; i < in.size(); i++)
|
||||
{
|
||||
auto expected = op(in[i]);
|
||||
if(!are_equal(expected, out[i], op.delta(in[i], expected), op))
|
||||
{
|
||||
print_error_msg(expected, out[i], i, op);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class unary_op>
|
||||
int test_unary_func(cl_device_id device, cl_context context, cl_command_queue queue, size_t count, unary_op op)
|
||||
{
|
||||
cl_mem buffers[2];
|
||||
cl_program program;
|
||||
cl_kernel kernel;
|
||||
size_t work_size[1];
|
||||
int err;
|
||||
|
||||
typedef typename unary_op::in_type INPUT;
|
||||
typedef typename unary_op::out_type OUTPUT;
|
||||
|
||||
// Don't run test for unsupported types
|
||||
if(!(type_supported<INPUT>(device) && type_supported<OUTPUT>(device)))
|
||||
{
|
||||
return CL_SUCCESS;
|
||||
}
|
||||
|
||||
std::string code_str = generate_kernel_unary<unary_op, INPUT, OUTPUT>(op);
|
||||
std::string kernel_name = op.get_kernel_name();
|
||||
|
||||
// -----------------------------------------------------------------------------------
|
||||
// ------------- ONLY FOR OPENCL 22 CONFORMANCE TEST 22 DEVELOPMENT ------------------
|
||||
// -----------------------------------------------------------------------------------
|
||||
// Only OpenCL C++ to SPIR-V compilation
|
||||
#if defined(DEVELOPMENT) && defined(ONLY_SPIRV_COMPILATION)
|
||||
err = create_opencl_kernel(context, &program, &kernel, code_str, kernel_name);
|
||||
RETURN_ON_ERROR(err)
|
||||
return err;
|
||||
// Use OpenCL C kernels instead of OpenCL C++ kernels (test C++ host code)
|
||||
#elif defined(DEVELOPMENT) && defined(USE_OPENCLC_KERNELS)
|
||||
err = create_opencl_kernel(context, &program, &kernel, code_str, kernel_name, "-cl-std=CL2.0", false);
|
||||
RETURN_ON_ERROR(err)
|
||||
#else
|
||||
err = create_opencl_kernel(context, &program, &kernel, code_str, kernel_name);
|
||||
RETURN_ON_ERROR(err)
|
||||
#endif
|
||||
|
||||
std::vector<INPUT> input = generate_input<INPUT>(count, op.min1(), op.max1(), op.in_special_cases());
|
||||
std::vector<OUTPUT> output = generate_output<OUTPUT>(count);
|
||||
|
||||
buffers[0] = clCreateBuffer(
|
||||
context, (cl_mem_flags)(CL_MEM_READ_WRITE), sizeof(INPUT) * input.size(), NULL, &err
|
||||
);
|
||||
RETURN_ON_CL_ERROR(err, "clCreateBuffer")
|
||||
|
||||
buffers[1] = clCreateBuffer(
|
||||
context, (cl_mem_flags)(CL_MEM_READ_WRITE), sizeof(OUTPUT) * output.size(), NULL, &err
|
||||
);
|
||||
RETURN_ON_CL_ERROR(err, "clCreateBuffer")
|
||||
|
||||
err = clEnqueueWriteBuffer(
|
||||
queue, buffers[0], CL_TRUE, 0, sizeof(INPUT) * input.size(),
|
||||
static_cast<void *>(input.data()), 0, NULL, NULL
|
||||
);
|
||||
RETURN_ON_CL_ERROR(err, "clEnqueueWriteBuffer");
|
||||
|
||||
err = clSetKernelArg(kernel, 0, sizeof(buffers[0]), &buffers[0]);
|
||||
err |= clSetKernelArg(kernel, 1, sizeof(buffers[1]), &buffers[1]);
|
||||
RETURN_ON_CL_ERROR(err, "clSetKernelArg");
|
||||
|
||||
work_size[0] = count;
|
||||
err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, work_size, NULL, 0, NULL, NULL);
|
||||
RETURN_ON_CL_ERROR(err, "clEnqueueNDRangeKernel");
|
||||
|
||||
err = clEnqueueReadBuffer(
|
||||
queue, buffers[1], CL_TRUE, 0, sizeof(OUTPUT) * output.size(),
|
||||
static_cast<void *>(output.data()), 0, NULL, NULL
|
||||
);
|
||||
RETURN_ON_CL_ERROR(err, "clEnqueueReadBuffer");
|
||||
|
||||
if (!verify_unary(input, output, op))
|
||||
{
|
||||
RETURN_ON_ERROR_MSG(-1, "test_%s %s(%s) failed", op.str().c_str(), type_name<OUTPUT>().c_str(), type_name<INPUT>().c_str());
|
||||
}
|
||||
log_info("test_%s %s(%s) passed\n", op.str().c_str(), type_name<OUTPUT>().c_str(), type_name<INPUT>().c_str());
|
||||
|
||||
clReleaseMemObject(buffers[0]);
|
||||
clReleaseMemObject(buffers[1]);
|
||||
clReleaseKernel(kernel);
|
||||
clReleaseProgram(program);
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif // TEST_CONFORMANCE_CLCPP_UTILS_TEST_UNARY_HPP
|
||||
Reference in New Issue
Block a user