#include "viennacl/matrix.hpp" #include "viennacl/vector.hpp" #include "viennacl/tools/timer.hpp" #include "atidlas/tools/misc.hpp" #include "atidlas/model/import.hpp" #include "atidlas/model/model.hpp" #include #include namespace ad = atidlas; typedef atidlas::atidlas_int_t int_t; template void bench(std::vector BLAS1_N, std::map > & models) { viennacl::tools::timer timer; float total_time = 0; std::vector times; #define BENCHMARK(OP, resname) \ times.clear();\ total_time = 0;\ OP;\ viennacl::backend::finish();\ while(total_time < 1e-1){\ timer.start(); \ OP;\ viennacl::backend::finish();\ times.push_back(timer.get());\ total_time += times.back();\ }\ viennacl::backend::finish();\ float resname = ad::tools::median(times); //BLAS1 { for(std::vector::const_iterator it = BLAS1_N.begin() ; it != BLAS1_N.end() ; ++it) { viennacl::vector x(*it), y(*it), z(*it); viennacl::scheduler::statement statement(z, viennacl::op_assign(), x + y); BENCHMARK(models["vector-axpy-float32"]->execute(statement), time_model); BENCHMARK(models["vector-axpy-float32"]->execute(statement, true), time_unique_kernel); models["vector-axpy-float32"]->tune(statement); BENCHMARK(models["vector-axpy-float32"]->execute(statement), time_opt); std::cout << *it << " " << 3*(*it)*sizeof(T)*1e-9/time_unique_kernel << " " << 3*(*it)*sizeof(T)*1e-9/time_model << " " << 3*(*it)*sizeof(T)*1e-9/time_opt << std::endl; } } } std::vector create_log_range(int_t min, int_t max, int_t N) { std::vector res(N); for(int_t i = 0 ; i < N ; ++i) //res[i] = std::exp(std::log(min) + float(std::log(max) - std::log(min)*i)/N); res[i] = std::exp(std::log(min) + (float)(std::log(max) - std::log(min))*i/N); return res; } int main(int argc, char* argv[]) { if(argc != 2) { std::cerr << "Usage : PROG model_file" << std::endl; } std::map > models = ad::import(argv[1]); std::vector BLAS1_N = create_log_range(1e3, 2e7, 50); std::cout << "Benchmark : BLAS" << std::endl; std::cout << "----------------" << std::endl; bench(BLAS1_N, models); }