Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
Sps.cpp
1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright (c) 2016 The SKA organisation
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #include "cheetah/sps/Sps.h"
25 #include "panda/ResourcePool.h"
26 #include "panda/TypeTraits.h"
27 #include "panda/Log.h"
28 
29 
30 namespace ska {
31 namespace cheetah {
32 namespace sps {
33 
34 
35 template<class ConfigType, typename NumericalRep>
36 Sps<ConfigType, NumericalRep>::Sps(ConfigType const& config, DmHandler dm_handler, SpHandler sp_handler)
37  : _pool(config.pool())
38  , _agg_buf_filler( [this](typename BufferFillerType::AggregationBufferType buffer)
39  {
40  _task_ptr->submit(std::move(buffer));
41  }
42  ,0, config.rfiexcision_config())
43  , _current_number_of_channels(0)
44  , _algo_count(0)
45  , _config(config)
46 {
47  if(config.astroaccelerate_config().active()) {
48 #ifdef ENABLE_ASTROACCELERATE
49  _task_ptr.reset(new AlgoLauncher<astroaccelerate::Sps<CommonTraits>>( std::move(dm_handler)
50  , std::move(sp_handler)
51  , _pool
52  , std::move(astroaccelerate::Sps<CommonTraits>(config))));
53  ++_algo_count;
54 #else //ENABLE_ASTROACCELERATE
55  PANDA_LOG_WARN << "Sps: request for astroaccelearte, but cheetah has not been build with CUDA support. Please use cmake compile flag -DENABLE_CUDA=true";
56 #endif //ENABLE_ASTROACCELERATE
57 
58  }
59 
60  if(config.emulator_config().active()) {
61  _task_ptr.reset(new AlgoLauncher<emulator::Sps<CommonTraits>>( std::move(dm_handler)
62  , std::move(sp_handler)
63  , _pool
64  , std::move(emulator::Sps<CommonTraits>(config)))
65  );
66  ++_algo_count;
67  }
68  if(_algo_count > 1 ) { // at the moment this is currently an error
69  throw panda::Error("Multiple sps algorithms have been selected");
70  }
71  else if(_algo_count == 0)
72  {
73  _task_ptr.reset(new TaskType(std::move(dm_handler), std::move(sp_handler)));
74  }
75  _dedisp_samples = config.dedispersion_samples();
76 }
77 
78 
79 template<class ConfigType, typename NumericalRep>
81 {
82  _task_ptr->finish(_agg_buf_filler);
83  PANDA_LOG_DEBUG << "~Sps() destructor";
84 }
85 
86 template<class ConfigType, typename NumericalRep>
88 {
89  if (data.number_of_channels() != _current_number_of_channels)
90  {
91  std::size_t buffer_memory_max = panda::nvidia::min_gpu_memory(_pool); // TODO poll all device types in pool matching algo reqs
92  _dedisp_samples = _task_ptr->set_dedispersion_strategy(buffer_memory_max, data);
93 
94  std::size_t overlap = _task_ptr->buffer_overlap(); // in numbers of spectra
95  if(overlap == 0) {
96  overlap = _config.maximum_delay_offset(data);
97  }
98  std::size_t min_memory_size = sizeof(NumericalRep) * (1 + overlap) * data.number_of_channels();
99  if(min_memory_size >= buffer_memory_max && buffer_memory_max != 0) {
100  PANDA_LOG_ERROR << "configuration error: dedispersion plan requires at least" << overlap + 1
101  << " samples (min mem required=" << min_memory_size
102  << " , mem available(suitable pool devices)=" << buffer_memory_max << ")";
103  throw panda::Error("dedispersion sample buffer size is too small");
104  }
105 
106  if(overlap >= _dedisp_samples) {
107  PANDA_LOG_ERROR << "configuration error: samples requested < minimum required for dedispersion plan(" << overlap << ")";
108  throw panda::Error("dedispersion sample buffer size is too small");
109  }
110  PANDA_LOG << "setting dedispersion buffer size to " << _dedisp_samples << " spectra";
111  _agg_buf_filler.resize(data.number_of_channels() * _dedisp_samples);
112 
113  PANDA_LOG << "setting buffer overlap to " << overlap << " spectra";
114  _agg_buf_filler.set_overlap( overlap * data.number_of_channels() );
115 
116  _current_number_of_channels = data.number_of_channels();
117  }
118 }
119 
120 template<class ConfigType, typename NumericalRep>
121 template<typename DataT>
123 {
124  TimeFrequencyType& tf_data = static_cast<TimeFrequencyType&>(panda::is_pointer_wrapper<typename std::remove_reference<DataT>::type>::extract(data));
125  if(_algo_count>0) {
126  agg_buffer_init(tf_data);
127  _agg_buf_filler << data;
128  } else {
129  (void) data;
130  PANDA_LOG_WARN << "No available Sps algorithm";
131  }
132 }
133 
134 template<class ConfigType, typename NumericalRep>
136 {
137  this->template agg_buffer_fill(data);
138 }
139 
140 template<class ConfigType, typename NumericalRep>
142 {
143  this->template agg_buffer_fill(data);
144 }
145 
146 template<class ConfigType, typename NumericalRep>
147 template<typename T>
148 void Sps<ConfigType, NumericalRep>::operator()(std::shared_ptr<T> const& data)
149 {
150  (*this)(*data);
151 }
152 
153 } // namespace sps
154 } // namespace cheetah
155 } // namespace ska
Single pulse search asynchronous task.
Definition: SpsTask.h:47
Produces a stream of random SpCandidate&#39;s.
Definition: Sps.h:44
Single Pulse Search top level interface.
Definition: Sps.h:61
TimeFrequency data with flags representing rfim detection.
Some limits and constants for FLDO.
Definition: Brdz.h:35
std::size_t number_of_channels() const
Sps(ConfigType const &, DmHandler dm_handler, SpHandler sm_handler)
Constructor takes two Handlers.
Definition: Sps.cpp:36