Skip to content

Commit a78d55b

Browse files
author
contuandrea
committed
Fix slowness in cuda backend
1 parent 035e86d commit a78d55b

File tree

4 files changed

+55
-47
lines changed

4 files changed

+55
-47
lines changed

include/details/datatypes.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,15 @@ using ReducedTuple_t = hydra::tuple<double,double,double,double,double,
5353
ReducedTuple_t ReducedTuple_init(0.,0.,0.,0.,0.,0.,0.,0.);
5454

5555
template<typename T>
56-
using VecHost_t = hydra::host::vector<T>; //vector container double
56+
using VecHost_t = hydra::host::vector<T>; //vector container
5757
template<typename T>
58-
using VecDev_t = hydra::device::vector<T>; //vector container double
58+
using VecDev_t = hydra::device::vector<T>; //vector container
59+
60+
//maps multiarrays
61+
using PhysMapHost_t = hydra::multiarray<double,8,hydra::host::sys_t>; //map container
62+
using VectorMapHost_t = hydra::multiarray<double,3,hydra::host::sys_t>; //map container
63+
using PhysMapDev_t = hydra::multiarray<double,8,hydra::device::sys_t>; //map container
64+
using VectorMapDev_t = hydra::multiarray<double,3,hydra::device::sys_t>; //map container
5965

6066
//currents vector
6167
using CurrentVec_t = std::vector<ReducedTuple_t>;

include/maps/preparemaps.h

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ namespace maps{
434434
class mapconfig{
435435
private:
436436
bool _multimap = false;
437+
bool _isloaded = false;
437438
std::tuple<double,double,double,double,double,double> _borders;
438439

439440
maps::physmap<double,11> _pm;
@@ -443,12 +444,15 @@ namespace maps{
443444
maps::physmap<double,4> _hmobm;
444445

445446
VecDev_t<double> _xvec, _yvec, _zvec;
447+
PhysMapHost_t _vec_map;
448+
446449
//efield vecs
447450
VecDev_t<double> _xvec_ef, _yvec_ef, _zvec_ef;
448-
VecDev_t<double> efieldvecx, efieldvecy, efieldvecz;
451+
VectorMapHost_t _vec_ef;
452+
449453
//wfield vecs
450454
VecDev_t<double> _xvec_wf, _yvec_wf, _zvec_wf;
451-
VecDev_t<double> wfieldvecx, wfieldvecy, wfieldvecz;
455+
VectorMapHost_t _vec_wf;
452456

453457
//emob vecs
454458
VecDev_t<double> _xvec_emob, _yvec_emob, _zvec_emob;
@@ -459,14 +463,23 @@ namespace maps{
459463
VecDev_t<double> hmobvec;
460464

461465
public:
462-
mapconfig(){}
466+
mapconfig() {
467+
_isloaded = false;
468+
};
469+
470+
mapconfig(std::string map_path) {
471+
this->load(map_path);
472+
}
473+
mapconfig(std::string efield_path, std::string emob_path, std::string hmob_path, std::string wfield_path){
474+
this->load(efield_path, emob_path, hmob_path, wfield_path);
475+
}
463476

464477
void load(std::string map_path){
465478
INFO_LINE("Loading single map")
466479
_pm.init(map_path);
467480
_pm.prepare();
468481
_pm.fillspacepoints<VecDev_t<double> >(_xvec,_yvec,_zvec);
469-
_pm.fillallquantities<VecDev_t<double> >(efieldvecx,efieldvecy,efieldvecz,emobvec,hmobvec,wfieldvecx,wfieldvecy,wfieldvecz);
482+
_pm.fillallquantities<PhysMapHost_t >(_vec_map);
470483
std::get<0>(_borders) = *(_pm.getx().begin());
471484
std::get<1>(_borders) = *(_pm.getx().rbegin());
472485
std::get<2>(_borders) = *(_pm.gety().begin());
@@ -476,43 +489,35 @@ namespace maps{
476489
_multimap = false;
477490
std::cout << MIDDLEROW << std::endl;
478491
INFO_LINE("Volume boundaries: [ "<< std::get<0>(_borders) << " < x < "<< std::get<1>(_borders) << " ] micron, "<<"[ "<< std::get<2>(_borders) << " < y < "<< std::get<3>(_borders) <<" ] micron, "<<"[ "<< std::get<4>(_borders) << " < z < "<< std::get<5>(_borders) <<" ] micron")
492+
_isloaded = true;
479493
}
480494

481495
void load(std::string efield_path, std::string emob_path, std::string hmob_path, std::string wfield_path){
482496
INFO_LINE("Loading separate maps")
483497

484-
498+
//get efield
485499
_efieldm.init(efield_path); //E field is a vector
486500
_efieldm.prepare();
487-
_efieldm.fillspacepoints<VecDev_t<double> >(_xvec_ef,_yvec_ef,_zvec_ef);
488-
_efieldm.fillvector<VecDev_t<double> >(efieldvecx,efieldvecy,efieldvecz);
489-
490-
// for(auto cf:configlist){
491-
// if(std::get<bool>(cf.get("plot"))){
492-
// VecHost_t<double> efieldvecx_host, efieldvecy_host, efieldvecz_host;
493-
// efieldm.fillvector<VecHost_t<double> >(efieldvecx_host,efieldvecy_host,efieldvecz_host);
494-
// h3=analysis::getHist3DDraw( efieldvecx_host, efieldvecy_host, efieldvecz_host, efieldm.getx(),efieldm.gety(),efieldm.getz());
495-
// break;
496-
// }
497-
// }
501+
_efieldm.fillspacepoints(_xvec_ef,_yvec_ef,_zvec_ef);
502+
_efieldm.fillvector(_vec_ef);
498503

499504

500505
_wfieldm.init(wfield_path); // Weighting field is a vector
501506
_wfieldm.prepare();
502-
_wfieldm.fillspacepoints<VecDev_t<double> >(_xvec_wf,_yvec_wf,_zvec_wf);
503-
_wfieldm.fillvector<VecDev_t<double> >(wfieldvecx,wfieldvecy,wfieldvecz);
507+
_wfieldm.fillspacepoints(_xvec_wf,_yvec_wf,_zvec_wf);
508+
_wfieldm.fillvector(_vec_wf);
504509

505510

506511
_emobm.init(emob_path); // Electron mobility is a scalar
507512
_emobm.prepare();
508-
_emobm.fillspacepoints<VecDev_t<double> >(_xvec_emob,_yvec_emob,_zvec_emob);
509-
_emobm.fillscalar<VecDev_t<double> >(emobvec);
513+
_emobm.fillspacepoints(_xvec_emob,_yvec_emob,_zvec_emob);
514+
_emobm.fillscalar(emobvec);
510515

511516

512517
_hmobm.init(hmob_path); // Hole mobility is a scalar
513518
_hmobm.prepare();
514-
_hmobm.fillspacepoints<VecDev_t<double> >(_xvec_hmob,_yvec_hmob,_zvec_hmob);
515-
_hmobm.fillscalar<VecDev_t<double> >(hmobvec);
519+
_hmobm.fillspacepoints(_xvec_hmob,_yvec_hmob,_zvec_hmob);
520+
_hmobm.fillscalar(hmobvec);
516521

517522

518523
std::get<0>(_borders) = std::min(*(_efieldm.getx().begin()),std::min(*(_wfieldm.getx().begin()),std::min(*(_emobm.getx().begin()),*(_hmobm.getx().begin()))));
@@ -526,10 +531,13 @@ namespace maps{
526531

527532
std::cout << MIDDLEROW << std::endl;
528533
INFO_LINE("Volume boundaries: [ "<< std::get<0>(_borders) << " < x < "<< std::get<1>(_borders) << " ] micron, "<<"[ "<< std::get<2>(_borders) << " < y < "<< std::get<3>(_borders) <<" ] micron, "<<"[ "<< std::get<4>(_borders) << " < z < "<< std::get<5>(_borders) <<" ] micron")
534+
535+
_isloaded = true;
529536
}
530537

531538
//is multimap or not?
532539
bool ismulti(){return _multimap;}
540+
bool isloaded(){return _isloaded;}
533541
};
534542

535543
//prepare maps

include/simulation/Evolve.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,8 @@ namespace evolve{
227227

228228
//calculate diffusion velocity
229229
double s = sqrt(2*(_fDiff*mobility)/_fStep)*hydra::get<_tc_gauss_x>(p);
230-
hydra::Vector3R ref(1.,0.,0.);
231230

232-
double theta = hydra::get<_tc_angle_2>(p);
233-
double phi = hydra::get<_tc_angle_1>(p);
234-
235-
ref.set(s*sin(theta)*cos(phi),s*sin(theta)*sin(phi),s*cos(theta));
231+
hydra::Vector3R ref(s*sin(hydra::get<_tc_angle_2>(p))*cos(hydra::get<_tc_angle_1>(p)),s*sin(hydra::get<_tc_angle_2>(p))*sin(hydra::get<_tc_angle_1>(p)),s*cos(hydra::get<_tc_angle_2>(p)));
236232

237233
//set diffusion velocity to be used in evolution step
238234
hydra::get<_tc_gauss_x>(p) = ref.get(0);
@@ -363,12 +359,8 @@ namespace evolve{
363359

364360
//calculate diffusion velocity
365361
double s = sqrt(2*(_fDiff*mobility)/_fStep)*hydra::get<_tc_gauss_x>(p);
366-
hydra::Vector3R ref(1.,0.,0.);
367-
368-
double theta = hydra::get<_tc_angle_2>(p);
369-
double phi = hydra::get<_tc_angle_1>(p);
370362

371-
ref.set(s*sin(theta)*cos(phi),s*sin(theta)*sin(phi),s*cos(theta));
363+
hydra::Vector3R ref(s*sin(hydra::get<_tc_angle_2>(p))*cos(hydra::get<_tc_angle_1>(p)),s*sin(hydra::get<_tc_angle_2>(p))*sin(hydra::get<_tc_angle_1>(p)),s*cos(hydra::get<_tc_angle_2>(p)));
372364

373365
//set diffusion velocity to be used in evolution step
374366
hydra::get<_tc_gauss_x>(p) = ref.get(0);

include/simulation/HydraSim.h

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,21 @@ void signal_simulation(cfg::Setting const& root, int icfg=-1){
4545

4646
// size_t nl=countlines(physmap_path);
4747

48+
49+
4850
//3d hist of efield
4951
TH3D* h3=NULL;
5052

5153
VecDev_t<double> _xvec, _yvec, _zvec;
52-
hydra::multiarray<double,8,hydra::host::sys_t> _vec_map;
54+
hydra::multiarray<double,8,hydra::device::sys_t> _vec_map;
5355

5456
//efield vecs
5557
VecDev_t<double> _xvec_ef, _yvec_ef, _zvec_ef;
56-
hydra::multiarray<double,3,hydra::host::sys_t> _vec_ef;
58+
hydra::multiarray<double,3,hydra::device::sys_t> _vec_ef;
5759

5860
//wfield vecs
5961
VecDev_t<double> _xvec_wf, _yvec_wf, _zvec_wf;
60-
hydra::multiarray<double,3,hydra::host::sys_t> _vec_wf;
62+
hydra::multiarray<double,3,hydra::device::sys_t> _vec_wf;
6163

6264

6365
//emob vecs
@@ -83,7 +85,7 @@ void signal_simulation(cfg::Setting const& root, int icfg=-1){
8385
pm.prepare();
8486

8587
pm.fillspacepoints<VecDev_t<double> >(_xvec,_yvec,_zvec);
86-
pm.fillallquantities<hydra::multiarray<double,8,hydra::host::sys_t> >(_vec_map);
88+
pm.fillallquantities<hydra::multiarray<double,8,hydra::device::sys_t> >(_vec_map);
8789

8890
_xmin = *(pm.getx().begin());
8991
_xmax = *(pm.getx().rbegin());
@@ -111,13 +113,13 @@ void signal_simulation(cfg::Setting const& root, int icfg=-1){
111113
maps::physmap<double,6> efieldm(efieldmap_path); //E field is a vector
112114
efieldm.prepare();
113115

114-
efieldm.fillspacepoints<VecDev_t<double> >(_xvec_ef,_yvec_ef,_zvec_ef);
115-
efieldm.fillvector< hydra::multiarray<double,3,hydra::host::sys_t> >(_vec_ef);
116+
efieldm.fillspacepoints(_xvec_ef,_yvec_ef,_zvec_ef);
117+
efieldm.fillvector(_vec_ef);
116118

117119
for(auto cf:configlist){
118120
if(std::get<bool>(cf.get("plot"))){
119121
VecHost_t<double> efieldvecx_host, efieldvecy_host, efieldvecz_host;
120-
efieldm.fillvector<VecHost_t<double> >(efieldvecx_host,efieldvecy_host,efieldvecz_host);
122+
efieldm.fillvector(efieldvecx_host,efieldvecy_host,efieldvecz_host);
121123
h3=analysis::getHist3DDraw( efieldvecx_host, efieldvecy_host, efieldvecz_host, efieldm.getx(),efieldm.gety(),efieldm.getz());
122124
break;
123125
}
@@ -127,20 +129,20 @@ void signal_simulation(cfg::Setting const& root, int icfg=-1){
127129
std::string wfieldmap_path=root["PhysicsMaps"]["wfield"];
128130
maps::physmap<double,6> wfieldm(wfieldmap_path); // Weighting field is a vector
129131
wfieldm.prepare();
130-
wfieldm.fillspacepoints<VecDev_t<double> >(_xvec_wf,_yvec_wf,_zvec_wf);
131-
wfieldm.fillvector< hydra::multiarray<double,3,hydra::host::sys_t> >(_vec_wf);
132+
wfieldm.fillspacepoints(_xvec_wf,_yvec_wf,_zvec_wf);
133+
wfieldm.fillvector(_vec_wf);
132134

133135
std::string emobmap_path=root["PhysicsMaps"]["emob"];
134136
maps::physmap<double,4> emobm(emobmap_path); // Electron mobility is a scalar
135137
emobm.prepare();
136-
emobm.fillspacepoints<VecDev_t<double> >(_xvec_emob,_yvec_emob,_zvec_emob);
137-
emobm.fillscalar<VecDev_t<double> >(emobvec);
138+
emobm.fillspacepoints(_xvec_emob,_yvec_emob,_zvec_emob);
139+
emobm.fillscalar(emobvec);
138140

139141
std::string hmobmap_path=root["PhysicsMaps"]["hmob"];
140142
maps::physmap<double,4> hmobm(hmobmap_path); // Hole mobility is a scalar
141143
hmobm.prepare();
142-
hmobm.fillspacepoints<VecDev_t<double> >(_xvec_hmob,_yvec_hmob,_zvec_hmob);
143-
hmobm.fillscalar<VecDev_t<double> >(hmobvec);
144+
hmobm.fillspacepoints(_xvec_hmob,_yvec_hmob,_zvec_hmob);
145+
hmobm.fillscalar(hmobvec);
144146

145147

146148
_xmin = std::max(*(efieldm.getx().begin()),std::max(*(wfieldm.getx().begin()),std::max(*(emobm.getx().begin()),*(hmobm.getx().begin()))));

0 commit comments

Comments
 (0)