24 #include "cheetah/sps/astroaccelerate/detail/SpsCuda.h" 25 #include "cheetah/cuda_utils/cuda_errorhandling.h" 26 #include "cheetah/data/DmTrialsMetadata.h" 27 #include "cheetah/data/DmTrials.h" 28 #include "cheetah/data/SpCcl.h" 29 #include "cheetah/data/TimeFrequency.h" 30 #include "cheetah/data/Units.h" 31 #include "cheetah/data/DedispersionMeasure.h" 32 #include "cheetah/cuda_utils/nvtx.h" 33 #include "panda/Resource.h" 34 #include "panda/Log.h" 35 #include "panda/Error.h" 43 namespace astroaccelerate {
46 #ifdef ENABLE_ASTROACCELERATE 47 template<
typename DmHandler,
typename SpHandler>
48 void SpsCuda::operator()(panda::PoolResource<panda::nvidia::Cuda>& gpu
50 , DmHandler& dm_handler
51 , SpHandler& sp_handler
54 PUSH_NVTX_RANGE(
"sps_astroaccelerate_SpsCuda_operator",0);
55 PANDA_LOG <<
"astroaccelerate::SpsCuda::operator() invoked (on device "<< gpu.device_id() <<
")";
59 if (agg_buf.data_size() < (std::size_t) _dedispersion_strategy->get_maxshift())
61 const std::string msg(
"SpsCuda: data buffer size < maxshift ");
62 PANDA_LOG_ERROR << msg <<
"(" << agg_buf.data_size() <<
"<" << _dedispersion_strategy->get_maxshift() <<
")";
63 throw panda::Error(msg);
66 auto new_samples = agg_buf.data_size()/ _dedispersion_strategy->get_nchans();
68 if(new_samples != _samples)
71 PANDA_LOG_WARN <<
"Aggregation buffer size has changed from " 72 << _samples <<
" to " << new_samples <<
" samples";
73 _dedispersion_strategy->resize(new_samples, _dedispersion_strategy->get_gpu_memory());
74 calculate_internals(_dm_trial_metadata->fundamental_sampling_interval());
75 _samples = new_samples;
76 PANDA_LOG_DEBUG <<
"SpsCuda will now output " 77 << _dedispersion_strategy->get_dedispersed_time_samples()
78 <<
" time samples per call";
84 data::DimensionIndex<data::Time> offset_samples(agg_buf.offset_first_block()/_dedispersion_strategy->get_nchans());
85 auto const& start_time = agg_buf.composition().front()->start_time(offset_samples);
86 PANDA_LOG_DEBUG <<
"Start time of current buffer: " << start_time;
91 auto dmtrials = data::DmTrials<Cpu,float>::make_shared(_dm_trial_metadata, start_time);
92 std::vector<float> sps_cands;
93 DataType* tf_data =
reinterpret_cast<DataType*
>(agg_buf.data());
95 ::astroaccelerate::AstroAccelerate<void> sps_astroaccelerate(*_dedispersion_strategy);
96 PANDA_LOG_DEBUG <<
"Calling astroaccelerate::AstroAccelerate::run_dedispersion_sps";
97 PUSH_NVTX_RANGE(
"astroaccelerate_run_dedispersion_sps",1);
99 sps_astroaccelerate.run_dedispersion_sps(
106 PANDA_LOG_DEBUG <<
"astroaccelerate::AstroAccelerate::run_dedispersion_sps complete";
110 PUSH_NVTX_RANGE(
"astroaccelerate_cands_to_cheetah_cands",2);
111 auto sp_candidate_list = std::make_shared<data::SpCcl<uint8_t>>(agg_buf.composition(), offset_samples);
112 sp_candidate_list->reserve(sps_cands.size()/4);
113 for (std::size_t idx=0; idx<sps_cands.size(); idx+=4)
115 if(sps_cands[idx] == 0 && sps_cands[idx + 1 ]==0 && sps_cands[idx+2] ==0)
break;
116 sp_candidate_list->emplace_back(
117 sps_cands[idx] * data::parsecs_per_cube_cm
118 , data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType(sps_cands[idx+1] * boost::units::si::seconds)
119 , data::SpCcl<uint8_t>::SpCandidateType::MsecTimeType(sps_cands[idx+3] * boost::units::si::seconds)
126 PANDA_LOG_DEBUG <<
"run_dedispersion_sps returned " 127 << sp_candidate_list->size() <<
" candidates";
130 PUSH_NVTX_RANGE(
"astroaccelerate_trials_to_cheetah_trials",3);
131 PANDA_LOG_DEBUG <<
"Copying astroaccelerate::DmTime object contents into DmTrials instance";
132 std::size_t true_trial = 0;
133 for (std::size_t range=0; range < _dm_time->number_of_dm_ranges(); ++range)
135 for (
int trial=0; trial < _dedispersion_strategy->get_ndms()[range]; ++trial)
137 assert((*dmtrials)[true_trial].size() == _dm_time->nsamples()[range]);
138 std::copy((*_dm_time)[range][trial],
139 (*_dm_time)[range][trial]+_dm_time->nsamples()[range],
140 (*dmtrials)[true_trial].begin());
145 dm_handler(dmtrials);
146 sp_handler(sp_candidate_list);
147 PANDA_LOG <<
"astroaccelerate::SpsCuda::operator() complete";
150 #endif // ENABLE_ASTROACCELERATE Some limits and constants for FLDO.