-
Notifications
You must be signed in to change notification settings - Fork 144
Add fp32 winograd for gfx12 #5092
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
Open
pfultz2
wants to merge
26
commits into
develop
Choose a base branch
from
fp32-winograd
base: develop
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
26 commits
Select commit
Hold shift + click to select a range
821f3c3
Add initial fp32 kernel
pfultz2 d075e5b
Format
pfultz2 704f950
Improve perf
pfultz2 7b3a5db
Format
pfultz2 6039ad5
Implement split_c
pfultz2 a3b7321
Format
pfultz2 6c308dd
Add pipelining
pfultz2 1c339d1
Make pipe a bool
pfultz2 def596b
Improve load latency
pfultz2 d845d34
Support S-store
pfultz2 d42f88f
Tweak heuristic
pfultz2 51cf0e2
Initial NHWC rewrite
pfultz2 f7cef8f
v-inner cont
pfultz2 756214a
Format
pfultz2 46c2dbc
Add NHWC heuristic
pfultz2 56761df
Simplify
pfultz2 9b3e04c
Some cleanup
pfultz2 c2d267e
Fix tidy
pfultz2 7d7e1e0
Add check for inner_v
pfultz2 6a77837
Add unit tests
pfultz2 0c801ac
Add more tests
pfultz2 50eeb9f
Merge branch 'develop' into fp32-winograd
pfultz2 11c3ef9
Apply suggestions from code review
pfultz2 47cd8da
Potential fix for pull request finding
pfultz2 eeef2c5
Update comments
pfultz2 7379722
Remove static_cast
pfultz2 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
78 changes: 78 additions & 0 deletions
78
src/targets/gpu/kernels/include/migraphx/kernels/buffer_load.hpp
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,78 @@ | ||
| /* | ||
| * The MIT License (MIT) | ||
| * | ||
| * Copyright (c) 2015-2026 Advanced Micro Devices, Inc. All rights reserved. | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| */ | ||
| #ifndef MIGRAPHX_GUARD_KERNELS_BUFFER_LOAD_HPP | ||
| #define MIGRAPHX_GUARD_KERNELS_BUFFER_LOAD_HPP | ||
|
|
||
| #include <migraphx/kernels/bit_cast.hpp> | ||
| #include <migraphx/kernels/vec.hpp> | ||
| #include <migraphx/kernels/types.hpp> | ||
|
|
||
| namespace migraphx { | ||
|
|
||
| // gfx12 buffer-resource word 3 (from composable_kernel): makes raw buffer loads | ||
| // return 0 for out-of-range byte offsets, so bounds/halo checks collapse to an | ||
| // offset select against a sentinel instead of a per-load branch. | ||
| constexpr uint32_t oob_buffer_rsrc_word3 = 0x31004000; | ||
|
|
||
| // Build an out-of-bounds-tolerant buffer descriptor for a read-only pointer (the | ||
| // resource is only ever loaded from; the const_cast is required by the builtin's | ||
| // non-const pointer parameter). | ||
| template <class T> | ||
| __device__ inline __amdgpu_buffer_rsrc_t make_oob_buffer_rsrc(const T* p, uint32_t byte_count) | ||
| { | ||
| auto* base = const_cast<T*>(p); // NOLINT(cppcoreguidelines-pro-type-const-cast) | ||
| return __builtin_amdgcn_make_buffer_rsrc(base, 0, byte_count, oob_buffer_rsrc_word3); | ||
| } | ||
|
Comment on lines
+33
to
+46
|
||
|
|
||
| // Raw buffer load of N contiguous T (N*sizeof(T) must be 2/4/8/16 bytes -> | ||
| // b16/b32/b64/b128; gfx12 tolerates 4-byte alignment). OOB bytes read as 0. | ||
| template <class T, index_int N> | ||
| __device__ inline vec<T, N> buffer_load_vec(__amdgpu_buffer_rsrc_t rsrc, int byte_offset) | ||
| { | ||
| constexpr index_int bytes = N * sizeof(T); | ||
| static_assert(bytes == 2 or bytes == 4 or bytes == 8 or bytes == 16, | ||
| "buffer_load_vec width must be 2, 4, 8, or 16 bytes"); | ||
| if constexpr(bytes == 16) | ||
| return bit_cast<vec<T, N>>(__builtin_amdgcn_raw_buffer_load_b128(rsrc, byte_offset, 0, 0)); | ||
| else if constexpr(bytes == 8) | ||
| return bit_cast<vec<T, N>>(__builtin_amdgcn_raw_buffer_load_b64(rsrc, byte_offset, 0, 0)); | ||
| else if constexpr(bytes == 4) | ||
| return bit_cast<vec<T, N>>(__builtin_amdgcn_raw_buffer_load_b32(rsrc, byte_offset, 0, 0)); | ||
| else | ||
| return bit_cast<vec<T, N>>(__builtin_amdgcn_raw_buffer_load_b16(rsrc, byte_offset, 0, 0)); | ||
| } | ||
|
|
||
| // Raw buffer load of a single T (2- or 4-byte element). OOB reads as 0. | ||
| template <class T> | ||
| __device__ inline T buffer_load(__amdgpu_buffer_rsrc_t rsrc, int byte_offset) | ||
| { | ||
| static_assert(sizeof(T) == 2 or sizeof(T) == 4, "buffer_load element must be 2 or 4 bytes"); | ||
| if constexpr(sizeof(T) == 2) | ||
| return bit_cast<T>(__builtin_amdgcn_raw_buffer_load_b16(rsrc, byte_offset, 0, 0)); | ||
| else | ||
| return bit_cast<T>(__builtin_amdgcn_raw_buffer_load_b32(rsrc, byte_offset, 0, 0)); | ||
| } | ||
|
|
||
| } // namespace migraphx | ||
| #endif // MIGRAPHX_GUARD_KERNELS_BUFFER_LOAD_HPP | ||
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.
Uh oh!
There was an error while loading. Please reload this page.