-
Notifications
You must be signed in to change notification settings - Fork 135
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 meta dimensions specifiers to cudax::launch #2001
Open
pciolkosz
wants to merge
33
commits into
NVIDIA:main
Choose a base branch
from
pciolkosz:dims_meta_specifier
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
caf08d3
Kinda working at_least specifier
pciolkosz e0fa74f
Rebase to launch
pciolkosz 03c579c
Hierarchy type transformation trait
pciolkosz e8ba03e
Occupancy meta specifier
pciolkosz 1475b6d
Example fixes
pciolkosz ddba659
Add max_coresident and finalize functor overload
pciolkosz e47fb4e
Take into account cluster size in max_coresident
pciolkosz e3c8120
Add finalize to launch, take dyn smem into account
pciolkosz bf40e09
Add tests for dynamic smem handling in finalize
pciolkosz 9b10ec7
Minor improvements
pciolkosz 70d8799
Add stream argument to finalize
pciolkosz a42eef2
Rename transform to finalize
pciolkosz a6c8ce0
Rename transform to finalize
pciolkosz 08c8717
Inline docs and some comments
pciolkosz ae74327
Fix at_least
pciolkosz fe78bab
Remove accidental swp file
pciolkosz 1ab1793
Add safety TODO
pciolkosz eefbc06
Compilation fixes
pciolkosz 818a1bf
More compilation fixes
pciolkosz d9375a0
Some more fixes for MSVC
pciolkosz b0bf125
Add pragma for warning in is_function
pciolkosz 9121424
Help confused MSVC
pciolkosz 1b14e37
Fix typo in a comment
pciolkosz 4ccc364
Merge branch 'main' into dims_meta_specifier
pciolkosz 5cc3f2f
Fix formatting
pciolkosz 2a8f57a
Fix formatting
pciolkosz e675d1a
Change best_occupancy to max_occupancy
pciolkosz 899f72e
Merge remote-tracking branch 'upstream/main' into dims_meta_specifier
pciolkosz 1392a97
Fix extra comma, add missing empty kernel
pciolkosz bba433b
Push context once when launching a draft
pciolkosz ce653b6
Remove constexpr from finalize
pciolkosz a8b78a1
Unused parameter
pciolkosz ab263a1
Pragma for is_function
pciolkosz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,8 +39,16 @@ struct extents_corrected : public ::cuda::std::extents<T, Extents...> { | |
}; | ||
*/ | ||
|
||
struct base_dimensions_handler | ||
{ | ||
// TODO: Should these two be merged into one bool? | ||
static constexpr bool is_type_supported = true; | ||
template <typename Level> | ||
static constexpr bool is_level_supported = true; | ||
}; | ||
|
||
template <typename Dims> | ||
struct dimensions_handler | ||
struct dimensions_handler : public base_dimensions_handler | ||
{ | ||
static constexpr bool is_type_supported = ::cuda::std::is_integral_v<Dims>; | ||
|
||
|
@@ -51,10 +59,8 @@ struct dimensions_handler | |
}; | ||
|
||
template <> | ||
struct dimensions_handler<dim3> | ||
struct dimensions_handler<dim3> : public base_dimensions_handler | ||
{ | ||
static constexpr bool is_type_supported = true; | ||
|
||
_CCCL_NODISCARD _CCCL_HOST_DEVICE static constexpr auto translate(const dim3& d) noexcept | ||
{ | ||
return dimensions<dimensions_index_type, | ||
|
@@ -65,15 +71,25 @@ struct dimensions_handler<dim3> | |
}; | ||
|
||
template <typename Dims, Dims Val> | ||
struct dimensions_handler<::cuda::std::integral_constant<Dims, Val>> | ||
struct dimensions_handler<::cuda::std::integral_constant<Dims, Val>> : public base_dimensions_handler | ||
{ | ||
static constexpr bool is_type_supported = true; | ||
|
||
_CCCL_NODISCARD _CCCL_HOST_DEVICE static constexpr auto translate(const Dims& d) noexcept | ||
{ | ||
return dimensions<dimensions_index_type, size_t(d), 1, 1>(); | ||
} | ||
}; | ||
|
||
// needs_finalization or similar might be a better name | ||
template <typename Dims> | ||
inline constexpr bool usable_for_queries = false; | ||
|
||
template <typename T, size_t... Extents> | ||
inline constexpr bool usable_for_queries<dimensions<T, Extents...>> = true; | ||
Comment on lines
+83
to
+87
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. Remark: I love variable templates as traits instead of structs. They are shorter and more to the point. They require C++14 though, which is why we don't see many of those around here. |
||
|
||
template <typename... LevelDims> | ||
inline constexpr bool usable_for_queries<::cuda::std::tuple<LevelDims...>> = | ||
(... && usable_for_queries<::cuda::std::decay_t<decltype(::cuda::std::declval<LevelDims>().dims)>>); | ||
|
||
} // namespace detail | ||
|
||
/** | ||
|
@@ -113,11 +129,27 @@ template <typename Level, typename Dimensions> | |
struct level_dimensions | ||
{ | ||
static_assert(::cuda::std::is_base_of_v<hierarchy_level, Level>); | ||
using level_type = Level; | ||
using level_type = Level; | ||
using dimensions_type = Dimensions; | ||
|
||
// Needs alignas to work around an issue with tuple | ||
alignas(16) const Dimensions dims; // Unit for dimensions is implicit | ||
|
||
// TODO might be deleted one we are confident rest of the code properly check usabe_for_queries | ||
template <typename T = void> | ||
_CCCL_HOST_DEVICE constexpr const Dimensions& dims_for_query() const | ||
{ | ||
static_assert(detail::usable_for_queries<Dimensions>, | ||
"Dimensions type is not usable for queries, finalize the dimensions first"); | ||
return dims; | ||
} | ||
|
||
template <typename NewDims> | ||
_CCCL_NODISCARD _CCCL_HOST_DEVICE level_dimensions<Level, NewDims> finalize(const NewDims& new_dims) const | ||
{ | ||
return level_dimensions<Level, NewDims>(new_dims); | ||
} | ||
|
||
_CCCL_HOST_DEVICE constexpr level_dimensions(const Dimensions& d) | ||
: dims(d) | ||
{} | ||
|
@@ -148,6 +180,8 @@ template <typename T> | |
_CCCL_HOST_DEVICE constexpr auto grid_dims(T t) noexcept | ||
{ | ||
static_assert(detail::dimensions_handler<T>::is_type_supported); | ||
static_assert(detail::dimensions_handler<T>::template is_level_supported<grid_level>, | ||
"This level type does not support the provided type of dimensions"); | ||
auto dims = detail::dimensions_handler<T>::translate(t); | ||
return level_dimensions<grid_level, decltype(dims)>(dims); | ||
} | ||
|
@@ -172,6 +206,8 @@ template <typename T> | |
_CCCL_HOST_DEVICE constexpr auto cluster_dims(T t) noexcept | ||
{ | ||
static_assert(detail::dimensions_handler<T>::is_type_supported); | ||
static_assert(detail::dimensions_handler<T>::template is_level_supported<cluster_level>, | ||
"This level type does not support the provided type of dimensions"); | ||
auto dims = detail::dimensions_handler<T>::translate(t); | ||
return level_dimensions<cluster_level, decltype(dims)>(dims); | ||
} | ||
|
@@ -196,6 +232,8 @@ template <typename T> | |
_CCCL_HOST_DEVICE constexpr auto block_dims(T t) noexcept | ||
{ | ||
static_assert(detail::dimensions_handler<T>::is_type_supported); | ||
static_assert(detail::dimensions_handler<T>::template is_level_supported<block_level>, | ||
"This level type does not support the provided type of dimensions"); | ||
auto dims = detail::dimensions_handler<T>::translate(t); | ||
return level_dimensions<block_level, decltype(dims)>(dims); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Remark:
struct
base classes arepublic
by default.I don't know why this triggers me enough to write a comment. Feel free to ignore!
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.
We tend to prefer explicitness about these things. Makes the code more accessible to less experienced contributors.