PTQ-Level Efficiency, QAT-Level Accuracy | 训练后量化的效率,量化感知训练的精度
set(SYCL_TLA_GENERATED_DIR ${CMAKE_CURRENT_BINARY_DIR}/generated/sycl_tla)
set(SYCL_TLA_TEMPLATE_DIR ${CMAKE_CURRENT_LIST_DIR})
file(MAKE_DIRECTORY ${SYCL_TLA_GENERATED_DIR})
function(generate_sycl_tla_source template_name output_name)
set(_generated_src ${SYCL_TLA_GENERATED_DIR}/${output_name})
configure_file(${SYCL_TLA_TEMPLATE_DIR}/${template_name} ${_generated_src} @ONLY)
list(APPEND SYCL_TLA_GENERATED_SRCS ${_generated_src})
set(SYCL_TLA_GENERATED_SRCS ${SYCL_TLA_GENERATED_SRCS} PARENT_SCOPE)
endfunction()
set(DENSE_SOURCE_MODE 1)
set(S8_SOURCE_MODE 0)
set(_dense_dtypes f16 bf16 f32)
foreach(_dense_dtype IN LISTS _dense_dtypes)
if(_dense_dtype STREQUAL "f16")
set(DENSE_ELEMENT_TYPE "cute::half_t")
elseif(_dense_dtype STREQUAL "bf16")
set(DENSE_ELEMENT_TYPE "cute::bfloat16_t")
else()
set(DENSE_ELEMENT_TYPE "float")
endif()
foreach(_dense_bias IN ITEMS bias no_bias)
if(_dense_bias STREQUAL "bias")
set(DENSE_HAS_BIAS true)
set(DENSE_FUNCTION_BIAS with_bias)
set(DENSE_BIAS_PARAMETER ", const void* bias")
set(DENSE_BIAS_ARGUMENT "static_cast<const ${DENSE_ELEMENT_TYPE}*>(bias)")
else()
set(DENSE_HAS_BIAS false)
set(DENSE_FUNCTION_BIAS without_bias)
set(DENSE_BIAS_PARAMETER "")
set(DENSE_BIAS_ARGUMENT "static_cast<const ${DENSE_ELEMENT_TYPE}*>(nullptr)")
endif()
foreach(_dense_tile IN ITEMS small mid medium large)
if(_dense_tile STREQUAL "small")
set(DENSE_TILE_M 8)
set(DENSE_TILE_N 128)
set(DENSE_LAYOUT DenseSmallTileSG)
set(_dense_output sycl_tla_dense_gemm_${_dense_dtype}_${_dense_bias}.cpp)
elseif(_dense_tile STREQUAL "mid")
set(DENSE_TILE_M 64)
set(DENSE_TILE_N 128)
set(DENSE_LAYOUT DenseSmallMidTileSG)
set(_dense_output sycl_tla_dense_gemm_${_dense_dtype}_${_dense_bias}_mid.cpp)
elseif(_dense_tile STREQUAL "medium")
set(DENSE_TILE_M 128)
set(DENSE_TILE_N 128)
set(DENSE_LAYOUT DenseMediumTileSG)
set(_dense_output sycl_tla_dense_gemm_${_dense_dtype}_${_dense_bias}_medium.cpp)
else()
set(DENSE_TILE_M 256)
set(DENSE_TILE_N 256)
set(DENSE_LAYOUT DenseLargeTileSG)
set(_dense_output sycl_tla_dense_gemm_${_dense_dtype}_${_dense_bias}_large.cpp)
endif()
set(DENSE_FUNCTION_NAME run_${_dense_dtype}_${DENSE_FUNCTION_BIAS}_${_dense_tile})
generate_sycl_tla_source(sycl_tla_gemm.cpp.in ${_dense_output})
endforeach()
endforeach()
endforeach()
set(DENSE_SOURCE_MODE 0)
set(S8_SOURCE_MODE 1)
set(S8_KBLOCK_SUPPORTED 0)
set(_s8_dtypes f16 bf16 f32)
foreach(_s8_dtype IN LISTS _s8_dtypes)
if(_s8_dtype STREQUAL "f16")
set(S8_ELEMENT_TYPE "cute::half_t")
elseif(_s8_dtype STREQUAL "bf16")
set(S8_ELEMENT_TYPE "cute::bfloat16_t")
else()
set(S8_ELEMENT_TYPE "float")
endif()
set(_s8_paths normal)
if(NOT _s8_dtype STREQUAL "bf16")
list(APPEND _s8_paths kblock)
endif()
foreach(_s8_path IN LISTS _s8_paths)
if(_s8_path STREQUAL "normal")
set(S8_ROUTE_MACRO ARK_DEFINE_S8_NORMAL_ROUTE)
else()
set(S8_ROUTE_MACRO ARK_DEFINE_S8_KBLOCK_ROUTE)
endif()
foreach(_s8_tile IN ITEMS small mid medium large)
if(_s8_tile STREQUAL "small")
set(S8_TILE_M 8)
set(S8_TILE_N 128)
elseif(_s8_tile STREQUAL "mid")
set(S8_TILE_M 64)
set(S8_TILE_N 128)
elseif(_s8_tile STREQUAL "medium")
set(S8_TILE_M 128)
set(S8_TILE_N 128)
elseif(_s8_path STREQUAL "normal")
set(S8_TILE_M 256)
set(S8_TILE_N 256)
else()
set(S8_TILE_M 256)
set(S8_TILE_N 128)
endif()
if(_s8_tile STREQUAL "small")
set(_s8_output_suffix small)
set(S8_LAYOUT SmallTileSG)
elseif(_s8_tile STREQUAL "mid")
set(_s8_output_suffix mid)
set(S8_LAYOUT SmallMidTileSG)
elseif(_s8_tile STREQUAL "medium")
set(_s8_output_suffix medium)
set(S8_LAYOUT MediumTileSG)
else()
set(_s8_output_suffix large)
set(S8_LAYOUT LargeTileSG)
endif()
set(S8_FUNCTION_NAME run_${_s8_dtype}_${_s8_path}_${_s8_tile})
set(_s8_output sycl_tla_s8_gemm_${_s8_dtype}_${_s8_path}_${_s8_output_suffix}.cpp)
generate_sycl_tla_source(sycl_tla_gemm.cpp.in ${_s8_output})
endforeach()
endforeach()
endforeach()
function(generate_dense_woq_s4_policy policy_suffix policy_name)
foreach(_dense_woq_s4_scale_layout IN ITEMS group_n n_group)
if(_dense_woq_s4_scale_layout STREQUAL "group_n")
set(DENSE_WOQ_S4_SCALE_GROUP_MAJOR true)
else()
set(DENSE_WOQ_S4_SCALE_GROUP_MAJOR false)
endif()
set(DENSE_WOQ_S4_POLICY_NAME ${policy_name})
set(DENSE_WOQ_S4_FUNCTION_NAME run_${policy_suffix}_${_dense_woq_s4_scale_layout})
generate_sycl_tla_source(sycl_tla_dense_woq_s4_dpas.cpp.in
sycl_tla_dense_woq_s4_dpas_${policy_suffix}_${_dense_woq_s4_scale_layout}.cpp)
endforeach()
set(SYCL_TLA_GENERATED_SRCS ${SYCL_TLA_GENERATED_SRCS} PARENT_SCOPE)
endfunction()
generate_dense_woq_s4_policy(m4_n128 dpas_w4a16_dense_policy_m_4_n128)
generate_dense_woq_s4_policy(m8_n128 dpas_w4a16_dense_policy_m_8_n128)
generate_dense_woq_s4_policy(m16 dpas_w4a16_dense_policy_m_16)
generate_dense_woq_s4_policy(m32 dpas_w4a16_dense_policy_m_32)
generate_dense_woq_s4_policy(m32_n256 dpas_w4a16_dense_policy_m_32_n256)
generate_dense_woq_s4_policy(m64_n256 dpas_w4a16_dense_policy_m_64_n256)
generate_dense_woq_s4_policy(m128 dpas_w4a16_dense_policy_m_128)
set(MOE_SOURCE_MODE 8)
set(MOE_DEFINE_FP8_HELPERS 0)
set(MOE_DEFINE_INT8_HELPERS 0)
set(MOE_DEFINE_S4_HELPERS 0)
set(_moe_tiles small mid large)
foreach(_moe_tile IN LISTS _moe_tiles)
if(_moe_tile STREQUAL "small")
set(MOE_POLICY_SUFFIX small)
set(MOE_POLICY_NAME dpas_w8a16_policy_m_16)
set(MOE_S4_POLICY_NAME dpas_w4a16_policy_m_16)
elseif(_moe_tile STREQUAL "mid")
set(MOE_POLICY_SUFFIX mid)
set(MOE_POLICY_NAME dpas_w8a16_policy_m_32)
set(MOE_S4_POLICY_NAME dpas_w4a16_policy_m_32)
else()
set(MOE_POLICY_SUFFIX large)
set(MOE_POLICY_NAME dpas_w8a16_policy)
set(MOE_S4_POLICY_NAME dpas_w4a16_policy)
endif()
foreach(_moe_dtype IN ITEMS f16 bf16)
if(_moe_dtype STREQUAL "f16")
set(MOE_SCALAR_TYPE sycl::half)
else()
set(MOE_SCALAR_TYPE sycl::ext::oneapi::bfloat16)
endif()
foreach(_moe_format IN ITEMS e4m3 e5m2)
if(_moe_format STREQUAL "e4m3")
set(MOE_FORMAT_ARGUMENT true)
else()
set(MOE_FORMAT_ARGUMENT false)
endif()
set(MOE_POLICY_ARGS "${MOE_FORMAT_ARGUMENT}, moe_dpas_fp8::${MOE_POLICY_NAME}")
set(MOE_FUNCTION_NAME dispatch_${_moe_dtype}_${_moe_format}_${MOE_POLICY_SUFFIX})
if(_moe_tile STREQUAL "small")
set(_moe_output_suffix "")
else()
set(_moe_output_suffix _${MOE_POLICY_SUFFIX})
endif()
set(_moe_output sycl_tla_moe_prefill_fp8_${_moe_dtype}_${_moe_format}${_moe_output_suffix}.cpp)
set(MOE_HELPER_HEADER sycl_tla_moe_prefill_fp8_helpers.hpp)
set(MOE_DPAS_HEADER sycl_tla_moe_prefill_fp8_dpas.hpp)
set(MOE_NAMESPACE moe_prefill_fp8_detail)
set(MOE_DPAS_NAMESPACE moe_dpas_fp8)
set(MOE_DISPATCH_FUNCTION moe_prefill_fp8_dpas_per_group_dispatch_policy)
set(MOE_WEIGHT_TYPE uint8_t)
set(MOE_DEFINE_FP8_HELPERS 0)
set(MOE_DEFINE_INT8_HELPERS 0)
set(MOE_DEFINE_S4_HELPERS 0)
if(_moe_tile STREQUAL "small" AND _moe_dtype STREQUAL "f16" AND _moe_format STREQUAL "e4m3")
set(MOE_DEFINE_FP8_HELPERS 1)
endif()
generate_sycl_tla_source(sycl_tla_moe.cpp.in ${_moe_output})
endforeach()
set(MOE_POLICY_ARGS "moe_dpas_int::${MOE_POLICY_NAME}")
set(MOE_FUNCTION_NAME dispatch_${_moe_dtype}_${MOE_POLICY_SUFFIX})
if(_moe_tile STREQUAL "small")
set(_moe_output_suffix "")
else()
set(_moe_output_suffix _${MOE_POLICY_SUFFIX})
endif()
set(_moe_output sycl_tla_moe_prefill_int8_${_moe_dtype}${_moe_output_suffix}.cpp)
set(MOE_HELPER_HEADER sycl_tla_moe_prefill_int8_helpers.hpp)
set(MOE_DPAS_HEADER sycl_tla_moe_prefill_int_dpas.hpp)
set(MOE_NAMESPACE moe_prefill_int8_detail)
set(MOE_DPAS_NAMESPACE moe_dpas_int)
set(MOE_DISPATCH_FUNCTION moe_prefill_int_dpas_per_group_dispatch_policy)
set(MOE_WEIGHT_TYPE int8_t)
set(MOE_DEFINE_FP8_HELPERS 0)
set(MOE_DEFINE_INT8_HELPERS 0)
set(MOE_DEFINE_S4_HELPERS 0)
if(_moe_tile STREQUAL "small" AND _moe_dtype STREQUAL "f16")
set(MOE_DEFINE_INT8_HELPERS 1)
endif()
generate_sycl_tla_source(sycl_tla_moe.cpp.in ${_moe_output})
set(MOE_POLICY_ARGS "moe_dpas_s4::${MOE_S4_POLICY_NAME}")
set(MOE_FUNCTION_NAME dispatch_${_moe_dtype}_${MOE_POLICY_SUFFIX})
set(_moe_output sycl_tla_moe_prefill_s4_${_moe_dtype}${_moe_output_suffix}.cpp)
set(MOE_HELPER_HEADER sycl_tla_moe_prefill_s4_helpers.hpp)
set(MOE_DPAS_HEADER sycl_tla_moe_prefill_s4_dpas.hpp)
set(MOE_NAMESPACE moe_prefill_s4_detail)
set(MOE_DPAS_NAMESPACE moe_dpas_s4)
set(MOE_DISPATCH_FUNCTION moe_prefill_s4_dpas_per_group_dispatch_policy)
set(MOE_WEIGHT_TYPE uint8_t)
set(MOE_DEFINE_FP8_HELPERS 0)
set(MOE_DEFINE_INT8_HELPERS 0)
set(MOE_DEFINE_S4_HELPERS 0)
if(_moe_tile STREQUAL "small" AND _moe_dtype STREQUAL "f16")
set(MOE_DEFINE_S4_HELPERS 1)
endif()
generate_sycl_tla_source(sycl_tla_moe.cpp.in ${_moe_output})
endforeach()
endforeach()
# The S4-sym dispatch uses a four-tier `A_avg_M` ladder (`_m_8` -> `_m_16` ->
# `_m_32` -> wide) matching the reference `w4a16` grouped GEMM, so it needs one
# extra 8-row tile on top of the three tiers the INT8 / FP8 dispatches share.
set(MOE_POLICY_SUFFIX tiny)
set(MOE_POLICY_ARGS "moe_dpas_s4::dpas_w4a16_policy_m_8")
set(MOE_HELPER_HEADER sycl_tla_moe_prefill_s4_helpers.hpp)
set(MOE_DPAS_HEADER sycl_tla_moe_prefill_s4_dpas.hpp)
set(MOE_NAMESPACE moe_prefill_s4_detail)
set(MOE_DPAS_NAMESPACE moe_dpas_s4)
set(MOE_DISPATCH_FUNCTION moe_prefill_s4_dpas_per_group_dispatch_policy)
set(MOE_WEIGHT_TYPE uint8_t)
set(MOE_DEFINE_FP8_HELPERS 0)
set(MOE_DEFINE_INT8_HELPERS 0)
set(MOE_DEFINE_S4_HELPERS 0)
foreach(_moe_dtype IN ITEMS f16 bf16)
if(_moe_dtype STREQUAL "f16")
set(MOE_SCALAR_TYPE sycl::half)
else()
set(MOE_SCALAR_TYPE sycl::ext::oneapi::bfloat16)
endif()
set(MOE_FUNCTION_NAME dispatch_${_moe_dtype}_${MOE_POLICY_SUFFIX})
generate_sycl_tla_source(sycl_tla_moe.cpp.in sycl_tla_moe_prefill_s4_${_moe_dtype}_${MOE_POLICY_SUFFIX}.cpp)
endforeach()
# The FP8 *decode* dispatch uses the same four-tier ladder as S4 (`_m_8` ->
# `_m_16` -> `_m_32` -> wide), so it needs the same extra 8-row tile. Keeping
# these instantiations in their own translation units (rather than expanding
# the whole ladder inside `sycl_tla_moe_decode_fp8.cpp`) is what keeps peak
# compiler RSS per TU bounded -- one policy per TU instead of all four.
# `dpas_w4a16_policy_m_8` carries no 4-bit-specific types; it is purely a
# `WGTile`/`SGLayout` shape, so the FP8 mainloop reuses it verbatim.
set(MOE_POLICY_SUFFIX tiny)
set(MOE_HELPER_HEADER sycl_tla_moe_prefill_fp8_helpers.hpp)
set(MOE_DPAS_HEADER sycl_tla_moe_prefill_fp8_dpas.hpp)
set(MOE_NAMESPACE moe_prefill_fp8_detail)
set(MOE_DPAS_NAMESPACE moe_dpas_fp8)
set(MOE_DISPATCH_FUNCTION moe_prefill_fp8_dpas_per_group_dispatch_policy)
set(MOE_WEIGHT_TYPE uint8_t)
set(MOE_DEFINE_FP8_HELPERS 0)
set(MOE_DEFINE_INT8_HELPERS 0)
set(MOE_DEFINE_S4_HELPERS 0)
foreach(_moe_dtype IN ITEMS f16 bf16)
if(_moe_dtype STREQUAL "f16")
set(MOE_SCALAR_TYPE sycl::half)
else()
set(MOE_SCALAR_TYPE sycl::ext::oneapi::bfloat16)
endif()
foreach(_moe_format IN ITEMS e4m3 e5m2)
if(_moe_format STREQUAL "e4m3")
set(MOE_FORMAT_ARGUMENT true)
else()
set(MOE_FORMAT_ARGUMENT false)
endif()
set(MOE_POLICY_ARGS "${MOE_FORMAT_ARGUMENT}, moe_dpas_fp8::dpas_w4a16_policy_m_8")
set(MOE_FUNCTION_NAME dispatch_${_moe_dtype}_${_moe_format}_${MOE_POLICY_SUFFIX})
generate_sycl_tla_source(
sycl_tla_moe.cpp.in sycl_tla_moe_prefill_fp8_${_moe_dtype}_${_moe_format}_${MOE_POLICY_SUFFIX}.cpp)
endforeach()
endforeach()
# FP8 scalar-GEMV decode kernels, one translation unit per
# (dtype, format, byte-decode mode). `sycl_tla_moe_decode_fp8.cpp` used to
# instantiate `launch_fp8_by_mode` for all four dtype/format pairs, and each of
# those expands three decode modes x (one plain kernel + three K-split column
# factors) -- 48 SYCL kernels in a single TU, measured at ~14.4 GiB peak
# compiler RSS. Every other decode TU instantiates only four to eight kernels,
# which is why this one file was the outlier. Splitting on the mode as well as
# the dtype/format keeps each TU to exactly four kernels; the decode TU itself
# is left with none.
set(MOE_SOURCE_MODE 19)
foreach(_moe_dtype IN ITEMS f16 bf16)
if(_moe_dtype STREQUAL "f16")
set(MOE_SCALAR_TYPE sycl::half)
else()
set(MOE_SCALAR_TYPE sycl::ext::oneapi::bfloat16)
endif()
foreach(_moe_format IN ITEMS e4m3 e5m2)
if(_moe_format STREQUAL "e4m3")
set(MOE_FORMAT_ARGUMENT true)
else()
set(MOE_FORMAT_ARGUMENT false)
endif()
foreach(_moe_fp8_mode IN ITEMS word lut bits)
if(_moe_fp8_mode STREQUAL "word")
set(MOE_FP8_DECODE_MODE kWord)
elseif(_moe_fp8_mode STREQUAL "lut")
set(MOE_FP8_DECODE_MODE kLut)
else()
set(MOE_FP8_DECODE_MODE kBits)
endif()
set(MOE_FUNCTION_NAME dispatch_${_moe_dtype}_${_moe_format}_${_moe_fp8_mode})
generate_sycl_tla_source(
sycl_tla_moe.cpp.in sycl_tla_moe_decode_fp8_${_moe_dtype}_${_moe_format}_${_moe_fp8_mode}.cpp)
endforeach()
endforeach()
endforeach()
set(MOE_SOURCE_MODE 9)
foreach(_moe_dtype IN ITEMS f16 bf16)
if(_moe_dtype STREQUAL "f16")
set(MOE_SCALAR_TYPE sycl::half)
else()
set(MOE_SCALAR_TYPE sycl::ext::oneapi::bfloat16)
endif()
foreach(_moe_tile IN LISTS _moe_tiles)
if(_moe_tile STREQUAL "small")
set(MOE_POLICY_SUFFIX small)
set(MOE_POLICY_NAME dpas_w8a16_policy_m_16)
elseif(_moe_tile STREQUAL "mid")
set(MOE_POLICY_SUFFIX mid)
set(MOE_POLICY_NAME dpas_w8a16_policy_m_32)
else()
set(MOE_POLICY_SUFFIX large)
set(MOE_POLICY_NAME dpas_w8a16_policy)
endif()
set(MOE_POLICY_ARGS "moe_dpas_int::${MOE_POLICY_NAME}")
set(MOE_FUNCTION_NAME dispatch_${_moe_dtype}_${MOE_POLICY_SUFFIX})
set(_moe_output sycl_tla_moe_prefill_int_tensor_${_moe_dtype}_${MOE_POLICY_SUFFIX}.cpp)
set(MOE_HELPER_HEADER sycl_tla_moe_prefill_int_tensor_helpers.hpp)
set(MOE_DPAS_HEADER sycl_tla_moe_prefill_int_dpas.hpp)
set(MOE_NAMESPACE moe_prefill_int_tensor_detail)
set(MOE_DPAS_NAMESPACE moe_dpas_int)
set(MOE_DISPATCH_FUNCTION moe_prefill_int_dpas_per_tensor_dispatch_policy)
set(MOE_WEIGHT_TYPE int8_t)
set(MOE_SCALE_TYPE float)
generate_sycl_tla_source(sycl_tla_moe.cpp.in ${_moe_output})
endforeach()
endforeach()
set(DENSE_SOURCE_MODE 2)
set(S8_SOURCE_MODE 0)
generate_sycl_tla_source(sycl_tla_gemm.cpp.in sycl_tla_dense_gemm.cpp)
foreach(_dense_dispatch_dtype IN ITEMS f16 bf16 f32)
set(DENSE_SOURCE_MODE 3)
set(DENSE_DISPATCH_DTYPE ${_dense_dispatch_dtype})
generate_sycl_tla_source(sycl_tla_gemm.cpp.in sycl_tla_dense_gemm_${_dense_dispatch_dtype}.cpp)
endforeach()
set(DENSE_SOURCE_MODE 0)
set(S8_SOURCE_MODE 2)
generate_sycl_tla_source(sycl_tla_gemm.cpp.in sycl_tla_s8_gemm.cpp)
foreach(_s8_dispatch_dtype IN ITEMS f16 bf16 f32)
set(S8_SOURCE_MODE 3)
set(S8_DISPATCH_DTYPE ${_s8_dispatch_dtype})
if(_s8_dispatch_dtype STREQUAL "bf16")
set(S8_KBLOCK_SUPPORTED 0)
else()
set(S8_KBLOCK_SUPPORTED 1)
endif()
generate_sycl_tla_source(sycl_tla_gemm.cpp.in sycl_tla_s8_gemm_${_s8_dispatch_dtype}.cpp)
endforeach()
set(MOE_SOURCE_MODE 1)
generate_sycl_tla_source(sycl_tla_moe.cpp.in sycl_tla_moe.cpp)
foreach(_moe_dispatch_dtype IN ITEMS f16 bf16)
set(MOE_DISPATCH_DTYPE ${_moe_dispatch_dtype})
if(_moe_dispatch_dtype STREQUAL "f16")
set(MOE_DISPATCH_ELEMENT cutlass::half_t)
else()
set(MOE_DISPATCH_ELEMENT cutlass::bfloat16_t)
endif()
# The bf16/fp16 grouped MoE GEMM picks one of three work-group tile policies
# from N. Expanding all three in `sycl_tla_moe_<dtype>.cpp` put three full
# cutlass grouped-GEMM instantiations in one translation unit, measured at
# ~2219 MB peak compiler RSS; every other cutlass TU in this build carries
# exactly one policy and stays well under that. Give each policy its own TU
# and leave `sycl_tla_moe_<dtype>.cpp` as a pure host-side dispatcher.
foreach(_moe_tile IN ITEMS n64 n128 n256)
set(MOE_TILE_SUFFIX ${_moe_tile})
if(_moe_tile STREQUAL "n64")
set(MOE_TILE_POLICY kN64)
elseif(_moe_tile STREQUAL "n128")
set(MOE_TILE_POLICY kN128)
else()
set(MOE_TILE_POLICY kN256)
endif()
set(MOE_SOURCE_MODE 20)
generate_sycl_tla_source(sycl_tla_moe.cpp.in
sycl_tla_moe_${_moe_dispatch_dtype}_${_moe_tile}.cpp)
endforeach()
set(MOE_SOURCE_MODE 2)
generate_sycl_tla_source(sycl_tla_moe.cpp.in sycl_tla_moe_${_moe_dispatch_dtype}.cpp)
endforeach()
set(MOE_SOURCE_MODE 3)
generate_sycl_tla_source(sycl_tla_moe.cpp.in sycl_tla_moe_decode.cpp)
set(MOE_SOURCE_MODE 4)
generate_sycl_tla_source(sycl_tla_moe.cpp.in sycl_tla_moe_decode_fp.cpp)
set(MOE_SOURCE_MODE 5)
generate_sycl_tla_source(sycl_tla_moe.cpp.in sycl_tla_moe_decode_fp8.cpp)
foreach(_decode_int_kind IN ITEMS int2 int8)
set(DECODE_INT_KIND ${_decode_int_kind})
set(MOE_SOURCE_MODE 6)
generate_sycl_tla_source(sycl_tla_moe.cpp.in sycl_tla_moe_decode_${_decode_int_kind}.cpp)
endforeach()
# int4 decode has its own translation unit: on top of the shared scalar GEMV it
# owns the coalesced-load fallback and the S4-sym DPAS fast path.
set(MOE_SOURCE_MODE 18)
generate_sycl_tla_source(sycl_tla_moe.cpp.in sycl_tla_moe_decode_int4.cpp)
set(MOE_SOURCE_MODE 7)
generate_sycl_tla_source(sycl_tla_moe.cpp.in sycl_tla_moe_mixed.cpp)
set(MOE_SOURCE_MODE 11)
foreach(_moe_dequant_dtype IN ITEMS f16 bf16)
set(MOE_DEQUANT_DTYPE ${_moe_dequant_dtype})
if(_moe_dequant_dtype STREQUAL "f16")
set(MOE_DEQUANT_SCALAR sycl::half)
else()
set(MOE_DEQUANT_SCALAR sycl::ext::oneapi::bfloat16)
endif()
generate_sycl_tla_source(sycl_tla_moe.cpp.in sycl_tla_moe_prefill_dequant_${_moe_dequant_dtype}.cpp)
endforeach()
set(MOE_SOURCE_MODE 12)
generate_sycl_tla_source(sycl_tla_moe.cpp.in sycl_tla_moe_prefill_fp8.cpp)
set(MOE_SOURCE_MODE 13)
generate_sycl_tla_source(sycl_tla_moe.cpp.in sycl_tla_moe_prefill_fp8_tensor.cpp)
set(MOE_SOURCE_MODE 14)
generate_sycl_tla_source(sycl_tla_moe.cpp.in sycl_tla_moe_prefill_int8.cpp)
set(MOE_SOURCE_MODE 15)
generate_sycl_tla_source(sycl_tla_moe.cpp.in sycl_tla_moe_prefill_int_tensor.cpp)
set(MOE_SOURCE_MODE 16)
generate_sycl_tla_source(sycl_tla_moe.cpp.in sycl_tla_moe_prefill_s4.cpp)
set(MOE_SOURCE_MODE 17)
generate_sycl_tla_source(sycl_tla_moe.cpp.in sycl_tla_moe_prefill_native_fp8.cpp)
# W4A8 (int4 weights re-scaled to int8, int8 activations) prepack + GEMM.
#
# This used to be a single `sycl_tla_moe_w4a8.cpp`, which instantiated all 52
# W4A8 kernels -- 12 grouped DPAS GEMMs, 14 decode GEMVs, 22 activation-quant
# and 4 prepack kernels -- and peaked at ~4.2 GB of compiler RSS. It is now
# fanned out the same way the S4 prefill is (see MOE_SOURCE_MODE 8): one TU per
# variant, with the dispatcher left holding no kernels at all.
#
# mode 21 dispatcher 0 kernels, cutlass-free
# mode 22 prefill, dtype x tile 1 DPAS kernel each (12 TUs)
# mode 23 decode, dtype 7 kernels each (2 TUs, cutlass-free)
# mode 24 act quant, dtype 11 kernels each (2 TUs, cutlass-free)
# mode 25 prepack, dtype 2 kernels each (2 TUs, cutlass-free)
#
# Only the 12 prefill TUs include the CuTe stack; the other seven take
# `sycl_tla_moe_w4a8_kernels.hpp` / `..._helpers.hpp`, which stop at plain SYCL.
set(MOE_SOURCE_MODE 21)
generate_sycl_tla_source(sycl_tla_moe.cpp.in sycl_tla_moe_w4a8.cpp)
# Prefill tile ladder: the policy names must match `W4A8PrefillTile` /
# `moe_w4a8_prefill_select_tile` in `sycl_tla_moe_w4a8_helpers.hpp`, and the
# function names the `prefill_*` declarations there.
set(_w4a8_tiles m8 m64 m128 m128n256 m256n128 large)
foreach(_w4a8_dtype IN ITEMS f16 bf16)
if(_w4a8_dtype STREQUAL "f16")
set(MOE_SCALAR_TYPE sycl::half)
else()
set(MOE_SCALAR_TYPE sycl::ext::oneapi::bfloat16)
endif()
set(MOE_SOURCE_MODE 22)
foreach(_w4a8_tile IN LISTS _w4a8_tiles)
if(_w4a8_tile STREQUAL "m8")
set(MOE_POLICY_NAME w4a8_policy_m_8)
elseif(_w4a8_tile STREQUAL "m64")
set(MOE_POLICY_NAME w4a8_policy_m_64)
elseif(_w4a8_tile STREQUAL "m128")
set(MOE_POLICY_NAME w4a8_policy_m_128)
elseif(_w4a8_tile STREQUAL "m128n256")
set(MOE_POLICY_NAME w4a8_policy_m_128_n256)
elseif(_w4a8_tile STREQUAL "m256n128")
set(MOE_POLICY_NAME w4a8_policy_m_256_n128)
else()
set(MOE_POLICY_NAME w4a8_policy_large)
endif()
set(MOE_FUNCTION_NAME prefill_${_w4a8_dtype}_${_w4a8_tile})
generate_sycl_tla_source(sycl_tla_moe.cpp.in
sycl_tla_moe_w4a8_prefill_${_w4a8_dtype}_${_w4a8_tile}.cpp)
endforeach()
set(MOE_SOURCE_MODE 23)
set(MOE_FUNCTION_NAME decode_${_w4a8_dtype})
generate_sycl_tla_source(sycl_tla_moe.cpp.in sycl_tla_moe_w4a8_decode_${_w4a8_dtype}.cpp)
set(MOE_SOURCE_MODE 24)
set(MOE_FUNCTION_NAME quant_${_w4a8_dtype})
generate_sycl_tla_source(sycl_tla_moe.cpp.in sycl_tla_moe_w4a8_quant_${_w4a8_dtype}.cpp)
set(MOE_SOURCE_MODE 25)
set(MOE_FUNCTION_NAME prepack_${_w4a8_dtype})
generate_sycl_tla_source(sycl_tla_moe.cpp.in sycl_tla_moe_w4a8_prepack_${_w4a8_dtype}.cpp)
endforeach()
foreach(_moe_dtype IN ITEMS f16 bf16)
if(_moe_dtype STREQUAL "f16")
set(MOE_SCALAR_TYPE sycl::half)
else()
set(MOE_SCALAR_TYPE sycl::ext::oneapi::bfloat16)
endif()
foreach(_moe_format IN ITEMS e4m3 e5m2)
if(_moe_format STREQUAL "e4m3")
set(MOE_FORMAT_ARGUMENT true)
else()
set(MOE_FORMAT_ARGUMENT false)
endif()
foreach(_moe_tile IN LISTS _moe_tiles)
if(_moe_tile STREQUAL "small")
set(MOE_POLICY_SUFFIX small)
set(MOE_POLICY_NAME dpas_w8a16_policy_m_16)
elseif(_moe_tile STREQUAL "mid")
set(MOE_POLICY_SUFFIX mid)
set(MOE_POLICY_NAME dpas_w8a16_policy_m_32)
else()
set(MOE_POLICY_SUFFIX large)
set(MOE_POLICY_NAME dpas_w8a16_policy)
endif()
set(MOE_POLICY_ARGS "${MOE_FORMAT_ARGUMENT}, moe_dpas_fp8::${MOE_POLICY_NAME}")
set(MOE_FUNCTION_NAME dispatch_${_moe_dtype}_${_moe_format}_${MOE_POLICY_SUFFIX})
set(_moe_output sycl_tla_moe_prefill_fp8_tensor_${_moe_dtype}_${_moe_format}_${MOE_POLICY_SUFFIX}.cpp)
set(MOE_HELPER_HEADER sycl_tla_moe_prefill_fp8_tensor_helpers.hpp)
set(MOE_DPAS_HEADER sycl_tla_moe_prefill_fp8_dpas.hpp)
set(MOE_NAMESPACE moe_prefill_fp8_tensor_detail)
set(MOE_DPAS_NAMESPACE moe_dpas_fp8)
set(MOE_DISPATCH_FUNCTION moe_prefill_fp8_dpas_per_tensor_dispatch_policy)
set(MOE_WEIGHT_TYPE uint8_t)
set(MOE_SCALE_TYPE float)
set(MOE_SOURCE_MODE 9)
generate_sycl_tla_source(sycl_tla_moe.cpp.in ${_moe_output})
endforeach()
endforeach()
endforeach()
foreach(_moe_dtype IN ITEMS f16 bf16)
if(_moe_dtype STREQUAL "f16")
set(MOE_SCALAR_TYPE sycl::half)
else()
set(MOE_SCALAR_TYPE sycl::ext::oneapi::bfloat16)
endif()
foreach(_moe_tile IN LISTS _moe_tiles)
if(_moe_tile STREQUAL "small")
set(MOE_POLICY_SUFFIX small)
set(MOE_POLICY_NAME dpas_w8a16_policy_m_16)
elseif(_moe_tile STREQUAL "mid")
set(MOE_POLICY_SUFFIX mid)
set(MOE_POLICY_NAME dpas_w8a16_policy_m_32)
else()
set(MOE_POLICY_SUFFIX large)
set(MOE_POLICY_NAME dpas_w8a16_policy)
endif()
set(MOE_POLICY_ARGS "moe_dpas_int::${MOE_POLICY_NAME}")
set(MOE_FUNCTION_NAME dispatch_lowbit_${_moe_dtype}_${MOE_POLICY_SUFFIX})
if(_moe_tile STREQUAL "small")
set(_moe_output_suffix "")
else()
set(_moe_output_suffix _${MOE_POLICY_SUFFIX})
endif()
set(_moe_output sycl_tla_moe_prefill_int8_lowbit_${_moe_dtype}${_moe_output_suffix}.cpp)
set(MOE_HELPER_HEADER sycl_tla_moe_prefill_int8_helpers.hpp)
set(MOE_DPAS_HEADER sycl_tla_moe_prefill_int_dpas.hpp)
set(MOE_NAMESPACE moe_prefill_int8_detail)
set(MOE_DPAS_NAMESPACE moe_dpas_int)
set(MOE_DISPATCH_FUNCTION moe_prefill_int_dpas_per_group_dispatch_policy)
set(MOE_SOURCE_MODE 10)
generate_sycl_tla_source(sycl_tla_moe.cpp.in ${_moe_output})
endforeach()
endforeach()