Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
AlgorithmTester.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/utils/test_utils/AlgorithmTester.h"
25 #include "cheetah/utils/System.h"
26 #include <panda/arch/nvidia/DeviceCapability.h>
27 namespace ska {
28 namespace cheetah {
29 namespace utils {
30 namespace test {
31 
32 // generic helper to get devices of a specifc architecture
33 template <typename Arch>
34 struct get_devices {
35  auto operator()() -> decltype( system().resources<Arch>()) {
36  return system().resources<Arch>();
37  }
38 };
39 
40 // specialisation for Cpu - only want to run on a single thread
41 template <>
42 struct get_devices<ska::panda::Cpu> {
43  auto operator()() -> std::decay<decltype(system().resources<ska::panda::Cpu>())>::type {
44  auto devices = system().resources<ska::panda::Cpu>();
45  if(devices.size() > 1) devices.resize(1);
46  return devices;
47  }
48 };
49 
50 template <typename Traits>
52 {
53  auto devices=get_devices<typename Traits::Arch>()();
54 
55  std::copy_if(devices.begin(),devices.end(),std::back_inserter(_devices),
56  [](std::shared_ptr<panda::PoolResource<typename Traits::Arch> > const& device){
58  });
59 
60  if (!_devices.size()) throw panda::Error("No suitable device found to run test");
61 }
62 
63 template <typename Traits>
65 {
66 }
67 
68 template<typename DeviceType, typename Traits> // device type and device capability are the same type
69 struct supports<panda::PoolResource<DeviceType>, Traits>
70 {
71  static bool compatible(panda::PoolResource<DeviceType> const& )
72  {
73  return true;
74  }
75 };
76 
77 #ifdef ENABLE_CUDA
78 
81 template<typename Traits>
82 struct supports<panda::PoolResource<panda::nvidia::Cuda>, Traits>
83 {
84  static bool compatible(panda::PoolResource<panda::nvidia::Cuda> const& device)
85  {
86  typedef typename Traits::Capability Capability;
87  if(typename Capability::CapabilityVersion(device.device_properties().major, device.device_properties().minor) >=
88  Capability::compute_capability()
89  && (Capability::total_memory <= device.device_properties().totalGlobalMem))
90  return true;
91  return false;
92  }
93 };
94 #endif // ENABLE_CUDA
95 
96 } // namespace test
97 } // namespace utils
98 } // namespace cheetah
99 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35
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 ...