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 size function to alpaka::Vec #2416

Closed

Conversation

mehmetyusufoglu
Copy link
Contributor

@mehmetyusufoglu mehmetyusufoglu commented Oct 23, 2024

This PR adds a static function to the alpaka::Vec. It is defined static so that it can be used with the type aliases as well.

@mehmetyusufoglu mehmetyusufoglu force-pushed the addSizeToVec branch 3 times, most recently from 3161732 to f4ff21e Compare October 23, 2024 20:03
@@ -227,6 +227,13 @@ namespace alpaka
return m_data[Dim::value - 4];
}

//! Function returns the size of the static array
//! \return The size
ALPAKA_FN_HOST_ACC static constexpr decltype(auto) size()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please put an explicit return type.
I understand that the compiler can guess what it is, but the users shouldn't have to try and guess.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please copy the function signature from my PR #2415
This is the state of the art definition for C++20.

@fwyzard
Copy link
Contributor

fwyzard commented Oct 23, 2024

What is the different wrt #2415 ?

@mehmetyusufoglu
Copy link
Contributor Author

mehmetyusufoglu commented Oct 23, 2024 via email

@SimeonEhrig
Copy link
Member

Dim is not the correct name. This is a 1D static array and can be used for any reason. (Using Dim assumes Vec is used only to define dimensions of a grid, block or data.) 23 Eki 2024 Çar 23:28 tarihinde Andrea Bocci @.> şunu yazdı:

What is the different wrt #2415 <#2415> ? — Reply to this email directly, view it on GitHub <#2416 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUYXIJMGBCUAXUJ42I5E3QTZ5AIGJAVCNFSM6AAAAABQPR2EXWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMZTGQ4TMNBVGA . You are receiving this because you authored the thread.Message ID: @.
>

I disagree. 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
``

@SimeonEhrig
Copy link
Member

What is the different wrt #2415 ?

By the way, I don't know @mehmetyusufoglu open the same PR again and didn't ask for changing the name in my PR.

@mehmetyusufoglu
Copy link
Contributor Author

mehmetyusufoglu commented Oct 24, 2024 via email

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 this pull request may close these issues.

3 participants