views:

633

answers:

3

Hi all, I'm trying to apply a Kalman filter to the data coming out from the iPhone accelerometer. I need to perform matrix multiplication and inversion as fast as possible, so I was curious about the possibility of using the GPU to perform these two tasks. As of now I found only one reference for the matrix multiplication:

float mBone01[16] = { ... }
float mBone02[16] = { ... }
float mResult[16];

glMatrixMode  ( GL_MODELVIEW );
glLoadIdentity( );
glLoadMatrix  ( mBone01 );
glMultMatrix  ( mBone02 );
glGetMatrix   ( GL_MODELVIEW, mResult );

even tough the user is not really sure about the fact that this multiplication is performed inside the GPU. Do you have any hint on how to do (if possible) the same for the inversion?

Thank you all!

+2  A: 

The only sure way to perform calculations on the GPU is by using shaders.

That said, neither OpenGL nor GLSL has a built-in function for calculating inverse matrices, you have to code it by yourself.

Kornel Kisielewicz
+3  A: 

As Kornel (and the OpenGL FAQ) already said, OpenGL does not provide an implementation of a matrix inversion.
This thread has some C++ implementations, that should work with the iPhone SDK.
Also, by calling the OpenGL API your code is not running on the GPU.
To use the GPU of the iPhone, you have to use OpenGL ES 2.0, which currently is only available on the following models:

  • iPhone 3GS
  • new iPod touch 32GB
  • new iPod touch 64GB

Apple has a sample project, that makes use of OpenGL ES 2.0 and shaders: http://developer.apple.com/iphone/library/samplecode/GLES2Sample/index.html

weichsel
+1 for a more complete answer :)
Kornel Kisielewicz
Thank you! I just gave you a vote, because your's is correct too.
weichsel
"your code is not running on the GPU" --> you probably mean the matrix code, since without GPU acceleration in other areas, OpenGL would make very little sense on iPhone.
Ivan Vučica
+1  A: 

The vfpmathlibrary on Google code contains fast vfp assembly for several matrix operations, including an invert. This would probably win out over using shaders simply due to the overhead that would entail.

Andy J Buchanan