SWDEV-426270 - Remove duplicated operators
Remove duplicated operators of hipComplexFloat and
hipComplexDouble.
If users need complex number multiplication and division,
they should call
hipCmulf() and hipCdivf() for hipComplexFloat,
hipCmul() and hipCdiv() for hipComplexComplex
SWDEV-428198 - Add missing operators
Add missing operators of vectors in host
Change-Id: Ie58d1642d579e7119997db49a9fd6a6641b666fd
[ROCm/clr commit: d4799b2a3f]
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
|
||||
cmake_minimum_required(VERSION 3.16.8)
|
||||
cmake_minimum_required(VERSION 3.16.3)
|
||||
project(clr)
|
||||
|
||||
##########
|
||||
|
||||
@@ -20,6 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/* The header defines complex numbers and related functions*/
|
||||
|
||||
#ifndef HIP_INCLUDE_HIP_AMD_DETAIL_HIP_COMPLEX_H
|
||||
#define HIP_INCLUDE_HIP_AMD_DETAIL_HIP_COMPLEX_H
|
||||
|
||||
@@ -53,100 +55,6 @@ THE SOFTWARE.
|
||||
#endif
|
||||
#endif // !defined(__HIPCC_RTC__)
|
||||
|
||||
#if __cplusplus
|
||||
#define COMPLEX_NEG_OP_OVERLOAD(type) \
|
||||
__HOST_DEVICE__ static inline type operator-(const type& op) { \
|
||||
type ret; \
|
||||
ret.x = -op.x; \
|
||||
ret.y = -op.y; \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
#define COMPLEX_EQ_OP_OVERLOAD(type) \
|
||||
__HOST_DEVICE__ static inline bool operator==(const type& lhs, const type& rhs) { \
|
||||
return lhs.x == rhs.x && lhs.y == rhs.y; \
|
||||
}
|
||||
|
||||
#define COMPLEX_NE_OP_OVERLOAD(type) \
|
||||
__HOST_DEVICE__ static inline bool operator!=(const type& lhs, const type& rhs) { \
|
||||
return !(lhs == rhs); \
|
||||
}
|
||||
|
||||
#define COMPLEX_ADD_OP_OVERLOAD(type) \
|
||||
__HOST_DEVICE__ static inline type operator+(const type& lhs, const type& rhs) { \
|
||||
type ret; \
|
||||
ret.x = lhs.x + rhs.x; \
|
||||
ret.y = lhs.y + rhs.y; \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
#define COMPLEX_SUB_OP_OVERLOAD(type) \
|
||||
__HOST_DEVICE__ static inline type operator-(const type& lhs, const type& rhs) { \
|
||||
type ret; \
|
||||
ret.x = lhs.x - rhs.x; \
|
||||
ret.y = lhs.y - rhs.y; \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
#define COMPLEX_MUL_OP_OVERLOAD(type) \
|
||||
__HOST_DEVICE__ static inline type operator*(const type& lhs, const type& rhs) { \
|
||||
type ret; \
|
||||
ret.x = lhs.x * rhs.x - lhs.y * rhs.y; \
|
||||
ret.y = lhs.x * rhs.y + lhs.y * rhs.x; \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
#define COMPLEX_DIV_OP_OVERLOAD(type) \
|
||||
__HOST_DEVICE__ static inline type operator/(const type& lhs, const type& rhs) { \
|
||||
type ret; \
|
||||
ret.x = (lhs.x * rhs.x + lhs.y * rhs.y); \
|
||||
ret.y = (rhs.x * lhs.y - lhs.x * rhs.y); \
|
||||
ret.x = ret.x / (rhs.x * rhs.x + rhs.y * rhs.y); \
|
||||
ret.y = ret.y / (rhs.x * rhs.x + rhs.y * rhs.y); \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
#define COMPLEX_ADD_PREOP_OVERLOAD(type) \
|
||||
__HOST_DEVICE__ static inline type& operator+=(type& lhs, const type& rhs) { \
|
||||
lhs.x += rhs.x; \
|
||||
lhs.y += rhs.y; \
|
||||
return lhs; \
|
||||
}
|
||||
|
||||
#define COMPLEX_SUB_PREOP_OVERLOAD(type) \
|
||||
__HOST_DEVICE__ static inline type& operator-=(type& lhs, const type& rhs) { \
|
||||
lhs.x -= rhs.x; \
|
||||
lhs.y -= rhs.y; \
|
||||
return lhs; \
|
||||
}
|
||||
|
||||
#define COMPLEX_MUL_PREOP_OVERLOAD(type) \
|
||||
__HOST_DEVICE__ static inline type& operator*=(type& lhs, const type& rhs) { \
|
||||
type temp{lhs}; \
|
||||
lhs.x = rhs.x * temp.x - rhs.y * temp.y; \
|
||||
lhs.y = rhs.y * temp.x + rhs.x * temp.y; \
|
||||
return lhs; \
|
||||
}
|
||||
|
||||
#define COMPLEX_DIV_PREOP_OVERLOAD(type) \
|
||||
__HOST_DEVICE__ static inline type& operator/=(type& lhs, const type& rhs) { \
|
||||
type temp; \
|
||||
temp.x = (lhs.x*rhs.x + lhs.y * rhs.y) / (rhs.x*rhs.x + rhs.y*rhs.y); \
|
||||
temp.y = (lhs.y * rhs.x - lhs.x * rhs.y) / (rhs.x*rhs.x + rhs.y*rhs.y); \
|
||||
lhs = temp; \
|
||||
return lhs; \
|
||||
}
|
||||
|
||||
#define COMPLEX_SCALAR_PRODUCT(type, type1) \
|
||||
__HOST_DEVICE__ static inline type operator*(const type& lhs, type1 rhs) { \
|
||||
type ret; \
|
||||
ret.x = lhs.x * rhs; \
|
||||
ret.y = lhs.y * rhs; \
|
||||
return ret; \
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
typedef float2 hipFloatComplex;
|
||||
|
||||
__HOST_DEVICE__ static inline float hipCrealf(hipFloatComplex z) { return z.x; }
|
||||
@@ -240,56 +148,6 @@ __HOST_DEVICE__ static inline hipDoubleComplex hipCdiv(hipDoubleComplex p, hipDo
|
||||
|
||||
__HOST_DEVICE__ static inline double hipCabs(hipDoubleComplex z) { return sqrt(hipCsqabs(z)); }
|
||||
|
||||
|
||||
#if __cplusplus
|
||||
|
||||
COMPLEX_NEG_OP_OVERLOAD(hipFloatComplex)
|
||||
COMPLEX_EQ_OP_OVERLOAD(hipFloatComplex)
|
||||
COMPLEX_NE_OP_OVERLOAD(hipFloatComplex)
|
||||
COMPLEX_ADD_OP_OVERLOAD(hipFloatComplex)
|
||||
COMPLEX_SUB_OP_OVERLOAD(hipFloatComplex)
|
||||
COMPLEX_MUL_OP_OVERLOAD(hipFloatComplex)
|
||||
COMPLEX_DIV_OP_OVERLOAD(hipFloatComplex)
|
||||
COMPLEX_ADD_PREOP_OVERLOAD(hipFloatComplex)
|
||||
COMPLEX_SUB_PREOP_OVERLOAD(hipFloatComplex)
|
||||
COMPLEX_MUL_PREOP_OVERLOAD(hipFloatComplex)
|
||||
COMPLEX_DIV_PREOP_OVERLOAD(hipFloatComplex)
|
||||
COMPLEX_SCALAR_PRODUCT(hipFloatComplex, unsigned short)
|
||||
COMPLEX_SCALAR_PRODUCT(hipFloatComplex, signed short)
|
||||
COMPLEX_SCALAR_PRODUCT(hipFloatComplex, unsigned int)
|
||||
COMPLEX_SCALAR_PRODUCT(hipFloatComplex, signed int)
|
||||
COMPLEX_SCALAR_PRODUCT(hipFloatComplex, float)
|
||||
COMPLEX_SCALAR_PRODUCT(hipFloatComplex, unsigned long)
|
||||
COMPLEX_SCALAR_PRODUCT(hipFloatComplex, signed long)
|
||||
COMPLEX_SCALAR_PRODUCT(hipFloatComplex, double)
|
||||
COMPLEX_SCALAR_PRODUCT(hipFloatComplex, signed long long)
|
||||
COMPLEX_SCALAR_PRODUCT(hipFloatComplex, unsigned long long)
|
||||
|
||||
COMPLEX_NEG_OP_OVERLOAD(hipDoubleComplex)
|
||||
COMPLEX_EQ_OP_OVERLOAD(hipDoubleComplex)
|
||||
COMPLEX_NE_OP_OVERLOAD(hipDoubleComplex)
|
||||
COMPLEX_ADD_OP_OVERLOAD(hipDoubleComplex)
|
||||
COMPLEX_SUB_OP_OVERLOAD(hipDoubleComplex)
|
||||
COMPLEX_MUL_OP_OVERLOAD(hipDoubleComplex)
|
||||
COMPLEX_DIV_OP_OVERLOAD(hipDoubleComplex)
|
||||
COMPLEX_ADD_PREOP_OVERLOAD(hipDoubleComplex)
|
||||
COMPLEX_SUB_PREOP_OVERLOAD(hipDoubleComplex)
|
||||
COMPLEX_MUL_PREOP_OVERLOAD(hipDoubleComplex)
|
||||
COMPLEX_DIV_PREOP_OVERLOAD(hipDoubleComplex)
|
||||
COMPLEX_SCALAR_PRODUCT(hipDoubleComplex, unsigned short)
|
||||
COMPLEX_SCALAR_PRODUCT(hipDoubleComplex, signed short)
|
||||
COMPLEX_SCALAR_PRODUCT(hipDoubleComplex, unsigned int)
|
||||
COMPLEX_SCALAR_PRODUCT(hipDoubleComplex, signed int)
|
||||
COMPLEX_SCALAR_PRODUCT(hipDoubleComplex, float)
|
||||
COMPLEX_SCALAR_PRODUCT(hipDoubleComplex, unsigned long)
|
||||
COMPLEX_SCALAR_PRODUCT(hipDoubleComplex, signed long)
|
||||
COMPLEX_SCALAR_PRODUCT(hipDoubleComplex, double)
|
||||
COMPLEX_SCALAR_PRODUCT(hipDoubleComplex, signed long long)
|
||||
COMPLEX_SCALAR_PRODUCT(hipDoubleComplex, unsigned long long)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
typedef hipFloatComplex hipComplex;
|
||||
|
||||
__HOST_DEVICE__ static inline hipComplex make_hipComplex(float x, float y) {
|
||||
|
||||
@@ -38,6 +38,7 @@ THE SOFTWARE.
|
||||
|
||||
#if defined(__has_attribute)
|
||||
#if __has_attribute(ext_vector_type)
|
||||
#define __HIP_USE_NATIVE_VECTOR__ 1
|
||||
#define __NATIVE_VECTOR__(n, T) T __attribute__((ext_vector_type(n)))
|
||||
#else
|
||||
#define __NATIVE_VECTOR__(n, T) T[n]
|
||||
@@ -427,7 +428,11 @@ THE SOFTWARE.
|
||||
__HOST_DEVICE__
|
||||
HIP_vector_type& operator+=(const HIP_vector_type& x) noexcept
|
||||
{
|
||||
#if __HIP_USE_NATIVE_VECTOR__
|
||||
data += x.data;
|
||||
#else
|
||||
for (auto i = 0u; i != rank; ++i) data[i] += x.data[i];
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
template<
|
||||
@@ -443,7 +448,11 @@ THE SOFTWARE.
|
||||
__HOST_DEVICE__
|
||||
HIP_vector_type& operator-=(const HIP_vector_type& x) noexcept
|
||||
{
|
||||
#if __HIP_USE_NATIVE_VECTOR__
|
||||
data -= x.data;
|
||||
#else
|
||||
for (auto i = 0u; i != rank; ++i) data[i] -= x.data[i];
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
template<
|
||||
@@ -459,7 +468,11 @@ THE SOFTWARE.
|
||||
__HOST_DEVICE__
|
||||
HIP_vector_type& operator*=(const HIP_vector_type& x) noexcept
|
||||
{
|
||||
#if __HIP_USE_NATIVE_VECTOR__
|
||||
data *= x.data;
|
||||
#else
|
||||
for (auto i = 0u; i != rank; ++i) data[i] *= x.data[i];
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -488,7 +501,11 @@ THE SOFTWARE.
|
||||
__HOST_DEVICE__
|
||||
HIP_vector_type& operator/=(const HIP_vector_type& x) noexcept
|
||||
{
|
||||
#if __HIP_USE_NATIVE_VECTOR__
|
||||
data /= x.data;
|
||||
#else
|
||||
for (auto i = 0u; i != rank; ++i) data[i] /= x.data[i];
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
template<
|
||||
@@ -508,7 +525,11 @@ THE SOFTWARE.
|
||||
HIP_vector_type operator-() const noexcept
|
||||
{
|
||||
auto tmp(*this);
|
||||
#if __HIP_USE_NATIVE_VECTOR__
|
||||
tmp.data = -tmp.data;
|
||||
#else
|
||||
for (auto i = 0u; i != rank; ++i) tmp.data[i] = -tmp.data[i];
|
||||
#endif
|
||||
return tmp;
|
||||
}
|
||||
|
||||
@@ -519,7 +540,11 @@ THE SOFTWARE.
|
||||
HIP_vector_type operator~() const noexcept
|
||||
{
|
||||
HIP_vector_type r{*this};
|
||||
#if __HIP_USE_NATIVE_VECTOR__
|
||||
r.data = ~r.data;
|
||||
#else
|
||||
for (auto i = 0u; i != rank; ++i) r.data[i] = ~r.data[i];
|
||||
#endif
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -529,7 +554,11 @@ THE SOFTWARE.
|
||||
__HOST_DEVICE__
|
||||
HIP_vector_type& operator%=(const HIP_vector_type& x) noexcept
|
||||
{
|
||||
#if __HIP_USE_NATIVE_VECTOR__
|
||||
data %= x.data;
|
||||
#else
|
||||
for (auto i = 0u; i != rank; ++i) data[i] %= x.data[i];
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -539,7 +568,11 @@ THE SOFTWARE.
|
||||
__HOST_DEVICE__
|
||||
HIP_vector_type& operator^=(const HIP_vector_type& x) noexcept
|
||||
{
|
||||
#if __HIP_USE_NATIVE_VECTOR__
|
||||
data ^= x.data;
|
||||
#else
|
||||
for (auto i = 0u; i != rank; ++i) data[i] ^= x.data[i];
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -549,7 +582,11 @@ THE SOFTWARE.
|
||||
__HOST_DEVICE__
|
||||
HIP_vector_type& operator|=(const HIP_vector_type& x) noexcept
|
||||
{
|
||||
#if __HIP_USE_NATIVE_VECTOR__
|
||||
data |= x.data;
|
||||
#else
|
||||
for (auto i = 0u; i != rank; ++i) data[i] |= x.data[i];
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -559,7 +596,11 @@ THE SOFTWARE.
|
||||
__HOST_DEVICE__
|
||||
HIP_vector_type& operator&=(const HIP_vector_type& x) noexcept
|
||||
{
|
||||
#if __HIP_USE_NATIVE_VECTOR__
|
||||
data &= x.data;
|
||||
#else
|
||||
for (auto i = 0u; i != rank; ++i) data[i] &= x.data[i];
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -569,7 +610,11 @@ THE SOFTWARE.
|
||||
__HOST_DEVICE__
|
||||
HIP_vector_type& operator>>=(const HIP_vector_type& x) noexcept
|
||||
{
|
||||
#if __HIP_USE_NATIVE_VECTOR__
|
||||
data >>= x.data;
|
||||
#else
|
||||
for (auto i = 0u; i != rank; ++i) data[i] >>= x.data[i];
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -579,7 +624,11 @@ THE SOFTWARE.
|
||||
__HOST_DEVICE__
|
||||
HIP_vector_type& operator<<=(const HIP_vector_type& x) noexcept
|
||||
{
|
||||
#if __HIP_USE_NATIVE_VECTOR__
|
||||
data <<= x.data;
|
||||
#else
|
||||
for (auto i = 0u; i != rank; ++i) data[i] <<= x.data[i];
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
@@ -682,10 +731,10 @@ THE SOFTWARE.
|
||||
__HOST_DEVICE__
|
||||
inline
|
||||
constexpr
|
||||
bool _hip_any_zero(const V& x, int n) noexcept
|
||||
bool _hip_compare(const V& x, const V& y, int n) noexcept
|
||||
{
|
||||
return
|
||||
(n == -1) ? true : ((x[n] == 0) ? false : _hip_any_zero(x, n - 1));
|
||||
(n == -1) ? true : ((x[n] != y[n]) ? false : _hip_compare(x, y, n - 1));
|
||||
}
|
||||
|
||||
template<typename T, unsigned int n>
|
||||
@@ -695,7 +744,7 @@ THE SOFTWARE.
|
||||
bool operator==(
|
||||
const HIP_vector_type<T, n>& x, const HIP_vector_type<T, n>& y) noexcept
|
||||
{
|
||||
return _hip_any_zero(x.data == y.data, n - 1);
|
||||
return _hip_compare(x.data, y.data, n - 1);
|
||||
}
|
||||
template<typename T, unsigned int n, typename U>
|
||||
__HOST_DEVICE__
|
||||
|
||||
مرجع در شماره جدید
Block a user