java - JavaCL reading from a CLBuffer after Running Kernel -


i writing program computes n-body simulation having problem getting result of kernel after operates. velocity array being calculated kernel thing not acctualy know how read data out again javacl wrapper.

//clbuffer generator convenience method private clbuffer<floatbuffer> genbuff(float[] dest) {     floatbuffer ptrlx = bytebuffer.allocate(numparticles * 4).asfloatbuffer();     ptrlx.put(dest);     return context.createbuffer(clmem.usage.inputoutput, ptrlx); }  private void calculatetimestep(float e, float dt) {     float[] params = { dt, e, this.particlemass, (float) this.numparticles };      //generates clbuffers convenience method      clbuffer<floatbuffer> plxbuffer = this.genbuff(plx);     clbuffer<floatbuffer> plybuffer = this.genbuff(ply);     clbuffer<floatbuffer> pvxbuffer = this.genbuff(pvx);     clbuffer<floatbuffer> pvybuffer = this.genbuff(pvy);     clbuffer<floatbuffer> paramsbuffer = this.genbuff(params);     //sets kernel arguments     this.nbodykernel.setarg(0, plxbuffer);     this.nbodykernel.setarg(1, plybuffer);     this.nbodykernel.setarg(2, pvxbuffer);     this.nbodykernel.setarg(3, pvybuffer);     this.nbodykernel.setarg(4, paramsbuffer);     //enqueue kernel      clevent evt = this.nbodykernel.enqueuendrange(que, new int[]{numparticles}); 

this problem because not actualy update array leaves was.

    pvxbuffer.readbytes(que, 0, this.numparticles,evt).asfloatbuffer().get(pvx);     pvybuffer.readbytes(que, 0, this.numparticles,evt).asfloatbuffer().get(pvy); 

problem area above

    //and release temerary opencl components manualy     pvxbuffer.release();     pvybuffer.release();     plxbuffer.release();     plybuffer.release();     paramsbuffer.release();     } 

and opencl kernel

__kernel void nbody(__global float *posx,__global float *posy, __global float *volx , __global float *voly, __global float *params) {  //params // dt -> e -> pm -> np     float deltat = params[0]; float e = params[1]; float mass = params[2]; int numpart = as_int(params[3]);  int x = get_global_id(0); //create local variables global variables used lower memeroy overhead float mposx = posx[x]; float mposy = posy[x]; float mvolx = volx[x]; float mvoly = voly[x]; for(int = 0; < numpart; i++) {     if(i != x)     {         float sx = posx[i] - mposx;         float sy = posy[i] - mposy;         float r2 = sx*sx + sy*sy;         float r = sqrt(r2);         float r3 = r2*r;         mvolx += sx*mass*deltat/(r3+e);         mvolx += sy*mass*deltat/(r3+e);     } }  volx[x] = mvolx; voly[x] = mvoly; } 

it looks using jna version of javacl. 1 old, please use bridj version - see migrating jna bridj.

do intend reinterpret float int in line?

int numpart = as_int(params[3]); 

this not convert 1.0f integer 1, directly interpret bits in float if integer, giving number. think want @ section 6.2.4.2: reinterpreting types. think wanted convert_int function, explicit type cast function convert integers.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -