Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
6e12aeb
Create test_sm90_fp8_fp4.py
zhangxiaolei123456 May 11, 2026
b118d88
Create sm90_fp8_fp4_gemm_1d1d.cuh
zhangxiaolei123456 May 11, 2026
561cf21
Create sm90_fp8_fp4_gemm_1d2d.cuh
zhangxiaolei123456 May 11, 2026
4122a7d
Update gemm.hpp
zhangxiaolei123456 May 11, 2026
b3d92e0
Update __init__.py
zhangxiaolei123456 May 11, 2026
825cbdb
Update __init__.py
zhangxiaolei123456 May 11, 2026
9625f4f
Update test_sm90_fp8_fp4.py
zhangxiaolei123456 May 11, 2026
6a3b1ee
Merge pull request #1 from zhangxiaolei123456/zhangxiaolei123456-patch-1
zhangxiaolei123456 May 11, 2026
043f007
Create sm90_fp8_fp4_gemm_1d2d.hpp
zhangxiaolei123456 May 11, 2026
eebc4f4
Update sm90_fp8_fp4_gemm_1d2d.hpp
zhangxiaolei123456 May 11, 2026
48dec94
Update ld_st.cuh
zhangxiaolei123456 May 11, 2026
2520585
Update sm90_fp8_fp4_gemm_1d2d.cuh
zhangxiaolei123456 May 11, 2026
214baaf
Update test_sm90_fp8_fp4.py
zhangxiaolei123456 May 11, 2026
4392c08
Update test_sm90_fp8_fp4.py
zhangxiaolei123456 May 11, 2026
83cd196
Update gemm.hpp
zhangxiaolei123456 May 11, 2026
02ff071
Update gemm.hpp
zhangxiaolei123456 May 18, 2026
2f98946
Update layout.hpp
zhangxiaolei123456 May 18, 2026
d2e9012
Update sm90_fp8_fp4_gemm_1d2d.hpp
zhangxiaolei123456 May 18, 2026
307455a
Create sm90_fp8_fp4_gemm_1d2d_rs.hpp
zhangxiaolei123456 May 18, 2026
d7f3149
Update smxx_layout.hpp
zhangxiaolei123456 May 18, 2026
79a5c8c
Update layout.hpp
zhangxiaolei123456 May 18, 2026
08d51f2
Update __init__.py
zhangxiaolei123456 May 18, 2026
8542680
Update sm90_fp8_fp4_gemm_1d2d.cuh
zhangxiaolei123456 May 18, 2026
698155f
Create sm90_fp8_fp4_gemm_1d2d_rs.cuh
zhangxiaolei123456 May 18, 2026
fafbce3
Update sm90.cuh
zhangxiaolei123456 May 18, 2026
53c15be
Update math.py
zhangxiaolei123456 May 18, 2026
87debb1
Update test_sm90_fp8_fp4.py
zhangxiaolei123456 May 18, 2026
f05e493
Update test_sm90_fp8_fp4.py
zhangxiaolei123456 May 19, 2026
f784be7
Create test_sm90_int4_a8.py
zhangxiaolei123456 May 27, 2026
b6aa5d7
Update gemm.hpp
zhangxiaolei123456 May 27, 2026
31a6971
Update layout.hpp
zhangxiaolei123456 May 27, 2026
30b26f4
Update sm90_fp8_fp4_gemm_1d2d.hpp
zhangxiaolei123456 May 27, 2026
8d4894f
Update sm90_fp8_fp4_gemm_1d2d_rs.hpp
zhangxiaolei123456 May 27, 2026
29cfbf6
Update smxx_layout.hpp
zhangxiaolei123456 May 27, 2026
8d8aaf6
Update layout.hpp
zhangxiaolei123456 May 27, 2026
0603791
Update math.py
zhangxiaolei123456 May 27, 2026
48689a1
Update test_sm90_fp8_fp4.py
zhangxiaolei123456 May 27, 2026
720da9f
Update sm90_fp8_fp4_gemm_1d2d_rs.hpp
zhangxiaolei123456 Jun 2, 2026
180e71c
Update sm90_fp8_fp4_gemm_1d2d_rs.cuh
zhangxiaolei123456 Jun 2, 2026
40c4fb2
Support redundant expert groups in FP4 fast path
zhangxiaolei123456 Jun 8, 2026
a3646af
Merge pull request #2 from zhangxiaolei123456/fix/dsv4-num-groups-36
zhangxiaolei123456 Jun 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions csrc/apis/gemm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#if DG_FP8_COMPATIBLE and DG_TENSORMAP_COMPATIBLE
#include "../jit_kernels/impls/sm90_fp8_gemm_1d1d.hpp"
#include "../jit_kernels/impls/sm90_fp8_gemm_1d2d.hpp"
#include "../jit_kernels/impls/sm90_fp8_fp4_gemm_1d2d.hpp"
#include "../jit_kernels/impls/sm90_bf16_gemm.hpp"
#include "../jit_kernels/impls/sm100_fp8_fp4_gemm_1d1d.hpp"
#include "../jit_kernels/impls/sm100_bf16_gemm.hpp"
Expand Down Expand Up @@ -140,6 +141,27 @@ static void fp8_fp4_gemm_tt(const std::pair<torch::Tensor, torch::Tensor>& a,
d, c, recipe, recipe_a, recipe_b, compiled_dims, disable_ue8m0_cast);
}

static void fp8_fp4_gemm_nt_sm90_fused_wgmma(const std::pair<torch::Tensor, torch::Tensor>& a,
const std::pair<torch::Tensor, torch::Tensor>& b,
const torch::Tensor& d,
const std::optional<torch::Tensor>& c,
const int& gran_k,
const std::string& compiled_dims) {
const auto [m, k] = get_shape<2>(a.first);
const auto [n, half_k] = get_shape<2>(b.first);
DG_HOST_ASSERT(half_k * 2 == k);

std::optional<std::tuple<int, int, int>> recipe = std::nullopt;
std::optional<std::tuple<int, int>> recipe_a = std::make_tuple(1, gran_k);
std::optional<std::tuple<int, int>> recipe_b = std::make_tuple(1, gran_k);
const auto [sfa, sfb, gran_k_a, gran_k_b] = layout::transform_sf_pair_into_required_layout(
a.second, b.second, m, n, k, recipe, recipe_a, recipe_b, std::nullopt, std::nullopt, false);
DG_HOST_ASSERT(gran_k_a == gran_k and gran_k_b == gran_k);

sm90_fp8_fp4_gemm_1d1d_fused(
{a.first, sfa}, {b.first, sfb}, d, c, gran_k, compiled_dims);
}

static void m_grouped_fp8_fp4_gemm_nt_contiguous(const std::pair<torch::Tensor, torch::Tensor>& a,
const std::pair<torch::Tensor, torch::Tensor>& b,
const torch::Tensor& d,
Expand Down Expand Up @@ -624,6 +646,37 @@ static void register_apis(pybind11::module_& m) {
py::arg("recipe_a") = std::nullopt, py::arg("recipe_b") = std::nullopt,
py::arg("compiled_dims") = "mn",
py::arg("disable_ue8m0_cast") = false);
m.def("fp8_fp4_gemm_nt_sm90_fused_wgmma", &fp8_fp4_gemm_nt_sm90_fused_wgmma,
py::arg("a"), py::arg("b"), py::arg("d"),
py::arg("c") = std::nullopt,
py::arg("gran_k") = 128,
py::arg("compiled_dims") = "nk");
m.def("m_grouped_fp8_fp4_gemm_nt_contiguous_sm90_fused_wgmma",
&sm90_m_grouped_fp8_fp4_gemm_contiguous_1d1d_fused,
py::arg("a"), py::arg("b"), py::arg("d"), py::arg("grouped_layout"),
py::arg("gran_k") = 128,
py::arg("compiled_dims") = "nk",
py::arg("use_psum_layout") = false,
py::arg("expected_m_for_psum_layout") = std::nullopt,
py::arg("block_m_override") = std::nullopt,
py::arg("block_n_override") = std::nullopt,
py::arg("decode_stub") = false);
m.def("m_grouped_fp8_fp4_gemm_nt_masked_sm90_fused_wgmma",
&sm90_m_grouped_fp8_fp4_gemm_masked_1d1d_fused,
py::arg("a"), py::arg("b"), py::arg("d"), py::arg("masked_m"),
py::arg("expected_m"),
py::arg("gran_k") = 128,
py::arg("gran_k_a") = std::nullopt,
py::arg("gran_k_b") = std::nullopt,
py::arg("compiled_dims") = "nk",
py::arg("block_m_override") = std::nullopt,
py::arg("block_n_override") = std::nullopt,
py::arg("decode_stub") = false,
py::arg("b_is_int4_sym") = false,
py::arg("masked_m_max_hint") = std::nullopt,
py::arg("active_groups_hint") = std::nullopt);
m.attr("m_grouped_fp8_fp4_gemm_nt_mask_sm90_fused_wgmma") =
m.attr("m_grouped_fp8_fp4_gemm_nt_masked_sm90_fused_wgmma");
m.def("m_grouped_fp8_fp4_gemm_nt_contiguous", &m_grouped_fp8_fp4_gemm_nt_contiguous,
py::arg("a"), py::arg("b"), py::arg("d"), py::arg("grouped_layout"),
py::arg("recipe") = std::nullopt,
Expand Down
19 changes: 17 additions & 2 deletions csrc/apis/layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,23 @@ static torch::Tensor transform_sf_into_required_layout(const torch::Tensor& sf,
// Pre-transform checks
check_sf_layout(sf, mn, k, gran_mn, gran_k, num_groups);

// (FP32, 1, 128) on SM90: transform to TMA-aligned and MN-major
if (sf.scalar_type() == torch::kFloat and gran_mn == 1 and gran_k == 128 and (arch_major == 9 or disable_ue8m0_cast))
// (BF16, 1, 32/128) on SM90 SFB fast path: path-A (k128) 与 path-B fast-path (k32)
// 都支持 bf16 sfb,体积砍半。tensor 已由调用方按 MN-major + tma_aligned_mn=align(N,8)
// 构造,这里跳过 fp32 only 的 transpose,直接复用 align 路径。
if (sf.scalar_type() == torch::kBFloat16 and gran_mn == 1 and (gran_k == 32 or gran_k == 128) and arch_major == 9)
return get_mn_major_tma_aligned_tensor(sf);
// (UInt8/E8M0, 1, 32) on SM90 SFB fast path:path-B 专用,每元素 1B 即 fp32 的
// 8 位指数。tensor 已由调用方按 MN-major + tma_aligned_mn=align(N,16) 构造。
if (sf.scalar_type() == torch::kUInt8 and gran_mn == 1 and gran_k == 32 and arch_major == 9)
return get_mn_major_tma_aligned_tensor(sf);

// (FP32, 1, 32/128) on SM90: transform to TMA-aligned and MN-major
if (sf.scalar_type() == torch::kFloat and gran_mn == 1 and (gran_k == 32 or gran_k == 128) and
(arch_major == 9 or disable_ue8m0_cast))
return get_mn_major_tma_aligned_tensor(sf);

// (INT packed UE8M0, 1, 32/128) on SM90: transform to TMA-aligned and MN-major.
if (sf.scalar_type() == torch::kInt and gran_mn == 1 and (gran_k == 32 or gran_k == 128) and arch_major == 9)
return get_mn_major_tma_aligned_tensor(sf);

// (FP32, 128, 128) on SM90: no need to transform, check SFB requirements
Expand Down
Loading