Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
AlgorithmTester.h
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 #ifndef SKA_CHEETAH_TEST_UTILS_ALGORITHMTESTER_H
25 #define SKA_CHEETAH_TEST_UTILS_ALGORITHMTESTER_H
26 
27 #include "panda/System.h"
28 #include "panda/arch/nvidia/Nvidia.h"
29 #include "panda/test/TestResourcePool.h"
30 
31 #include <gtest/gtest.h>
32 #include <functional>
33 
47 #define ALGORITHM_TYPED_TEST_P(CaseName ,TestName) \
48  template<typename TestTraits> void _algorithm_test_case_##CaseName##TestName(typename TestTraits::DeviceType&); \
49  TYPED_TEST_P(CaseName , TestName) \
50  { \
51  ASSERT_NE(0U, this->devices().size()) << "no suitable devices"; \
52  unsigned count = 0; \
53  for( auto & device : this->devices()) { \
54  std::cout << "running on device " << count++ << std::endl; \
55  device->run([](typename std::decay<decltype(device)>::type::element_type & device) { _algorithm_test_case_##CaseName##TestName<TypeParam>(device); } ); \
56  } \
57  } \
58  template<typename TypeParam> void _algorithm_test_case_##CaseName##TestName(typename TypeParam::DeviceType& device)
59 
73 #define POOL_ALGORITHM_TYPED_TEST_P(CaseName ,TestName) \
74  template<typename TestTraits> void _pool_algorithm_test_case_##CaseName##TestName(typename TestTraits::PoolType); \
75  TYPED_TEST_P(CaseName , TestName) \
76  { \
77  ASSERT_NE(0U, this->devices().size()) << "no suitable devices"; \
78  unsigned count = 0; \
79  for( auto & device : this->devices()) { \
80  typename TypeParam::PoolType pool; \
81  pool.template add_resource<typename TypeParam::Arch>(device); \
82  std::cout << "running on pool with device " << count++ << std::endl; \
83  _pool_algorithm_test_case_##CaseName##TestName<TypeParam>(std::move(pool)); \
84  } \
85  } \
86  template<typename TypeParam> void _pool_algorithm_test_case_##CaseName##TestName(typename TypeParam::PoolType pool)
87 
88 namespace ska {
89 namespace cheetah {
90 namespace utils {
91 namespace test {
92 
99 template <typename DeviceType, typename Traits>
100 struct supports {
101  static bool compatible(DeviceType const&);
102 };
103 
110 template <typename ArchitectureType,
111  typename CapabilityType,
112  typename DeviceTypeParam=panda::PoolResource<ArchitectureType>
113  >
115  typedef ArchitectureType Arch;
116  typedef DeviceTypeParam DeviceType;
117  typedef CapabilityType Capability;
118  typedef std::shared_ptr<panda::PoolResource<Arch>> TestParam;
119 };
120 
121 template <typename ArchitectureType,
122  typename CapabilityType=void,
123  typename DeviceTypeParam=panda::PoolResource<ArchitectureType>,
124  typename PoolTypeParam=panda::test::TestResourcePool<ArchitectureType>>
126  typedef ArchitectureType Arch;
127  typedef CapabilityType Capability;
128  typedef DeviceTypeParam DeviceType;
129  typedef PoolTypeParam PoolType;
130  typedef PoolType TestParam;
131 };
132 
141 template <typename Traits>
142 class AlgorithmTester : public ::testing::TestWithParam<typename Traits::TestParam>
143 {
144  public:
145  typedef Traits AlgorithmTraits;
146  typedef std::shared_ptr<panda::PoolResource<typename Traits::Arch>> DeviceType;
147 
148  public:
149  AlgorithmTester();
150  virtual ~AlgorithmTester();
151 
152  protected:
153  std::vector<DeviceType>& devices() { return _devices; }
154 
155  private:
156  std::vector<DeviceType> _devices;
157 };
158 
159 } // namepsace test
160 } // namespace utils
161 } // namespace cheetah
162 } // namespace ska
163 
164 #include "cheetah/utils/test_utils/detail/AlgorithmTester.cpp"
165 
166 #endif // SKA_CHEETAH_TEST_UTILS_ALGORITHMTESTER_H
Some limits and constants for FLDO.
Definition: Brdz.h:35
describes the algorithm to be tested to the AlgorithmTester
Base class for generic algortihm tests that require an accelerator device.
specified how to tell if a given device is capable enough. The ResourceCapability is specifed in the ...