#include <arrayfire.h>
#include <stdio.h>
using namespace af;
#define TRIALS_MATRIX_SIZE 128
#define TRIALS_MATRIX_COUNT 400
#define TRIALS_COUNT 30
int main(int argc, char ** argv)
{
try {
array init = ones(1,1);
eval(init);
printf("Benchmark N-by-N matrix multiply\n");
for (int n = 128; n <= 2048; n += 128) {
printf("%d x %d: ", n, n);
array A = ones(n,n);
array B = A * A;
af::sync();
unsigned count = 0;
double accum = 0;
timer start = timer::tic();
while (timer::toc(start) < 1) {
timer::tic();
B = A * A;
af::sync();
accum += timer::toc();
count++;
}
accum /= count;
double gflops = 2.0 * powf(n,3) / (accum * 1e9);
printf(" %g Gflops\n", gflops);
fflush(stdout);
}
} catch (af::exception& e) {
fprintf(stderr, "%s\n", e.what());
}
#ifdef WIN32 // pause in Windows
if (!(argc == 2 && argv[1][0] == '-')) {
printf("hit [enter]...");
getchar();
}
#endif
return 0;
}