summaryrefslogtreecommitdiff
path: root/utests/runtime_event.cpp
diff options
context:
space:
mode:
authorYang Rong <rong.r.yang@intel.com>2013-08-12 16:07:21 +0800
committerZhigang Gong <zhigang.gong@linux.intel.com>2013-08-12 16:36:10 +0800
commitae6719600abb288762608671ad704325b2980712 (patch)
treea0ccba1b604a4e783f49698fc5e935725f565e07 /utests/runtime_event.cpp
parent645a3895a01501aea55b99e5c87e9a25519454c6 (diff)
Add event unit test.
Signed-off-by: Yang Rong <rong.r.yang@intel.com> Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
Diffstat (limited to 'utests/runtime_event.cpp')
-rw-r--r--utests/runtime_event.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/utests/runtime_event.cpp b/utests/runtime_event.cpp
new file mode 100644
index 00000000..1ec8692a
--- /dev/null
+++ b/utests/runtime_event.cpp
@@ -0,0 +1,61 @@
+#include "utest_helper.hpp"
+
+#define BUFFERSIZE 32*1024
+void runtime_event(void)
+{
+ const size_t n = BUFFERSIZE;
+ cl_int cpu_src[BUFFERSIZE];
+ cl_event ev[3];
+ cl_int status = 0;
+ cl_int value = 34;
+
+ // Setup kernel and buffers
+ OCL_CREATE_KERNEL("compiler_event");
+ OCL_CREATE_BUFFER(buf[0], 0, BUFFERSIZE*sizeof(int), NULL);
+
+ for(cl_uint i=0; i<BUFFERSIZE; i++)
+ cpu_src[i] = 3;
+
+ OCL_CREATE_USER_EVENT(ev[0]);
+
+ clEnqueueWriteBuffer(queue, buf[0], CL_TRUE, 0, BUFFERSIZE*sizeof(int), (void *)cpu_src, 1, &ev[0], &ev[1]);
+
+ OCL_SET_ARG(0, sizeof(cl_mem), &buf[0]);
+ OCL_SET_ARG(1, sizeof(int), &value);
+
+ // Run the kernel
+ globals[0] = n;
+ locals[0] = 32;
+ clEnqueueNDRangeKernel(queue, kernel, 1, NULL, globals, locals, 2, &ev[0], &ev[2]);
+
+ for (cl_uint i = 0; i != sizeof(ev) / sizeof(cl_event); ++i) {
+ clGetEventInfo(ev[i], CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof(status), &status, NULL);
+ OCL_ASSERT(status >= CL_SUBMITTED);
+ }
+
+ OCL_SET_USER_EVENT_STATUS(ev[0], CL_COMPLETE);
+
+ clGetEventInfo(ev[0], CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof(status), &status, NULL);
+ OCL_ASSERT(status == CL_COMPLETE);
+
+ OCL_FINISH();
+
+ for (cl_uint i = 0; i != sizeof(ev) / sizeof(cl_event); ++i) {
+ clGetEventInfo(ev[i], CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof(status), &status, NULL);
+ OCL_ASSERT(status <= CL_COMPLETE);
+ }
+
+ // Check results
+ OCL_MAP_BUFFER(0);
+
+ for (uint32_t i = 0; i < n; ++i) {
+ OCL_ASSERT(((int*)buf_data[0])[i] == (int)value + 0x3);
+ }
+ OCL_UNMAP_BUFFER(0);
+
+ for (cl_uint i = 0; i != sizeof(ev) / sizeof(cl_event); ++i) {
+ clReleaseEvent(ev[i]);
+ }
+}
+
+MAKE_UTEST_FROM_FUNCTION(runtime_event);