LGTM, pushed, thanks.
On Mon, Apr 28, 2014 at 01:31:05PM +0800, Yi Sun wrote: > The first benchmark case is name enqueue_copy_buf. > > Signed-off-by: Yi Sun <[email protected]> > > diff --git a/CMakeLists.txt b/CMakeLists.txt > index 60e6358..ccfc443 100644 > --- a/CMakeLists.txt > +++ b/CMakeLists.txt > @@ -163,6 +163,7 @@ ADD_SUBDIRECTORY(include) > ADD_SUBDIRECTORY(backend) > ADD_SUBDIRECTORY(src) > ADD_SUBDIRECTORY(utests) > +ADD_SUBDIRECTORY(benchmark) > > SET(CPACK_PACKAGE_VERSION_MAJOR "${LIBCL_DRIVER_VERSION_MAJOR}") > SET(CPACK_PACKAGE_VERSION_MINOR "${LIBCL_DRIVER_VERSION_MINOR}") > diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt > new file mode 100644 > index 0000000..fb28023 > --- /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 0000000..b29ccc3 > --- /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 <[email protected]> > + */ > + > +/** > + * \file utest_run.cpp > + * \author Benjamin Segovia <[email protected]> > + * > + * 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 0000000..0d0d4df > --- /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); > diff --git a/utests/utest.hpp b/utests/utest.hpp > index 0381bfe..375ef70 100644 > --- a/utests/utest.hpp > +++ b/utests/utest.hpp > @@ -90,6 +90,10 @@ 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_BENCHMARK_FROM_FUNCTION(FN) \ > + static void __ANON__##FN##__(void) { BENCHMARK(FN()); } \ > + static const UTest __##FN##__(__ANON__##FN##__, #FN); > > /*! No assert is expected */ > #define UTEST_EXPECT_SUCCESS(EXPR) \ > @@ -119,5 +123,17 @@ struct UTest > } \ > } while (0) > > +#define BENCHMARK(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 > > _______________________________________________ > Beignet mailing list > [email protected] > http://lists.freedesktop.org/mailman/listinfo/beignet _______________________________________________ Beignet mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/beignet
