-
Notifications
You must be signed in to change notification settings - Fork 75
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 alpaka::getPreferredWarpSize(dev)
#2216
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/* Copyright 2023 Jan Stephan, Antonio Di Pilato, Luca Ferragina, Aurora Perego | ||
/* Copyright 2024 Jan Stephan, Antonio Di Pilato, Luca Ferragina, Aurora Perego, Andrea Bocci | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
|
@@ -18,6 +18,7 @@ | |
|
||
#include <algorithm> | ||
#include <cstddef> | ||
#include <functional> | ||
#include <memory> | ||
#include <mutex> | ||
#include <shared_mutex> | ||
|
@@ -181,10 +182,22 @@ namespace alpaka::trait | |
auto find64 = std::find(warp_sizes.begin(), warp_sizes.end(), 64); | ||
if(find64 != warp_sizes.end()) | ||
warp_sizes.erase(find64); | ||
// Sort the warp sizes in decreasing order | ||
std::sort(warp_sizes.begin(), warp_sizes.end(), std::greater<>{}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Nit] If the vector size can be large somehow, "initially sorting then finding the element in vector" (logarithmic time) is faster compared to "finding deleting then sorting" (linear time). After sorting, using std::lower_bound function finds in log(n) time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The largest vector I encountered had 5 elements: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mehmetyusufoglu your analysis is correct, but I am with @fwyzard: the supported warp sizes are probably a small set here :) Also, binary search is slower than linear for small sizes due to data dependent access pattern. So @fwyzard's version is probably faster for our use case :D |
||
return warp_sizes; | ||
} | ||
}; | ||
|
||
//! The SYCL device preferred warp size get trait specialization. | ||
template<typename TPlatform> | ||
struct GetPreferredWarpSize<DevGenericSycl<TPlatform>> | ||
{ | ||
static auto getPreferredWarpSize(DevGenericSycl<TPlatform> const& dev) -> std::size_t | ||
{ | ||
return GetWarpSizes<DevGenericSycl<TPlatform>>::getWarpSizes(dev).front(); | ||
} | ||
}; | ||
|
||
//! The SYCL device reset trait specialization. | ||
template<typename TPlatform> | ||
struct Reset<DevGenericSycl<TPlatform>> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, in C++20, this should be just
std::erase(warp_sizes, 64)
. Looking forward to the upgrade :)