-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Batched GEMM Multiple D based on Universal GEMM (#1655)
* Batched GEMM Multiple D based on Universal GEMM Co-authored-by: Jing Zhang <[email protected]> * CI fixes Co-authored-by: Jing Zhang <[email protected]> --------- Co-authored-by: Jing Zhang <[email protected]>
- Loading branch information
Showing
21 changed files
with
2,655 additions
and
11 deletions.
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 |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) 2024, Advanced Micro Devices, Inc. All rights reserved. | ||
#include <iostream> | ||
#include <numeric> | ||
#include <initializer_list> | ||
#include <cstdlib> | ||
|
||
#include "ck/ck.hpp" | ||
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp" | ||
#include "ck/tensor_operation/gpu/device/gemm_specialization.hpp" | ||
#include "ck/tensor_operation/gpu/device/impl/device_batched_gemm_multiple_d_xdl_cshuffle_v3.hpp" | ||
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp" | ||
|
||
#include "ck/library/utility/check_err.hpp" | ||
#include "ck/library/utility/device_memory.hpp" | ||
#include "ck/library/utility/host_tensor.hpp" | ||
#include "ck/library/utility/host_tensor_generator.hpp" | ||
#include "ck/library/reference_tensor_operation/cpu/reference_batched_gemm.hpp" | ||
#include "ck/library/utility/literals.hpp" | ||
|
||
template <ck::index_t... Is> | ||
using S = ck::Sequence<Is...>; | ||
|
||
using BF16 = ck::bhalf_t; | ||
using F32 = float; | ||
|
||
using Row = ck::tensor_layout::gemm::RowMajor; | ||
using Col = ck::tensor_layout::gemm::ColumnMajor; | ||
|
||
using PassThrough = ck::tensor_operation::element_wise::PassThrough; | ||
|
||
using ADataType = BF16; | ||
using BDataType = BF16; | ||
using AccDataType = F32; | ||
using CShuffleDataType = BF16; | ||
using DsDataType = ck::Tuple<>; | ||
using EDataType = BF16; | ||
|
||
using ALayout = Row; | ||
using BLayout = Col; | ||
using DsLayout = ck::Tuple<>; | ||
using ELayout = Row; | ||
|
||
using AElementOp = PassThrough; | ||
using BElementOp = PassThrough; | ||
using CDEElementOp = PassThrough; | ||
|
||
static constexpr auto GemmDefault = ck::tensor_operation::device::GemmSpecialization::Default; | ||
|
||
using DeviceGemmInstance = ck::tensor_operation::device::DeviceBatchedGemmMultiD_Xdl_CShuffle_V3< | ||
ALayout, | ||
BLayout, | ||
DsLayout, | ||
ELayout, | ||
ADataType, | ||
BDataType, | ||
DsDataType, | ||
EDataType, | ||
AccDataType, | ||
CShuffleDataType, | ||
AElementOp, | ||
BElementOp, | ||
CDEElementOp, | ||
GemmDefault, | ||
256, // BlockSize | ||
256, // MPerBlock | ||
128, // NPerBlock | ||
32, // KPerBlock | ||
8, // AK1 | ||
8, // BK1 | ||
32, // MPerXDL | ||
32, // NPerXDL | ||
4, // MXdlPerWave | ||
2, // NXdlPerWave | ||
S<4, 64, 1>, // ABlockTransferThreadClusterLengths_AK0_M_AK1 | ||
S<1, 0, 2>, // ABlockTransferThreadClusterArrangeOrder | ||
S<1, 0, 2>, // ABlockTransferSrcAccessOrder | ||
2, // ABlockTransferSrcVectorDim | ||
8, // ABlockTransferSrcScalarPerVector | ||
8, // ABlockTransferDstScalarPerVector_AK1 | ||
1, // ABlockLdsExtraM | ||
S<4, 64, 1>, // BBlockTransferThreadClusterLengths_BK0_N_BK1 | ||
S<1, 0, 2>, // BBlockTransferThreadClusterArrangeOrder | ||
S<1, 0, 2>, // BBlockTransferSrcAccessOrder | ||
2, // BBlockTransferSrcVectorDim | ||
8, // BBlockTransferSrcScalarPerVector | ||
8, // BBlockTransferDstScalarPerVector_BK1 | ||
1, // BBlockLdsExtraN | ||
1, // CShuffleMXdlPerWavePerShuffle | ||
1, // CShuffleNXdlPerWavePerShuffle | ||
S<1, 32, 1, 8>, // CShuffleBlockTransferClusterLengths_MBlock_MPerBlock_NBlock_NPerBlock | ||
S<8>, // CDEShuffleBlockTransferScalarPerVectors | ||
ck::BlockGemmPipelineScheduler::Intrawave, // BlockGemmPipelineScheduler | ||
ck::BlockGemmPipelineVersion::v3 // BlockGemmPipelineVersion | ||
>; | ||
|
||
#include "run_batched_gemm_example.inc" | ||
|
||
int main(int argc, char* argv[]) { return !run_batched_gemm_example(argc, argv); } |
106 changes: 106 additions & 0 deletions
106
example/24_batched_gemm/batched_gemm_xdl_fp8_rowwise_v3.cpp
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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// SPDX-License-Identifier: MIT | ||
// Copyright (c) 2024, Advanced Micro Devices, Inc. All rights reserved. | ||
#include <iostream> | ||
#include <numeric> | ||
#include <initializer_list> | ||
#include <cstdlib> | ||
|
||
#include "ck/ck.hpp" | ||
#include "ck/tensor_operation/gpu/device/tensor_layout.hpp" | ||
#include "ck/tensor_operation/gpu/device/gemm_specialization.hpp" | ||
#include "ck/tensor_operation/gpu/device/impl/device_batched_gemm_multiple_d_xdl_cshuffle_v3.hpp" | ||
#include "ck/tensor_operation/gpu/element/element_wise_operation.hpp" | ||
|
||
#include "ck/library/utility/check_err.hpp" | ||
#include "ck/library/utility/device_memory.hpp" | ||
#include "ck/library/utility/host_tensor.hpp" | ||
#include "ck/library/utility/host_tensor_generator.hpp" | ||
#include "ck/library/reference_tensor_operation/cpu/reference_batched_gemm.hpp" | ||
#include "ck/library/utility/literals.hpp" | ||
|
||
template <ck::index_t... Is> | ||
using S = ck::Sequence<Is...>; | ||
|
||
using F8 = ck::f8_t; | ||
using BF16 = ck::bhalf_t; | ||
using F32 = float; | ||
|
||
using Row = ck::tensor_layout::gemm::RowMajor; | ||
using Col = ck::tensor_layout::gemm::ColumnMajor; | ||
|
||
using PassThrough = ck::tensor_operation::element_wise::PassThrough; | ||
using MultiplyMultiply = ck::tensor_operation::element_wise::MultiplyMultiply; | ||
|
||
using ADataType = F8; | ||
using BDataType = F8; | ||
using AccDataType = F32; | ||
using CShuffleDataType = F32; | ||
using D0DataType = F32; | ||
using D1DataType = F32; | ||
using DsDataType = ck::Tuple<D0DataType, D1DataType>; | ||
using EDataType = BF16; | ||
|
||
using ALayout = Row; | ||
using BLayout = Col; | ||
using D0Layout = Row; | ||
using D1Layout = Col; | ||
using DsLayout = ck::Tuple<D0Layout, D1Layout>; | ||
using ELayout = Row; | ||
|
||
using AElementOp = PassThrough; | ||
using BElementOp = PassThrough; | ||
using CDEElementOp = MultiplyMultiply; | ||
|
||
static constexpr auto GemmDefault = ck::tensor_operation::device::GemmSpecialization::Default; | ||
|
||
using DeviceGemmInstance = ck::tensor_operation::device::DeviceBatchedGemmMultiD_Xdl_CShuffle_V3< | ||
ALayout, | ||
BLayout, | ||
DsLayout, | ||
ELayout, | ||
ADataType, | ||
BDataType, | ||
DsDataType, | ||
EDataType, | ||
AccDataType, | ||
CShuffleDataType, | ||
AElementOp, | ||
BElementOp, | ||
CDEElementOp, | ||
GemmDefault, | ||
256, // BlockSize | ||
256, // MPerBlock | ||
128, // NPerBlock | ||
32, // KPerBlock | ||
8, // AK1 | ||
8, // BK1 | ||
32, // MPerXDL | ||
32, // NPerXDL | ||
4, // MXdlPerWave | ||
2, // NXdlPerWave | ||
S<4, 64, 1>, // ABlockTransferThreadClusterLengths_AK0_M_AK1 | ||
S<1, 0, 2>, // ABlockTransferThreadClusterArrangeOrder | ||
S<1, 0, 2>, // ABlockTransferSrcAccessOrder | ||
2, // ABlockTransferSrcVectorDim | ||
8, // ABlockTransferSrcScalarPerVector | ||
8, // ABlockTransferDstScalarPerVector_AK1 | ||
1, // ABlockLdsExtraM | ||
S<4, 64, 1>, // BBlockTransferThreadClusterLengths_BK0_N_BK1 | ||
S<1, 0, 2>, // BBlockTransferThreadClusterArrangeOrder | ||
S<1, 0, 2>, // BBlockTransferSrcAccessOrder | ||
2, // BBlockTransferSrcVectorDim | ||
8, // BBlockTransferSrcScalarPerVector | ||
8, // BBlockTransferDstScalarPerVector_BK1 | ||
1, // BBlockLdsExtraN | ||
1, // CShuffleMXdlPerWavePerShuffle | ||
1, // CShuffleNXdlPerWavePerShuffle | ||
S<1, 32, 1, 8>, // CShuffleBlockTransferClusterLengths_MBlock_MPerBlock_NBlock_NPerBlock | ||
S<8, 8, 1>, // CDEShuffleBlockTransferScalarPerVectors | ||
ck::BlockGemmPipelineScheduler::Interwave, // BlockGemmPipelineScheduler | ||
ck::BlockGemmPipelineVersion::v1, // BlockGemmPipelineVersion | ||
F8 // ComputeTypeA | ||
>; | ||
|
||
#include "run_batched_gemm_example_rowwise.inc" | ||
|
||
int main(int argc, char* argv[]) { return !run_batched_gemm_rowwise_example(argc, argv); } |
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.