Files
triton/bench/blas.cpp

79 lines
2.3 KiB
C++
Raw Normal View History

2014-10-27 05:35:04 -04:00
#include "viennacl/matrix.hpp"
#include "viennacl/vector.hpp"
#include "viennacl/tools/timer.hpp"
2014-10-29 17:03:24 +01:00
#include "atidlas/tools/misc.hpp"
2014-10-27 05:35:04 -04:00
#include "atidlas/model/import.hpp"
#include "atidlas/model/model.hpp"
#include <iomanip>
#include <stdlib.h>
namespace ad = atidlas;
typedef atidlas::atidlas_int_t int_t;
template<class T>
void bench(std::vector<int_t> BLAS1_N, std::map<std::string, ad::tools::shared_ptr<ad::model> > & models)
{
viennacl::tools::timer timer;
2014-10-29 17:03:24 +01:00
float total_time = 0;
std::vector<T> times;
2014-10-27 05:35:04 -04:00
#define BENCHMARK(OP, resname) \
2014-10-29 17:03:24 +01:00
times.clear();\
total_time = 0;\
2014-10-27 05:35:04 -04:00
OP;\
viennacl::backend::finish();\
2014-10-29 17:03:24 +01:00
while(total_time < 1e-1){\
timer.start(); \
OP;\
viennacl::backend::finish();\
times.push_back(timer.get());\
total_time += times.back();\
}\
2014-10-27 05:35:04 -04:00
viennacl::backend::finish();\
2014-10-29 17:03:24 +01:00
float resname = ad::tools::median(times);
2014-10-27 05:35:04 -04:00
//BLAS1
{
for(std::vector<int_t>::const_iterator it = BLAS1_N.begin() ; it != BLAS1_N.end() ; ++it)
{
viennacl::vector<T> 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);
2014-10-29 17:03:24 +01:00
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;
2014-10-27 05:35:04 -04:00
}
}
}
std::vector<int_t> create_log_range(int_t min, int_t max, int_t N)
{
std::vector<int_t> 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;
}
2014-10-29 17:03:24 +01:00
int main(int argc, char* argv[])
2014-10-27 05:35:04 -04:00
{
2014-10-29 17:03:24 +01:00
if(argc != 2)
{
std::cerr << "Usage : PROG model_file" << std::endl;
}
std::map<std::string, ad::tools::shared_ptr<ad::model> > models = ad::import(argv[1]);
2014-10-27 05:35:04 -04:00
2014-10-29 17:03:24 +01:00
std::vector<int_t> BLAS1_N = create_log_range(1e3, 2e7, 50);
2014-10-27 05:35:04 -04:00
std::cout << "Benchmark : BLAS" << std::endl;
std::cout << "----------------" << std::endl;
bench<float>(BLAS1_N, models);
}