Results 1 to 3 of 3

Thread: caching variables from arrays

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    8

    caching variables from arrays

    Hi all, I have the following kernel code

    Code :
    typedef struct {
    	float2 vel;
    	float mass;
    	float life;
    } Particle;
     
    typedef struct {
    	float2 pos;
    	float ejectForce;
    	float attractForce;
    	float waveAmp;
    	float waveFreq;
    } Node;
     
    __kernel void update(__global Particle* particles,		//0
    					 __global float2* posBuffer,		//1
    					 __global float4 *colBuffer,		//2
    					 __global Node *nodes,				//3
    					 const int numNodes,				//4
    					 ) {				
     
    	int		id				= get_global_id(0);
     
    	__global Particle	*p	= &particles[id];
    	__global Node		*n	= &nodes[id % numNodes];
     
     
    	float	mass			= particles[id].mass;
    	float2	pos				= posBuffer[vboIndex];

    In my kernel code after that, I directly use p, n, mass and pos. I've been trying to determine if that is faster, or directly accessing from the arrays, but the results seem roughly the same. I was wondering if those who understand the architecture better than I do can comment on theoretical performance difference? (NVidia 9600GT in Macbook Pro).

  2. #2
    Senior Member
    Join Date
    Jul 2009
    Location
    Northern Europe
    Posts
    311

    Re: caching variables from arrays

    I don't think it should matter. The compiler will load the memory access into a register, and if it can reuse that load later on it will do so. So in effect you get the version where you use a private variable either way if the compiler thinks it is better. The case where you can get a performance speedup is if you load a lot of data and have reuse, particularly within a workgroup. In that case you can manually load the data into the local memory and access it from there as a software managed cache.

  3. #3
    Junior Member
    Join Date
    Oct 2009
    Posts
    8

    Re: caching variables from arrays

    ok makes sense thanks.

Similar Threads

  1. Caching of source files
    By Peccable in forum OpenCL
    Replies: 1
    Last Post: 01-19-2012, 04:30 AM
  2. Caching consideration
    By zaemin in forum OpenVG and VGU
    Replies: 1
    Last Post: 04-18-2007, 02:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •