Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
Rfim.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/rfim/cuda/Rfim.h"
25 
26 
27 namespace ska {
28 namespace cheetah {
29 namespace rfim {
30 namespace cuda {
31 
32 
33 template<typename RfimTraits>
34 Rfim<RfimTraits>::Rfim(Config const& )
35 {
36 }
37 
38 template<typename RfimTraits>
39 Rfim<RfimTraits>::~Rfim()
40 {
41 }
42 
43 #ifndef ENABLE_CUDA
44 
45 // dummy version
46 template<typename RfimTraits>
47 inline void Rfim<RfimTraits>::operator()(panda::PoolResource<Cuda>&, DataType&, DataAdapter&)
48 {
49 }
50 #else // ENABLE_CUDA
51 void flagger_freq_kernel(data::TimeFrequency<Cpu, uint8_t> const&, unsigned char*);
52 
53 namespace {
54 template<typename DataType>
55 struct CudaRfimExecutor
56 {
57  template<typename DataAdapter, typename DataT>
58  inline static void exec(panda::PoolResource<Cuda>&, DataT const&, DataAdapter&) {
59  PANDA_LOG_WARN << "Rfim::cuda:: No algorithm available for this data type";
60  }
61 };
62 
63 template<>
64 struct CudaRfimExecutor<uint8_t>
65 {
66  template<typename DataAdapter, typename DataT>
67  inline static void exec(panda::PoolResource<Cuda>&, DataT const& data, DataAdapter&)
68  {
69  typedef typename std::decay<decltype(data)>::type::DataType DataType;
70  typedef unsigned char LocalFlagsType;
71 
72  std::size_t data_size=data.number_of_channels() * data.number_of_spectra();
73  if(data_size == 0) return;
74 
75  // Allocate host memory
76  LocalFlagsType* host_flags = new LocalFlagsType[data_size];
77 
78  try {
79  flagger_freq_kernel(data, host_flags);
80  // Populate the TimeFrequencyFlags data structure
81  /*
82  for ( unsigned int channel = 0; channel < data.number_of_channels(); channel++ ) {
83  auto channel_iterator = (data.get_flags())->channel(channel);
84  unsigned int sample_number = 0;
85 
86  for ( auto sample = channel_iterator.begin(); sample != channel_iterator.end(); ++sample ) {
87  *sample = static_cast<data::FlagsType>(host_flags[(channel * data.number_of_spectra()) + sample_number]);
88  sample_number++;
89  }
90  }
91  */
92  } catch(...)
93  {
94  delete[] host_flags;
95  throw;
96  }
97  delete[] host_flags;
98  }
99 };
100 } // namespace
101 
102 template<typename RfimTraits>
103 inline void Rfim<RfimTraits>::operator()(panda::PoolResource<Cuda>& device, DataType& data, DataAdapter& adapter)
104 {
105  typedef typename std::decay<decltype(data)>::type::DataType NumericalT;
106  CudaRfimExecutor<NumericalT>::exec(device, data, adapter);
107 }
108 #endif //ENABLE_CUDA
109 
110 } // namespace cuda
111 } // namespace rfim
112 } // namespace cheetah
113 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35