aboutsummaryrefslogtreecommitdiff
path: root/tests/test_kernel.cpp
diff options
context:
space:
mode:
authorGil Pitney <gil.pitney@linaro.org>2016-06-29 18:27:29 +0000
committerGil Pitney <gil.pitney@linaro.org>2016-06-29 22:50:52 +0000
commit3f53cee30e45b7225b895f9c79c90a6722e2196a (patch)
tree0601dbffae8f94a32d2cba3dd306352d228d2128 /tests/test_kernel.cpp
parent9461fcfd1434d3cb3c0a1a5de1827d375a1ad5af (diff)
Fix the tests kernel sanity test to enqueue the right kernel2.
Previously, the sanity test was assuming a certain order in the kernel list returned from clCreateKernelsInProgram(), which order is not guarranteed, and which changed due to a previous commit (bug fix). Signed-off-by: Gil Pitney <gil.pitney@linaro.org>
Diffstat (limited to 'tests/test_kernel.cpp')
-rw-r--r--tests/test_kernel.cpp29
1 files changed, 25 insertions, 4 deletions
diff --git a/tests/test_kernel.cpp b/tests/test_kernel.cpp
index 6c61ed2..32f4500 100644
--- a/tests/test_kernel.cpp
+++ b/tests/test_kernel.cpp
@@ -75,9 +75,10 @@ START_TEST (test_compiled_kernel)
cl_kernel kernels[2];
cl_uint num_kernels;
cl_mem buf;
-
+ cl_char kernName[64]; // Max size is sizeof("kernel1")
const char *src = source;
size_t program_len = sizeof(source);
+ int i, found;
unsigned int buffer[256];
@@ -137,7 +138,27 @@ START_TEST (test_compiled_kernel)
"unable to get the two kernels of the program"
);
- // Try to run kernel2
+ // Try to run "kernel2"
+ // Note: the order of kernels in kernels[] array is not guarranteed to
+ // be same as the order in the OCL program source! So, search:
+ found = 0;
+ for (i = 0; i < num_kernels; i++) {
+ result = clGetKernelInfo( kernels[i], CL_KERNEL_FUNCTION_NAME, sizeof( kernName), kernName, NULL);
+ fail_if(
+ result != CL_SUCCESS,
+ "Unable to get name from kernel"
+ );
+
+ if(!strcmp((char *)kernName, "kernel2" )) {
+ found = 1; // i has the kernel index.
+ break;
+ }
+ }
+ fail_if(
+ !found,
+ "Unable to find kernel named kernel2"
+ );
+
buf = clCreateBuffer(ctx, CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR,
sizeof(buffer), buffer, &result);
fail_if(
@@ -145,7 +166,7 @@ START_TEST (test_compiled_kernel)
"cannot create a valid CL_MEM_COPY_HOST_PTR read-write buffer"
);
- result = clSetKernelArg(kernels[1], 0, sizeof(cl_mem), &buf);
+ result = clSetKernelArg(kernels[i], 0, sizeof(cl_mem), &buf);
fail_if(
result != CL_SUCCESS,
"cannot set kernel argument"
@@ -156,7 +177,7 @@ START_TEST (test_compiled_kernel)
cl_event event;
bool ok;
- result = clEnqueueNDRangeKernel(queue, kernels[1], 1, 0, &global_size, 0, 0, 0, &event);
+ result = clEnqueueNDRangeKernel(queue, kernels[i], 1, 0, &global_size, 0, 0, 0, &event);
fail_if(
result != CL_SUCCESS,
"unable to queue a NDRange kernel with local work size guessed"