-
Notifications
You must be signed in to change notification settings - Fork 294
TF32 POC in Conv3d on MI30x platform #2763
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
Merged
Changes from all commits
Commits
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
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,85 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| // Copyright (c) 2025, Advanced Micro Devices, Inc. All rights reserved. | ||
|
|
||
| #include <iostream> | ||
|
|
||
| #include "common.hpp" | ||
|
|
||
| #define USING_DIRECT_LOADS 1 | ||
| #if USING_DIRECT_LOADS | ||
| #include "ck/tensor_operation/gpu/device/impl/device_gemm_xdl_cshuffle_lds_direct_load.hpp" | ||
| #else | ||
| #include "ck/tensor_operation/gpu/device/impl/device_gemm_xdl_cshuffle.hpp" | ||
| #endif | ||
|
|
||
| #define EXAMPLE_WITH_COMPUTE_DATATYPE | ||
|
|
||
| using F32 = float; | ||
|
|
||
| using ADataType = F32; | ||
| using BDataType = F32; | ||
| using AccDataType = F32; | ||
| using CShuffleDataType = F32; | ||
| using CDataType = F32; | ||
| using ComputeDataType = ck::tf32_t; | ||
|
|
||
| using ALayout = Row; | ||
| using BLayout = Col; | ||
| using CLayout = Row; | ||
|
|
||
| using AElementOp = PassThrough; | ||
| using BElementOp = PassThrough; | ||
| using CElementOp = PassThrough; | ||
|
|
||
| static constexpr auto GemmDefault = ck::tensor_operation::device::GemmSpecialization::Default; | ||
|
|
||
| #if USING_DIRECT_LOADS | ||
| // clang-format off | ||
| using DeviceGemmInstance = ck::tensor_operation::device::DeviceGemm_Xdl_CShuffle_LdsDirectLoad | ||
| // ######| ALayout| BLayout| CLayout| AData| BData| CData| AccData| CShuffle| A| B| C| GEMM| NumGemmK| Block| MPer| NPer| KPer| | ||
| // ######| AK1| BK1| MPer| NPer| MXdl| NXdl| ABlockTransfer| ABlockTransfer| ABlockTransfer| ABlockTransfer| ABlockLds| BBlockTransfer| BBlockTransfer| BlockTransfer| BBlockTransfer| BBlockLds| | ||
| // ######| CShuffle| CShuffle| CBlockTransferClusterLengths| CBlockTransfer| LoopScheduler | pipeline ver | gemm type | | ||
| // ######| | | | Type| Type| Type| Type| DataType| Elementwise| Elementwise| Elementwise| Spacialization| Prefetch| Size| Block| Block| Block| | ||
| // ######| XDL| XDL| Per| Per| ThreadCluster| SrcAccessOrder| SrcVectorDim| Scalar| AddExtraM| ThreadCluster| SrcAccessOrder| SrcVectorDim| Scalar| AddExtraN| MXdlPerWave| NXdlPerWave| _MBlock_MWaveMPerXdl| ScalarPerVector| | ||
| // ######| | | | | | | | | Operation| Operation| Operation| | Stage| | | | | | | | | Wave| Wave| Lengths_K0_M_K1| | | PerVector| | Lengths_K0_N_K1| | | PerVector| | PerShuffle| PerShuffle| _NBlock_NWaveNPerXdl| _NWaveNPerXdl| | ||
| // ######| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ||
| < ALayout, BLayout, CLayout, ADataType, BDataType, CDataType, AccDataType, CShuffleDataType, AElementOp, BElementOp, CElementOp, GemmDefault, 1, 256, 128, 128, 32, | ||
| 8, 8, 32, 32, 2, 2, S<4, 8, 8>, S<1, 0, 2>, 2, 1, 1, S<4, 8, 8>, S<1, 0, 2>, 2, 1, 1, | ||
| 1, 1, S<1, 8, 1, 8>, 4, ck::LoopScheduler::Default, ck::PipelineVersion::v4, ComputeDataType>; | ||
| // clang-format on | ||
| #else | ||
| // clang-format off | ||
| using DeviceGemmInstance = ck::tensor_operation::device::DeviceGemm_Xdl_CShuffle | ||
| // ######| ALayout| BLayout| CLayout| AData| BData| CData| AccData| CShuffle| A| B| C| GEMM| NumGemmK| Block| MPer| NPer| KPer| AK1| BK1| MPer| NPer| MXdl| NXdl| ABlockTransfer| ABlockTransfer| ABlockTransfer| ABlockTransfer| ABlockTransfer| ABlockTransfer| ABlockLds| BBlockTransfer| BBlockTransfer| BBlockTransfer| BlockTransfer| BBlockTransfer| BBlockTransfer| BBlockLds| CShuffle| CShuffle| CBlockTransferClusterLengths| CBlockTransfer| | ||
| // ######| | | | Type| Type| Type| Type| DataType| Elementwise| Elementwise| Elementwise| Spacialization| Prefetch| Size| Block| Block| Block| | | XDL| XDL| Per| Per| ThreadCluster| ThreadCluster| SrcAccessOrder| SrcVectorDim| SrcScalar| DstScalar| AddExtraM| ThreadCluster| ThreadCluster| SrcAccessOrder| SrcVectorDim| SrcScalar| DstScalar| AddExtraN| MXdlPerWave| NXdlPerWave| _MBlock_MWaveMPerXdl| ScalarPerVector| | ||
| // ######| | | | | | | | | Operation| Operation| Operation| | Stage| | | | | | | | | Wave| Wave| Lengths_K0_M_K1| ArrangeOrder| | | PerVector| PerVector_K1| | Lengths_K0_N_K1| ArrangeOrder| | | PerVector| PerVector_K1| | PerShuffle| PerShuffle| _NBlock_NWaveNPerXdl| _NWaveNPerXdl| | ||
| // ######| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ||
| < ALayout, BLayout, CLayout, ADataType, BDataType, CDataType, AccDataType, CShuffleDataType, AElementOp, BElementOp, CElementOp, GemmDefault, 1, 256, 128, 128, 32, 8, 8, 32, 32, 2, 2, S<4, 32, 1>, S<1, 0, 2>, S<1, 0, 2>, 2, 8, 8, 1, S<4, 32, 1>, S<1, 0, 2>, S<1, 0, 2>, 2, 8, 8, 1, 1, 1, S<1, 8, 1, 8>, 4>; | ||
| // clang-format on | ||
| #endif | ||
| using ReferenceGemmInstance = ck::tensor_operation::host::ReferenceGemm<ADataType, | ||
| BDataType, | ||
| CDataType, | ||
| AccDataType, | ||
| AElementOp, | ||
| BElementOp, | ||
| CElementOp, | ||
| ComputeDataType, | ||
| ComputeDataType>; | ||
|
|
||
| using ReferenceGemmInstanceGPU = ck::tensor_operation::device::ReferenceGemm<ALayout, | ||
| BLayout, | ||
| CLayout, | ||
| ADataType, | ||
| BDataType, | ||
| CDataType, | ||
| AccDataType, | ||
| AElementOp, | ||
| BElementOp, | ||
| CElementOp>; | ||
|
|
||
| #include "run_gemm_example.inc" | ||
|
|
||
| int main(int argc, char* argv[]) { return !run_gemm_example(argc, argv); } | ||
|
|
||
| #undef EXAMPLE_WITH_COMPUTE_DATATYPE | ||
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
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 |
|---|---|---|
|
|
@@ -27,10 +27,14 @@ void print_helper_msg() | |
| << ck::utils::conv::get_conv_param_parser_helper_msg() << std::endl; | ||
| } | ||
|
|
||
| template <typename DataType> | ||
| template <typename DataType, typename GemmType = DataType> | ||
| inline __host__ __device__ constexpr double get_rtol() | ||
| { | ||
| if constexpr(std::is_same_v<DataType, float>) | ||
| if constexpr(std::is_same_v<DataType, float> && std::is_same_v<GemmType, ck::tf32_t>) | ||
| { | ||
| return 5e-3; | ||
| } | ||
| else if constexpr(std::is_same_v<DataType, float>) | ||
| { | ||
| return 1e-3; | ||
| } | ||
|
|
@@ -68,10 +72,14 @@ inline __host__ __device__ constexpr double get_rtol() | |
| } | ||
| } | ||
|
|
||
| template <typename DataType> | ||
| template <typename DataType, typename GemmType = DataType> | ||
|
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. Compute Type
Contributor
Author
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. Done. |
||
| inline __host__ __device__ constexpr double get_atol() | ||
| { | ||
| if constexpr(std::is_same_v<DataType, float>) | ||
| if constexpr(std::is_same_v<DataType, float> && std::is_same_v<GemmType, ck::tf32_t>) | ||
| { | ||
| return 1e-2; | ||
| } | ||
| else if constexpr(std::is_same_v<DataType, float>) | ||
| { | ||
| return 1e-3; | ||
| } | ||
|
|
@@ -116,7 +124,8 @@ template <ck::index_t NDimSpatial, | |
| typename InElementOp, | ||
| typename WeiElementOp, | ||
| typename OutElementOp, | ||
| typename DeviceConvNDFwdInstance> | ||
| typename DeviceConvNDFwdInstance, | ||
| typename ComputeDataType = OutDataType> | ||
| bool run_grouped_conv_fwd(bool do_verification, | ||
| int init_method, | ||
| bool time_kernel, | ||
|
|
@@ -228,7 +237,11 @@ bool run_grouped_conv_fwd(bool do_verification, | |
| OutDataType, | ||
| InElementOp, | ||
| WeiElementOp, | ||
| OutElementOp>(); | ||
| OutElementOp, | ||
| 0, | ||
| 0, | ||
| 0, | ||
| ComputeDataType>(); | ||
|
|
||
| auto ref_invoker = ref_conv.MakeInvoker(); | ||
| auto ref_argument = ref_conv.MakeArgument(in, | ||
|
|
@@ -249,8 +262,8 @@ bool run_grouped_conv_fwd(bool do_verification, | |
| return ck::utils::check_err(out_device, | ||
| out_host, | ||
| "Error: incorrect results!", | ||
| get_rtol<OutDataType>(), | ||
| get_atol<OutDataType>()); | ||
| get_rtol<OutDataType, ComputeDataType>(), | ||
| get_atol<OutDataType, ComputeDataType>()); | ||
| } | ||
|
|
||
| return true; | ||
|
|
||
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,89 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| // Copyright (c) 2025, Advanced Micro Devices, Inc. All rights reserved. | ||
|
|
||
| #include "convnd_fwd_common.hpp" | ||
|
|
||
| #include "ck/tensor_operation/gpu/device/impl/device_grouped_conv_fwd_multiple_abd_xdl_cshuffle.hpp" | ||
|
|
||
| #include "ck/library/utility/convolution_host_tensor_descriptor_helper.hpp" | ||
|
|
||
| #define EXAMPLE_WITH_COMPUTE_DATATYPE | ||
|
|
||
| using InDataType = float; | ||
| using WeiDataType = float; | ||
| using AccDataType = float; | ||
| using CShuffleDataType = float; | ||
| using OutDataType = float; | ||
| using ComputeDataType = ck::tf32_t; | ||
|
|
||
| template <ck::index_t... Is> | ||
| using S = ck::Sequence<Is...>; | ||
|
|
||
| using InElementOp = ck::tensor_operation::element_wise::PassThrough; | ||
| using WeiElementOp = ck::tensor_operation::element_wise::PassThrough; | ||
| using OutElementOp = ck::tensor_operation::element_wise::PassThrough; | ||
|
|
||
| static constexpr auto ConvSpec = | ||
| ck::tensor_operation::device::ConvolutionForwardSpecialization::Default; | ||
|
|
||
| static constexpr auto GemmSpec = ck::tensor_operation::device::GemmSpecialization::MNKPadding; | ||
|
|
||
| template <ck::index_t NDimSpatial, typename InLayout, typename WeiLayout, typename OutLayout> | ||
| using DeviceGroupedConvNDFwdInstance = | ||
| ck::tensor_operation::device::DeviceGroupedConvFwdMultipleABD_Xdl_CShuffle< | ||
| NDimSpatial, | ||
| InLayout, // ALayout | ||
| WeiLayout, // BLayout | ||
| ck::Tuple<>, // DsLayout | ||
| OutLayout, // ELayout | ||
| InDataType, // ADataType | ||
| WeiDataType, // BDataType | ||
| AccDataType, // AccDataType | ||
| CShuffleDataType, // CShuffleDataType | ||
| ck::Tuple<>, // DsDataType | ||
| OutDataType, // EDataType | ||
| InElementOp, // AElementwiseOperation | ||
| WeiElementOp, // BElementwiseOperation | ||
| OutElementOp, // CDEElementwiseOperation | ||
| ConvSpec, // ConvForwardSpecialization | ||
| GemmSpec, // GemmSpecialization | ||
| 1, // NumGemmKPrefetchStage | ||
| 256, // BlockSize | ||
| 128, // MPerBlock | ||
| 192, // NPerBlock | ||
| 16, // KPerBlock | ||
| 4, // AK1 | ||
| 4, // BK1 | ||
| 32, // MPerXdl | ||
| 32, // NPerXdl | ||
| 2, // MXdlPerWave | ||
| 3, // NXdlPerWave | ||
| S<4, 64, 1>, // ABlockTransferThreadClusterLengths_AK0_M_AK1 | ||
| S<1, 0, 2>, // ABlockTransferThreadClusterArrangeOrder | ||
| S<1, 0, 2>, // ABlockTransferSrcAccessOrder | ||
| 2, // ABlockTransferSrcVectorDim | ||
| 4, // ABlockTransferSrcScalarPerVector | ||
| 4, // ABlockTransferDstScalarPerVector_AK1 | ||
| 1, // ABlockLdsExtraM | ||
| S<4, 64, 1>, // BBlockTransferThreadClusterLengths_BK0_N_BK1 | ||
| S<1, 0, 2>, // BBlockTransferThreadClusterArrangeOrder | ||
| S<1, 0, 2>, // BBlockTransferSrcAccessOrder | ||
| 2, // BBlockTransferSrcVectorDim | ||
| 4, // BBlockTransferSrcScalarPerVector | ||
| 4, // BBlockTransferDstScalarPerVector_BK1 | ||
| 1, // BBlockLdsExtraN | ||
| 1, // CShuffleMXdlPerWavePerShuffle | ||
| 1, // CShuffleNXdlPerWavePerShuffle | ||
| S<1, 16, 1, 16>, // CDEBlockTransferClusterLengths_MBlock_MPerBlock_NBlock_NPerBlock | ||
| 4, // CDEBlockTransferScalarPerVector_NPerBlock | ||
| ComputeDataType, // AComputeDataType | ||
| ComputeDataType, // BComputeDataType | ||
| ck::LoopScheduler::Default, // LoopScheduler | ||
| 1 // NumGroupsToMerge | ||
| >; | ||
|
|
||
| #include "run_convnd_fwd_example.inc" | ||
|
|
||
| int main(int argc, char* argv[]) { return run_convnd_fwd_example(argc, argv) ? 0 : 1; } | ||
|
|
||
| #undef EXAMPLE_WITH_COMPUTE_DATATYPE |
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
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.