Ask Your Question
1

Sequence of calls in the cv::gemm(...) function

asked 2016-12-01 08:33:10 -0600

pi-null-mezon gravatar image

Recently I'have digged into the opencv sources, the reason was low performance of the opencv_dnn module. Searching around I have came to the cv::gemm(...) function. So, I see that function can be divided in two parts. First, optional part that calls optimized version of gemm routine from ocl module or if clAMDBLAS defined from clAMDBLAS. The second part makes some optional transpositions and in the end calls gemm32/64f(...) whitch (track the chain calls) will call "manual" non optimized gemmImpl(...) function! From the source code we can see, that two mentioned parts are independent, so if cv::gemm will be called both of them will be executed... and the performance drammatically drops. If I comment second part, I get 15x speed up, BUT also different results on the same data. It means that the second part does something very important, but I can not find what exactly. So, is this an issue, what does exactly cv::gemm(...) do?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2016-12-02 07:33:28 -0600

mshabunin gravatar image

OpenCL path

Actually macro CV_OCL_RUN returns from function if the call succeeded. There is also check for _matD.isUMat() - if it is not then OpenCL branch will be skipped. If you compiled with -DWITH_OPENCL=OFF then these functions will be stripped completely.

CPU path

Then _cv::hal::gemm32/64f_ is called which tries Lapack implementation first (or user-defined implementation via HAL replacement mechanism), then uses basic CPU implementation

So, if you build with -DWITH_LAPACK=ON cmake option and have MKL or some other Lapack backend available, then gemm should fall into that part.

edit flag offensive delete link more

Comments

Great thanks, you have clarified all that I want to know!

pi-null-mezon gravatar imagepi-null-mezon ( 2016-12-05 02:33:51 -0600 )edit

@pi-null-mezon - please do not post answers, if you have a comment or question

berak gravatar imageberak ( 2016-12-05 03:07:29 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2016-12-01 08:33:10 -0600

Seen: 846 times

Last updated: Dec 05 '16