ArrayFire slower than Eigen in cpu mode ?

501 views
Skip to first unread message

William Tambellini

unread,
Aug 12, 2016, 6:08:27 PM8/12/16
to ArrayFire Users
Good morning gentlemen

In order to evaluate ArrayFire, I am converting some Eigen codes to ArrayFire :

Eigen (w and n are float32 matrix):
    EigenRowVector maxCoeff = w.colwise().maxCoeff();
    EigenMatrix normTerms = (w.rowwise() - maxCoeff).unaryExpr(Exp()).colwise().sum().unaryExpr(Log()) + maxCoeff;
    n.noalias() = w.rowwise() - normTerms.row(0);

ArrayFire:
      n = w - af::tile( af::log(af::sum( af::exp(w - af::tile(af::max(w), w.dims(0), 1)) )) + af::max(w), w.dims(0), 1);  // I m not fan of the af::tile() thing but did nt find better.

When run in CPU mode (not opengl), AF is about 3 to 4 times slower than Eigen.
Am I doing anything wrong ?
Cheers
WT.

Umar Arshad

unread,
Aug 14, 2016, 9:11:06 PM8/14/16
to ArrayFire Users
The CPU backend of ArrayFire was implemented as a fallback for the CUDA/OpenCL
backends. With that said, we are evaluating ways of improving the performance of
the CPU backend.

I am also curious why you do not want to use the OpenCL backend to perform CPU
operations. We have been discussing how we can improve the CPU performance
but it looks like it will just be an exercise to repeat the OpenCL implementations with
extra complexity in the binary. The reason this is not a problem in libraries like Eigen
is because they are header only library whereas ArrayFire is an actual library. In order
to support all architectures, we will need implementations for AVX, SSE, and Non-vectorized
versions in the library and switch to it at runtime which requires additional logic for each
function. This is not a problem with the OpenCL backend because it compiles the
kernels at runtime so it is optimized for that architecture.

Umar

William Tambellini

unread,
Aug 15, 2016, 7:55:20 PM8/15/16
to ArrayFire Users
Hi Umar
Thanks very much.
Of course, I m going to try the Intel OpenCL backend in order to compare.
Cheers
William T.
Reply all
Reply to author
Forward
0 new messages