Created
April 25, 2012 21:57
-
-
Save pavanky/2493843 to your computer and use it in GitHub Desktop.
Benchmarking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <arrayfire.h> | |
using namespace af; | |
array in; | |
void bench_blas() | |
{ | |
array out = matmul(in, in); | |
} | |
void bench_fft() | |
{ | |
array out = fft2(in); | |
} | |
void bench_lu() | |
{ | |
array l, u; | |
lu(l, u, in); | |
} | |
void bench_sort() | |
{ | |
array sorted = sort(in); | |
} | |
int main(int argc, char **argv) | |
{ | |
af::deviceset(1); | |
af::info(); | |
printf("Benching blas\n"); | |
for (int n = 1024; n <= 8192; n+=1024) { | |
double time_s, time_d; | |
in = randu(n, n, f32); | |
time_s = timeit(bench_blas); | |
in = randu(n, n, f64); | |
time_d = timeit(bench_blas) : -1; | |
printf("[%4d x %4d] Single: %4.4lf Double: %4.4lf\n", n, n, time_s, time_d); | |
} | |
printf("\n\n"); | |
printf("Benching lu\n"); | |
for (int n = 512; n <= 4096; n+=512) { | |
double time_s, time_d; | |
in = randu(n, n, f32); | |
time_s = timeit(bench_lu); | |
in = randu(n, n, f64); | |
time_d = timeit(bench_lu); | |
printf("[%4d x %4d] Single: %4.4lf Double: %4.4lf\n", n, n, time_s, time_d); | |
} | |
printf("\n\n"); | |
printf("Benching fft\n"); | |
for (int n = 256; n <= 4096; n*=2) { | |
double time_s, time_d; | |
in = randu(n, n, f32); | |
time_s = timeit(bench_fft); | |
in = randu(n, n, f64); | |
time_d = timeit(bench_fft); | |
printf("[%4d x %4d] Single: %4.4lf Double: %4.4lf\n", n, n, time_s, time_d); | |
} | |
printf("\n\n"); | |
printf("Benching sort\n"); | |
for (int n = 1024; n <= 50e6; n*=2) { | |
double time_s, time_d; | |
in = randu(n, 1, f32); | |
time_s = timeit(bench_sort); | |
in = randu(n, 1, f64); | |
time_d = timeit(bench_sort); | |
printf("[%8d x 1] Single: %4.4lf Double: %4.4lf\n", n, time_s, time_d); | |
} | |
printf("\n\n"); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment