94057c3d3e
PR Test (NPU) / check-changes (push) Has been cancelled
PR Test (NPU) / pr-gate (push) Has been cancelled
PR Test (NPU) / set-image-config (push) Has been cancelled
PR Test (NPU) / stage-b-test-1-npu-a2 (0) (push) Has been cancelled
PR Test (NPU) / stage-b-test-1-npu-a2 (1) (push) Has been cancelled
PR Test (NPU) / stage-b-test-2-npu-a2 (0) (push) Has been cancelled
PR Test (NPU) / stage-b-test-2-npu-a2 (1) (push) Has been cancelled
PR Test (NPU) / stage-b-test-4-npu-a3 (push) Has been cancelled
PR Test (NPU) / stage-b-test-16-npu-a3 (push) Has been cancelled
PR Test (NPU) / multimodal-gen-test-1-npu-a3 (push) Has been cancelled
PR Test (NPU) / multimodal-gen-test-2-npu-a3 (push) Has been cancelled
PR Test (Arm64) / pr-gate (push) Has been cancelled
PR Test (Arm64) / check-changes (push) Has been cancelled
PR Test (Arm64) / build-test (push) Has been cancelled
PR Test (sgl-router) / gate (push) Has been cancelled
PR Test (sgl-router) / tier-1 — lint (push) Has been cancelled
PR Test (sgl-router) / tier-2 — build + test (push) Has been cancelled
PR Test (sgl-router) / tier-3 — docker (placeholder) (push) Has been cancelled
PR Test (sgl-router) / tier-3 — k8s integration (push) Has been cancelled
PR Test (sgl-router) / tier-3 — e2e (push) Has been cancelled
PR Test (sgl-router) / finish (push) Has been cancelled
PR Test (NPU) / single-node-poc (map[name:qwen3_6_27b_w8a8_1p_in64k_out1k_50ms runner:linux-aarch64-a3-2 test_case:test/registered/ascend/performance/qwen3_6_27b/test_npu_qwen3_6_27b_w8a8_1p_in64k_out1k_50ms.py test_type:perf]) (push) Has been cancelled
PR Test (NPU) / pr-test-npu-finish (push) Has been cancelled
PR Test (Xeon) / pr-gate (push) Has been cancelled
PR Test (Xeon) / check-changes (push) Has been cancelled
PR Test (Xeon) / build-test (, xeon-gnr, base-b-test-cpu) (push) Has been cancelled
PR Test (XPU) / check-changes (push) Has been cancelled
PR Test (XPU) / pr-gate (push) Has been cancelled
PR Test (XPU) / stage-a-test-1-gpu-xpu (push) Has been cancelled
PR Test (XPU) / wait-for-stage-a (push) Has been cancelled
PR Test (XPU) / stage-b-test-1-gpu-xpu (push) Has been cancelled
PR Test (XPU) / finish (push) Has been cancelled
CI Model Inventory / build-inventory (push) Has been cancelled
Lint / lint (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark Compilation Check (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark - Manual Policy (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark - Request Processing (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark Summary (push) Has been cancelled
PR Test (SMG) / build-wheel (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on windows (x86_64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on macos (x86_64 - auto) (push) Has been cancelled
PR Test (SMG) / python-unit-tests (push) Has been cancelled
PR Test (SMG) / unit-tests (push) Has been cancelled
PR Test (SMG) / benchmarks (push) Has been cancelled
PR Test (SMG) / chat-completions (push) Has been cancelled
PR Test (SMG) / chat-completions-4gpu (push) Has been cancelled
PR Test (SMG) / e2e (push) Has been cancelled
PR Test (SMG) / docker-build-test (push) Has been cancelled
PR Test (SMG) / k8s-integration (push) Has been cancelled
PR Test (SMG) / finish (push) Has been cancelled
PR Test (SMG) / summarize-benchmarks (push) Has been cancelled
Release SGLang Model Gateway Docker Image / publish (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on macos (aarch64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (aarch64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (x86_64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (aarch64 - musllinux_1_1) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (x86_64 - musllinux_1_1) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / Build SDist (push) Has been cancelled
Release SGLang Model Gateway to PyPI / Upload to PyPI (push) Has been cancelled
Release SGLang Kernels / build-cu129-matrix (aarch64, 12.9, 3.10, arm-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / build-cu129-matrix (x86_64, 12.9, 3.10, x64-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / release-cu129 (push) Has been cancelled
Release SGLang Kernels / build-cu130-matrix (aarch64, 13.0, 3.10, arm-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / build-cu130-matrix (x86_64, 13.0, 3.10, x64-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / release-cu130 (push) Has been cancelled
Release SGLang Kernels / build-rocm-matrix (3.10, 700) (push) Has been cancelled
Release SGLang Kernels / build-rocm-matrix (3.10, 720) (push) Has been cancelled
Release SGLang Kernels / release-rocm700 (push) Has been cancelled
Release SGLang Kernels / release-rocm720 (push) Has been cancelled
Release SGLang Kernels / build-musa43 (43, 3.10) (push) Has been cancelled
Release SGLang Kernels / release-musa43 (push) Has been cancelled
280 lines
8.9 KiB
C++
280 lines
8.9 KiB
C++
#pragma once
|
|
#include "vec.h"
|
|
|
|
template <typename scalar_t>
|
|
inline void fill_stub(scalar_t* __restrict__ out, scalar_t val, int64_t size) {
|
|
using Vec = at::vec::Vectorized<scalar_t>;
|
|
const Vec data_vec(val);
|
|
at::vec::map<scalar_t>([data_vec](Vec out) { return out = data_vec; }, out, out, size);
|
|
}
|
|
|
|
template <typename scalar_t>
|
|
inline void copy_stub(scalar_t* __restrict__ out, const scalar_t* __restrict__ input, int64_t size) {
|
|
using Vec = at::vec::Vectorized<scalar_t>;
|
|
constexpr int kVecSize = Vec::size();
|
|
int64_t d;
|
|
#pragma GCC unroll 4
|
|
for (d = 0; d <= size - kVecSize; d += kVecSize) {
|
|
Vec data = Vec::loadu(input + d);
|
|
data.store(out + d);
|
|
}
|
|
for (; d < size; ++d) {
|
|
out[d] = input[d];
|
|
}
|
|
}
|
|
|
|
template <typename scalar_t>
|
|
inline void copy_stub(scalar_t* __restrict__ out, const float* __restrict__ input, int64_t size) {
|
|
using bVec = at::vec::Vectorized<scalar_t>;
|
|
using fVec = at::vec::Vectorized<float>;
|
|
constexpr int kVecSize = bVec::size();
|
|
int64_t d;
|
|
#pragma GCC unroll 4
|
|
for (d = 0; d <= size - kVecSize; d += kVecSize) {
|
|
auto [x0, x1] = load_float_vec2(input + d);
|
|
bVec out_vec = convert_from_float_ext<scalar_t>(x0, x1);
|
|
out_vec.store(out + d);
|
|
}
|
|
for (; d < size; ++d) {
|
|
out[d] = static_cast<scalar_t>(input[d]);
|
|
}
|
|
}
|
|
|
|
template <>
|
|
inline void copy_stub<uint8_t>(uint8_t* __restrict__ out, const uint8_t* __restrict__ input, int64_t size) {
|
|
// size might be 64x + 32
|
|
std::memcpy(out, input, size * sizeof(uint8_t));
|
|
}
|
|
|
|
template <typename scalar_t, typename input_t>
|
|
inline void copy_mul_stub(scalar_t* __restrict__ out, const input_t* __restrict__ input, float weight, int64_t size) {
|
|
static_assert(
|
|
std::is_same_v<input_t, float> || std::is_same_v<input_t, scalar_t>,
|
|
"copy_mul_stub only supports input_t == float or input_t == scalar_t");
|
|
using bVec = at::vec::Vectorized<scalar_t>;
|
|
using fVec = at::vec::Vectorized<float>;
|
|
constexpr int kVecSize = bVec::size();
|
|
const fVec weight_vec = fVec(weight);
|
|
int64_t d;
|
|
#pragma GCC unroll 4
|
|
for (d = 0; d <= size - kVecSize; d += kVecSize) {
|
|
auto [x0, x1] = load_float_vec2(input + d);
|
|
x0 = x0 * weight_vec;
|
|
x1 = x1 * weight_vec;
|
|
bVec out_vec = convert_from_float_ext<scalar_t>(x0, x1);
|
|
out_vec.store(out + d);
|
|
}
|
|
for (; d < size; ++d) {
|
|
out[d] = static_cast<scalar_t>(input[d] * weight);
|
|
}
|
|
}
|
|
|
|
// acc from [topk, K] to [K]
|
|
template <typename scalar_t>
|
|
inline void sum_stub(scalar_t* __restrict__ out, const scalar_t* __restrict__ input, int64_t topk, int64_t K) {
|
|
using bVec = at::vec::Vectorized<scalar_t>;
|
|
using fVec = at::vec::Vectorized<float>;
|
|
constexpr int kVecSize = bVec::size();
|
|
if (topk == 1) {
|
|
// do copy for topk = 1
|
|
copy_stub(out, input, K);
|
|
} else {
|
|
// do sum for topk != 1
|
|
int64_t d;
|
|
#pragma GCC unroll 4
|
|
for (d = 0; d <= K - kVecSize; d += kVecSize) {
|
|
fVec sum_fvec0 = fVec(0.f);
|
|
fVec sum_fvec1 = fVec(0.f);
|
|
for (int t = 0; t < topk; ++t) {
|
|
bVec x_bvec = bVec::loadu(input + t * K + d);
|
|
fVec x_fvec0, x_fvec1;
|
|
std::tie(x_fvec0, x_fvec1) = at::vec::convert_to_float(x_bvec);
|
|
|
|
sum_fvec0 += x_fvec0;
|
|
sum_fvec1 += x_fvec1;
|
|
}
|
|
bVec out_bvec = convert_from_float_ext<scalar_t>(sum_fvec0, sum_fvec1);
|
|
out_bvec.store(out + d);
|
|
}
|
|
for (; d < K; ++d) {
|
|
float sum_val = 0.f;
|
|
for (int t = 0; t < topk; ++t) {
|
|
sum_val += static_cast<float>(input[t * K + d]);
|
|
}
|
|
out[d] = static_cast<scalar_t>(sum_val);
|
|
}
|
|
}
|
|
}
|
|
|
|
// out = input + input2 * scale
|
|
template <typename scalar_t, typename input_t>
|
|
inline void add_mul_stub(
|
|
scalar_t* __restrict__ out,
|
|
const input_t* __restrict__ input,
|
|
const scalar_t* __restrict__ input2,
|
|
float scale,
|
|
int64_t size) {
|
|
static_assert(
|
|
std::is_same_v<input_t, float> || std::is_same_v<input_t, scalar_t>,
|
|
"add_mul_stub only supports input_t == float or input_t == scalar_t");
|
|
|
|
// out = input (without scale factor)
|
|
if (input2 == nullptr) {
|
|
copy_stub(out, input, size);
|
|
return;
|
|
}
|
|
|
|
using bVec = at::vec::Vectorized<scalar_t>;
|
|
using fVec = at::vec::Vectorized<float>;
|
|
constexpr int kVecSize = bVec::size();
|
|
const fVec s_vec = fVec(scale);
|
|
int64_t d;
|
|
#pragma GCC unroll 4
|
|
for (d = 0; d <= size - kVecSize; d += kVecSize) {
|
|
auto [x0, x1] = load_float_vec2(input + d);
|
|
|
|
bVec y_bvec = bVec::loadu(input2 + d);
|
|
fVec y0, y1;
|
|
std::tie(y0, y1) = at::vec::convert_to_float(y_bvec);
|
|
|
|
x0 = x0 + y0 * s_vec;
|
|
x1 = x1 + y1 * s_vec;
|
|
bVec out_vec = convert_from_float_ext<scalar_t>(x0, x1);
|
|
out_vec.store(out + d);
|
|
}
|
|
for (; d < size; ++d) {
|
|
out[d] = static_cast<scalar_t>(input[d] + float(input2[d]) * scale);
|
|
}
|
|
}
|
|
|
|
template <typename scalar_t>
|
|
inline void silu_and_mul_stub(
|
|
scalar_t* __restrict__ out, const scalar_t* __restrict__ input, const scalar_t* __restrict__ input2, int64_t size) {
|
|
using bVec = at::vec::Vectorized<scalar_t>;
|
|
using fVec = at::vec::Vectorized<float>;
|
|
const fVec one = fVec(1.f);
|
|
|
|
// no remainder
|
|
#pragma GCC unroll 4
|
|
for (int64_t d = 0; d < size; d += bVec::size()) {
|
|
bVec x = bVec::loadu(input + d);
|
|
fVec x0, x1;
|
|
std::tie(x0, x1) = at::vec::convert_to_float(x);
|
|
bVec y = bVec::loadu(input2 + d);
|
|
fVec y0, y1;
|
|
std::tie(y0, y1) = at::vec::convert_to_float(y);
|
|
x0 = x0 / (one + x0.neg().exp_u20());
|
|
x1 = x1 / (one + x1.neg().exp_u20());
|
|
x0 = x0 * y0;
|
|
x1 = x1 * y1;
|
|
bVec out_vec = convert_from_float_ext<scalar_t>(x0, x1);
|
|
out_vec.store(out + d);
|
|
}
|
|
}
|
|
|
|
template <typename scalar_t>
|
|
inline void copy_mul_stub(scalar_t* __restrict__ out, const float* __restrict__ input, float weight, int64_t size) {
|
|
using bVec = at::vec::Vectorized<scalar_t>;
|
|
using fVec = at::vec::Vectorized<float>;
|
|
constexpr int kVecSize = bVec::size();
|
|
const fVec weight_vec = fVec(weight);
|
|
int64_t d;
|
|
#pragma GCC unroll 4
|
|
for (d = 0; d <= size - kVecSize; d += kVecSize) {
|
|
fVec data0 = fVec::loadu(input + d) * weight_vec;
|
|
fVec data1 = fVec::loadu(input + d + fVec::size()) * weight_vec;
|
|
bVec out_vec = convert_from_float_ext<scalar_t>(data0, data1);
|
|
out_vec.store(out + d);
|
|
}
|
|
for (; d < size; ++d) {
|
|
out[d] = static_cast<scalar_t>(input[d] * weight);
|
|
}
|
|
}
|
|
|
|
// input = input + input2
|
|
inline void add_bias_stub(float* __restrict__ input, const float* __restrict__ input2, int64_t size) {
|
|
using fVec = at::vec::Vectorized<float>;
|
|
constexpr int kVecSize = fVec::size();
|
|
int64_t d;
|
|
#pragma GCC unroll 4
|
|
for (d = 0; d <= size - kVecSize; d += kVecSize) {
|
|
fVec x_fvec = fVec::loadu(input + d);
|
|
fVec y_fvec = fVec::loadu(input2 + d);
|
|
x_fvec = x_fvec + y_fvec;
|
|
x_fvec.store(input + d);
|
|
}
|
|
for (; d < size; ++d) {
|
|
input[d] = input[d] + input2[d];
|
|
}
|
|
}
|
|
|
|
template <typename scalar_t>
|
|
inline void copy_mul_stub(scalar_t* __restrict__ out, const scalar_t* __restrict__ input, float weight, int64_t size) {
|
|
using bVec = at::vec::Vectorized<scalar_t>;
|
|
using fVec = at::vec::Vectorized<float>;
|
|
constexpr int kVecSize = bVec::size();
|
|
const fVec weight_vec = fVec(weight);
|
|
int64_t d;
|
|
#pragma GCC unroll 4
|
|
for (d = 0; d <= size - kVecSize; d += kVecSize) {
|
|
bVec x = bVec::loadu(input + d);
|
|
fVec x0, x1;
|
|
std::tie(x0, x1) = at::vec::convert_to_float(x);
|
|
x0 = x0 * weight_vec;
|
|
x1 = x1 * weight_vec;
|
|
bVec out_vec = convert_from_float_ext<scalar_t>(x0, x1);
|
|
out_vec.store(out + d);
|
|
}
|
|
for (; d < size; ++d) {
|
|
out[d] = static_cast<scalar_t>(input[d] * weight);
|
|
}
|
|
}
|
|
|
|
template <typename scalar_t>
|
|
inline void clamp_sigmoid_and_mul_stub(
|
|
scalar_t* __restrict__ out,
|
|
const scalar_t* __restrict__ input,
|
|
int64_t size,
|
|
const float alpha,
|
|
const float limit) {
|
|
using bVec = at::vec::Vectorized<scalar_t>;
|
|
using fVec = at::vec::Vectorized<float>;
|
|
const fVec one = fVec(1.f);
|
|
const fVec zero = fVec(0.f);
|
|
const fVec limit_v = fVec(limit);
|
|
const fVec nlimit_v = fVec(-limit);
|
|
const fVec alpha_v = fVec(alpha);
|
|
|
|
// no remainder
|
|
#pragma GCC unroll 4
|
|
for (int64_t d = 0; d < size; d += bVec::size()) {
|
|
bVec x = bVec::loadu(input + d);
|
|
fVec x0_, y0_;
|
|
std::tie(x0_, y0_) = at::vec::convert_to_float(x);
|
|
float tmp_buffer[fVec::size() * 2]; // 32
|
|
float tmp_glu[fVec::size()]; // 16
|
|
float tmp_linear[fVec::size()]; // 16
|
|
x0_.store(tmp_buffer);
|
|
y0_.store(tmp_buffer + fVec::size());
|
|
// interleaved: x[2i] = glu, x[2i+1] = linear
|
|
for (int j = 0; j < fVec::size(); ++j) {
|
|
// x0 [0,2,..30]
|
|
tmp_glu[j] = tmp_buffer[j * 2];
|
|
// y0 [1,3,...31]
|
|
tmp_linear[j] = tmp_buffer[j * 2 + 1];
|
|
}
|
|
fVec x0 = fVec::loadu(tmp_glu);
|
|
fVec y0 = fVec::loadu(tmp_linear);
|
|
|
|
// clamp
|
|
x0 = at::vec::minimum(x0, limit_v);
|
|
y0 = at::vec::minimum(limit_v, at::vec::maximum(nlimit_v, y0));
|
|
// x * sigmoid(x * alpha)
|
|
x0 = x0 / (one + (x0 * alpha_v).neg().exp_u20());
|
|
// (y + 1) * x
|
|
y0 = y0 + one;
|
|
x0 = x0 * y0;
|
|
convert_from_float_and_store<scalar_t>(out + d / 2, x0);
|
|
}
|
|
}
|