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

add static function dim() to alpaka::Vec #2415

Merged
merged 1 commit into from
Nov 7, 2024

Conversation

SimeonEhrig
Copy link
Member

Easy way to get the dim of a alpaka::Vec.

- Easy way to get the dim of a alpaka::Vec.
@mehmetyusufoglu
Copy link
Contributor

I opened another PR (#2416) without noticing this is already opened, I closed the other one but I think the name should be size insead of dim.

@SimeonEhrig
Copy link
Member Author

My explanation from the other PR, why we should not name the function size().

We can compare alpaka::Vec with std::extents. std::extents has no explicit size but rank, what is the same like your Dim. If we use std::extents with std::mdspan, we have the function size() which returns the production of the values of each rank in the std::extents. See this example:

std::vector data(100, 0);
std::mdspan md(data.data(), std::extents{10, 10});

// output: 100
std::cout << md.size() << "\n";

// output:
// rank 0: 10
// rank 1: 10
for(auto i = 0; i < md.rank(); ++i){
    std::cout << "rank " << i << ": " << md.extent(i) << "\n"; 
}

Also the special case alpaka::Vec<int, alpaka::DimInt<1>> is the same like std::vector<int>. And in the case of std::vector size() will return the value of the one dimension.

Therefore is clear what is size() is doing. We can discuss, if we want to name the function rank() or dim() something else but size() is already used for a different function. For alpaka::Vec it is:

alpaka::Vec<int, alpaka::DimInt<1>> vec = {10};
std::cout << vec[0] << "\n"; // outputs the size 10
std::cout << vec.size() << "\n"; // outputs the size 10

alpaka::Vec<int, alpaka::DimInt<1>> vec2 = {10, 2};
std::cout << vec.size() << "\n"; // outputs the size 20
``

@psychocoderHPC psychocoderHPC merged commit 6140bce into alpaka-group:develop Nov 7, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants