PTQ-Level Efficiency, QAT-Level Accuracy | 训练后量化的效率,量化感知训练的精度
// Generated by CMake. Do not edit directly.
#if defined(ARK_XPU) && defined(ARK_SYCL_TLA)
#if @DENSE_SOURCE_MODE@ > 0
#if @DENSE_SOURCE_MODE@ == 1
#include "sycl_tla_dense_gemm.hpp"
#include "sycl_tla_dense_gemm_helpers.hpp"
namespace ark {
namespace dense_gemm_detail {
void @DENSE_FUNCTION_NAME@(sycl::queue* q, int m, int n, int k, const void* a, const void* b, void* c@DENSE_BIAS_PARAMETER@) {
run_dense_gemm_fixed_tile<@DENSE_HAS_BIAS@, @DENSE_TILE_M@, @DENSE_TILE_N@, @DENSE_LAYOUT@>(
q, m, n, k, static_cast<const @DENSE_ELEMENT_TYPE@*>(a), static_cast<const @DENSE_ELEMENT_TYPE@*>(b),
static_cast<@DENSE_ELEMENT_TYPE@*>(c), @DENSE_BIAS_ARGUMENT@);
}
} // namespace dense_gemm_detail
} // namespace ark
#elif @DENSE_SOURCE_MODE@ == 2
#include "sycl_tla_common.hpp"
namespace ark {
void sycl_tla_dense_gemm(sycl::queue* q, int m, int n, int k, const void* a, BTLA_DTYPE at, const void* b,
BTLA_DTYPE bt, void* c, BTLA_DTYPE ct, const void* bias, bool BT) {
if (!q) {
throw std::invalid_argument("sycl_tla_dense_gemm: stream must be a valid SYCL queue");
}
if (!BT) {
throw std::invalid_argument("sycl_tla_dense_gemm: only the A @ B.T contract is supported");
}
if (!a || !b || !c) {
throw std::invalid_argument("sycl_tla_dense_gemm: input and output pointers must not be null");
}
if (m <= 0 || n <= 0 || k <= 0) return;
if (at != bt) {
throw std::invalid_argument("sycl_tla_dense_gemm: A and B must use the same dtype");
}
if (ct != at) {
throw std::invalid_argument("sycl_tla_dense_gemm: output dtype must match input dtype");
}
switch (at) {
case BTLA_DTYPE::F32:
sycl_tla_dense_gemm_f32(q, m, n, k, a, b, c, bias);
return;
case BTLA_DTYPE::F16:
sycl_tla_dense_gemm_f16(q, m, n, k, a, b, c, bias);
return;
case BTLA_DTYPE::BF16:
sycl_tla_dense_gemm_bf16(q, m, n, k, a, b, c, bias);
return;
default:
throw std::invalid_argument("sycl_tla_dense_gemm: only FP32, FP16 and BF16 are supported");
}
}
} // namespace ark
#elif @DENSE_SOURCE_MODE@ == 3
#include "sycl_tla_dense_gemm_helpers.hpp"
namespace ark {
void sycl_tla_dense_gemm_@DENSE_DISPATCH_DTYPE@(sycl::queue* q, int m, int n, int k, const void* a, const void* b,
void* c, const void* bias) {
if (bias != nullptr) {
if (m < 32) dense_gemm_detail::run_@DENSE_DISPATCH_DTYPE@_with_bias_small(q, m, n, k, a, b, c, bias);
else if (m < 128) dense_gemm_detail::run_@DENSE_DISPATCH_DTYPE@_with_bias_mid(q, m, n, k, a, b, c, bias);
else if (m <= 1024) dense_gemm_detail::run_@DENSE_DISPATCH_DTYPE@_with_bias_medium(q, m, n, k, a, b, c, bias);
else dense_gemm_detail::run_@DENSE_DISPATCH_DTYPE@_with_bias_large(q, m, n, k, a, b, c, bias);
} else {
if (m < 32) dense_gemm_detail::run_@DENSE_DISPATCH_DTYPE@_without_bias_small(q, m, n, k, a, b, c);
else if (m < 128) dense_gemm_detail::run_@DENSE_DISPATCH_DTYPE@_without_bias_mid(q, m, n, k, a, b, c);
else if (m <= 1024) dense_gemm_detail::run_@DENSE_DISPATCH_DTYPE@_without_bias_medium(q, m, n, k, a, b, c);
else dense_gemm_detail::run_@DENSE_DISPATCH_DTYPE@_without_bias_large(q, m, n, k, a, b, c);
}
}
} // namespace ark
#endif
#elif @S8_SOURCE_MODE@ > 0
#if @S8_SOURCE_MODE@ == 1
#include "sycl_tla_s8_gemm_fixed.hpp"
@S8_ROUTE_MACRO@(@S8_FUNCTION_NAME@, @S8_ELEMENT_TYPE@, @S8_TILE_M@, @S8_TILE_N@, @S8_LAYOUT@)
#elif @S8_SOURCE_MODE@ == 2
#include "sycl_tla_common.hpp"
namespace ark {
void sycl_tla_igemm_s8s8_dequant(sycl::queue* q, int m, int n, int k, const void* a, const void* b, void* c,
BTLA_DTYPE ct, const void* scale_a, const void* scale_b, const void* bias,
int blocksize) {
if (!q) throw std::invalid_argument("sycl_tla_igemm_s8s8_dequant: queue must not be null");
if (!a || !b || !c || !scale_a || !scale_b) {
throw std::invalid_argument("sycl_tla_igemm_s8s8_dequant: input pointers must not be null");
}
if (m <= 0 || n <= 0 || k <= 0) return;
if (ct == BTLA_DTYPE::BF16 && !(blocksize == k || blocksize == -1)) {
throw std::invalid_argument("sycl_tla_igemm_s8s8_dequant: k-block path supports only F32/F16 output");
}
switch (ct) {
case BTLA_DTYPE::F32:
sycl_tla_igemm_s8s8_dequant_f32(q, m, n, k, a, b, c, scale_a, scale_b, bias, blocksize);
return;
case BTLA_DTYPE::F16:
sycl_tla_igemm_s8s8_dequant_f16(q, m, n, k, a, b, c, scale_a, scale_b, bias, blocksize);
return;
case BTLA_DTYPE::BF16:
sycl_tla_igemm_s8s8_dequant_bf16(q, m, n, k, a, b, c, scale_a, scale_b, bias, blocksize);
return;
default:
throw std::invalid_argument("sycl_tla_igemm_s8s8_dequant: unsupported output dtype");
}
}
} // namespace ark
#elif @S8_SOURCE_MODE@ == 3
#include "sycl_tla_s8_gemm_helpers.hpp"
namespace ark {
void sycl_tla_igemm_s8s8_dequant_@S8_DISPATCH_DTYPE@(sycl::queue* q, int m, int n, int k, const void* a,
const void* b, void* c, const void* scale_a, const void* scale_b,
const void* bias, int blocksize) {
if (blocksize == k || blocksize == -1) {
if (m < 16) sycl_tla_s8_detail::run_@S8_DISPATCH_DTYPE@_normal_small(q, m, n, k, a, b, c, scale_a, scale_b, bias);
else if (m < 128) sycl_tla_s8_detail::run_@S8_DISPATCH_DTYPE@_normal_mid(q, m, n, k, a, b, c, scale_a, scale_b, bias);
else if (m <= 1024) sycl_tla_s8_detail::run_@S8_DISPATCH_DTYPE@_normal_medium(q, m, n, k, a, b, c, scale_a, scale_b, bias);
else sycl_tla_s8_detail::run_@S8_DISPATCH_DTYPE@_normal_large(q, m, n, k, a, b, c, scale_a, scale_b, bias);
return;
}
#if @S8_KBLOCK_SUPPORTED@
sycl_tla_s8_detail::validate_kblock_args(k, blocksize);
if (m < 16) sycl_tla_s8_detail::run_@S8_DISPATCH_DTYPE@_kblock_small(q, m, n, k, a, b, c, scale_a, scale_b, bias, blocksize);
else if (m < 128) sycl_tla_s8_detail::run_@S8_DISPATCH_DTYPE@_kblock_mid(q, m, n, k, a, b, c, scale_a, scale_b, bias, blocksize);
else if (m <= 1024) sycl_tla_s8_detail::run_@S8_DISPATCH_DTYPE@_kblock_medium(q, m, n, k, a, b, c, scale_a, scale_b, bias, blocksize);
else sycl_tla_s8_detail::run_@S8_DISPATCH_DTYPE@_kblock_large(q, m, n, k, a, b, c, scale_a, scale_b, bias, blocksize);
#else
throw std::invalid_argument("sycl_tla_igemm_s8s8_dequant: k-block path supports only F32/F16 output");
#endif
}
} // namespace ark
#endif
#endif
#endif // ARK_XPU && ARK_SYCL_TLA