From: Yang Rong Date: Mon, 12 Aug 2013 08:07:21 +0000 (+0800) Subject: Add event unit test. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ae6719600abb288762608671ad704325b2980712;p=contrib%2Fbeignet.git Add event unit test. Signed-off-by: Yang Rong Reviewed-by: Zhigang Gong --- 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= 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)