Thread Subject: speeding up floating point operations

Subject: speeding up floating point operations

From: NIcholas

Date: 8 May, 2009 22:35:02

Message: 1 of 9

Some C++ compilers have an option for performing floating point computations precisely vs. quickly (e.g. visual studio c++ compiler: http://msdn.microsoft.com/en-us/library/e7s85ffb(VS.80).aspx). Is there a way to specify such an option in MATLAB to speedup general purpose floating point operations, such as Matrix Multiplication or element wise addition/multiplication etc.?

Subject: speeding up floating point operations

From: John D'Errico

Date: 8 May, 2009 23:35:02

Message: 2 of 9

"NIcholas " <remove.this_nmg33@cornell.edu> wrote in message <gu2c2m$mup$1@fred.mathworks.com>...
> Some C++ compilers have an option for performing floating point computations precisely vs. quickly (e.g. visual studio c++ compiler: http://msdn.microsoft.com/en-us/library/e7s85ffb(VS.80).aspx). Is there a way to specify such an option in MATLAB to speedup general purpose floating point operations, such as Matrix Multiplication or element wise addition/multiplication etc.?

No.

Subject: speeding up floating point operations

From: James Tursa

Date: 9 May, 2009 01:00:17

Message: 3 of 9

"NIcholas " <remove.this_nmg33@cornell.edu> wrote in message <gu2c2m$mup$1@fred.mathworks.com>...
> Some C++ compilers have an option for performing floating point computations precisely vs. quickly (e.g. visual studio c++ compiler: http://msdn.microsoft.com/en-us/library/e7s85ffb(VS.80).aspx). Is there a way to specify such an option in MATLAB to speedup general purpose floating point operations, such as Matrix Multiplication or element wise addition/multiplication etc.?

For matrix multiplication, in particular, MATLAB uses an optimized BLAS library in the background and is *very* fast. You will be very hard pressed to find anything faster.

James Tursa

Subject: speeding up floating point operations

From: NIcholas

Date: 10 May, 2009 22:03:01

Message: 4 of 9

"James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message <gu2kj1$ea8$1@fred.mathworks.com>...
> "NIcholas " <remove.this_nmg33@cornell.edu> wrote in message <gu2c2m$mup$1@fred.mathworks.com>...
> > Some C++ compilers have an option for performing floating point computations precisely vs. quickly (e.g. visual studio c++ compiler: http://msdn.microsoft.com/en-us/library/e7s85ffb(VS.80).aspx). Is there a way to specify such an option in MATLAB to speedup general purpose floating point operations, such as Matrix Multiplication or element wise addition/multiplication etc.?
>
> For matrix multiplication, in particular, MATLAB uses an optimized BLAS library in the background and is *very* fast. You will be very hard pressed to find anything faster.
>
> James Tursa

In the version of MATLAB I have, r2008a, MATLAB uses INTEL MKL for matrix multiplication and it is really quick. The computation I am doing doesn't require high precision and I was hoping it was possible to speed up the computation by doing lower precision computations, like some compilers allow (see above), within this library call.

Subject: speeding up floating point operations

From: James Tursa

Date: 11 May, 2009 18:42:02

Message: 5 of 9

"NIcholas " <remove.this_nmg33@cornell.edu> wrote in message <gu7iul$cut$1@fred.mathworks.com>...
> "James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message <gu2kj1$ea8$1@fred.mathworks.com>...
> > "NIcholas " <remove.this_nmg33@cornell.edu> wrote in message <gu2c2m$mup$1@fred.mathworks.com>...
> > > Some C++ compilers have an option for performing floating point computations precisely vs. quickly (e.g. visual studio c++ compiler: http://msdn.microsoft.com/en-us/library/e7s85ffb(VS.80).aspx). Is there a way to specify such an option in MATLAB to speedup general purpose floating point operations, such as Matrix Multiplication or element wise addition/multiplication etc.?
> >
> > For matrix multiplication, in particular, MATLAB uses an optimized BLAS library in the background and is *very* fast. You will be very hard pressed to find anything faster.
> >
> > James Tursa
>
> In the version of MATLAB I have, r2008a, MATLAB uses INTEL MKL for matrix multiplication and it is really quick. The computation I am doing doesn't require high precision and I was hoping it was possible to speed up the computation by doing lower precision computations, like some compilers allow (see above), within this library call.

As I understand it, the Intel MKL includes optimized BLAS routines for things such as matrix multiplication. So Intel has already gone to great lengths to make these operations as fast as possible. Are you saying you want something even faster than that?

James Tursa

Subject: speeding up floating point operations

From: James Tursa

Date: 11 May, 2009 19:57:01

Message: 6 of 9

"James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message <gu9rhq$plj$1@fred.mathworks.com>...
> "NIcholas " <remove.this_nmg33@cornell.edu> wrote in message <gu7iul$cut$1@fred.mathworks.com>...
> > "James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message <gu2kj1$ea8$1@fred.mathworks.com>...
> > > "NIcholas " <remove.this_nmg33@cornell.edu> wrote in message <gu2c2m$mup$1@fred.mathworks.com>...
> > > > Some C++ compilers have an option for performing floating point computations precisely vs. quickly (e.g. visual studio c++ compiler: http://msdn.microsoft.com/en-us/library/e7s85ffb(VS.80).aspx). Is there a way to specify such an option in MATLAB to speedup general purpose floating point operations, such as Matrix Multiplication or element wise addition/multiplication etc.?
> > >
> > > For matrix multiplication, in particular, MATLAB uses an optimized BLAS library in the background and is *very* fast. You will be very hard pressed to find anything faster.
> > >
> > > James Tursa
> >
> > In the version of MATLAB I have, r2008a, MATLAB uses INTEL MKL for matrix multiplication and it is really quick. The computation I am doing doesn't require high precision and I was hoping it was possible to speed up the computation by doing lower precision computations, like some compilers allow (see above), within this library call.
>
> As I understand it, the Intel MKL includes optimized BLAS routines for things such as matrix multiplication. So Intel has already gone to great lengths to make these operations as fast as possible. Are you saying you want something even faster than that?
>
> James Tursa

P.S. If you really don't care much about precision, consider using single precision. I just did a quick test of a simple A * B matrix multiply where A and B are both large double matrices. Converting both operands to single, calling SGEMM from the MATLAB supplied BLAS library, and then converting the result back to double does give you a significant time savings over the A * B operation at the MATLAB prompt. So the benefit of doing the multiply in single far outweighs the overhead of the conversions, at least for large matrices. The key is using an optimized BLAS library for the SGEMM call.

James Tursa

Subject: speeding up floating point operations

From: NIcholas

Date: 11 May, 2009 20:41:01

Message: 7 of 9

"James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message <gu9vud$nek$1@fred.mathworks.com>...
> "James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message <gu9rhq$plj$1@fred.mathworks.com>...
> > "NIcholas " <remove.this_nmg33@cornell.edu> wrote in message <gu7iul$cut$1@fred.mathworks.com>...
> > > "James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message <gu2kj1$ea8$1@fred.mathworks.com>...
> > > > "NIcholas " <remove.this_nmg33@cornell.edu> wrote in message <gu2c2m$mup$1@fred.mathworks.com>...
> > > > > Some C++ compilers have an option for performing floating point computations precisely vs. quickly (e.g. visual studio c++ compiler: http://msdn.microsoft.com/en-us/library/e7s85ffb(VS.80).aspx). Is there a way to specify such an option in MATLAB to speedup general purpose floating point operations, such as Matrix Multiplication or element wise addition/multiplication etc.?
> > > >
> > > > For matrix multiplication, in particular, MATLAB uses an optimized BLAS library in the background and is *very* fast. You will be very hard pressed to find anything faster.
> > > >
> > > > James Tursa
> > >
> > > In the version of MATLAB I have, r2008a, MATLAB uses INTEL MKL for matrix multiplication and it is really quick. The computation I am doing doesn't require high precision and I was hoping it was possible to speed up the computation by doing lower precision computations, like some compilers allow (see above), within this library call.
> >
> > As I understand it, the Intel MKL includes optimized BLAS routines for things such as matrix multiplication. So Intel has already gone to great lengths to make these operations as fast as possible. Are you saying you want something even faster than that?
> >
> > James Tursa
>
> P.S. If you really don't care much about precision, consider using single precision. I just did a quick test of a simple A * B matrix multiply where A and B are both large double matrices. Converting both operands to single, calling SGEMM from the MATLAB supplied BLAS library, and then converting the result back to double does give you a significant time savings over the A * B operation at the MATLAB prompt. So the benefit of doing the multiply in single far outweighs the overhead of the conversions, at least for large matrices. The key is using an optimized BLAS library for the SGEMM call.
>
> James Tursa

I am currently using single precision matrix mult and my data (input and output) is in single and it is almost 2x as quick as double. Is the MATLAB '*' operator on singles calling the optimized BLAS SGEMM that you are referring to? Also, I have a dual core processor and have enabled multithreading (about 1.7x speedup for matrices i'm working with).

I just found that some MKL operations allow control of precision -
http://www.intel.com/software/products/mkl/data/vml/vmldata.htm - but I'm not sure if this is just for vector operations (like sqrt, acos, etc.) or if there is a way to set low precision for operations like matrix multiply. I am asking if there was a similar flag to be set in MATLAB or if it is possible to set such a flag for ops like mat mult.

The reason I am asking is I have a very intensive compuation where essentially all the time is spent doing a matrix mult but the result only needs a few decimal digits of accuracy. So any small speedup in this operation would speed up my entire computation.

Thanks again,
Nick

Subject: speeding up floating point operations

From: James Tursa

Date: 11 May, 2009 22:44:02

Message: 8 of 9

"NIcholas " <remove.this_nmg33@cornell.edu> wrote in message <gua2gt$j1q$1@fred.mathworks.com>...
>
> I am currently using single precision matrix mult and my data (input and output) is in single and it is almost 2x as quick as double. Is the MATLAB '*' operator on singles calling the optimized BLAS SGEMM that you are referring to?

Yes. The MATLAB intrinsic * operator for single class variables is calling the BLAS SGEMM routine in the background to do the work (using whatever library you have connected to MATLAB, e.g. your Intel MKL). So you are already getting the max speedup here. To check this I wrote a mex routine that called SGEMM directly and got the same timing results as the MATLAB intrinsic *.

MATLAB recently changed vendors for their BLAS / LAPACK libraries. I did a test case and found that a large matrix multiply that took 6.5 seconds in R2007a was only taking 2.6 seconds in R2008b. So results for these operations are very critically dependent on the particular BLAS / LAPACK library you are using.

> Also, I have a dual core processor and have enabled multithreading (about 1.7x speedup for matrices i'm working with).
>

I am not sure if the MKL version you are using takes advantage of this. You might read the doc to see.

> I just found that some MKL operations allow control of precision -
> http://www.intel.com/software/products/mkl/data/vml/vmldata.htm - but I'm not sure if this is just for vector operations (like sqrt, acos, etc.) or if there is a way to set low precision for operations like matrix multiply. I am asking if there was a similar flag to be set in MATLAB or if it is possible to set such a flag for ops like mat mult.
>

I doubt it. For functions like sqrt or acos that iterate, I guess I could see there being a user-settable flag that stops the iteration process before max precision has been achieved, but for something as basic as multiplication I just can't imagine there being an equivalent.

> The reason I am asking is I have a very intensive compuation where essentially all the time is spent doing a matrix mult but the result only needs a few decimal digits of accuracy. So any small speedup in this operation would speed up my entire computation.
>

I think you are stuck, unless you can reformulate your problem. Wish I could help you more.

James Tursa

Subject: speeding up floating point operations

From: Sebastien Paris

Date: 12 May, 2009 11:24:02

Message: 9 of 9

Have a look to :

http://wwwuser.gwdg.de/~mleuten/MATLABToolbox/index.html

Regards,

Sebastien

"James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message <gua9ni$e9h$1@fred.mathworks.com>...
> "NIcholas " <remove.this_nmg33@cornell.edu> wrote in message <gua2gt$j1q$1@fred.mathworks.com>...
> >
> > I am currently using single precision matrix mult and my data (input and output) is in single and it is almost 2x as quick as double. Is the MATLAB '*' operator on singles calling the optimized BLAS SGEMM that you are referring to?
>
> Yes. The MATLAB intrinsic * operator for single class variables is calling the BLAS SGEMM routine in the background to do the work (using whatever library you have connected to MATLAB, e.g. your Intel MKL). So you are already getting the max speedup here. To check this I wrote a mex routine that called SGEMM directly and got the same timing results as the MATLAB intrinsic *.
>
> MATLAB recently changed vendors for their BLAS / LAPACK libraries. I did a test case and found that a large matrix multiply that took 6.5 seconds in R2007a was only taking 2.6 seconds in R2008b. So results for these operations are very critically dependent on the particular BLAS / LAPACK library you are using.
>
> > Also, I have a dual core processor and have enabled multithreading (about 1.7x speedup for matrices i'm working with).
> >
>
> I am not sure if the MKL version you are using takes advantage of this. You might read the doc to see.
>
> > I just found that some MKL operations allow control of precision -
> > http://www.intel.com/software/products/mkl/data/vml/vmldata.htm - but I'm not sure if this is just for vector operations (like sqrt, acos, etc.) or if there is a way to set low precision for operations like matrix multiply. I am asking if there was a similar flag to be set in MATLAB or if it is possible to set such a flag for ops like mat mult.
> >
>
> I doubt it. For functions like sqrt or acos that iterate, I guess I could see there being a user-settable flag that stops the iteration process before max precision has been achieved, but for something as basic as multiplication I just can't imagine there being an equivalent.
>
> > The reason I am asking is I have a very intensive compuation where essentially all the time is spent doing a matrix mult but the result only needs a few decimal digits of accuracy. So any small speedup in this operation would speed up my entire computation.
> >
>
> I think you are stuck, unless you can reformulate your problem. Wish I could help you more.
>
> James Tursa

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
performance NIcholas 8 May, 2009 18:39:02
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com