Xmipp  v3.23.11-Nereus
utils.h
Go to the documentation of this file.
1 #ifndef CUFFTADVISOR_UTILS_H_
2 #define CUFFTADVISOR_UTILS_H_
3 
4 #include <cstring>
5 #include <sstream>
6 #include <vector>
7 
8 namespace cuFFTAdvisor {
9 #define CLOCKS_PER_MS (CLOCKS_PER_SEC / 1000)
10 #define SEP "|"
11 
12 template <typename T>
13 static inline std::string numToString(T num) {
14  std::stringstream ss;
15  ss << num;
16  return ss.str();
17 }
18 
19 // define utilities
20 static inline float toMB(size_t bytes) { return bytes / 1048576.f; }
21 
22 template <typename T>
23 static inline void deleteEach(std::vector<T *> &v) {
24  typename std::vector<T *>::iterator it;
25  for (it = v.begin(); it != v.end(); ++it) {
26  delete *it;
27  }
28 }
29 
30 template <typename T>
31 struct Triplet {
32  Triplet(T f, T s, T r) : fst(f), snd(s), rd(r) {}
33  T fst;
34  T snd;
35  T rd;
36 };
37 
38 namespace Tristate {
39 enum Tristate { FALSE = 0, TRUE = 1, BOTH = 2 };
40 
41 static inline bool is(Tristate tr) { return (TRUE == tr) || (BOTH == tr); }
42 static inline bool isNot(Tristate tr) { return (FALSE == tr) || (BOTH == tr); }
43 
44 static inline const char *toString(Tristate t) {
45  if (t == FALSE) return "false";
46  if (t == TRUE) return "true";
47  return "both";
48 }
49 
50 } // namespace Tristate
51 
52 namespace CudaVersion { // FIXME implement auto detection
53 enum CudaVersion { V_8, V_9 };
54 } // namespace CudaVersion
55 
56 static inline const char *toString(cuFFTAdvisor::Tristate::Tristate t) {
57  switch (t) {
58  case Tristate::TRUE:
59  return "true";
60  case Tristate::FALSE:
61  return "false";
62  case Tristate::BOTH:
63  return "both";
64  default:
65  return "Tristate undefined";
66  }
67 }
68 
69 static inline bool safeEquals(const char *l, const char *r) {
70  if ((NULL == l) || (NULL == r))
71  return l == r;
72  else
73  return (0 == std::strcmp(l, r));
74 }
75 
76 } // namespace cuFFTAdvisor
77 
78 #endif // CUFFTADVISOR_UTILS_H_
Triplet(T f, T s, T r)
Definition: utils.h:32
double * f