Ask Your Question
0

Is their a cuda namespace equivalent of Mat::dot for GpuMat's?

asked 2016-03-24 18:18:22 -0600

izaak gravatar image

Hello, I am currently translating various sections of a registration algorithm to the cuda:: namespace - make use of our lab titan. The code has a Mat::dot product, for which, I believe is just a standard vector dot product - summation of element-wise multiplication of the two vectors. When I compute a couple of small matrices, the results are the same as calculated by hand. However, there seems to be no GpuMat.dot(), or anything equivalent in the cuda namespace for performing the dot product. Also, the results am getting when I try larger matricies vary from the Mat.dot(), and I am struggling to understand how it is calculated, so I can replicate it with cubla's or the like if need be.

The code in the repo for Mat::dot is

double Mat::dot(InputArray _mat) const
{
    Mat mat = _mat.getMat();
    int cn = channels();
    DotProdFunc func = getDotProdFunc(depth());
    CV_Assert( mat.type() == type() && mat.size == size && func != 0 );

if( isContinuous() && mat.isContinuous() )
{
    size_t len = total()*cn;
    if( len == (size_t)(int)len )
    return func(data, mat.data, (int)len);
}

    const Mat* arrays[] = {this, &mat, 0};
    uchar* ptrs[2];
    NAryMatIterator it(arrays, ptrs);
    int len = (int)(it.size*cn);
    double r = 0;

for( size_t i = 0; i < it.nplanes; i++, ++it )
    r += func( ptrs[0], ptrs[1], len );

    return r;
}

But, where and what is func()? I cant locate it in the repo. The description in the documentation: "The method computes a dot-product of two matrices. If the matrices are not single-column or single-row vectors, the top-to-bottom left-to-right scan ordering is used to treat them as 1D vectors. The vectors must have the same size and type. If the matrices have more than one channel, the dot products from all the channels are summed together." Seems to suggest that, if dot is called on two images, so multi-row vectors, the function performs the calculation A[i] * B[j], so takes a row vector from A, a column vector from B and multiplies to get a Scalar, if so, the result would be a single-row vector, which it them performs a final summation over?

If their is a cuda version that replicates its function, that would be perfect, otherwise, if someone could explain how the computation is performed that would be great!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
-1

answered 2017-07-25 09:43:31 -0600

Emory gravatar image

Hey buddy,

I not sure if it is what you were looking for, but I found a method in cuda to performe multiplcation.

http://docs.opencv.org/2.4/modules/co... gemm(InputArray src1, InputArray src2, double alpha, InputArray src3, double beta, OutputArray dst, int flags)

I hope this can be helpful.

edit flag offensive delete link more

Comments

naw, not really helpful, unfortunately.

question is about cuda and opencv3, you're refering to outdated 2.4 version

also gemm != dot product.

berak gravatar imageberak ( 2017-07-25 09:53:55 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-03-24 18:18:22 -0600

Seen: 866 times

Last updated: Jul 25 '17