Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

Vector fixes #8

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open

Vector fixes #8

wants to merge 3 commits into from

Conversation

Oblomov
Copy link

@Oblomov Oblomov commented Dec 16, 2021

This patchset fixes the behavior of HIP vector types when used on host and building with a host compiler. Closes issues #3 and #4, that emerged while introducing HIP support in GPUSPH and affect both g++ and clang++ as host compiler. The last patch also fixes operators that assume ext_vector_type is supported (which is not the case for g++).

Oblomov added 3 commits July 1, 2022 14:05
This is necessary for consistency between the representation of vector types
between host and device, as well as for consistency with the way vector types
behave when defined as structures (as is the case for code ported from CUDA).

Without this patch, this simple test case:

````

const float& pick(float4 const& v)
{ return v.x; }

const volatile float& pick(float4 const volatile& v)
{ return v.x; }

int main() {
	const float4 c = make_float4(0, 1, 2, 3);
	volatile float4 v = make_float4(1, 2, 3, 0);
	std::cout << pick(c) << std::endl;
	std::cout << pick(v) << std::endl;
}
````

will fail to compile when built with the host compiler.

Closes hipamd issue ROCm#3
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 allows compilation of code such as
````

int main() {
	float4 v1, v2, v3;
	v3 = v1 + v2;
	v3 = v1 - v2;
	v3 = v1 * v2;
	v3 = v1 / v2;

	int4 i1, i2, i3;
	i3 = -i1;
	i3 = ~i2;
	i3 = i1 % i2;
	i3 = i1 ^ i2;
	i3 = i1 >> i2;
	i3 = i1 << i2;

}
````
with a host compiler that supports __has_attribute,
but does not support the ext_vector_type attribute (e.g. g++).
@Oblomov
Copy link
Author

Oblomov commented Jul 2, 2022

OK, this merge has become the only remaining blocker to add AMD GPU support to GPUSPH. Is there anything that can be done to bring it to someone's attention?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant