Skip to content

Commit 5cb8109

Browse files
[rocm-libraries] ROCm/rocm-libraries#4640 (commit 37b8c81)
Fix the Composable Kernel CI and versions incompatibility (#4640) ## Motivation This PR has 4 patches: 1. Fix the CI error of grouped gemm. 2. Fix the incompatibility of old linux version. 3. Fix the potential errors of flatmm. 4. Address the previous comments of abquant eight warps pipeline solution.
1 parent 1f67684 commit 5cb8109

12 files changed

Lines changed: 67 additions & 65 deletions

File tree

example/12_reduce/reduce_blockwise_two_call.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ using DeviceReduceInstance_2 = DeviceReduceMultiBlock<InOutDataType,
8888
static bool do_verify;
8989
static int init_method;
9090
static float alpha;
91-
static float beta;
91+
static float beta_;
9292
static bool time_kernel;
9393

9494
int main(int argc, char* argv[])
@@ -150,7 +150,7 @@ int main(int argc, char* argv[])
150150
};
151151

152152
alpha = 1.0f;
153-
beta = 0.0f;
153+
beta_ = 0.0f;
154154

155155
Tensor<InOutDataType> in_1(inLengths_1);
156156

@@ -174,22 +174,22 @@ int main(int argc, char* argv[])
174174
case 0: break;
175175
case 1:
176176
in_1.GenerateTensorValue(GeneratorTensor_1<InOutDataType>{1}, num_thread);
177-
if(beta != 0.0f)
177+
if(beta_ != 0.0f)
178178
out_ref.GenerateTensorValue(GeneratorTensor_1<InOutDataType>{1}, num_thread);
179179
break;
180180
case 2:
181181
in_1.GenerateTensorValue(GeneratorTensor_2<InOutDataType>{-5, 5}, num_thread);
182-
if(beta != 0.0f)
182+
if(beta_ != 0.0f)
183183
out_ref.GenerateTensorValue(GeneratorTensor_2<InOutDataType>{-5, 5}, num_thread);
184184
break;
185185
default:
186186
in_1.GenerateTensorValue(GeneratorTensor_3<InOutDataType>{-5.0, 5.0}, num_thread);
187-
if(beta != 0.0f)
187+
if(beta_ != 0.0f)
188188
out_ref.GenerateTensorValue(GeneratorTensor_3<InOutDataType>{-5.0, 5.0},
189189
num_thread);
190190
}
191191

192-
if(beta != 0.0f)
192+
if(beta_ != 0.0f)
193193
for(size_t i = 0; i < out_ref.mDesc.GetElementSpaceSize(); i++)
194194
out.mData[i] = out_ref.mData[i];
195195
};
@@ -200,7 +200,7 @@ int main(int argc, char* argv[])
200200

201201
in_1_dev.ToDevice(in_1.mData.data());
202202

203-
if(beta != 0.0f)
203+
if(beta_ != 0.0f)
204204
out_dev.ToDevice(out.mData.data());
205205

206206
InElementwiseOperation in_elementwise_op;
@@ -246,7 +246,7 @@ int main(int argc, char* argv[])
246246
arrOutStrides,
247247
reduceDims,
248248
static_cast<double>(alpha),
249-
static_cast<double>(beta),
249+
static_cast<double>(beta_),
250250
in_1.mData.data(),
251251
nullptr,
252252
out_ref.mData.data(),
@@ -298,7 +298,7 @@ int main(int argc, char* argv[])
298298
arrOutStrides,
299299
reduceDims_2,
300300
static_cast<double>(alpha),
301-
static_cast<double>(beta),
301+
static_cast<double>(beta_),
302302
in_2_dev.GetDeviceBuffer(),
303303
nullptr,
304304
out_dev.GetDeviceBuffer(),

example/ck_tile/18_flatmm/flatmm_basic.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <ostream>
99
#include <string>
1010
#include <tuple>
11+
#include <numeric>
1112

1213
#include "ck_tile/host.hpp"
1314
#include "flatmm_basic.hpp"

example/ck_tile/18_flatmm/grouped_flatmm.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <ostream>
99
#include <string>
1010
#include <tuple>
11+
#include <numeric>
1112

1213
#include "flatmm_basic.hpp"
1314

example/ck_tile/18_flatmm/run_grouped_flatmm_example.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ int run_contiguous_grouped_flatmm_example_with_layouts(
166166
}
167167

168168
ck_tile::index_t M =
169-
std::reduce(Ms.begin(), Ms.begin() + group_count, 0, [](auto acc, auto group_m) {
169+
std::accumulate(Ms.begin(), Ms.begin() + group_count, 0, [](auto acc, auto group_m) {
170170
// round up to the multiple of BlockM
171171
return acc + (group_m + BlockM - 1) / BlockM * BlockM;
172172
});

example/ck_tile/38_block_scale_gemm/run_gemm_quant_example.inc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,19 @@ float gemm_calc_quant(const ck_tile::QuantGemmHostArgs& args, const ck_tile::str
3535
{
3636
static_assert(std::is_same_v<CLayout, ck_tile::tensor_layout::gemm::RowMajor>);
3737
constexpr bool IS_FP8BLOCKSCALE =
38-
QuantMode == ck_tile::QuantType::ABQuantGrouped && BQuantGroupSize::kN == 128 &&
38+
QuantMode == ck_tile::QuantType::ABQuantGrouped &&
3939
(std::is_same_v<typename TypeConfig::ADataType, ck_tile::fp8_t> ||
4040
std::is_same_v<typename TypeConfig::ADataType, ck_tile::bf8_t>) &&
4141
(std::is_same_v<typename TypeConfig::BDataType, ck_tile::fp8_t> ||
4242
std::is_same_v<typename TypeConfig::BDataType, ck_tile::bf8_t>);
4343
constexpr bool transpose_c = GemmConfig::TransposeC;
4444
constexpr bool eight_warps =
45-
IS_FP8BLOCKSCALE && BQuantGroupSize::kN == 128 &&
46-
(GemmConfig::M_Warp * GemmConfig::N_Warp * GemmConfig::K_Warp == 8) &&
45+
#ifdef CK_GFX950_SUPPORT
46+
IS_FP8BLOCKSCALE && (GemmConfig::M_Warp * GemmConfig::N_Warp * GemmConfig::K_Warp == 8) &&
4747
GemmConfig::K_Warp_Tile == 128;
48+
#else
49+
false;
50+
#endif
4851

4952
using ComputeDataType =
5053
std::conditional_t<IS_FP8BLOCKSCALE, typename TypeConfig::ADataType, void>;

include/ck_tile/core/config.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
#define CK_TILE_FLOAT_TO_BFLOAT16_RTA_ASM 4
7474

7575
#ifndef CK_TILE_FLOAT_TO_BFLOAT16_DEFAULT
76-
#define CK_TILE_FLOAT_TO_BFLOAT16_DEFAULT CK_TILE_FLOAT_TO_BFLOAT16_TRUNCATE
76+
#define CK_TILE_FLOAT_TO_BFLOAT16_DEFAULT CK_TILE_FLOAT_TO_BFLOAT16_STANDARD
7777
#endif
7878

7979
#define CK_TILE_FLOAT_TO_FP8_STANDARD 0

include/ck_tile/host/check_err.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ CK_TILE_HOST double get_absolute_threshold(const double max_possible_num,
137137
int>::value,
138138
"Warning: Unhandled ComputeDataType for setting up the absolute threshold!");
139139

140-
auto expo = std::log2(std::abs(max_possible_num));
140+
auto expo = std::floor(std::log2(std::abs(max_possible_num)));
141141
double compute_error = 0;
142142
if constexpr(is_any_of<ComputeDataType, pk_int4_t, I8, I32, int>::value)
143143
{
@@ -158,7 +158,7 @@ CK_TILE_HOST double get_absolute_threshold(const double max_possible_num,
158158
}
159159
else
160160
{
161-
output_error = std::pow(2, expo - numeric_traits<OutDataType>::mant) * 0.5;
161+
output_error = std::pow(2, expo - numeric_traits<OutDataType>::mant) * 1.0;
162162
}
163163
double midway_error = std::max(compute_error, output_error);
164164

include/ck_tile/host/device_prop.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,7 @@ inline bool is_gfx12_supported()
6565
return get_device_name() == "gfx1200" || get_device_name() == "gfx1201";
6666
}
6767

68-
inline bool is_gfx95_supported()
69-
{
70-
// Check if load transpose is supported.
71-
return get_device_name() == "gfx950";
72-
}
68+
inline bool is_gfx95_supported() { return get_device_name() == "gfx950"; }
7369

7470
inline size_t get_num_cus()
7571
{

include/ck_tile/ops/epilogue/cshuffle_epilogue.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ struct CShuffleEpilogue
116116
static constexpr index_t isCTransposed = Problem::isCTransposed;
117117
static constexpr bool FixedVectorSize = Problem::FixedVectorSize;
118118
static constexpr bool TiledMMAPermuteN = Problem::TiledMMAPermuteN;
119-
#ifdef __gfx9__
120-
static constexpr bool AsyncPipeline = (MWave * NWave == 8);
119+
#ifdef __gfx95__
120+
static constexpr bool EightWave = (MWave * NWave == 8);
121121
#else
122-
static constexpr bool AsyncPipeline = false;
122+
static constexpr bool EightWave = false;
123123
#endif
124124
static constexpr index_t BlockedXDLN_PerWarp =
125-
AsyncPipeline ? kNPerBlock / NWave / NPerXdl : Problem::BlockedXDLN_PerWarp;
125+
EightWave ? kNPerBlock / NWave / NPerXdl : Problem::BlockedXDLN_PerWarp;
126126
static constexpr bool DoubleSmemBuffer = Problem::DoubleSmemBuffer;
127127
static constexpr index_t VectorSizeC = Problem::VectorSizeC;
128128
static constexpr index_t MPerIteration = MPerXdl * MWave;
@@ -447,7 +447,7 @@ struct CShuffleEpilogue
447447
if constexpr(is_950 || is_any_of<ADataType, pk_int4_t, pk_fp4_t>::value ||
448448
is_any_of<BDataType, pk_int4_t, pk_fp4_t>::value)
449449
{
450-
if constexpr(AsyncPipeline)
450+
if constexpr(EightWave)
451451
{
452452
return tile_distribution_encoding<
453453
sequence<>,

include/ck_tile/ops/flatmm/kernel/flatmm_kernel.hpp

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -780,29 +780,31 @@ struct FlatmmKernel
780780
const SplitKBatchOffset& splitk_batch_offset,
781781
const index_t block_idx_m)
782782
{
783-
constexpr int ScaleGranularityM = decltype(kargs.scale_m_ptr)::GranularityMN;
784-
constexpr int ScaleGranularityKA = decltype(kargs.scale_m_ptr)::GranularityK;
783+
constexpr int GM = decltype(kargs.scale_m_ptr)::GranularityMN;
784+
constexpr int GK = decltype(kargs.scale_m_ptr)::GranularityK;
785785

786-
auto scale_stride_m = ScaleGranularityM == 0 ? 0 // per-tensor scale
787-
: 1; // per-token scale
786+
static_assert(GM != -1,
787+
"MakeScaleMWindow should only be instantiated when scale is enabled");
788+
789+
// per-tensor (GM==0) -> Mdim = 1, stride 0
790+
const index_t m_dim = (GM == 0) ? 1 : (kargs.M / GM);
791+
const index_t m_stride = (GM == 0) ? 0 : 1;
792+
793+
const index_t k_dim = (GK == 0) ? 1 : (splitk_batch_offset.splitted_k / GK);
794+
const index_t k_stride = 0; // your original code keeps K stride 0
788795

789-
// Step 1: Create tensor view
790796
const auto scale_m_view = make_naive_tensor_view<address_space_enum::global>(
791797
kargs.scale_m_ptr.ptr,
792-
make_tuple(kargs.M / ScaleGranularityM,
793-
ScaleGranularityKA == 0
794-
? 1
795-
: (splitk_batch_offset.splitted_k / ScaleGranularityKA)),
796-
make_tuple(scale_stride_m, 0),
797-
number < ScaleGranularityM == 1 ? FlatmmPipeline::GetVectorSizeA() : 1 > {},
798+
make_tuple(m_dim, k_dim),
799+
make_tuple(m_stride, k_stride),
800+
number < (GM == 1) ? FlatmmPipeline::GetVectorSizeA() : 1 > {},
798801
number<1>{});
799802

800-
// Step 2: Create tile window
803+
// Window extents: if GM==0, we still just broadcast from [0,*]
801804
return make_tile_window(scale_m_view,
802805
make_tuple(number<TilePartitioner::MPerBlock>{},
803-
number < ScaleGranularityKA == 0
804-
? TilePartitioner::NPerBlock
805-
: TilePartitioner::KPerBlock > {}),
806+
number < (GK == 0) ? TilePartitioner::NPerBlock
807+
: TilePartitioner::KPerBlock > {}),
806808
{block_idx_m, 0});
807809
}
808810

@@ -811,27 +813,29 @@ struct FlatmmKernel
811813
const SplitKBatchOffset& splitk_batch_offset,
812814
const index_t block_idx_n)
813815
{
814-
constexpr int ScaleGranularityN = decltype(kargs.scale_n_ptr)::GranularityMN;
815-
constexpr int ScaleGranularityKB = decltype(kargs.scale_n_ptr)::GranularityK;
816+
constexpr int GN = decltype(kargs.scale_n_ptr)::GranularityMN;
817+
constexpr int GK = decltype(kargs.scale_n_ptr)::GranularityK;
816818

817-
auto scale_stride_n = ScaleGranularityN == 0 ? 0 // per-tensor scale
818-
: 1; // per-channel scale
819+
static_assert(GN != -1,
820+
"MakeScaleNWindow should only be instantiated when scale is enabled");
821+
822+
// per-tensor (GN==0) -> Ndim = 1, stride 0
823+
const index_t n_dim = (GN == 0) ? 1 : (kargs.N / GN);
824+
const index_t n_stride = (GN == 0) ? 0 : 1;
825+
826+
const index_t k_dim = (GK == 0) ? 1 : (splitk_batch_offset.splitted_k / GK);
827+
const index_t k_stride = 0;
819828

820-
// Step 1: Create tensor view
821829
const auto scale_n_view = make_naive_tensor_view<address_space_enum::global>(
822830
kargs.scale_n_ptr.ptr,
823-
make_tuple(
824-
ScaleGranularityKB == 0 ? 1 : (splitk_batch_offset.splitted_k / ScaleGranularityKB),
825-
kargs.N / ScaleGranularityN),
826-
make_tuple(0, scale_stride_n),
827-
number < ScaleGranularityN == 1 ? FlatmmPipeline::GetVectorSizeB() : 1 > {},
831+
make_tuple(k_dim, n_dim),
832+
make_tuple(k_stride, n_stride),
833+
number < (GN == 1) ? FlatmmPipeline::GetVectorSizeB() : 1 > {},
828834
number<1>{});
829835

830-
// Step 2: Create tile window
831836
return make_tile_window(scale_n_view,
832-
make_tuple(number < ScaleGranularityKB == 0
833-
? TilePartitioner::MPerBlock
834-
: TilePartitioner::KPerBlock > {},
837+
make_tuple(number < (GK == 0) ? TilePartitioner::MPerBlock
838+
: TilePartitioner::KPerBlock > {},
835839
number<TilePartitioner::NPerBlock>{}),
836840
{0, block_idx_n});
837841
}
@@ -854,8 +858,6 @@ struct FlatmmKernel
854858
MakeABlockWindow(a_ptr, kargs, splitk_batch_offset.splitted_k, block_idx_m);
855859
const auto& b_flat_block_window = MakeBFlatBlockWindow(b_flat_ptr, kargs, block_idx_n);
856860
const auto& ds_block_window = MakeDBlockWindows(ds_ptr, kargs, block_idx_m, block_idx_n);
857-
const auto& scale_m_window = MakeScaleMWindow(kargs, splitk_batch_offset, block_idx_m);
858-
const auto& scale_n_window = MakeScaleNWindow(kargs, splitk_batch_offset, block_idx_n);
859861

860862
const index_t num_loop = TilePartitioner::GetLoopNum(splitk_batch_offset.splitted_k);
861863

@@ -866,6 +868,8 @@ struct FlatmmKernel
866868
// Run Epilogue Pipeline with k_batch dispatching
867869
if constexpr(ScaleM::GranularityMN != -1 || ScaleN::GranularityMN != -1)
868870
{
871+
const auto& scale_m_window = MakeScaleMWindow(kargs, splitk_batch_offset, block_idx_m);
872+
const auto& scale_n_window = MakeScaleNWindow(kargs, splitk_batch_offset, block_idx_n);
869873
if(kargs.k_batch == 1)
870874
{
871875
auto e_block_window = MakeEBlockWindow<memory_operation_enum::set>(

0 commit comments

Comments
 (0)