Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
3 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/bash
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation.  All rights reserved.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
#
# Profile the CUDA QMoE GEMV decode path with nsys.
#
# Usage:
#   ./profile_qmoe_gemv.sh
#   ./profile_qmoe_gemv.sh --list-cases
#   ./profile_qmoe_gemv.sh --case m8_top2_fp16_128x256 --warmup 5 --repeat 200
#   ./profile_qmoe_gemv.sh --case gpt_oss_20b_m1_top4_fp16_2880x2880_e32 --warmup 5 --repeat 100
#   ./profile_qmoe_gemv.sh --case gpt_oss_20b_m1_top4_fp16_2880x2880_e32 --disable-splitk2-swiglu --warmup 5 --repeat 100
#   ./profile_qmoe_gemv.sh --batch-size 1 --sequence-length 1 --hidden-size 1024 --intermediate-size 4096 --num-experts 8 --top-k 2 --quant-bits 8 --block-size 128
#   CUDA_VISIBLE_DEVICES=1 ./profile_qmoe_gemv.sh -o /tmp/qmoe_gemv
#
 
set -e
set -o pipefail
 
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CASE="m1_top2_fp16_128x256"
WARMUP=5
REPEAT=100
OUTPUT_NAME="qmoe_gemv_profile"
PY="${PYTHON:-python}"
EXTRA_ARGS=()
LIST_CASES=0
DISABLE_SPLITK2_SWIGLU=0
 
while [[ "$#" -gt 0 ]]; do
    case $1 in
        --case)
            CASE="$2"
            shift
            ;;
        --list-cases)
            LIST_CASES=1
            ;;
        --splitk2-swiglu)
            DISABLE_SPLITK2_SWIGLU=0
            ;;
        --disable-splitk2-swiglu)
            DISABLE_SPLITK2_SWIGLU=1
            ;;
        --batch-size|--sequence-length|--hidden-size|--intermediate-size|--num-experts|--top-k|--dtype|--quant-bits|--block-size)
            EXTRA_ARGS+=("$1" "$2")
            shift
            ;;
        --repeat)
            REPEAT="$2"
            shift
            ;;
        --warmup)
            WARMUP="$2"
            shift
            ;;
        --python)
            PY="$2"
            shift
            ;;
        -o|--output)
            OUTPUT_NAME="$2"
            shift
            ;;
        *)
            echo "Unknown option: $1"
            echo "Usage: $0 [--list-cases] [--case NAME] [--splitk2-swiglu] [--disable-splitk2-swiglu] [--batch-size N] [--sequence-length N] [--hidden-size N] [--intermediate-size N] [--num-experts N] [--top-k N] [--dtype FLOAT16|BFLOAT16] [--quant-bits 4|8] [--block-size 0|32|64|128] [--warmup N] [--repeat N] [--python PYTHON] [-o NAME]"
            exit 1
            ;;
    esac
    shift
done
 
if [[ "${LIST_CASES}" -eq 1 ]]; then
    "${PY}" "${SCRIPT_DIR}/profile_qmoe_gemv.py" --list-cases
    exit 0
fi
 
if ! command -v nsys >/dev/null; then
    echo "Error: nsys not found. Install NVIDIA Nsight Systems or add it to PATH."
    exit 1
fi
 
HAVE_NVTX=0
if "${PY}" -c "import nvtx" 2>/dev/null; then
    HAVE_NVTX=1
else
    echo "Note: 'nvtx' package not installed. NVTX range markers will be disabled."
    echo "      Install with: pip install nvtx"
    echo "      Falling back to --skip-first to exclude warmup-like first calls."
fi
 
echo ""
echo "========================================"
echo "  Profiling: CUDA QMoE GEMV"
echo "========================================"
echo "Case:   ${CASE}"
echo "Warmup: ${WARMUP}"
echo "Repeat: ${REPEAT}"
echo "Python: ${PY}"
if [[ -n "${CUDA_VISIBLE_DEVICES:-}" ]]; then
    echo "CUDA_VISIBLE_DEVICES: ${CUDA_VISIBLE_DEVICES}"
fi
if [[ "${#EXTRA_ARGS[@]}" -gt 0 ]]; then
    echo "Custom args: ${EXTRA_ARGS[*]}"
fi
if [[ "${DISABLE_SPLITK2_SWIGLU}" -eq 1 ]]; then
    echo "Split-K2 SwiGLU: disabled for GEMV mode"
fi
 
profile_one() {
    local mode="$1"
    local disable_arg=""
    local splitk2_arg=""
    local base="${OUTPUT_NAME}_${mode}"
    if [[ "${mode}" == "gemm" ]]; then
        disable_arg="--disable-gemv"
    elif [[ "${DISABLE_SPLITK2_SWIGLU}" -eq 1 ]]; then
        splitk2_arg="--disable-splitk2-swiglu"
    fi
 
    echo ""
    echo "---- Profiling ${mode} ----"
    rm -f "${base}.nsys-rep" "${base}.sqlite"
    nsys profile -t cuda,nvtx --force-overwrite true -o "${base}" --export=sqlite \
        "${PY}" "${SCRIPT_DIR}/profile_qmoe_gemv.py" \
            --case "${CASE}" "${EXTRA_ARGS[@]}" --warmup "${WARMUP}" --repeat "${REPEAT}" --nvtx \
            ${disable_arg} ${splitk2_arg}
 
    echo ""
    echo "---- Kernel results (${mode}) ----"
    if [[ "${HAVE_NVTX}" -eq 1 ]]; then
        "${PY}" "${SCRIPT_DIR}/parse_nsys.py" "${base}.sqlite" --nvtx-range benchmark
    else
        "${PY}" "${SCRIPT_DIR}/parse_nsys.py" "${base}.sqlite" --skip-first 1
    fi
}
 
profile_one gemv
profile_one gemm
 
echo ""
echo "Done."