Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: add .x(), .y(), ... accessors to alpaka::Vec #2185

Closed
fwyzard opened this issue Oct 31, 2023 · 2 comments · Fixed by #2201
Closed

Proposal: add .x(), .y(), ... accessors to alpaka::Vec #2185

fwyzard opened this issue Oct 31, 2023 · 2 comments · Fixed by #2201

Comments

@fwyzard
Copy link
Contributor

fwyzard commented Oct 31, 2023

As we gain more experience rewriting CUDA code and porting it to Alpaka, one of the aspects that people are struggling a lot with is the use of OpenCL-like indices for accessing alpaka::Vec variables, when they are used for the work division, execution index, etc.

For 1 dimensional kernel things are easy

dim3 id = ...;
f(id.x);

maps to

Vec<DimInt<1u>, float> id = ...'
f(id[0]);

For a 2 dimensional kernel things are already complicated:

dim3 id = ...;
f(id.x, id.y);

maps to

Vec<DimInt<2u>, float> id = ...'
f(id[1], id[0]);

The problem is not so much that .x, .y map to [1], [0]...

The biggest problem is that .x maps to [N-1], .y maps to [N-2], etc.
This means that .x maps to [0] in a 1-dimensional kernel, but .x maps to [1] in a 2-Dimensional kernel, etc. - which is very confusing for users, when they mix 1D and 2D kernels.

Even though we briefly entertained the possibility, it's clear that we cannot change the ordering of the indices used in Alpaka, as it would break all existing code.

But we could add a more familiar syntax to Vec variables: .x(), .y(), .z() accessors.

Vec<DimInt<1u>, float> id = ...'
f(id.x());
Vec<DimInt<2u>, float> id = ...'
f(id.x(), id.y());

We should be able to use SFINAE or partial specialisation to make .x() available only when N > 0, .y() available only when N > 1, etc.

What do you think ?

@fwyzard fwyzard changed the title Proposal: add .x(), .y(), _etc_ accessors to alpaka::Vec Proposal: add .x(), .y(), ... accessors to alpaka::Vec Oct 31, 2023
@psychocoderHPC
Copy link
Member

I agree that the indexing model alpaka is using is complicated for codes coming from CUDA. We have the same issue with PIConGPU which can be used for 2D and 3D.

psychocoderHPC added a commit to psychocoderHPC/alpaka that referenced this issue Dec 1, 2023
Provide access to the vector components via named methods. `x()`, `y()`,
`z()` and `w()`.
The avalble names depends on the dimension of the vector.
psychocoderHPC added a commit to psychocoderHPC/alpaka that referenced this issue Dec 1, 2023
fix alpaka-group#2185

Provide access to the vector components via named methods. `x()`, `y()`,
`z()` and `w()`.
The avalble names depends on the dimension of the vector.
@psychocoderHPC
Copy link
Member

psychocoderHPC commented Dec 1, 2023

@fwyzard #2201 provides the named access to the vector data.

The biggest problem is that .x maps to [N-1], .y maps to [N-2], etc.

This is currently not solved. Maybe we should add a method s(idx),at(idx) which is reverting the index order and internally map the access of these method to the alpaka element order.

psychocoderHPC added a commit to psychocoderHPC/alpaka that referenced this issue Dec 1, 2023
fix alpaka-group#2185

Provide access to the vector components via named methods. `x()`, `y()`,
`z()` and `w()`.
The avalble names depends on the dimension of the vector.
psychocoderHPC added a commit to psychocoderHPC/alpaka that referenced this issue Dec 1, 2023
fix alpaka-group#2185

Provide access to the vector components via named methods. `x()`, `y()`,
`z()` and `w()`.
The avalble names depends on the dimension of the vector.
bernhardmgruber pushed a commit that referenced this issue Dec 2, 2023
fix #2185

Provide access to the vector components via named methods. `x()`, `y()`,
`z()` and `w()`.
The avalble names depends on the dimension of the vector.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants