Matrix self multiplication

301 views
Skip to first unread message

Pierre Wilmot

unread,
Oct 4, 2016, 1:17:54 PM10/4/16
to torch7
Hey Torch developers,

I'm working with code generating a lot of Gram matrices (covariance matrices), which are made by multiplying a matrix by it's transpose. This creates a symmetric matrix, which means you can compute only half of the matrix and just copy the result across the diagonal to save computing time.
Is there any function doing that in Torch?
Is that worth creating a feature request for it ?

For what I've seen matrix multiplication is done with LAPLACK / cuBLAS, does someone knows if there's a built in method for this specific operation in those libraries ?

Best regards,
Pierre

Pierre Wilmot

unread,
Oct 5, 2016, 4:50:54 AM10/5/16
to torch7
Hey, after going over my post again I noticed it wasn't really clear.

What I'm trying to do is to optimize some matrix multiplication operations.
At the moment, matrix multiplication is done with the sgemm / dgemm in the LAPACK or cuBLAS libraries.
My question is, is there an equivalent function to compute only half of the matrix when you know you're going to get a symmetric matrix as a result ? (and then copy the element across the diagonal, so you save about half the processing time)

Pierre

soumith

unread,
Oct 5, 2016, 9:32:50 AM10/5/16
to torch7 on behalf of Pierre Wilmot
Your question is if we have a blas binding for symm that does symmetric matrix multiply. We do not at this time, but if that's something you need, we can add it.

--
You received this message because you are subscribed to the Google Groups "torch7" group.
To unsubscribe from this group and stop receiving emails from it, send an email to torch7+unsubscribe@googlegroups.com.
To post to this group, send email to tor...@googlegroups.com.
Visit this group at https://groups.google.com/group/torch7.
For more options, visit https://groups.google.com/d/optout.

Pierre Wilmot

unread,
Oct 5, 2016, 10:27:49 AM10/5/16
to torch7 on behalf of smth chntla
Hi,

After some research, I found this thread https://software.intel.com/en-us/forums/intel-math-kernel-library/topic/277756 which recommend to use syrk.
I tried to hack into the torch code to use it, but it actually made the performance worse :/


After looking at the ssymm doc, I don't think this is what I'm looking for.

What I want to do is C = A * A'
Where A' is the transpose of A.
This results in C being symmetric.

The current way to do it is with Segmm, but that a waste of processing time since as we know C will be symmetric, we could just compute half of the matrix and then copy it across the diagonal.

If I can read the docs correctly, the symm subroutine is expecting A to be symmetric, which in my case is not true.

Best regards,
Pierre


On 5 October 2016 at 14:32, torch7 on behalf of smth chntla <tor...@googlegroups.com> wrote:
Your question is if we have a blas binding for symm that does symmetric matrix multiply. We do not at this time, but if that's something you need, we can add it.

On Wed, Oct 5, 2016 at 4:50 AM, Pierre Wilmot via torch7 <torch7+APn2wQfRB7EW464hInrP0luzBvNfQFJVAbsCtFrxBsegC1uu03AofjM9L@googlegroups.com> wrote:
Hey, after going over my post again I noticed it wasn't really clear.

What I'm trying to do is to optimize some matrix multiplication operations.
At the moment, matrix multiplication is done with the sgemm / dgemm in the LAPACK or cuBLAS libraries.
My question is, is there an equivalent function to compute only half of the matrix when you know you're going to get a symmetric matrix as a result ? (and then copy the element across the diagonal, so you save about half the processing time)

Pierre



On Tuesday, 4 October 2016 18:17:54 UTC+1, Pierre Wilmot wrote:
Hey Torch developers,

I'm working with code generating a lot of Gram matrices (covariance matrices), which are made by multiplying a matrix by it's transpose. This creates a symmetric matrix, which means you can compute only half of the matrix and just copy the result across the diagonal to save computing time.
Is there any function doing that in Torch?
Is that worth creating a feature request for it ?

For what I've seen matrix multiplication is done with LAPLACK / cuBLAS, does someone knows if there's a built in method for this specific operation in those libraries ?

Best regards,
Pierre

--
You received this message because you are subscribed to the Google Groups "torch7" group.
To unsubscribe from this group and stop receiving emails from it, send an email to torch7+unsubscribe@googlegroups.com.

To post to this group, send email to tor...@googlegroups.com.
Visit this group at https://groups.google.com/group/torch7.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "torch7" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/torch7/KCAwS3HXfj8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to torch7+unsubscribe@googlegroups.com.
log

soumith

unread,
Oct 5, 2016, 2:49:14 PM10/5/16
to torch7 on behalf of Pierre Wilmot
Maybe the syrk routine isn't as optimized as sgemm. Usually the ge* modules get the best optimizations because they are the most used :)

On Wed, Oct 5, 2016 at 10:27 AM, torch7 on behalf of Pierre Wilmot <tor...@googlegroups.com> wrote:
Hi,

After some research, I found this thread https://software.intel.com/en-us/forums/intel-math-kernel-library/topic/277756 which recommend to use syrk.
I tried to hack into the torch code to use it, but it actually made the performance worse :/


After looking at the ssymm doc, I don't think this is what I'm looking for.

What I want to do is C = A * A'
Where A' is the transpose of A.
This results in C being symmetric.

The current way to do it is with Segmm, but that a waste of processing time since as we know C will be symmetric, we could just compute half of the matrix and then copy it across the diagonal.

If I can read the docs correctly, the symm subroutine is expecting A to be symmetric, which in my case is not true.

Best regards,
Pierre

On 5 October 2016 at 14:32, torch7 on behalf of smth chntla <tor...@googlegroups.com> wrote:
Your question is if we have a blas binding for symm that does symmetric matrix multiply. We do not at this time, but if that's something you need, we can add it.
Reply all
Reply to author
Forward
0 new messages