diff options
author | Yi Sun <yi.sun@intel.com> | 2014-04-28 13:31:05 +0800 |
---|---|---|
committer | Zhigang Gong <zhigang.gong@intel.com> | 2014-04-30 09:36:10 +0800 |
commit | 3fa989b610844781bb3c0a1138659cf1bc54a06c (patch) | |
tree | 2334411822f1b9279f8ecc5d55944421bc0143f0 /benchmark | |
parent | e2374ee02183e69da5a271793330f8ee0782491f (diff) |
Init Benchmark suite
The first benchmark case is name enqueue_copy_buf.
Signed-off-by: Yi Sun <yi.sun@intel.com>
Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/CMakeLists.txt | 21 | ||||
-rw-r--r-- | benchmark/benchmark_run.cpp | 117 | ||||
-rw-r--r-- | benchmark/enqueue_copy_buf.cpp | 69 |
3 files changed, 207 insertions, 0 deletions
diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt new file mode 100644 index 00000000..fb28023b --- /dev/null +++ b/benchmark/CMakeLists.txt @@ -0,0 +1,21 @@ +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/../utests + ${CMAKE_CURRENT_SOURCE_DIR}/../include) + + +link_directories (${LLVM_LIBRARY_DIR}) +set (benchmark_sources + ../utests/utest_error.c + ../utests/utest_assert.cpp + ../utests/utest.cpp + ../utests/utest_file_map.cpp + ../utests/utest_helper.cpp + enqueue_copy_buf.cpp) + +ADD_LIBRARY(benchmarks SHARED ${ADDMATHFUNC} ${benchmark_sources}) + +#TARGET_LINK_LIBRARIES(benchmarks cl m ${OPENGL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) +TARGET_LINK_LIBRARIES(benchmarks cl m) + +ADD_EXECUTABLE(benchmark_run benchmark_run.cpp) +TARGET_LINK_LIBRARIES(benchmark_run benchmarks) diff --git a/benchmark/benchmark_run.cpp b/benchmark/benchmark_run.cpp new file mode 100644 index 00000000..b29ccc32 --- /dev/null +++ b/benchmark/benchmark_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@intel.com> + */ + +/** + * \file utest_run.cpp + * \author Benjamin Segovia <benjamin.segovia@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/benchmark/enqueue_copy_buf.cpp b/benchmark/enqueue_copy_buf.cpp new file mode 100644 index 00000000..0d0d4dfe --- /dev/null +++ b/benchmark/enqueue_copy_buf.cpp @@ -0,0 +1,69 @@ +#include "utests/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; + + 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() & 0xFF); + } + + 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(CL_SUCCESS == clEnqueueCopyBuffer(queue, buf[0], buf[1], + src_off, dst_off, cb*sizeof(char), 0, NULL, NULL)); +} + +int tim_subtract(struct timeval *y, struct timeval *x, struct timeval *result){ + if ( x->tv_sec > y->tv_sec ) + return -1; + + if ((x->tv_sec == y->tv_sec) && (x->tv_usec > y->tv_usec)) + return -1; + + if ( result != NULL){ + 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; + } + } + + int msec = 1000.0*(y->tv_sec - x->tv_sec) + (y->tv_usec - x->tv_usec)/1000.0; + return msec; +} + + +int enqueue_copy_buf(void) +{ + size_t i; + const size_t sz = 127 *1023 * 1023; + struct timeval start,stop; + + gettimeofday(&start,0); + + for (i=0; i<10; i++) { + test_copy_buf(sz, 0, 0, sz); + } + + gettimeofday(&stop,0); + return tim_subtract(&stop, &start, 0); +} + +MAKE_BENCHMARK_FROM_FUNCTION(enqueue_copy_buf); |