// // 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) #define BOOST_UBLAS_ENABLE_OPENCL #include #include #include "benchmark.hpp" #include #include namespace po = boost::program_options; namespace ublas = boost::numeric::ublas; namespace bm = boost::numeric::ublas::benchmark; namespace opencl = boost::numeric::ublas::opencl; namespace boost { namespace numeric { namespace ublas { namespace benchmark { namespace opencl { template class add; template class add : public benchmark { public: add(std::string const &name) : benchmark(name) {} virtual void operation(long l) { ublas::opencl::element_add(*this->a, *this->b, *this->c, this->queue); } }; }}}}} template void benchmark(std::string const &type, bool copy) { using vector = ublas::vector; std::string name = "opencl::elementwise_add(vector<" + type + ">)"; std::vector sizes({1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096}); if (copy) { bm::opencl::add p(name); p.run(sizes); } else { bm::opencl::add p(name); p.run(sizes); } } int main(int argc, char **argv) { opencl::library lib; po::variables_map vm; try { po::options_description desc("Matrix-vector product (OpenCL)\n" "Allowed options"); desc.add_options()("help,h", "produce help message"); desc.add_options()("type,t", po::value(), "select value-type (float, double, fcomplex, dcomplex)"); desc.add_options()("copy,c", po::value(), "include host<->device copy in timing"); po::store(po::parse_command_line(argc, argv, desc), vm); po::notify(vm); if (vm.count("help")) { std::cout << desc << std::endl; return 0; } } catch(std::exception &e) { std::cerr << "error: " << e.what() << std::endl; return 1; } std::string type = vm.count("type") ? vm["type"].as() : "float"; bool copy = vm.count("copy") ? vm["copy"].as() : false; if (type == "float") benchmark("float", copy); else if (type == "double") benchmark("double", copy); else if (type == "fcomplex") benchmark>("std::complex", copy); else if (type == "dcomplex") benchmark>("std::complex", copy); else std::cerr << "unsupported value-type \"" << vm["type"].as() << '\"' << std::endl; }