Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
Ddtr.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/ddtr/fpga/Ddtr.h"
25 #include <limits>
26 
27 namespace ska {
28 namespace cheetah {
29 namespace ddtr {
30 namespace fpga {
31 
32 template<typename DdtrTraits>
33 Ddtr<DdtrTraits>::WorkerFactory::WorkerFactory(ddtr::Config const& config)
34  : _config(config)
35 {
36 }
37 
38 template<typename DdtrTraits>
39 Ddtr<DdtrTraits>::Ddtr(ConfigType const& config)
40  : _first_call(true)
41  , _workers(WorkerFactory(config))
42  , _config(config)
43  , _dev_memory(std::numeric_limits<std::size_t>::max())
44 {
45  auto const& pool = config.pool();
46  if(pool.template free_resources<Architecture>().empty()) _dev_memory = 0;
47 
48 #ifdef ENABLE_OPENCL
49  for(auto const& fpga : pool.template free_resources<Architecture>())
50  {
51  _workers(*fpga); // construct a worker for each fpga device
52  std::size_t device_memory = fpga->device_memory();
53  if(device_memory < _dev_memory) {
54  _dev_memory=device_memory;
55  }
56  }
57  PANDA_LOG << "maximum device memory suitable for all devices in the pool is " << _dev_memory;
58 #endif // ENABLE_OPENCL
59 }
60 
61 template<typename DdtrTraits>
62 Ddtr<DdtrTraits>::Ddtr(Ddtr&& other)
63  : _first_call(other._first_call)
64  , _dedispersion_handler(other._dedispersion_handler)
65  , _workers(std::move(other._workers))
66  , _config(std::move(other._config))
67  , _dev_memory(std::move(other._dev_memory))
68 {
69  /*
70  _agg_buffer_filler_ptr->full_buffer_handler([this](BufferType buffer)
71  {
72  this->_pool.submit(*this, std::move(buffer));
73  });
74  */
75 }
76 
77 template<typename DdtrTraits>
78 Ddtr<DdtrTraits>::~Ddtr()
79 {
80  //_agg_buffer_filler_ptr.reset();
81  //_pool.wait();
82 }
83 
84 template<typename DdtrTraits>
85 void Ddtr<DdtrTraits>::operator()(panda::PoolResource<Architecture>& device, BufferType const& input_data)
86 {
87  _dedispersion_handler(_workers(device)(input_data,_dm_factors, _max_delay));
88 }
89 
90 template<typename DdtrTraits>
91 void Ddtr<DdtrTraits>::init(TimeFrequencyType const& data)
92 {
93  DmListType dm_trials = this->_config.dm_trials();
94  Dm max_dm = this->_config.max_dm();
95  auto const& channel_freqs = data.channel_frequencies();
96  auto freq_pair = data.low_high_frequencies();
97  FrequencyType freq_top = freq_pair.second;
98  FrequencyType freq_bottom = freq_pair.first;
99  _max_delay = std::size_t((_config.dm_constant().value()
100  * (1.0/(freq_bottom*freq_bottom) - 1.0/(freq_top*freq_top))
101  * max_dm / data.sample_interval()).value()) + 1;
102 
103  for (auto freq: channel_freqs)
104  {
105  double factor = (_config.dm_constant().value() * (1.0/(freq*freq) - 1.0/(freq_top*freq_top)) / data.sample_interval()).value();
106  _dm_factors.push_back(factor);
107  }
108  _dedispersion_samples = this->_config.dedispersion_samples();
109  if (_dedispersion_samples < 2 * _max_delay)
110  {
111  PANDA_LOG_WARN << "Requested number of samples to dedisperse ("
112  << this->_config.dedispersion_samples()
113  << ") is less than twice the max dispersion delay ("
114  << 2 * _max_delay << "): Setting number of samples to dedisperse to "
115  << 2 * _max_delay;
116  _dedispersion_samples = 2 * _max_delay;
117  }
118 
119  //generate_dmtrials_metadata(data.sample_interval(), _dedispersion_samples - _max_delay);
120  _agg_buffer_filler_ptr->resize(std::min(_dev_memory, this->_config.dedispersion_samples() * data.number_of_channels()));
121  _agg_buffer_filler_ptr->set_overlap(_max_delay * data.number_of_channels());
122 }
123 
124 template<typename DdtrTraits>
125 template<typename TimeFrequencyT>
126 void Ddtr<DdtrTraits>::operator()(TimeFrequencyT const& input_data)
127 {
128  if(_first_call) {
129  this->init(input_data);
130  _first_call=false;
131  }
132  (*_agg_buffer_filler_ptr) << input_data;
133 }
134 
135 } // namespace fpga
136 } // namespace ddtr
137 } // namespace cheetah
138 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35
void operator()(TimeFreqDataT const &input)
dedisperses chunk of buffer data to a dm-time chunk.
Definition: Ddtr.cpp:46