[Beignet] [PATCH 2/2] Add unit performance suite
Yi Sun
yi.sun at intel.com
Fri Mar 28 00:45:02 PDT 2014
Unit performance is named uperformance.
The first uperformance is enqueue_copy_buf.
Signed-off-by: Yi Sun <yi.sun at intel.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 23fdd63..0b85379 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -146,6 +146,7 @@ ADD_SUBDIRECTORY(include)
ADD_SUBDIRECTORY(backend)
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(utests/utest)
+ADD_SUBDIRECTORY(utests/uperformance)
SET(CPACK_PACKAGE_VERSION_MAJOR "${LIBCL_DRIVER_VERSION_MAJOR}")
SET(CPACK_PACKAGE_VERSION_MINOR "${LIBCL_DRIVER_VERSION_MINOR}")
diff --git a/utests/uperformance/CMakeLists.txt b/utests/uperformance/CMakeLists.txt
new file mode 100644
index 0000000..956e74f
--- /dev/null
+++ b/utests/uperformance/CMakeLists.txt
@@ -0,0 +1,21 @@
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/../utest
+ ${CMAKE_CURRENT_SOURCE_DIR}/../include)
+
+
+link_directories (${LLVM_LIBRARY_DIR})
+set (uperformance_sources
+ ../utest/utest_error.c
+ ../utest/utest_assert.cpp
+ ../utest/utest.cpp
+ ../utest/utest_file_map.cpp
+ ../utest/utest_helper.cpp
+ enqueue_copy_buf.cpp)
+
+ADD_LIBRARY(uperformances SHARED ${ADDMATHFUNC} ${uperformance_sources})
+
+#TARGET_LINK_LIBRARIES(uperformances cl m ${OPENGL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
+TARGET_LINK_LIBRARIES(uperformances cl m)
+
+ADD_EXECUTABLE(uperformance_run uperformance_run.cpp)
+TARGET_LINK_LIBRARIES(uperformance_run uperformances)
diff --git a/utests/uperformance/enqueue_copy_buf.cpp b/utests/uperformance/enqueue_copy_buf.cpp
new file mode 100644
index 0000000..5b4f50e
--- /dev/null
+++ b/utests/uperformance/enqueue_copy_buf.cpp
@@ -0,0 +1,80 @@
+#include "utest_helper.hpp"
+#include <sys/time.h>
+
+void test_copy_buf(size_t sz, size_t src_off, size_t dst_off, size_t cb)
+{
+ unsigned int i;
+ cl_char* buf0, *buf1;
+
+ OCL_CREATE_BUFFER(buf[0], 0, sz * sizeof(char), NULL);
+ OCL_CREATE_BUFFER(buf[1], 0, sz * sizeof(char), NULL);
+
+ buf0=(cl_char *)clEnqueueMapBuffer(queue, buf[0], CL_TRUE, CL_MAP_WRITE, 0, sizeof(char), 0, NULL, NULL, NULL);
+
+ for (i=0; i < sz; i++) {
+ buf0[i]=(rand() & 63);
+ }
+
+ clEnqueueUnmapMemObject(queue, buf[0], buf0, 0, NULL, NULL);
+
+ if (src_off + cb > sz || dst_off + cb > sz) {
+ /* Expect Error. */
+ OCL_ASSERT(clEnqueueCopyBuffer(queue, buf[0], buf[1],
+ src_off, dst_off, cb*sizeof(char), 0, NULL, NULL));
+ return;
+ }
+
+ OCL_ASSERT(!clEnqueueCopyBuffer(queue, buf[0], buf[1],
+ src_off, dst_off, cb*sizeof(char), 0, NULL, NULL));
+
+ buf0 = (cl_char*)clEnqueueMapBuffer(queue, buf[0], CL_TRUE, CL_MAP_READ, 0, sizeof(char), 0, NULL, NULL, NULL);
+ buf1 = (cl_char*)clEnqueueMapBuffer(queue, buf[1], CL_TRUE, CL_MAP_READ, 0, sizeof(char), 0, NULL, NULL, NULL);
+
+ for (i = 0; i < cb; ++i) {
+ //printf("%2.2u,%2.2u\n",buf0[i+src_off],buf1[i+dst_off]);
+ OCL_ASSERT(buf0[i+src_off] == buf1[i+dst_off]);
+ }
+
+ clEnqueueUnmapMemObject(queue, buf[0], buf0, 0, NULL, NULL);
+ clEnqueueUnmapMemObject(queue, buf[1], buf1, 0, NULL, NULL);
+}
+
+int tim_subtract(struct timeval *result, struct timeval *x, struct timeval *y){
+ if ( x->tv_sec > y->tv_sec )
+ return -1;
+
+ if ((x->tv_sec == y->tv_sec) && (x->tv_usec > y->tv_usec))
+ return -1;
+
+ result->tv_sec = ( y->tv_sec - x->tv_sec );
+ result->tv_usec = ( y->tv_usec - x->tv_usec );
+
+ if (result->tv_usec < 0){
+ result->tv_sec --;
+ result->tv_usec += 1000000;
+ }
+ return 0;
+}
+
+
+int enqueue_copy_buf(void)
+{
+ size_t i;
+ size_t j;
+ const size_t sz = 1024;
+ struct timeval start,stop,diff;
+
+ gettimeofday(&start,0);
+ for (i=0; i<sz; i+=8) {
+ for (j=0; j<sz; j+=10) {
+ test_copy_buf(sz, i, j, sz/2);
+ }
+ }
+ gettimeofday(&stop,0);
+ tim_subtract(&diff,&start,&stop);
+// printf("performance: %ld usec\n",diff.tv_usec);
+
+ return diff.tv_usec;
+}
+
+MAKE_UPERFORMANCE_FROM_FUNCTION(enqueue_copy_buf);
diff --git a/utests/uperformance/uperformance_run.cpp b/utests/uperformance/uperformance_run.cpp
new file mode 100644
index 0000000..b29ccc3
--- /dev/null
+++ b/utests/uperformance/uperformance_run.cpp
@@ -0,0 +1,117 @@
+/*
+ * Copyright © 2012 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Benjamin Segovia <benjamin.segovia at intel.com>
+ */
+
+/**
+ * \file utest_run.cpp
+ * \author Benjamin Segovia <benjamin.segovia at intel.com>
+ *
+ * Just run the unit tests. The user can possibly provides the subset of it
+ */
+#include "utest_helper.hpp"
+#include "utest_exception.hpp"
+#include <iostream>
+#include <getopt.h>
+
+static const char *shortopts = "c:lanh";
+struct option longopts[] = {
+{"casename", required_argument, NULL, 'c'},
+{"list", no_argument, NULL, 'l'},
+{"all", no_argument, NULL, 'a'},
+{"allnoissue", no_argument, NULL, 'n'},
+{"help", no_argument, NULL, 'h'},
+{0, 0, 0, 0},
+};
+
+void usage()
+{
+ std::cout << "\
+Usage:\n\
+ ./utest_run <option>\n\
+\n\
+ option:\n\
+ -c <casename>: run sub-case named 'casename'\n\
+ -l : list all the available case name\n\
+ -a : run all test cases\n\
+ -n : run all test cases without known issue (default option)\n\
+ -h : display this usage\n\
+\
+ "<< std::endl;
+}
+
+int main(int argc, char *argv[])
+{
+
+ int c = 0;
+ cl_ocl_init();
+
+ c = getopt_long (argc, argv, shortopts, longopts, NULL);
+
+ if (argc == 1)
+ c = 'n';
+ if (argc == 2 && c < 1 ){
+ c = 'c';
+ optarg = argv[1];
+ }
+
+ do {
+ switch (c)
+ {
+ case 'c':
+ try {
+ UTest::run(optarg);
+ }
+ catch (Exception e){
+ std::cout << " " << e.what() << " [SUCCESS]" << std::endl;
+ }
+
+ break;
+
+ case 'l':
+ UTest::listAllCases();
+ break;
+
+ case 'a':
+ try {
+ UTest::runAll();
+ }
+ catch (Exception e){
+ std::cout << " " << e.what() << " [SUCCESS]" << std::endl;
+ }
+
+ break;
+
+ case 'n':
+ try {
+ UTest::runAllNoIssue();
+ }
+ catch (Exception e){
+ std::cout << " " << e.what() << " [SUCCESS]" << std::endl;
+ }
+
+ break;
+
+ case 'h':
+ default:
+ usage();
+ exit(1);
+ }
+ } while ((c = getopt_long (argc, argv, shortopts, longopts, NULL)) != -1);
+
+ cl_ocl_destroy();
+}
diff --git a/utests/utest/utest.hpp b/utests/utest/utest.hpp
index 01d4a8c..dc47c71 100644
--- a/utests/utest/utest.hpp
+++ b/utests/utest/utest.hpp
@@ -78,6 +78,11 @@ struct UTest
static void __ANON__##FN##__(void) { UTEST_EXPECT_SUCCESS(FN()); } \
static const UTest __##FN##__(__ANON__##FN##__, #FN, true);
+/*! Turn a function into a unit performance test */
+#define MAKE_UPERFORMANCE_FROM_FUNCTION(FN) \
+ static void __ANON__##FN##__(void) { UPERFORMANCE(FN()); } \
+ static const UTest __##FN##__(__ANON__##FN##__, #FN);
+
/*! No assert is expected */
#define UTEST_EXPECT_SUCCESS(EXPR) \
@@ -103,5 +108,17 @@ struct UTest
} \
} while (0)
-#endif /* __UTEST_UTEST_HPP__ */
+#define UPERFORMANCE(EXPR) \
+ do { \
+ int ret = 0; \
+ try { \
+ ret = EXPR; \
+ printf(" %s [SUCCESS] [Result: %d]\n", #EXPR, ret);\
+ } \
+ catch (Exception e) { \
+ std::cout << " " << #EXPR << " [FAILED]" << std::endl; \
+ std::cout << " " << e.what() << std::endl; \
+ } \
+ } while (0)
+#endif /* __UTEST_UTEST_HPP__ */
--
1.8.5.3
More information about the Beignet
mailing list