Do more. Code less. Free software for GPU computing.
<scroll to top>

examples/misc/blas.cpp

#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 {
        // Force the system to initialize before we do any timings.
        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);

            // Warmup Pass
            array B = A * A;
            af::sync();

            // Time as many multiplications as we can in a period of
            // 1 second.  Accumulate how much time is actually spent
            // on the multiplies, then divide by the count.
            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;
}
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines