/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-roccv/checkouts/latest/include/common/math_vector.hpp Source File

/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-roccv/checkouts/latest/include/common/math_vector.hpp Source File#

5 min read time

Applies to Linux

rocCV: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-roccv/checkouts/latest/include/common/math_vector.hpp Source File
math_vector.hpp
Go to the documentation of this file.
1 
22 #pragma once
23 
24 #include <hip/hip_vector_types.h>
25 #include <hip/math_functions.h>
26 
27 #include <type_traits>
28 
29 class MathVector {
30  public:
31  template <typename T, unsigned int rank,
32  typename std::enable_if<(rank == 1), bool>::type = 0>
33  __host__ __device__ static HIP_vector_type<T, rank> pow(
34  HIP_vector_type<T, rank> vec, double p) {
35  vec.x = ::pow(vec.x, p);
36  return vec;
37  }
38  template <typename T, unsigned int rank,
39  typename std::enable_if<(rank == 2), bool>::type = 0>
40  __host__ __device__ static HIP_vector_type<T, rank> pow(
41  HIP_vector_type<T, rank> vec, double p) {
42  vec.x = ::pow(vec.x, p);
43  vec.y = ::pow(vec.y, p);
44  return vec;
45  }
46  template <typename T, unsigned int rank,
47  typename std::enable_if<(rank == 3), bool>::type = 0>
48  __host__ __device__ static HIP_vector_type<T, rank> pow(
49  HIP_vector_type<T, rank> vec, double p) {
50  vec.x = ::pow(vec.x, p);
51  vec.y = ::pow(vec.y, p);
52  vec.z = ::pow(vec.z, p);
53  return vec;
54  }
55  template <typename T, unsigned int rank,
56  typename std::enable_if<(rank == 4), bool>::type = 0>
57  __host__ __device__ static HIP_vector_type<T, rank> pow(
58  HIP_vector_type<T, rank> vec, double p) {
59  vec.x = ::pow(vec.x, p);
60  vec.y = ::pow(vec.y, p);
61  vec.z = ::pow(vec.z, p);
62  vec.w = ::pow(vec.w, p);
63  return vec;
64  }
65 
66  template <typename U, typename T, unsigned int rank,
67  typename std::enable_if<(rank == 1), bool>::type = 0>
68  __host__ __device__ static HIP_vector_type<U, rank> convert_base(
69  HIP_vector_type<T, rank> vec) {
70  HIP_vector_type<U, rank> out;
71  out.x = static_cast<U>(vec.x);
72  return out;
73  }
74  template <typename U, typename T, unsigned int rank,
75  typename std::enable_if<(rank == 2), bool>::type = 0>
76  __host__ __device__ static HIP_vector_type<U, rank> convert_base(
77  HIP_vector_type<T, rank> vec) {
78  HIP_vector_type<U, rank> out;
79  out.x = static_cast<U>(vec.x);
80  out.y = static_cast<U>(vec.y);
81  return out;
82  }
83  template <typename U, typename T, unsigned int rank,
84  typename std::enable_if<(rank == 3), bool>::type = 0>
85  __host__ __device__ static HIP_vector_type<U, rank> convert_base(
86  HIP_vector_type<T, rank> vec) {
87  HIP_vector_type<U, rank> out;
88  out.x = static_cast<U>(vec.x);
89  out.y = static_cast<U>(vec.y);
90  out.z = static_cast<U>(vec.z);
91  return out;
92  }
93  template <typename U, typename T, unsigned int rank,
94  typename std::enable_if<(rank == 4), bool>::type = 0>
95  __host__ __device__ static HIP_vector_type<U, rank> convert_base(
96  HIP_vector_type<T, rank> vec) {
97  HIP_vector_type<U, rank> out;
98  out.x = static_cast<U>(vec.x);
99  out.y = static_cast<U>(vec.y);
100  out.z = static_cast<U>(vec.z);
101  out.w = static_cast<U>(vec.w);
102  return out;
103  }
104 
105  template <typename T, unsigned int rank,
106  typename std::enable_if<(rank == 1), bool>::type = 0>
107  __host__ __device__ static HIP_vector_type<T, 4> fill(
108  HIP_vector_type<T, rank> vec) {
109  HIP_vector_type<T, 4> out{vec.x, 0, 0, 0};
110  return out;
111  }
112  template <typename T, unsigned int rank,
113  typename std::enable_if<(rank == 2), bool>::type = 0>
114  __host__ __device__ static HIP_vector_type<T, 4> fill(
115  HIP_vector_type<T, rank> vec) {
116  HIP_vector_type<T, 4> out{vec.x, vec.y, 0, 0};
117  return out;
118  }
119  template <typename T, unsigned int rank,
120  typename std::enable_if<(rank == 3), bool>::type = 0>
121  __host__ __device__ static HIP_vector_type<T, 4> fill(
122  HIP_vector_type<T, rank> vec) {
123  HIP_vector_type<T, 4> out{vec.x, vec.y, vec.z, 0};
124  return out;
125  }
126  template <typename T, unsigned int rank,
127  typename std::enable_if<(rank == 4), bool>::type = 0>
128  __host__ __device__ static HIP_vector_type<T, 4> fill(
129  HIP_vector_type<T, rank> vec) {
130  HIP_vector_type<T, 4> out{vec.x, vec.y, vec.z, vec.w};
131  return out;
132  }
133 
134  template <typename T, unsigned int rank,
135  typename std::enable_if<(rank == 1), bool>::type = 0>
136  __host__ __device__ static void trunc(HIP_vector_type<T, 4> vec,
137  HIP_vector_type<T, rank> *dst) {
138  HIP_vector_type<T, rank> out{vec.x /*, vec.y, vec.z, vec.w*/};
139  *dst = out;
140  }
141  template <typename T, unsigned int rank,
142  typename std::enable_if<(rank == 2), bool>::type = 0>
143  __host__ __device__ static void trunc(HIP_vector_type<T, 4> vec,
144  HIP_vector_type<T, rank> *dst) {
145  HIP_vector_type<T, rank> out{vec.x, vec.y /*, vec.z, vec.w*/};
146  *dst = out;
147  }
148  template <typename T, unsigned int rank,
149  typename std::enable_if<(rank == 3), bool>::type = 0>
150  __host__ __device__ static void trunc(HIP_vector_type<T, 4> vec,
151  HIP_vector_type<T, rank> *dst) {
152  HIP_vector_type<T, rank> out{vec.x, vec.y, vec.z /*, vec.w*/};
153  *dst = out;
154  }
155  template <typename T, unsigned int rank,
156  typename std::enable_if<(rank == 4), bool>::type = 0>
157  __host__ __device__ static void trunc(HIP_vector_type<T, 4> vec,
158  HIP_vector_type<T, rank> *dst) {
159  HIP_vector_type<T, rank> out{vec.x, vec.y, vec.z, vec.w};
160  *dst = out;
161  }
162 };
Definition: math_vector.hpp:29
__host__ static __device__ HIP_vector_type< T, 4 > fill(HIP_vector_type< T, rank > vec)
Definition: math_vector.hpp:107
__host__ static __device__ HIP_vector_type< U, rank > convert_base(HIP_vector_type< T, rank > vec)
Definition: math_vector.hpp:68
__host__ static __device__ HIP_vector_type< T, rank > pow(HIP_vector_type< T, rank > vec, double p)
Definition: math_vector.hpp:33
__host__ static __device__ void trunc(HIP_vector_type< T, 4 > vec, HIP_vector_type< T, rank > *dst)
Definition: math_vector.hpp:136