[Beignet] [PATCH V2 6/6] Add event unit test.
Yang Rong
rong.r.yang at intel.com
Mon Aug 12 01:07:21 PDT 2013
Signed-off-by: Yang Rong <rong.r.yang at intel.com>
---
kernels/compiler_event.cl | 6 +++++
utests/CMakeLists.txt | 1 +
utests/runtime_event.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++
utests/utest_helper.hpp | 10 ++++++--
4 files changed, 76 insertions(+), 2 deletions(-)
create mode 100644 kernels/compiler_event.cl
create mode 100644 utests/runtime_event.cpp
diff --git a/kernels/compiler_event.cl b/kernels/compiler_event.cl
new file mode 100644
index 0000000..a901b05
--- /dev/null
+++ b/kernels/compiler_event.cl
@@ -0,0 +1,6 @@
+__kernel void
+compiler_event(__global int *dst, int value)
+{
+ int id = (int)get_global_id(0);
+ dst[id] += value;
+}
diff --git a/utests/CMakeLists.txt b/utests/CMakeLists.txt
index c30e10e..e7d3e72 100644
--- a/utests/CMakeLists.txt
+++ b/utests/CMakeLists.txt
@@ -118,6 +118,7 @@ set (utests_sources
builtin_acos_asin.cpp
runtime_createcontext.cpp
runtime_null_kernel_arg.cpp
+ runtime_event.cpp
compiler_double.cpp
compiler_double_2.cpp
compiler_double_3.cpp
diff --git a/utests/runtime_event.cpp b/utests/runtime_event.cpp
new file mode 100644
index 0000000..1ec8692
--- /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);
diff --git a/utests/utest_helper.hpp b/utests/utest_helper.hpp
index 0365040..e7f43fc 100644
--- a/utests/utest_helper.hpp
+++ b/utests/utest_helper.hpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright © 2012 Intel Corporation
*
* This library is free software; you can redistribute it and/or
@@ -88,7 +88,13 @@ extern EGLSurface eglSurface;
} while (0)
#define OCL_CREATE_BUFFER(BUFFER, FLAGS, SIZE, DATA) \
- OCL_CALL2(clCreateBuffer, BUFFER, ctx, FLAGS, SIZE, DATA)
+ OCL_CALL2(clCreateBuffer, BUFFER, ctx, FLAGS, SIZE, DATA)
+
+#define OCL_CREATE_USER_EVENT(EVENT) \
+ OCL_CALL2(clCreateUserEvent, EVENT, ctx)
+
+#define OCL_SET_USER_EVENT_STATUS(EVENT, STATUS) \
+ OCL_CALL(clSetUserEventStatus, EVENT, STATUS)
#define OCL_CREATE_IMAGE(IMAGE, FLAGS, FORMAT, DESC, DATA) \
OCL_CALL2(clCreateImage, IMAGE, ctx, FLAGS, FORMAT, DESC, DATA)
--
1.7.10.4
More information about the Beignet
mailing list