You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.
This is again an issue that came up trying to introduce a HIP backend support in GPUSPH. We have Point and Vector classes that can be constructed from vector types, equipped with operators that allow adding (etc) them together.
This means that code such as this: double3 v ; Point pt ; Point n = v + pt works because the v gets converted to a Point and Point+Point is a defined operation —at least in CUDA and on CPU.
This is however does not work when using HIP vector types, because of definitions such as:
template<typename T, unsigned int n, typename U>
__HOST_DEVICE__
inline
constexpr
HIP_vector_type<T, n> operator+(
const HIP_vector_type<T, n>& x, U y) noexcept
{
return HIP_vector_type<T, n>{x} += HIP_vector_type<T, n>{y};
}
or the one with the flipped arguments. These take precedence of the conversion-enabled Point+Point operator, and result in an error because HIP_vector_type<T, n> cannot be constructed from a Point.
The solution is to enable these operators only for types for which the conversion is defined, for example using appropriate enable_if fencing:
This is necessary to avoid errors about ambiguous overloads in code such as
````
struct Point {
float4 pos;
float mass;
};
template<typename T>
Point operator+(Point const& p, T const& v)
{
return Point{p.pos + v, p.mass};
}
int main() {
float4 v = make_float4(0, 1, 2, 3);
Point p{make_float4(3, 2, 1, 0), 1.0f};
Point q = p + v;
}
````
when building with the host compiler.
Closes hipamd issue ROCm#4
This is necessary to avoid errors about ambiguous overloads in code such as
````
struct Point {
float4 pos;
float mass;
};
template<typename T>
Point operator+(Point const& p, T const& v)
{
return Point{p.pos + v, p.mass};
}
int main() {
float4 v = make_float4(0, 1, 2, 3);
Point p{make_float4(3, 2, 1, 0), 1.0f};
Point q = p + v;
}
````
when building with the host compiler.
Closes hipamd issue ROCm#4
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
This is again an issue that came up trying to introduce a HIP backend support in GPUSPH. We have
Point
andVector
classes that can be constructed from vector types, equipped with operators that allow adding (etc) them together.This means that code such as this:
double3 v ; Point pt ; Point n = v + pt
works because the v gets converted to aPoint
andPoint+Point
is a defined operation —at least in CUDA and on CPU.This is however does not work when using HIP vector types, because of definitions such as:
or the one with the flipped arguments. These take precedence of the conversion-enabled
Point+Point
operator, and result in an error becauseHIP_vector_type<T, n>
cannot be constructed from aPoint
.The solution is to enable these operators only for types for which the conversion is defined, for example using appropriate
enable_if
fencing:This should be done for all these operators. Additionally, the
U
argument should be aconst&
to avoid unnecessary invocations of copy constructors.The text was updated successfully, but these errors were encountered: