2015-04-29 15:50:57 -04:00
|
|
|
#include "isaac/array.h"
|
|
|
|
#include "isaac/symbolic/execute.h"
|
|
|
|
#include "isaac/tools/timer.hpp"
|
|
|
|
#ifdef BENCH_CLBLAS
|
2015-06-24 07:51:27 -07:00
|
|
|
#include "isaac/wrap/clBLAS.h"
|
2015-01-27 15:32:59 -05:00
|
|
|
#endif
|
|
|
|
#ifdef BENCH_CBLAS
|
|
|
|
#include "cblas.h"
|
|
|
|
#endif
|
|
|
|
#ifdef BENCH_CUBLAS
|
|
|
|
#include <cublas.h>
|
|
|
|
#endif
|
2014-10-27 05:35:04 -04:00
|
|
|
#include <iomanip>
|
|
|
|
#include <stdlib.h>
|
2015-01-12 13:20:53 -05:00
|
|
|
#include <cmath>
|
2015-02-08 23:19:38 -05:00
|
|
|
#include <numeric>
|
2015-04-29 15:50:57 -04:00
|
|
|
#include <regex>
|
2014-11-06 07:07:27 -05:00
|
|
|
|
2015-04-29 16:11:32 -04:00
|
|
|
#define HAS_A_BLAS defined(BENCH_CBLAS) or defined(BENCH_CLBLAS) or defined(BENCH_CUBLAS)
|
2015-07-21 13:27:48 -04:00
|
|
|
namespace isc = isaac;
|
|
|
|
typedef isc::int_t int_t;
|
2014-10-27 05:35:04 -04:00
|
|
|
|
2015-07-14 13:33:23 -04:00
|
|
|
template<std::size_t> struct int_{};
|
|
|
|
|
|
|
|
template <class Tuple, size_t Pos>
|
|
|
|
std::ostream& print_tuple(std::ostream& out, const Tuple& t, int_<Pos> ) {
|
|
|
|
out << std::get< std::tuple_size<Tuple>::value-Pos >(t) << ',';
|
|
|
|
return print_tuple(out, t, int_<Pos-1>());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class Tuple>
|
|
|
|
std::ostream& print_tuple(std::ostream& out, const Tuple& t, int_<1> ) {
|
|
|
|
return out << std::get<std::tuple_size<Tuple>::value-1>(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class... Args>
|
|
|
|
std::ostream& operator<<(std::ostream& out, const std::tuple<Args...>& t) {
|
|
|
|
print_tuple(out, t, int_<sizeof...(Args)>());
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2015-02-08 23:19:38 -05:00
|
|
|
int ceil(int N, int pad)
|
|
|
|
{
|
|
|
|
return (N%pad==0)?N:(N+pad-1)/pad*pad;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<int> create_log_range(int min, int max, int N, int pad)
|
|
|
|
{
|
|
|
|
std::vector<int> res(N);
|
|
|
|
for(int i = 0 ; i < N ; ++i)
|
|
|
|
{
|
|
|
|
res[i] = std::exp(std::log(min) + (float)(std::log(max) - std::log(min))*i/N);
|
|
|
|
res[i] = ceil(res[i], pad);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<int> create_full_range(int min, int max, int pad)
|
|
|
|
{
|
|
|
|
std::vector<int> N;
|
|
|
|
for(int i = ceil(min, pad) ; i < ceil(max, pad) ; i+=pad)
|
|
|
|
N.push_back(i);
|
|
|
|
return N;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-27 15:32:59 -05:00
|
|
|
template<class T>
|
2015-02-08 23:19:38 -05:00
|
|
|
T median(std::vector<T> x)
|
2014-10-30 13:04:33 -04:00
|
|
|
{
|
2015-02-08 23:19:38 -05:00
|
|
|
size_t size = x.size();
|
|
|
|
std::sort(x.begin(), x.end());
|
|
|
|
if (size % 2 == 0)
|
|
|
|
return (x[size / 2 - 1] + x[size / 2]) / 2;
|
|
|
|
else
|
|
|
|
return x[size / 2];
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
T mean(std::vector<T> x)
|
|
|
|
{
|
|
|
|
T res = 0;
|
|
|
|
int N = x.size();
|
|
|
|
for(int i = 0 ; i < N ; ++i)
|
|
|
|
res += x[i];
|
|
|
|
return res/N;
|
|
|
|
}
|
|
|
|
|
2015-07-21 13:27:48 -04:00
|
|
|
static double time_event(unsigned long sum, isc::driver::Event const & e)
|
2015-04-29 15:50:57 -04:00
|
|
|
{ return sum + e.elapsed_time();}
|
2015-02-08 23:19:38 -05:00
|
|
|
|
|
|
|
template<class T>
|
2015-07-21 13:27:48 -04:00
|
|
|
void bench(isc::numeric_type dtype, std::string operation)
|
2015-04-29 15:50:57 -04:00
|
|
|
{
|
2014-10-29 17:03:24 +01:00
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
//
|
|
|
|
// MACROS FOR BENCHMARKING
|
|
|
|
//
|
|
|
|
#define CL_HANDLE(X) (*X.handle().cl)()
|
|
|
|
#define BENCHMARK_ISAAC(OP, PERF) \
|
2015-02-08 00:56:24 -05:00
|
|
|
{\
|
|
|
|
std::vector<long> times;\
|
|
|
|
double total_time = 0;\
|
2015-02-09 01:58:32 -05:00
|
|
|
while(total_time*1e-9 < 1e-3){\
|
2015-07-21 13:27:48 -04:00
|
|
|
std::list<isc::driver::Event> events;\
|
|
|
|
flush = isc::zeros(1e6, 1, dtype);\
|
2015-02-08 00:56:24 -05:00
|
|
|
OP;\
|
2015-04-29 15:50:57 -04:00
|
|
|
queue.synchronize();\
|
2015-02-08 23:19:38 -05:00
|
|
|
times.push_back(std::accumulate(events.begin(), events.end(), 0, &time_event));\
|
2015-02-08 00:56:24 -05:00
|
|
|
total_time+=times.back();\
|
|
|
|
}\
|
|
|
|
double t = median(times);\
|
|
|
|
std::cout << " " << PERF << std::flush;\
|
|
|
|
}
|
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
#define BENCHMARK_CLBLAS(OP, PERF) \
|
2015-01-24 14:51:48 -05:00
|
|
|
{\
|
2015-02-05 23:11:16 -05:00
|
|
|
std::vector<long> times;\
|
|
|
|
double total_time = 0;\
|
2015-02-09 01:58:32 -05:00
|
|
|
while(total_time*1e-9 < 1e-3){\
|
2015-02-05 04:42:57 -05:00
|
|
|
cl::Event event;\
|
2015-07-21 13:27:48 -04:00
|
|
|
flush = isc::zeros(1e6, 1, dtype);\
|
2014-10-29 17:03:24 +01:00
|
|
|
OP;\
|
2015-04-29 15:50:57 -04:00
|
|
|
queue.synchronize();\
|
|
|
|
times.push_back(event.getProfilingInfo<CL_PROFILING_COMMAND_END>() - event.getProfilingInfo<CL_PROFILING_COMMAND_START>());\
|
2015-02-05 23:11:16 -05:00
|
|
|
total_time+=times.back();\
|
2014-10-29 17:03:24 +01:00
|
|
|
}\
|
2015-02-05 23:11:16 -05:00
|
|
|
double t = median(times);\
|
|
|
|
std::cout << " " << PERF << std::flush;\
|
|
|
|
}
|
|
|
|
|
|
|
|
#define BENCHMARK_HOST(OP, PERF) \
|
|
|
|
{\
|
2015-07-21 13:27:48 -04:00
|
|
|
isc::tools::timer tmr;\
|
2015-06-28 17:53:16 -07:00
|
|
|
double total_time = 0;\
|
|
|
|
std::vector<double> times;\
|
|
|
|
while(total_time < 1e-2){\
|
|
|
|
std::vector<int> cache_flusher(10000000, 0);\
|
|
|
|
tmr.start();\
|
|
|
|
OP;\
|
|
|
|
double time = tmr.get();\
|
|
|
|
times.push_back(time);\
|
|
|
|
total_time += time;\
|
|
|
|
}\
|
|
|
|
double t = 1e9*median(times);\
|
2015-02-05 23:11:16 -05:00
|
|
|
std::cout << " " << PERF << std::flush;\
|
|
|
|
}
|
|
|
|
|
|
|
|
#define BENCHMARK_CUDA(OP, PERF) \
|
|
|
|
{\
|
|
|
|
std::vector<long> times;\
|
|
|
|
double total_time = 0;\
|
2015-02-05 23:42:31 -05:00
|
|
|
float time;\
|
|
|
|
cudaEvent_t start, stop;\
|
|
|
|
cudaEventCreate(&start);\
|
|
|
|
cudaEventCreate(&stop);\
|
2015-06-28 17:53:16 -07:00
|
|
|
OP;\
|
|
|
|
cudaThreadSynchronize();\
|
2015-04-29 15:50:57 -04:00
|
|
|
while(total_time*1e-3 < 1e-3){\
|
2015-07-21 13:27:48 -04:00
|
|
|
flush = isc::zeros(1e6, 1, dtype);\
|
2015-02-05 23:42:31 -05:00
|
|
|
cudaEventRecord(start,0);\
|
2015-02-05 23:11:16 -05:00
|
|
|
OP;\
|
2015-02-05 23:42:31 -05:00
|
|
|
cudaEventRecord(stop,0);\
|
|
|
|
cudaEventSynchronize(stop);\
|
2015-02-05 23:11:16 -05:00
|
|
|
cudaEventElapsedTime(&time, start, stop);\
|
2015-02-05 23:42:31 -05:00
|
|
|
times.push_back(time*1e6);\
|
2015-02-05 23:11:16 -05:00
|
|
|
total_time+=time;\
|
|
|
|
}\
|
2015-02-05 23:42:31 -05:00
|
|
|
double t = median(times);\
|
2015-04-29 15:50:57 -04:00
|
|
|
std::cout << "\t" << PERF << std::flush;\
|
2015-01-24 14:51:48 -05:00
|
|
|
}
|
2014-10-27 05:35:04 -04:00
|
|
|
|
2015-07-21 13:27:48 -04:00
|
|
|
unsigned int dtsize = isc::size_of(dtype);
|
|
|
|
isc::driver::CommandQueue & queue = isc::driver::queues.default_queues()[0];
|
2015-04-29 15:50:57 -04:00
|
|
|
std::map<std::string, std::string> metric{ {"axpy", "GB/s"}, {"dot", "GB/s"}, {"gemv", "GB/s"}, {"gemm", "GFLOPS"}};
|
2015-07-21 13:27:48 -04:00
|
|
|
isc::array flush(1e6, dtype);
|
2015-04-29 15:50:57 -04:00
|
|
|
std::cout << "#" << operation << " (" << metric[operation] << ")" << std::endl;
|
|
|
|
std::cout << "N";
|
2015-06-25 08:12:16 -07:00
|
|
|
std::cout << "\tISAAC";
|
2015-04-29 15:50:57 -04:00
|
|
|
#ifdef BENCH_CLBLAS
|
|
|
|
std::cout << "\tclBLAS";
|
2015-02-08 23:19:38 -05:00
|
|
|
#endif
|
|
|
|
#ifdef BENCH_CBLAS
|
2015-04-29 15:50:57 -04:00
|
|
|
std::cout << "\tBLAS";
|
2015-02-08 23:19:38 -05:00
|
|
|
#endif
|
|
|
|
#ifdef BENCH_CUBLAS
|
2015-04-29 15:50:57 -04:00
|
|
|
std::cout << "\tcuBLAS";
|
2015-02-08 23:19:38 -05:00
|
|
|
#endif
|
2015-04-29 15:50:57 -04:00
|
|
|
std::cout << std::endl;
|
|
|
|
//
|
|
|
|
// RUN BENCHMARKS
|
|
|
|
//
|
2015-02-08 23:19:38 -05:00
|
|
|
|
2015-06-25 08:12:16 -07:00
|
|
|
/*---------*/
|
|
|
|
/*--BLAS1--*/
|
|
|
|
/*---------*/
|
2015-02-09 01:58:32 -05:00
|
|
|
|
2015-06-25 08:12:16 -07:00
|
|
|
if(operation=="axpy")
|
|
|
|
{
|
|
|
|
float alpha = 1;
|
|
|
|
for(int_t N: create_log_range(1e3, 2e7, 50, 64))
|
|
|
|
{
|
|
|
|
std::cout << N;
|
2015-07-21 13:27:48 -04:00
|
|
|
isc::array x(N, dtype), y(N, dtype);
|
2015-06-25 08:12:16 -07:00
|
|
|
/* ISAAC */
|
2015-07-21 13:27:48 -04:00
|
|
|
std::list<isc::driver::Event> events;\
|
|
|
|
BENCHMARK_ISAAC(y = isc::control(x + alpha*y, isc::execution_options_type(0, &events)), 3*N*dtsize/t)
|
2015-06-25 08:12:16 -07:00
|
|
|
/* clblas */
|
|
|
|
#ifdef BENCH_CLBLAS
|
|
|
|
BENCHMARK_CLBLAS(clblasSaxpy(N, alpha, CL_HANDLE(x.data()), 0, 1, CL_HANDLE(y.data()), 0, 1, 1, &CL_HANDLE(queue), 0, NULL, &event()), 3*N*dtsize/t)
|
|
|
|
#endif
|
|
|
|
/* BLAS */
|
|
|
|
#ifdef BENCH_CBLAS
|
|
|
|
std::vector<float> cx(N), cy(N);
|
2015-07-21 13:27:48 -04:00
|
|
|
isc::copy(x, cx);
|
|
|
|
isc::copy(y, cy);
|
2015-06-25 08:12:16 -07:00
|
|
|
BENCHMARK_HOST(cblas_saxpy(N, alpha, cx.data(), 1, cy.data(), 1), 3*N*dtsize/t);
|
|
|
|
#endif
|
|
|
|
/* CuBLAS */
|
|
|
|
#ifdef BENCH_CUBLAS
|
|
|
|
T *cux, *cuy;
|
|
|
|
cudaMalloc((void**) &cux, N * sizeof(T));
|
|
|
|
cudaMalloc((void**) &cuy, N * sizeof(T));
|
|
|
|
BENCHMARK_CUDA(cublasSaxpy(N, alpha, cux, 1, cuy, 1), 3*N*dtsize/t)
|
|
|
|
cudaFree(cux);
|
|
|
|
cudaFree(cuy);
|
|
|
|
#endif
|
|
|
|
std::cout << std::endl;
|
|
|
|
}
|
|
|
|
}
|
2015-01-28 22:07:09 -05:00
|
|
|
|
2015-06-25 08:12:16 -07:00
|
|
|
if(operation=="dot")
|
|
|
|
{
|
|
|
|
for(int_t N: create_log_range(1e3, 2e7, 50, 64))
|
|
|
|
{
|
|
|
|
std::cout << N;
|
|
|
|
/* ISAAC */
|
2015-07-21 13:27:48 -04:00
|
|
|
isc::array x(N, dtype), y(N, dtype);
|
|
|
|
isc::array scratch(N, dtype);
|
|
|
|
isc::scalar s(dtype);
|
2015-06-25 08:12:16 -07:00
|
|
|
s = dot(x,y); queue.synchronize();
|
2015-07-21 13:27:48 -04:00
|
|
|
BENCHMARK_ISAAC(s = isc::control(dot(x,y), isc::execution_options_type(0, &events)), 2*N*dtsize/t)
|
2015-06-25 08:12:16 -07:00
|
|
|
/* clblas */
|
|
|
|
#ifdef BENCH_CLBLAS
|
|
|
|
BENCHMARK_CLBLAS(clblasSdot(N, CL_HANDLE(s.data()), 0, CL_HANDLE(x.data()), 0, 1, CL_HANDLE(y.data()), 0, 1, CL_HANDLE(scratch.data()), 1, &CL_HANDLE(queue), 0, NULL, &event()), 2*N*dtsize/t)
|
|
|
|
#endif
|
|
|
|
/* BLAS */
|
|
|
|
#ifdef BENCH_CBLAS
|
|
|
|
std::vector<float> cx(N), cy(N);
|
2015-07-21 13:27:48 -04:00
|
|
|
isc::copy(x, cx);
|
|
|
|
isc::copy(y, cy);
|
2015-06-25 08:12:16 -07:00
|
|
|
BENCHMARK_HOST(cblas_sdot(N, cx.data(), 1, cy.data(), 1), 2*N*dtsize/t);
|
|
|
|
#endif
|
|
|
|
#ifdef BENCH_CUBLAS
|
|
|
|
T *cux, *cuy;
|
|
|
|
T result;
|
|
|
|
cudaMalloc((void**) &cux, N * sizeof(T));
|
|
|
|
cudaMalloc((void**) &cuy, N * sizeof(T));
|
|
|
|
BENCHMARK_CUDA(cublasSdot(N, cux, 1, cuy, 1), 2*N*dtsize/t)
|
|
|
|
cudaFree(cux);
|
|
|
|
cudaFree(cuy);
|
|
|
|
#endif
|
|
|
|
std::cout << std::endl;
|
|
|
|
}
|
|
|
|
std::cout << "\n\n" << std::flush;
|
|
|
|
}
|
2015-04-29 15:50:57 -04:00
|
|
|
|
2015-06-25 08:12:16 -07:00
|
|
|
if(operation.substr(0, 4)=="gemv")
|
|
|
|
{
|
|
|
|
std::vector<std::tuple<int_t, int_t> > MNs;
|
|
|
|
MNs.push_back(std::make_tuple(896,896));
|
|
|
|
MNs.push_back(std::make_tuple(3072,3072));
|
|
|
|
MNs.push_back(std::make_tuple(64,32000));
|
|
|
|
MNs.push_back(std::make_tuple(896,32000));
|
|
|
|
MNs.push_back(std::make_tuple(32000, 64));
|
|
|
|
MNs.push_back(std::make_tuple(32000, 896));
|
2015-04-29 15:50:57 -04:00
|
|
|
|
2015-06-25 08:12:16 -07:00
|
|
|
/*---------*/
|
|
|
|
/*--BLAS2--*/
|
|
|
|
/*---------*/
|
|
|
|
//T-layout
|
|
|
|
for(std::tuple<int_t, int_t> MN: MNs)
|
|
|
|
{
|
|
|
|
int_t M = std::get<0>(MN);
|
|
|
|
int_t N = std::get<1>(MN);
|
|
|
|
std::cout << M << "," << N;
|
|
|
|
/* ISAAC */
|
2015-07-21 13:27:48 -04:00
|
|
|
isc::array A(N, M, dtype), y(M, dtype), x(N, dtype);
|
2015-06-25 08:12:16 -07:00
|
|
|
#if HAS_A_BLAS
|
|
|
|
int_t lda = A.ld();
|
|
|
|
#endif
|
|
|
|
y = dot(trans(A),x); queue.synchronize();
|
2015-07-21 13:27:48 -04:00
|
|
|
BENCHMARK_ISAAC(y = isc::control(dot(trans(A),x), isc::execution_options_type(0, &events)),(M*N + M + N)*dtsize/t);
|
2015-06-25 08:12:16 -07:00
|
|
|
#ifdef BENCH_CLBLAS
|
|
|
|
BENCHMARK_CLBLAS(clblasSgemv(clblasColumnMajor, clblasTrans, N, M, 1, CL_HANDLE(A.data()), 0, lda, CL_HANDLE(x.data()), 0, 1, 0, CL_HANDLE(y.data()), 0, 1, 1, &CL_HANDLE(queue),0, NULL, &event()), (M*N + M + N)*dtsize/t)
|
|
|
|
#endif
|
|
|
|
#ifdef BENCH_CBLAS
|
|
|
|
std::vector<float> cA(N*M), cx(N), cy(M);
|
2015-07-21 13:27:48 -04:00
|
|
|
isc::copy(x, cx);
|
|
|
|
isc::copy(y, cy);
|
|
|
|
isc::copy(A, cA);
|
2015-06-25 08:12:16 -07:00
|
|
|
BENCHMARK_HOST(cblas_sgemv(CblasColMajor, CblasTrans, N, M, 1, cA.data(), lda, cx.data(), 1, 0, cy.data(), 1), (M*N + M + N)*dtsize/t);
|
|
|
|
#endif
|
|
|
|
#ifdef BENCH_CUBLAS
|
|
|
|
T *cuA, *cux, *cuy;
|
|
|
|
cudaMalloc((void**) &cuA, N * M * sizeof(T));
|
|
|
|
cudaMalloc((void**) &cux, N * sizeof(T));
|
|
|
|
cudaMalloc((void**) &cuy, M * sizeof(T));
|
|
|
|
BENCHMARK_CUDA(cublasSgemv('t', N, M, 1, cuA, lda, cux, 1, 0, cuy, 1), (M*N + M + N)*dtsize/t)
|
|
|
|
cudaFree(cuA);
|
|
|
|
cudaFree(cux);
|
|
|
|
cudaFree(cuy);
|
|
|
|
#endif
|
|
|
|
std::cout << std::endl;
|
|
|
|
}
|
|
|
|
std::cout << "\n\n" << std::flush;
|
|
|
|
}
|
2015-04-29 15:50:57 -04:00
|
|
|
|
|
|
|
if(operation.substr(0,4)=="gemm")
|
|
|
|
{
|
2015-07-14 13:33:23 -04:00
|
|
|
std::vector<std::tuple<char, char, int_t, int_t, int_t> > MNKs;
|
2015-07-18 17:23:53 -04:00
|
|
|
MNKs.push_back(std::make_tuple('N','T',1536,1536,1536));
|
2015-07-14 13:33:23 -04:00
|
|
|
//AlexNet (Forward)
|
|
|
|
MNKs.push_back(std::make_tuple('N','N',3025,96,363));
|
|
|
|
MNKs.push_back(std::make_tuple('N','N',729,128,1200));
|
2015-07-18 17:23:53 -04:00
|
|
|
MNKs.push_back(std::make_tuple('N','N',169,384,2304));
|
|
|
|
MNKs.push_back(std::make_tuple('N','N',169,192,1728));
|
|
|
|
MNKs.push_back(std::make_tuple('N','N',169,128,1728));
|
|
|
|
//AlexNet (Backward)
|
|
|
|
MNKs.push_back(std::make_tuple('T','N',1728,128,169));
|
|
|
|
MNKs.push_back(std::make_tuple('T','N',1728,192,169));
|
|
|
|
MNKs.push_back(std::make_tuple('T','N',2304,384,169));
|
|
|
|
MNKs.push_back(std::make_tuple('T','N',1200,128,729));
|
|
|
|
MNKs.push_back(std::make_tuple('T','N',363,96,3025));
|
2015-07-14 13:33:23 -04:00
|
|
|
|
2015-07-18 17:23:53 -04:00
|
|
|
MNKs.push_back(std::make_tuple('N','T',169,1728,128));
|
|
|
|
MNKs.push_back(std::make_tuple('N','T',169,1728,192));
|
|
|
|
MNKs.push_back(std::make_tuple('N','T',169,2304,384));
|
|
|
|
MNKs.push_back(std::make_tuple('N','T',729,1200,128));
|
2015-07-14 13:33:23 -04:00
|
|
|
|
2015-07-18 17:23:53 -04:00
|
|
|
//Covariance (e.g., ICA)
|
|
|
|
MNKs.push_back(std::make_tuple('N','N',64,64,32000));
|
|
|
|
MNKs.push_back(std::make_tuple('N','N',1024,1024,32000));
|
2015-04-29 15:50:57 -04:00
|
|
|
|
|
|
|
/*---------*/
|
|
|
|
/*--BLAS3--*/
|
|
|
|
/*---------*/
|
2015-07-14 13:33:23 -04:00
|
|
|
for(std::tuple<char, char, int_t, int_t, int_t> MNK: MNKs)
|
2015-04-29 15:50:57 -04:00
|
|
|
{
|
2015-07-14 13:33:23 -04:00
|
|
|
bool AT = std::get<0>(MNK)=='T';
|
|
|
|
bool BT = std::get<1>(MNK)=='T';
|
|
|
|
int_t M = std::get<2>(MNK);
|
|
|
|
int_t N = std::get<3>(MNK);
|
|
|
|
int_t K = std::get<4>(MNK);
|
|
|
|
std::cout << MNK;
|
2015-06-28 17:53:16 -07:00
|
|
|
std::cout << std::flush;
|
2015-04-29 15:50:57 -04:00
|
|
|
/* ISAAC */
|
2015-07-14 13:33:23 -04:00
|
|
|
int_t As1 = M, As2 = K;
|
|
|
|
if(AT) std::swap(As1, As2);
|
|
|
|
int_t Bs1 = K, Bs2 = N;
|
|
|
|
if(BT) std::swap(Bs1, Bs2);
|
|
|
|
|
2015-07-21 13:27:48 -04:00
|
|
|
isc::array C(M, N, dtype), A(As1, As2, dtype), B(Bs1, Bs2, dtype);
|
2015-04-29 16:11:32 -04:00
|
|
|
#if HAS_A_BLAS
|
2015-04-29 15:50:57 -04:00
|
|
|
int_t lda = A.ld(), ldb = B.ld(), ldc = C.ld();
|
2015-04-29 16:11:32 -04:00
|
|
|
#endif
|
2015-07-21 13:27:48 -04:00
|
|
|
BENCHMARK_ISAAC(C = isc::control(AT?(BT?dot(A.T(),B.T()):dot(A.T(),B)):(BT?dot(A,B.T()):dot(A,B)), isc::execution_options_type(0, &events)), (double)2*M*N*K/t);
|
2015-04-29 15:50:57 -04:00
|
|
|
/* clblas */
|
|
|
|
#ifdef BENCH_CLBLAS
|
2015-07-14 13:33:23 -04:00
|
|
|
BENCHMARK_CLBLAS(clblasSgemm(clblasColumnMajor, AT?clblasTrans:clblasNoTrans, BT?clblasTrans:clblasNoTrans, M, N, K, 1, CL_HANDLE(A.data()), 0, lda, CL_HANDLE(B.data()), 0, ldb,
|
2015-04-29 15:50:57 -04:00
|
|
|
0, CL_HANDLE(C.data()), 0, ldc, 1, &CL_HANDLE(queue),0, NULL, &event()), (double)2*M*N*K/t)
|
|
|
|
#endif
|
|
|
|
/* BLAS */
|
|
|
|
#ifdef BENCH_CBLAS
|
|
|
|
std::vector<float> cC(M*N), cA(M*K), cB(N*K);
|
2015-07-21 13:27:48 -04:00
|
|
|
isc::copy(C, cC);
|
|
|
|
isc::copy(A, cA);
|
|
|
|
isc::copy(B, cB);
|
2015-04-29 15:50:57 -04:00
|
|
|
BENCHMARK_HOST(cblas_sgemm(CblasColMajor, CblasNoTrans, CblasTrans, M, N, K, 1, cA.data(), lda, cB.data(), ldb, 1, cC.data(), ldc), (double)2*M*N*K/t);
|
|
|
|
#endif
|
|
|
|
#ifdef BENCH_CUBLAS
|
|
|
|
T *cuA, *cuB, *cuC;
|
|
|
|
cudaMalloc((void**) &cuA, M * K * sizeof(T));
|
|
|
|
cudaMalloc((void**) &cuB, K * N * sizeof(T));
|
|
|
|
cudaMalloc((void**) &cuC, M * N * sizeof(T));
|
|
|
|
BENCHMARK_CUDA(cublasSgemm('n', 't', M, N, K, 1, cuA, lda, cuB, ldb, 1, cuC, ldc), (double)2*M*N*K/t)
|
|
|
|
cudaFree(cuA);
|
|
|
|
cudaFree(cuB);
|
|
|
|
cudaFree(cuC);
|
|
|
|
#endif
|
|
|
|
std::cout << std::endl;
|
|
|
|
}
|
|
|
|
}
|
2015-01-25 18:19:19 -05:00
|
|
|
|
2014-10-27 05:35:04 -04:00
|
|
|
}
|
|
|
|
|
2014-10-29 17:03:24 +01:00
|
|
|
int main(int argc, char* argv[])
|
2014-10-27 05:35:04 -04:00
|
|
|
{
|
2015-04-29 15:50:57 -04:00
|
|
|
std::vector<std::string> args(argv, argv + argc);
|
|
|
|
#ifdef BENCH_CLBLAS
|
|
|
|
clblasSetup();
|
2015-01-24 14:51:48 -05:00
|
|
|
#endif
|
2015-07-21 13:27:48 -04:00
|
|
|
isc::driver::queues.queue_properties = CL_QUEUE_PROFILING_ENABLE;
|
2015-02-05 04:42:57 -05:00
|
|
|
|
2015-01-24 14:51:48 -05:00
|
|
|
int device_idx = 0;
|
2015-07-21 13:27:48 -04:00
|
|
|
isc::driver::queues_type::container_type queues = isc::driver::queues.contexts();
|
2015-02-04 22:06:15 -05:00
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
std::string operation;
|
|
|
|
if(queues.size() > 1)
|
|
|
|
{
|
|
|
|
if(args.size() != 3)
|
2015-01-24 14:51:48 -05:00
|
|
|
{
|
2015-04-29 15:50:57 -04:00
|
|
|
std::cerr << "usage : blas-bench DEVICE_IDX OPERATION" << std::endl;
|
2015-01-24 14:51:48 -05:00
|
|
|
std::cout << "Devices available: " << std::endl;
|
|
|
|
unsigned int current=0;
|
2015-07-21 13:27:48 -04:00
|
|
|
for(isc::driver::queues_type::container_type::const_iterator it = queues.begin() ; it != queues.end() ; ++it)
|
2015-04-29 15:50:57 -04:00
|
|
|
{
|
2015-07-21 13:27:48 -04:00
|
|
|
isc::driver::Device device = it->first.device();
|
2015-04-29 15:50:57 -04:00
|
|
|
std::cout << current++ << ": " << device.name() << " on " << device.platform().name() << " " << device.platform().version() << std::endl;
|
2015-01-24 14:51:48 -05:00
|
|
|
}
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2015-04-29 15:50:57 -04:00
|
|
|
device_idx = atoi(argv[1]);
|
|
|
|
operation = args[2];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(args.size() != 2)
|
|
|
|
{
|
|
|
|
std::cerr << "usage : blas-bench OPERATION" << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
operation = args[1];
|
2015-01-24 14:51:48 -05:00
|
|
|
}
|
|
|
|
|
2015-07-21 13:27:48 -04:00
|
|
|
isc::driver::queues.default_device = device_idx;
|
2014-10-30 13:04:33 -04:00
|
|
|
std::cout << "#Benchmark : BLAS" << std::endl;
|
|
|
|
std::cout << "#----------------" << std::endl;
|
2015-07-21 13:27:48 -04:00
|
|
|
bench<float>(isc::FLOAT_TYPE, operation);
|
2015-01-24 14:51:48 -05:00
|
|
|
|
2015-04-29 15:50:57 -04:00
|
|
|
#ifdef BENCH_CLBLAS
|
|
|
|
clblasTeardown();
|
2015-01-24 14:51:48 -05:00
|
|
|
#endif
|
2014-10-27 05:35:04 -04:00
|
|
|
}
|