Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve opencl #161

Open
wants to merge 8 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion inc/owOpenCLConstant.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

#define INTEL_OPENCL_DEBUG 0

const int local_NDRange_size = 256;
const int local_NDRange_size = MAX_NEIGHBOR_COUNT;

enum DEVICE { CPU = 0, GPU = 1, ALL = 2};
enum INTEGRATOR { EULER = 0, LEAPFROG = 1 };
Expand Down
5 changes: 3 additions & 2 deletions src/owOpenCLSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <stdexcept>

#include "owOpenCLSolver.h"
#include "owOpenCLConstant.h"

int comparator(const void *v1, const void *v2);

Expand Down Expand Up @@ -731,11 +732,11 @@ owOpenCLSolver::_run_pcisph_computeDensity(owConfigProperty *config) {
pcisph_computeDensity.setArg(5, config->getParticleCount());
int err = queue.enqueueNDRangeKernel(
pcisph_computeDensity, cl::NullRange,
cl::NDRange((int)(config->getParticleCount_RoundUp())),
cl::NDRange((int)(config->getParticleCount_RoundUp()*local_NDRange_size/2)),
#if defined(__APPLE__)
cl::NullRange, nullptr, nullptr);
#else
cl::NDRange((int)(local_NDRange_size)), nullptr, nullptr);
cl::NDRange((int)(local_NDRange_size/2)), nullptr, nullptr);
#endif
#if QUEUE_EACH_KERNEL
queue.finish();
Expand Down
46 changes: 31 additions & 15 deletions src/sphFluid.cl
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ __kernel void pcisph_computeDensity(
__global uint * particleIndexBack,
uint PARTICLE_COUNT )
{
int id = get_global_id( 0 );
int id = get_group_id( 0 );
if( id >= PARTICLE_COUNT ) return;
id = particleIndexBack[id]; //track selected particle (indices are not shuffled anymore)
int idx = id * MAX_NEIGHBOR_COUNT;
Expand All @@ -488,25 +488,41 @@ __kernel void pcisph_computeDensity(
float hScaled6 = hScaled2*hScaled2*hScaled2;
int real_nc = 0;

do // gather density contribution from all neighbors (if they exist)
{
if( NEIGHBOR_MAP_ID( neighborMap[ idx + nc ] ) != NO_PARTICLE_ID )
{
int lid = get_local_id(0);
__local float l_density[MAX_NEIGHBOR_COUNT/2];

l_density[lid] = 0.0;
barrier(CLK_LOCAL_MEM_FENCE);

nc = lid;
int offset = MAX_NEIGHBOR_COUNT/2;

if( NEIGHBOR_MAP_ID( neighborMap[ idx + nc ] ) != NO_PARTICLE_ID ) {
r_ij2= NEIGHBOR_MAP_DISTANCE( neighborMap[ idx + nc ] ); // distance is already scaled here
r_ij2 *= r_ij2;
if(r_ij2<hScaled2)
{
density += (hScaled2-r_ij2)*(hScaled2-r_ij2)*(hScaled2-r_ij2);
//if(r_ij2>hScaled2) printf("=Error: r_ij/h = %f\n", NEIGHBOR_MAP_DISTANCE( neighborMap[ idx + nc ] ) / hScaled);
real_nc++;
if(r_ij2<hScaled2) {
l_density[lid] += (hScaled2-r_ij2)*(hScaled2-r_ij2)*(hScaled2-r_ij2);
}
}
if( NEIGHBOR_MAP_ID( neighborMap[ idx + nc + offset ] ) != NO_PARTICLE_ID ) {
r_ij2= NEIGHBOR_MAP_DISTANCE( neighborMap[ idx + nc + offset ] ); // distance is already scaled here
r_ij2 *= r_ij2;
if(r_ij2<hScaled2) {
l_density[lid] += (hScaled2-r_ij2)*(hScaled2-r_ij2)*(hScaled2-r_ij2);
}
}

}while( ++nc < MAX_NEIGHBOR_COUNT );
if(density<hScaled6)
density = hScaled6;
density *= mass_mult_Wpoly6Coefficient; // since all particles are same fluid type, factor this out to here
rho[ id ] = density;
barrier(CLK_LOCAL_MEM_FENCE);
if (lid == 0) {
for (int i = 0; i < MAX_NEIGHBOR_COUNT/2; i++) {
density += l_density[i];
}
if(density<hScaled6) {
density = hScaled6;
}
density *= mass_mult_Wpoly6Coefficient; // since all particles are same fluid type, factor this out to here
rho[ id ] = density;
}
}

/** Run pcisph_computeForcesAndInitPressure kernel
Expand Down