MCPcopy Create free account
hub / github.com/KhronosGroup/OpenCL-CTS / test_binary_fn

Function test_binary_fn

test_conformance/commonfns/test_binary_fn.cpp:57–201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55
56template <typename T>
57int test_binary_fn(cl_device_id device, cl_context context,
58 cl_command_queue queue, int n_elems,
59 const std::string& fnName, bool vecSecParam,
60 VerifyFuncBinary<T> verifyFn)
61{
62 clMemWrapper streams[3];
63 std::vector<T> input_ptr[2], output_ptr;
64
65 std::vector<clProgramWrapper> programs;
66 std::vector<clKernelWrapper> kernels;
67 int err, i, j;
68 MTdataHolder d = MTdataHolder(gRandomSeed);
69
70 assert(BaseFunctionTest::type2name.find(sizeof(T))
71 != BaseFunctionTest::type2name.end());
72 auto tname = BaseFunctionTest::type2name[sizeof(T)];
73
74 programs.resize(kTotalVecCount);
75 kernels.resize(kTotalVecCount);
76
77 int num_elements = n_elems * (1 << (kTotalVecCount - 1));
78
79 for (i = 0; i < 2; i++) input_ptr[i].resize(num_elements);
80 output_ptr.resize(num_elements);
81
82 for( i = 0; i < 3; i++ )
83 {
84 streams[i] = clCreateBuffer(context, CL_MEM_READ_WRITE,
85 sizeof(T) * num_elements, NULL, &err);
86 test_error( err, "clCreateBuffer failed");
87 }
88
89 std::string pragma_str;
90 if (std::is_same<T, float>::value)
91 {
92 for (j = 0; j < num_elements; j++)
93 {
94 input_ptr[0][j] = get_random_float(-0x20000000, 0x20000000, d);
95 input_ptr[1][j] = get_random_float(-0x20000000, 0x20000000, d);
96 }
97 }
98 else if (std::is_same<T, double>::value)
99 {
100 pragma_str = "#pragma OPENCL EXTENSION cl_khr_fp64 : enable\n";
101 for (j = 0; j < num_elements; j++)
102 {
103 input_ptr[0][j] = get_random_double(-0x20000000, 0x20000000, d);
104 input_ptr[1][j] = get_random_double(-0x20000000, 0x20000000, d);
105 }
106 }
107 else if (std::is_same<T, half>::value)
108 {
109 const float fval = CL_HALF_MAX;
110 pragma_str = "#pragma OPENCL EXTENSION cl_khr_fp16 : enable\n";
111 for (int j = 0; j < num_elements; j++)
112 {
113 input_ptr[0][j] = conv_to_half(get_random_float(-fval, fval, d));
114 input_ptr[1][j] = conv_to_half(get_random_float(-fval, fval, d));

Callers

nothing calls this directly

Calls 8

MTdataHolderClass · 0.85
get_random_floatFunction · 0.85
get_random_doubleFunction · 0.85
conv_to_halfFunction · 0.85
str_sprintfFunction · 0.85
findMethod · 0.80
endMethod · 0.45

Tested by

no test coverage detected