Fixing issues with growing memory allocation with multiple init calls

This commit is contained in:
Trung Nguyen
2019-10-19 23:35:52 -05:00
parent aa2b885783
commit dfbee32575
6 changed files with 45 additions and 59 deletions

View File

@ -25,12 +25,16 @@ BaseAtomicT::BaseAtomic() : _compiled(false), _max_bytes(0) {
device=&global_device; device=&global_device;
ans=new Answer<numtyp,acctyp>(); ans=new Answer<numtyp,acctyp>();
nbor=new Neighbor(); nbor=new Neighbor();
pair_program=NULL;
} }
template <class numtyp, class acctyp> template <class numtyp, class acctyp>
BaseAtomicT::~BaseAtomic() { BaseAtomicT::~BaseAtomic() {
delete ans; delete ans;
delete nbor; delete nbor;
if (pair_program) delete pair_program;
k_pair_fast.clear();
k_pair.clear();
} }
template <class numtyp, class acctyp> template <class numtyp, class acctyp>
@ -109,19 +113,11 @@ void BaseAtomicT::clear_atomic() {
device->output_times(time_pair,*ans,*nbor,avg_split,_max_bytes+_max_an_bytes, device->output_times(time_pair,*ans,*nbor,avg_split,_max_bytes+_max_an_bytes,
_gpu_overhead,_driver_overhead,_threads_per_atom,screen); _gpu_overhead,_driver_overhead,_threads_per_atom,screen);
if (_compiled) {
k_pair_fast.clear();
k_pair.clear();
delete pair_program;
_compiled=false;
}
time_pair.clear(); time_pair.clear();
hd_balancer.clear(); hd_balancer.clear();
nbor->clear(); nbor->clear();
ans->clear(); ans->clear();
device->clear();
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -276,6 +272,7 @@ void BaseAtomicT::compile_kernels(UCL_Device &dev, const void *pair_str,
return; return;
std::string s_fast=std::string(kname)+"_fast"; std::string s_fast=std::string(kname)+"_fast";
if (pair_program) delete pair_program;
pair_program=new UCL_Program(dev); pair_program=new UCL_Program(dev);
pair_program->load_string(pair_str,device->compile_string().c_str()); pair_program->load_string(pair_str,device->compile_string().c_str());
k_pair_fast.set_function(*pair_program,s_fast.c_str()); k_pair_fast.set_function(*pair_program,s_fast.c_str());

View File

@ -25,12 +25,16 @@ BaseChargeT::BaseCharge() : _compiled(false), _max_bytes(0) {
device=&global_device; device=&global_device;
ans=new Answer<numtyp,acctyp>(); ans=new Answer<numtyp,acctyp>();
nbor=new Neighbor(); nbor=new Neighbor();
pair_program=NULL;
} }
template <class numtyp, class acctyp> template <class numtyp, class acctyp>
BaseChargeT::~BaseCharge() { BaseChargeT::~BaseCharge() {
delete ans; delete ans;
delete nbor; delete nbor;
if (pair_program) delete pair_program;
k_pair_fast.clear();
k_pair.clear();
} }
template <class numtyp, class acctyp> template <class numtyp, class acctyp>
@ -111,19 +115,11 @@ void BaseChargeT::clear_atomic() {
device->output_times(time_pair,*ans,*nbor,avg_split,_max_bytes+_max_an_bytes, device->output_times(time_pair,*ans,*nbor,avg_split,_max_bytes+_max_an_bytes,
_gpu_overhead,_driver_overhead,_threads_per_atom,screen); _gpu_overhead,_driver_overhead,_threads_per_atom,screen);
if (_compiled) {
k_pair_fast.clear();
k_pair.clear();
delete pair_program;
_compiled=false;
}
time_pair.clear(); time_pair.clear();
hd_balancer.clear(); hd_balancer.clear();
nbor->clear(); nbor->clear();
ans->clear(); ans->clear();
device->clear();
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -291,6 +287,7 @@ void BaseChargeT::compile_kernels(UCL_Device &dev, const void *pair_str,
return; return;
std::string s_fast=std::string(kname)+"_fast"; std::string s_fast=std::string(kname)+"_fast";
if (pair_program) delete pair_program;
pair_program=new UCL_Program(dev); pair_program=new UCL_Program(dev);
pair_program->load_string(pair_str,device->compile_string().c_str()); pair_program->load_string(pair_str,device->compile_string().c_str());
k_pair_fast.set_function(*pair_program,s_fast.c_str()); k_pair_fast.set_function(*pair_program,s_fast.c_str());

View File

@ -25,12 +25,16 @@ BaseDipoleT::BaseDipole() : _compiled(false), _max_bytes(0) {
device=&global_device; device=&global_device;
ans=new Answer<numtyp,acctyp>(); ans=new Answer<numtyp,acctyp>();
nbor=new Neighbor(); nbor=new Neighbor();
pair_program=NULL;
} }
template <class numtyp, class acctyp> template <class numtyp, class acctyp>
BaseDipoleT::~BaseDipole() { BaseDipoleT::~BaseDipole() {
delete ans; delete ans;
delete nbor; delete nbor;
if (pair_program) delete pair_program;
k_pair_fast.clear();
k_pair.clear();
} }
template <class numtyp, class acctyp> template <class numtyp, class acctyp>
@ -113,19 +117,11 @@ void BaseDipoleT::clear_atomic() {
device->output_times(time_pair,*ans,*nbor,avg_split,_max_bytes+_max_an_bytes, device->output_times(time_pair,*ans,*nbor,avg_split,_max_bytes+_max_an_bytes,
_gpu_overhead,_driver_overhead,_threads_per_atom,screen); _gpu_overhead,_driver_overhead,_threads_per_atom,screen);
if (_compiled) {
k_pair_fast.clear();
k_pair.clear();
delete pair_program;
_compiled=false;
}
time_pair.clear(); time_pair.clear();
hd_balancer.clear(); hd_balancer.clear();
nbor->clear(); nbor->clear();
ans->clear(); ans->clear();
device->clear();
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -299,6 +295,7 @@ void BaseDipoleT::compile_kernels(UCL_Device &dev, const void *pair_str,
return; return;
std::string s_fast=std::string(kname)+"_fast"; std::string s_fast=std::string(kname)+"_fast";
if (pair_program) delete pair_program;
pair_program=new UCL_Program(dev); pair_program=new UCL_Program(dev);
pair_program->load_string(pair_str,device->compile_string().c_str()); pair_program->load_string(pair_str,device->compile_string().c_str());
k_pair_fast.set_function(*pair_program,s_fast.c_str()); k_pair_fast.set_function(*pair_program,s_fast.c_str());

View File

@ -25,12 +25,16 @@ BaseDPDT::BaseDPD() : _compiled(false), _max_bytes(0) {
device=&global_device; device=&global_device;
ans=new Answer<numtyp,acctyp>(); ans=new Answer<numtyp,acctyp>();
nbor=new Neighbor(); nbor=new Neighbor();
pair_program=NULL;
} }
template <class numtyp, class acctyp> template <class numtyp, class acctyp>
BaseDPDT::~BaseDPD() { BaseDPDT::~BaseDPD() {
delete ans; delete ans;
delete nbor; delete nbor;
if (pair_program) delete pair_program;
k_pair_fast.clear();
k_pair.clear();
} }
template <class numtyp, class acctyp> template <class numtyp, class acctyp>
@ -112,19 +116,11 @@ void BaseDPDT::clear_atomic() {
device->output_times(time_pair,*ans,*nbor,avg_split,_max_bytes+_max_an_bytes, device->output_times(time_pair,*ans,*nbor,avg_split,_max_bytes+_max_an_bytes,
_gpu_overhead,_driver_overhead,_threads_per_atom,screen); _gpu_overhead,_driver_overhead,_threads_per_atom,screen);
if (_compiled) {
k_pair_fast.clear();
k_pair.clear();
delete pair_program;
_compiled=false;
}
time_pair.clear(); time_pair.clear();
hd_balancer.clear(); hd_balancer.clear();
nbor->clear(); nbor->clear();
ans->clear(); ans->clear();
device->clear();
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -297,6 +293,7 @@ void BaseDPDT::compile_kernels(UCL_Device &dev, const void *pair_str,
return; return;
std::string s_fast=std::string(kname)+"_fast"; std::string s_fast=std::string(kname)+"_fast";
if (pair_program) delete pair_program;
pair_program=new UCL_Program(dev); pair_program=new UCL_Program(dev);
pair_program->load_string(pair_str,device->compile_string().c_str()); pair_program->load_string(pair_str,device->compile_string().c_str());
k_pair_fast.set_function(*pair_program,s_fast.c_str()); k_pair_fast.set_function(*pair_program,s_fast.c_str());

View File

@ -33,12 +33,25 @@ BaseEllipsoidT::BaseEllipsoid() : _compiled(false), _max_bytes(0) {
device=&global_device; device=&global_device;
ans=new Answer<numtyp,acctyp>(); ans=new Answer<numtyp,acctyp>();
nbor=new Neighbor(); nbor=new Neighbor();
nbor_program=NULL;
ellipsoid_program=NULL;
lj_program=NULL;
} }
template <class numtyp, class acctyp> template <class numtyp, class acctyp>
BaseEllipsoidT::~BaseEllipsoid() { BaseEllipsoidT::~BaseEllipsoid() {
delete ans; delete ans;
delete nbor; delete nbor;
k_nbor_fast.clear();
k_nbor.clear();
k_ellipsoid.clear();
k_ellipsoid_sphere.clear();
k_sphere_ellipsoid.clear();
k_lj_fast.clear();
k_lj.clear();
if (nbor_program) delete nbor_program;
if (ellipsoid_program) delete ellipsoid_program;
if (lj_program) delete lj_program;
} }
template <class numtyp, class acctyp> template <class numtyp, class acctyp>
@ -146,20 +159,6 @@ void BaseEllipsoidT::clear_base() {
output_times(); output_times();
host_olist.clear(); host_olist.clear();
if (_compiled) {
k_nbor_fast.clear();
k_nbor.clear();
k_ellipsoid.clear();
k_ellipsoid_sphere.clear();
k_sphere_ellipsoid.clear();
k_lj_fast.clear();
k_lj.clear();
delete nbor_program;
delete ellipsoid_program;
delete lj_program;
_compiled=false;
}
time_nbor1.clear(); time_nbor1.clear();
time_ellipsoid.clear(); time_ellipsoid.clear();
time_nbor2.clear(); time_nbor2.clear();
@ -171,7 +170,6 @@ void BaseEllipsoidT::clear_base() {
nbor->clear(); nbor->clear();
ans->clear(); ans->clear();
device->clear();
} }
template <class numtyp, class acctyp> template <class numtyp, class acctyp>
@ -437,6 +435,7 @@ int** BaseEllipsoidT::compute(const int ago, const int inum_full, const int nall
ans->copy_answers(eflag,vflag,eatom,vatom); ans->copy_answers(eflag,vflag,eatom,vatom);
device->add_ans_object(ans); device->add_ans_object(ans);
hd_balancer.stop_timer(); hd_balancer.stop_timer();
return nbor->host_jlist.begin()-host_start; return nbor->host_jlist.begin()-host_start;
} }
@ -462,18 +461,21 @@ void BaseEllipsoidT::compile_kernels(UCL_Device &dev,
std::string flags=device->compile_string(); std::string flags=device->compile_string();
if (nbor_program) delete nbor_program;
nbor_program=new UCL_Program(dev); nbor_program=new UCL_Program(dev);
nbor_program->load_string(ellipsoid_nbor,flags.c_str()); nbor_program->load_string(ellipsoid_nbor,flags.c_str());
k_nbor_fast.set_function(*nbor_program,"kernel_nbor_fast"); k_nbor_fast.set_function(*nbor_program,"kernel_nbor_fast");
k_nbor.set_function(*nbor_program,"kernel_nbor"); k_nbor.set_function(*nbor_program,"kernel_nbor");
neigh_tex.get_texture(*nbor_program,"pos_tex"); neigh_tex.get_texture(*nbor_program,"pos_tex");
if (ellipsoid_program) delete ellipsoid_program;
ellipsoid_program=new UCL_Program(dev); ellipsoid_program=new UCL_Program(dev);
ellipsoid_program->load_string(ellipsoid_string,flags.c_str()); ellipsoid_program->load_string(ellipsoid_string,flags.c_str());
k_ellipsoid.set_function(*ellipsoid_program,kname); k_ellipsoid.set_function(*ellipsoid_program,kname);
pos_tex.get_texture(*ellipsoid_program,"pos_tex"); pos_tex.get_texture(*ellipsoid_program,"pos_tex");
quat_tex.get_texture(*ellipsoid_program,"quat_tex"); quat_tex.get_texture(*ellipsoid_program,"quat_tex");
if (lj_program) delete lj_program;
lj_program=new UCL_Program(dev); lj_program=new UCL_Program(dev);
lj_program->load_string(lj_string,flags.c_str()); lj_program->load_string(lj_string,flags.c_str());
k_sphere_ellipsoid.set_function(*lj_program,s_sphere_ellipsoid.c_str()); k_sphere_ellipsoid.set_function(*lj_program,s_sphere_ellipsoid.c_str());

View File

@ -27,6 +27,7 @@ BaseThreeT::BaseThree() : _compiled(false), _max_bytes(0) {
#ifdef THREE_CONCURRENT #ifdef THREE_CONCURRENT
ans2=new Answer<numtyp,acctyp>(); ans2=new Answer<numtyp,acctyp>();
#endif #endif
pair_program=NULL;
} }
template <class numtyp, class acctyp> template <class numtyp, class acctyp>
@ -36,6 +37,12 @@ BaseThreeT::~BaseThree() {
#ifdef THREE_CONCURRENT #ifdef THREE_CONCURRENT
delete ans2; delete ans2;
#endif #endif
if (pair_program) delete pair_program;
k_three_center.clear();
k_three_end.clear();
k_three_end_vatom.clear();
k_pair.clear();
k_short_nbor.clear();
} }
template <class numtyp, class acctyp> template <class numtyp, class acctyp>
@ -139,16 +146,6 @@ void BaseThreeT::clear_atomic() {
device->output_times(time_pair,*ans,*nbor,avg_split,_max_bytes+_max_an_bytes, device->output_times(time_pair,*ans,*nbor,avg_split,_max_bytes+_max_an_bytes,
_gpu_overhead,_driver_overhead,_threads_per_atom,screen); _gpu_overhead,_driver_overhead,_threads_per_atom,screen);
if (_compiled) {
k_three_center.clear();
k_three_end.clear();
k_three_end_vatom.clear();
k_pair.clear();
k_short_nbor.clear();
delete pair_program;
_compiled=false;
}
time_pair.clear(); time_pair.clear();
hd_balancer.clear(); hd_balancer.clear();
@ -161,7 +158,6 @@ void BaseThreeT::clear_atomic() {
// ucl_device will clean up the command queue in its destructor // ucl_device will clean up the command queue in its destructor
// ucl_device->pop_command_queue(); // ucl_device->pop_command_queue();
#endif #endif
device->clear();
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -378,7 +374,7 @@ void BaseThreeT::compile_kernels(UCL_Device &dev, const void *pair_str,
return; return;
std::string vatom_name=std::string(three_end)+"_vatom"; std::string vatom_name=std::string(three_end)+"_vatom";
if (pair_program) delete pair_program;
pair_program=new UCL_Program(dev); pair_program=new UCL_Program(dev);
pair_program->load_string(pair_str,device->compile_string().c_str()); pair_program->load_string(pair_str,device->compile_string().c_str());
k_three_center.set_function(*pair_program,three_center); k_three_center.set_function(*pair_program,three_center);