Skip to content

Commit

Permalink
removing divergence inside hitgrid, thanks to njuffa
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Oct 12, 2016
1 parent 5905e0b commit df62a0d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/mcx_core.cu
Expand Up @@ -146,6 +146,7 @@ __device__ inline void savedebugdata(MCXpos *p,uint id,float *gdebugdata){
gdebugdata[pos++]=0;
}
}

__device__ inline float mcx_nextafterf(float a, int dir){
union{
float f;
Expand All @@ -157,7 +158,7 @@ __device__ inline float mcx_nextafterf(float a, int dir){
}

__device__ inline float hitgrid(float3 *p0, float3 *v, float *htime,float* rv,int *id){
float dist;
float dist, xi[3];

//time-of-flight to hit the wall in each direction
htime[0]=fabs((floorf(p0->x)+(v->x>0.f)-p0->x)*rv[0]); // absolute distance of travel in x/y/z
Expand All @@ -173,11 +174,13 @@ __device__ inline float hitgrid(float3 *p0, float3 *v, float *htime,float* rv,in
htime[1]=p0->y+dist*v->y;
htime[2]=p0->z+dist*v->z;

(*id==0) ?
(htime[0]=mcx_nextafterf(__float2int_rn(htime[0]), (v->x > 0.f)-(v->x < 0.f))) :
((*id==1) ?
(htime[1]=mcx_nextafterf(__float2int_rn(htime[1]), (v->y > 0.f)-(v->y < 0.f))) :
(htime[2]=mcx_nextafterf(__float2int_rn(htime[2]), (v->z > 0.f)-(v->z < 0.f))) );
xi[0] = mcx_nextafterf(__float2int_rn(htime[0]), (v->x > 0.f)-(v->x < 0.f));
xi[1] = mcx_nextafterf(__float2int_rn(htime[1]), (v->y > 0.f)-(v->y < 0.f));
xi[2] = mcx_nextafterf(__float2int_rn(htime[2]), (v->z > 0.f)-(v->z < 0.f));

if (*id == 0) htime[0] = xi[0];
if (*id == 1) htime[1] = xi[1];
if (*id == 2) htime[2] = xi[2];

return dist;
}
Expand Down

0 comments on commit df62a0d

Please sign in to comment.