How can I improve performance for this compute shader?

Hi,

I have this code running in a compute shader for each pixel of a 1080p frame:

#define  BLK_SIZE 8
#define BLK_SIZE_SHIFT 3

vec2 zero=vec2(0.0, 0.0);
vec2 zero_horiz[2*BLK_SIZE-1]={zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero, zero};

vec2 pad[2*BLK_SIZE-1][2*BLK_SIZE-1]={zero_horiz, zero_horiz, zero_horiz, zero_horiz, zero_horiz, zero_horiz, zero_horiz, zero_horiz, zero_horiz, zero_horiz, zero_horiz, zero_horiz, zero_horiz, zero_horiz, zero_horiz};

vec2 kernel[2*BLK_SIZE-1] = {vec2(0.1250, 0.1250), vec2(0.2500, 0.2500), vec2(0.3750, 0.3750), vec2(0.5000, 0.5000), vec2(0.6250, 0.6250), vec2(0.7500,  0.7500), vec2(0.8750, 0.8750), vec2(1.0000, 1.0000),vec2(0.8750, 0.8750), vec2(0.7500, 0.7500), vec2(0.6250, 0.6250), vec2(0.5000, 0.5000), vec2(0.3750, 0.3750), vec2(0.2500, 0.2500), vec2(0.1250, 0.1250)};

	  //horizontal convolution for each 0..14 rows
	  for (int ky=0; ky<(2*BLK_SIZE-1); ky++)
	  {
	    vec2 conv=zero; 
	    for (int kx=0; kx<(2*BLK_SIZE-1); kx++)
	    {
	        conv+=pad[ky][kx]*kernel[kx];
	    } 
		pad[ky][BLK_SIZE-1]=conv;
	  }

	  //vertical convolution for colom 7th  
	  for (int ky=0; ky<(2*BLK_SIZE-1); ky++)
	  {
	     mv+=pad[ky][BLK_SIZE-1]*kernel[ky]; 
      }

This piece of code introduces a 500ms processing time which is prohibitive for my application.
This piece of code upscales motion vectors for 8x8 blocks to motion vectors per pixel.
Not sure why it takes so long, there are 250 multiplications with accumulation.

How can I speed up this computation?

Thanks,
Andrei

Each of your shader invocations is using ~2 KB of local scratch data.
Compare that to the total amount of shared memory on an SM.
That’s going to radically limit how many threads can run per SM at a time.

Also, would ensure tweak this to ensure the read-only data is stored once and shared. The compiler may do this, but…

Thank you so much that is very helpful! I thought that the shared memory is different than the local memory taken by the variables declared inside main().