Doing maths (multiplication & addition) in the GPU

edited May 2015 in GLSL / Shaders

Hi to all of the fellow members. I need to make some FIR filters with huge numbers of taps (200-400 taps) and I was thinking if it is possible to calculate everything in the gpu. My code now is

void fir (float[] audiodatain,float[] taps,float[] audiodataout){
  for (int i=0;i<(audiodatain.length)-(taps.length);i++){
    audiodataout [i]=0;
    for (int t=0;t<taps.length;t++) {
      audiodataout [i]+=audiodatain [t+i]*taps[t]*gain;
    }
  }
}

and it is very very slow... I heard that GPU's are very fast when dealing with Floating point arithmetic.

So is there any way to do such a thing in GPU and is it going to be faster?

Thank you very much in advance.

Tagged:

Answers

  • I am very sorry. It won't happen again.

  • Disclaimer: I'm interested in this topic but know very little.

    I suspect that you'll have to go to the Java level to do this. There's some great information about that at http://stackoverflow.com/questions/22866901/using-java-with-nvidia-gpus-cuda

    HTH

  • Hello !

    I don"t know exactly how to do it with Processing, but in Flash/AS3 it's possible to "hack" the GPU-Process in order to create sound filter :

    1) extract a sample of your sound in a bytearray

    2) draw a textured-quare and keep the reference of the texture-object

    3) [don't know if it's possible in Processing] take the texture object and "fill it" with the sound-sample-bytearray as if it was a picture-bytearray

    4) create a fragmentShader and apply your calculation in it (use it to draw your square)

    5) draw the result of your shader in a PGraphics

    6) [don't know if it's possible in Processing] take the bytearray of the result-texture used in the PGraphics and use it as if was a sound-sample to play your modifyed-sound

    Good luck !

  • @ bilmor : thank you very much sir but your option is completely unenviable.My gpu is AMD.

    @ tlecoz : I was thinking a similar kind of hack but in staid of doing it as a shader i was thinking of doing it as a Pvector. But I don't know if the Pvector.Mult function is calculated in the gpu.

    I will test your option when I'll have time (I am in the middle of my exams) and anounce the results.

    Thank you very much and if someone has another idea, please tell me...

  • edited May 2015 Answer ✓

    " I don't know if the Pvector.Mult function is calculated in the gpu"

    the answer is no

  • You might wan't to look into OpenCL. Once you have it working in OpenCL it should be possible to make it work in Processing using JNI. Note that this is not beginners stuff, but probably well worth learning.

Sign In or Register to comment.