// // Copyright (c) 2018 Stefan Seefeld // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or // copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef opencl_benchmark_hpp_ #define opencl_benchmark_hpp_ #define BOOST_UBLAS_ENABLE_OPENCL #include #include "../benchmark.hpp" #include "init.hpp" #include namespace boost { namespace numeric { namespace ublas { namespace benchmark { namespace opencl { struct base { base(compute::device d = compute::system::default_device()) : context(d), queue(context, d) {} compute::context context; compute::command_queue queue; }; template struct data_factory; template struct data_factory { typedef T type; typedef std::unique_ptr ptr_type; static ptr_type create(long) { return ptr_type(new T());} }; template struct data_factory { typedef T type; typedef std::unique_ptr ptr_type; static ptr_type create(long, compute::context) { return ptr_type(new T());} }; template <> struct data_factory { typedef void type; typedef void *ptr_type; static ptr_type create(long) { return 0;} }; template <> struct data_factory { typedef void type; typedef void *ptr_type; static ptr_type create(long, compute::context) { return 0;} }; template struct data_factory, true> { typedef ublas::vector type; typedef std::unique_ptr ptr_type; static ptr_type create(long l) { return ptr_type(new type(l));} }; template struct data_factory, false> { typedef ublas::vector type; typedef std::unique_ptr ptr_type; static ptr_type create(long l, compute::context c) { return ptr_type(new type(l, c));} }; template struct data_factory, true> { typedef ublas::matrix type; typedef std::unique_ptr ptr_type; static ptr_type create(long l) { return ptr_type(new type(l, l));} }; template struct data_factory, false> { typedef ublas::matrix type; typedef std::unique_ptr ptr_type; static ptr_type create(long l, compute::context c) { return ptr_type(new type(l, l, c));} }; template class benchmark; template class benchmark : public base, public ublas::benchmark::benchmark { public: benchmark(std::string const &name) : base(), ublas::benchmark::benchmark(name + " with copy") {} virtual void setup(long l) { r = data_factory::create(l); a = data_factory::create(l); init(*a, l, 200); } typename data_factory::ptr_type r; typename data_factory::ptr_type a; }; template class benchmark : public base, public ublas::benchmark::benchmark { public: benchmark(std::string const &name) : base(), ublas::benchmark::benchmark(name + " with copy") {} virtual void setup(long l) { r = data_factory::create(l); a = data_factory::create(l); init(*a, l, 200); b = data_factory::create(l); init(*b, l, 200); } typename data_factory::ptr_type r; typename data_factory::ptr_type a; typename data_factory::ptr_type b; }; template class benchmark : public base, public ublas::benchmark::benchmark { public: benchmark(std::string const &name) : base(), ublas::benchmark::benchmark(name + " with copy") {} virtual void setup(long l) { r = data_factory::create(l); a = data_factory::create(l); init(*a, l, 200); b = data_factory::create(l); init(*b, l, 200); c = data_factory::create(l); init(*c, l, 200); } typename data_factory::ptr_type r; typename data_factory::ptr_type a; typename data_factory::ptr_type b; typename data_factory::ptr_type c; }; template class benchmark : public base, public ublas::benchmark::benchmark { public: benchmark(std::string const &name) : base(), ublas::benchmark::benchmark(name + " w/o copy") {} virtual void setup(long l) { r = data_factory::create(l, context); a = data_factory::create(l, context); init(*a, l, 200); } typename data_factory::ptr_type r; typename data_factory::ptr_type a; }; template class benchmark : public base, public ublas::benchmark::benchmark { public: benchmark(std::string const &name) : base(), ublas::benchmark::benchmark(name + " w/o copy") {} virtual void setup(long l) { r = data_factory::create(l, context); a = data_factory::create(l, context); init(*a, l, 200); b = data_factory::create(l, context); init(*b, l, 200); } typename data_factory::ptr_type r; typename data_factory::ptr_type a; typename data_factory::ptr_type b; }; template class benchmark : public base, public ublas::benchmark::benchmark { public: benchmark(std::string const &name) : base(), ublas::benchmark::benchmark(name + " w/o copy") {} virtual void setup(long l) { r = data_factory::create(l, context); a = data_factory::create(l, context); init(*a, l, 200); b = data_factory::create(l, context); init(*b, l, 200); c = data_factory::create(l, context); init(*c, l, 200); } typename data_factory::ptr_type r; typename data_factory::ptr_type a; typename data_factory::ptr_type b; typename data_factory::ptr_type c; }; }}}}} #endif