-
Notifications
You must be signed in to change notification settings - Fork 300
Add class type support for __builtin_amdgcn_readfirstlane() #711
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
Merged
asroy
merged 18 commits into
develop
from
feature/support-readfirstlane-for-object-types
May 31, 2023
+84
−0
Merged
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
dea4506
Add overloaded version of __builtin_amdgcn_readfirstlane()
poyenc 55a8194
Remove 'static' specifiers
poyenc a8d4294
Remove more 'static' specifier
poyenc a609bfa
Replace unsigne char by std::byte
poyenc fb51f33
Add 'const' specifier to never changing variable
poyenc 8b7ea41
Add 'inline' specifier to funcion definition
poyenc ccebca5
Fix wrong boundar calculation logic
poyenc 85829b3
Merge branch 'develop' into feature/support-readfirstlane-for-object-…
poyenc 48feb28
Rename type trait
poyenc fc3df3b
Remove std:: qualifier from standard types
poyenc 813d406
Replace 'size_t' by 'unsigned'
poyenc 0840e01
Use type alias to hint usage
poyenc ad8bc60
Replace static_for<> by ordinary 'for' loop
poyenc ae8b307
Merge branch 'develop' into feature/support-readfirstlane-for-object-…
poyenc e698fdb
Rename readfirstlane() to amd_wave_read_first_lane()
poyenc 232972e
Rename file readfirstlance.hpp as amd_wave_read_first_lane.hpp
poyenc 1001c73
Reorder statements
poyenc afa3162
Merge branch 'develop' into feature/support-readfirstlane-for-object-…
poyenc 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| // Copyright (c) 2018-2022, Advanced Micro Devices, Inc. All rights reserved. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "ck/ck.hpp" | ||
| #include "ck/utility/functional2.hpp" | ||
| #include "ck/utility/math.hpp" | ||
|
|
||
| #include <cstddef> | ||
| #include <cstdint> | ||
| #include <type_traits> | ||
|
|
||
| namespace ck { | ||
| namespace detail { | ||
|
|
||
| template <std::size_t Size> | ||
| struct get_signed_int; | ||
|
|
||
| template <> | ||
| struct get_signed_int<1> | ||
| { | ||
| using type = std::int8_t; | ||
|
asroy marked this conversation as resolved.
Outdated
|
||
| }; | ||
|
|
||
| template <> | ||
| struct get_signed_int<2> | ||
| { | ||
| using type = std::int16_t; | ||
| }; | ||
|
|
||
| template <> | ||
| struct get_signed_int<4> | ||
| { | ||
| using type = std::int32_t; | ||
| }; | ||
|
|
||
| template <std::size_t Size> | ||
| using get_signed_int_t = typename get_signed_int<Size>::type; | ||
|
|
||
| } // namespace detail | ||
|
|
||
| __device__ inline std::int32_t readfirstlane(std::int32_t value) | ||
| { | ||
| return __builtin_amdgcn_readfirstlane(value); | ||
| } | ||
|
|
||
| template < | ||
| typename Object, | ||
| typename = std::enable_if_t<std::is_class_v<Object> && std::is_trivially_copyable_v<Object>>> | ||
| __device__ auto readfirstlane(const Object& obj) | ||
|
Contributor
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. This is a AMD specific function, not standard HIP. I think better rename to "amd_wave_read_first_lane", similar to "amd_buffer_load" |
||
| { | ||
| constexpr std::size_t SgprSize = 4; | ||
| constexpr std::size_t ObjectSize = sizeof(Object); | ||
|
|
||
| using Sgpr = detail::get_signed_int_t<SgprSize>; | ||
|
|
||
| alignas(Object) std::byte to_obj[ObjectSize]; | ||
|
|
||
| auto* const from_obj = reinterpret_cast<const std::byte*>(&obj); | ||
|
|
||
| constexpr std::size_t RemainedSize = ObjectSize % SgprSize; | ||
| constexpr std::size_t CompleteSgprCopyBoundary = ObjectSize - RemainedSize; | ||
| static_for<0, CompleteSgprCopyBoundary, SgprSize>{}([&](auto offset) { | ||
|
asroy marked this conversation as resolved.
Outdated
|
||
| *reinterpret_cast<Sgpr*>(to_obj + offset) = | ||
| readfirstlane(*reinterpret_cast<const Sgpr*>(from_obj + offset)); | ||
| }); | ||
|
|
||
| if constexpr(0 < RemainedSize) | ||
| { | ||
| using Carrier = detail::get_signed_int_t<RemainedSize>; | ||
|
|
||
| *reinterpret_cast<Carrier>(to_obj + CompleteSgprCopyBoundary) = | ||
| readfirstlane(*reinterpret_cast<const Carrier*>(from_obj + CompleteSgprCopyBoundary)); | ||
| } | ||
|
|
||
| /// NOTE: Implicitly start object lifetime. It's better to use | ||
| /// std::start_lifetime_at() in this scenario | ||
| return *reinterpret_cast<Object*>(to_obj); | ||
| } | ||
|
|
||
| } // namespace ck | ||
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.
Uh oh!
There was an error while loading. Please reload this page.