Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
FrequencyTimeTest.cu
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/data/cuda/test/FrequencyTimeTest.h"
25 #include "cheetah/data/TimeFrequency.h"
26 #include "cheetah/data/FrequencyTime.h"
27 #include "panda/Copy.h"
28 #include <random>
29 
30 namespace ska {
31 namespace cheetah {
32 namespace data {
33 namespace cuda {
34 namespace test {
35 
36 template <typename T>
37 FrequencyTimeTest<T>::FrequencyTimeTest()
38  : ::testing::Test()
39 {
40 }
41 
42 template <typename T>
43 FrequencyTimeTest<T>::~FrequencyTimeTest()
44 {
45 }
46 
47 template <typename T>
48 void FrequencyTimeTest<T>::SetUp()
49 {
50 }
51 
52 template <typename T>
53 void FrequencyTimeTest<T>::TearDown()
54 {
55 }
56 
57 template <class Arch, typename NumericalRepT, typename OtherNumericalRepT>
58 class DataTypes
59 {
60  public:
61  typedef Arch Architecture;
62  typedef NumericalRepT FirstType;
63  typedef NumericalRepT SecondType;
64 };
65 
66 typedef ::testing::Types<DataTypes<Cuda, uint8_t, uint8_t>,
83  DataTypes<Cpu, float, float>> FrequencyTimeTypes;
84 
85 
86 TYPED_TEST_CASE(FrequencyTimeTest, FrequencyTimeTypes);
87 
88 TYPED_TEST(FrequencyTimeTest, test_copy)
89 {
90  typedef typename TypeParam::Architecture Arch;
91  typedef typename TypeParam::FirstType NumericalRep;
92  typedef typename TypeParam::SecondType OtherNumericalRep;
93 
94  typedef FrequencyTime<Cpu, NumericalRep> FtDataType;
95 
96  std::random_device rd;
97  std::mt19937 mt(rd());
98  std::uniform_int_distribution<int> nspectra(8, 1024);
99  std::uniform_int_distribution<int> nchans(8, 32);
100 
101  data::DimensionSize<data::Time> number_of_spectra(nspectra(mt));
102  data::DimensionSize<data::Frequency> number_of_channels(nchans(mt));
103 
104  FtDataType tf_host_data(number_of_spectra, number_of_channels);
105 
106  srand((unsigned) time(0));
107  std::generate(tf_host_data.begin(), tf_host_data.end(), [&]() { return rand()%255; });
108 
109  auto f1 = typename data::TimeFrequency<Cpu, NumericalRep>::FrequencyType(100.0 * boost::units::si::hertz);
110  auto f2 = typename data::TimeFrequency<Cpu, NumericalRep>::FrequencyType(200.0 * boost::units::si::hertz);
111  typename utils::ModifiedJulianClock::time_point epoch(utils::julian_day(50000.0));
112  auto delta = (f2 - f1)/ (double)(number_of_channels-1);
113 
114  tf_host_data.set_channel_frequencies_const_width( f1, delta);
115  tf_host_data.start_time(epoch);
116 
117  FrequencyTime<Arch, NumericalRep> input_data(tf_host_data);
118  FrequencyTime<Cuda, OtherNumericalRep> output_data(input_data);
119  FrequencyTime<Cpu, OtherNumericalRep> output_data_copy(output_data);
120  FrequencyTime<Cpu, NumericalRep> input_data_copy(input_data);
121 
122  ASSERT_EQ(output_data_copy.number_of_spectra(), number_of_spectra);
123  ASSERT_EQ(output_data_copy.number_of_channels(), number_of_channels);
124 
125  for(unsigned i=0; i < input_data_copy.number_of_spectra(); ++i)
126  {
127  // iterate over channels
128  typename FrequencyTime<Cpu, NumericalRep>::Spectra input_spectrum = input_data_copy.spectrum(i);
129  auto input_channel_it = input_spectrum.begin();
130  typename FrequencyTime<Cpu,OtherNumericalRep>::Spectra output_spectrum = output_data_copy.spectrum(i);
131  auto output_channel_it = output_spectrum.begin();
132  while(input_channel_it != input_spectrum.end())
133  {
134  ASSERT_EQ(*input_channel_it, *output_channel_it);
135  ++input_channel_it;
136  ++output_channel_it;
137  }
138  }
139 }
140 
141 
142 TYPED_TEST(FrequencyTimeTest, test_cornerturn)
143 {
144  typedef typename TypeParam::Architecture Arch;
145  typedef typename TypeParam::FirstType NumericalRep;
146  typedef typename TypeParam::SecondType OtherNumericalRep;
147  typedef TimeFrequency<Cpu, NumericalRep> TfDataType;
148 
149  std::random_device rd;
150  std::mt19937 mt(rd());
151  std::uniform_int_distribution<int> nspectra(8, 1024);
152  std::uniform_int_distribution<int> nchans(8, 32);
153 
154  data::DimensionSize<data::Time> number_of_spectra(nspectra(mt));
155  data::DimensionSize<data::Frequency> number_of_channels(nchans(mt));
156 
157  TfDataType tf_host_data(number_of_spectra, number_of_channels);
158 
159  srand((unsigned) time(0));
160  std::generate(tf_host_data.begin(), tf_host_data.end(), [&]() { return ((rand())%255); });
161 
162  auto f1 = typename data::TimeFrequency<Cpu, NumericalRep>::FrequencyType(100.0 * boost::units::si::hertz);
163  auto f2 = typename data::TimeFrequency<Cpu, NumericalRep>::FrequencyType(200.0 * boost::units::si::hertz);
164  typename utils::ModifiedJulianClock::time_point epoch(utils::julian_day(50000.0));
165  auto delta = (f2 - f1)/ (double)(number_of_channels-1);
166 
167  tf_host_data.set_channel_frequencies_const_width( f1, delta);
168  tf_host_data.start_time(epoch);
169 
170  TimeFrequency<Arch, NumericalRep> input_data(tf_host_data);
171  FrequencyTime<Cuda, OtherNumericalRep> output_data(input_data);
172  FrequencyTime<Cpu, OtherNumericalRep> output_data_copy(output_data);
173  FrequencyTime<Cpu, NumericalRep> input_data_copy(input_data);
174 
175  ASSERT_EQ(output_data_copy.number_of_spectra(), number_of_spectra);
176  ASSERT_EQ(output_data_copy.number_of_channels(), number_of_channels);
177 
178  for(unsigned i=0; i < input_data_copy.number_of_spectra(); ++i)
179  {
180  // iterate over channels
181  typename FrequencyTime<Cpu, NumericalRep>::Spectra input_spectrum = input_data_copy.spectrum(i);
182  auto input_channel_it = input_spectrum.begin();
183  typename FrequencyTime<Cpu,OtherNumericalRep>::Spectra output_spectrum = output_data_copy.spectrum(i);
184  auto output_channel_it = output_spectrum.begin();
185  while(input_channel_it != input_spectrum.end())
186  {
187  ASSERT_EQ(*input_channel_it, *output_channel_it);
188  ++input_channel_it;
189  ++output_channel_it;
190  }
191  }
192 }
193 
194 } // namespace test
195 } // namespace cuda
196 } // namespace data
197 } // namespace cheetah
198 } // namespace ska
BaseT::Spectra Spectra
Iterator class for accessing each time sample.
Some limits and constants for FLDO.
Definition: Brdz.h:35