data: cat 3 SGEMM repos — siboehm, wangzyon, edtallison (full clone, no --depth)
Sources: siboehm/SGEMM_CUDA → upstream_ref/sgemm_siboehm/ (25 files) wangzyon/NVIDIA_SGEMM_PRACTICE → upstream_ref/nvidia_sgemm_practice/ (23 files, filled gaps) edtallison/sgemm-cuda → upstream_ref/sgemm_edtallison/ (41 files) All files cat'd one by one from git clone (no --depth). These are the 3 public SGEMM repos that can compile on CUDA 10.2 + CoreX ivcore10. Key files for BI-V100 porting: kernel 10 (warp tiling) — already proven on device with WARPSIZE=64 kernel 11/12 (double buffering) — next optimization target sgemm.cu + runner.cu — complete build+benchmark harness CMakeLists.txt — build system reference
This commit is contained in:
33
upstream_ref/sgemm_edtallison/scripts/bank_calc.py
Normal file
33
upstream_ref/sgemm_edtallison/scripts/bank_calc.py
Normal file
@@ -0,0 +1,33 @@
|
||||
banks_naive = lambda r, c: (r * 32 + c) % 32
|
||||
banks_one_extra = lambda r, c: (r * 33 + c) % 32
|
||||
|
||||
ITEMS_PER_WARP = 8
|
||||
|
||||
|
||||
def printBankConflicts(bank_fun):
|
||||
for c in range(1):
|
||||
banks = []
|
||||
for i in range(32):
|
||||
row = (i * ITEMS_PER_WARP) // 16
|
||||
col = (i * ITEMS_PER_WARP + c) % 16
|
||||
banks.append((i, row, col, bank_fun(row, col)))
|
||||
print("Step", c, "\n", "\n".join(["(" + ",".join(str(x) for x in i) + ")" for i in banks]))
|
||||
d = {k: 0 for k in range(32)}
|
||||
for i in banks:
|
||||
d[i[-1]] += 1
|
||||
|
||||
count = 0
|
||||
for key, val in d.items():
|
||||
if val > 0:
|
||||
count += 1
|
||||
|
||||
print(
|
||||
f"Bank conflicts (Step {c}): {sorted(d.items(), key=lambda item: item[1], reverse=True)[0][1]}, banks accessed: {count}/32\n"
|
||||
)
|
||||
|
||||
|
||||
print("---NAIVE---")
|
||||
printBankConflicts(banks_naive, 32)
|
||||
|
||||
print("\n---EXTRA COL---")
|
||||
printBankConflicts(banks_one_extra, 33)
|
||||
115
upstream_ref/sgemm_edtallison/scripts/kernel_10_autotuner.sh
Executable file
115
upstream_ref/sgemm_edtallison/scripts/kernel_10_autotuner.sh
Executable file
@@ -0,0 +1,115 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -u
|
||||
|
||||
# Define the range of values for each parameter
|
||||
BK_VALUES=(8 16 32 64)
|
||||
BM_VALUES=(64 128 256)
|
||||
BN_VALUES=(64 128 256)
|
||||
WM_VALUES=(32 64 128 256)
|
||||
WN_VALUES=(32 64 128 256)
|
||||
WNITER_VALUES=(1 2 4 8)
|
||||
TM_VALUES=(4 8 16 32)
|
||||
TN_VALUES=(4 8 16 32)
|
||||
NUM_THREADS_VALUES=(128 256)
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
cd "../build"
|
||||
|
||||
RUNNER="../src/runner.cu"
|
||||
OUTPUT="../benchmark_results/kernel_10_autotune_results.txt"
|
||||
|
||||
# Clear the output file
|
||||
echo "" > $OUTPUT
|
||||
|
||||
# Set GPU to use
|
||||
export DEVICE="0"
|
||||
WARPSIZE=32
|
||||
|
||||
|
||||
TOTAL_CONFIGS="$(( ${#BK_VALUES[@]} * ${#BM_VALUES[@]} * ${#BN_VALUES[@]} * ${#WM_VALUES[@]} * ${#WN_VALUES[@]} * ${#WNITER_VALUES[@]} * ${#TM_VALUES[@]} * ${#TN_VALUES[@]} * ${#NUM_THREADS_VALUES[@]} ))"
|
||||
CONFIG_NUM=0
|
||||
|
||||
# Loop through all combinations of parameters
|
||||
for BK in "${BK_VALUES[@]}"; do
|
||||
for BM in "${BM_VALUES[@]}"; do
|
||||
for BN in "${BN_VALUES[@]}"; do
|
||||
for WM in "${WM_VALUES[@]}"; do
|
||||
for WN in "${WN_VALUES[@]}"; do
|
||||
for WN_ITER in "${WNITER_VALUES[@]}"; do
|
||||
for TM in "${TM_VALUES[@]}"; do
|
||||
for TN in "${TN_VALUES[@]}"; do
|
||||
for NUM_THREADS in "${NUM_THREADS_VALUES[@]}"; do
|
||||
echo ""
|
||||
CONFIG_NUM=$(( CONFIG_NUM + 1 ))
|
||||
# skip configurations that don't fullfil preconditions
|
||||
NUM_WARPS=$(( NUM_THREADS / 32 ))
|
||||
if ! (( BN % WN == 0 && BM % WM == 0 )); then
|
||||
echo "Error: BN % WN must be 0 and BM % WM must be 0."
|
||||
continue
|
||||
fi
|
||||
if ! (( (BN / WN) * (BM / WM) == NUM_WARPS )); then
|
||||
echo "Error: (BN / WN) * (BM / WM) must be equal to NUM_WARPS."
|
||||
continue
|
||||
fi
|
||||
if ! (( (WM * WN) % (WARPSIZE * TM * TN * WN_ITER) == 0 )); then
|
||||
echo "Error: (WM * WN) % (WARPSIZE * TM * TN * WN_ITER) must be 0."
|
||||
continue
|
||||
fi
|
||||
WM_ITER=$(( (WM * WN) / (WARPSIZE * TM * TN * WN_ITER) ))
|
||||
if ! (( WM % WM_ITER == 0 && WN % WN_ITER == 0 )); then
|
||||
echo "Error: WM % WM_ITER must be 0 and WN % WN_ITER must be 0."
|
||||
continue
|
||||
fi
|
||||
if ! (( (NUM_THREADS * 4) % BK == 0 )); then
|
||||
echo "Error: (NUM_THREADS * 4) % BK must be 0."
|
||||
continue
|
||||
fi
|
||||
if ! (( (NUM_THREADS * 4) % BN == 0 )); then
|
||||
echo "Error: (NUM_THREADS * 4) % BN must be 0."
|
||||
continue
|
||||
fi
|
||||
if ! (( BN % (16 * TN) == 0 )); then
|
||||
echo "Error: BN must be a multiple of 16 * TN."
|
||||
continue
|
||||
fi
|
||||
if ! (( BM % (16 * TM) == 0 )); then
|
||||
echo "Error: BM must be a multiple of 16 * TM."
|
||||
continue
|
||||
fi
|
||||
if ! (( (BM * BK) % (4 * NUM_THREADS) == 0 )); then
|
||||
echo "Error: (BM * BK) % (4 * NUM_THREADS) must be 0."
|
||||
continue
|
||||
fi
|
||||
if ! (( (BN * BK) % (4 * NUM_THREADS) == 0 )); then
|
||||
echo "Error: (BN * BK) % (4 * NUM_THREADS) must be 0."
|
||||
continue
|
||||
fi
|
||||
|
||||
# Update the parameters in the source code
|
||||
sed -i "s/const uint K10_NUM_THREADS = .*/const uint K10_NUM_THREADS = $NUM_THREADS;/" $RUNNER
|
||||
sed -i "s/const uint K10_BN = .*/const uint K10_BN = $BN;/" $RUNNER
|
||||
sed -i "s/const uint K10_BM = .*/const uint K10_BM = $BM;/" $RUNNER
|
||||
sed -i "s/const uint K10_BK = .*/const uint K10_BK = $BK;/" $RUNNER
|
||||
sed -i "s/const uint K10_WM = .*/const uint K10_WM = $WM;/" $RUNNER
|
||||
sed -i "s/const uint K10_WN = .*/const uint K10_WN = $WN;/" $RUNNER
|
||||
sed -i "s/const uint K10_WNITER = .*/const uint K10_WNITER = $WN_ITER;/" $RUNNER
|
||||
sed -i "s/const uint K10_TM = .*/const uint K10_TM = $TM;/" $RUNNER
|
||||
sed -i "s/const uint K10_TN = .*/const uint K10_TN = $TN;/" $RUNNER
|
||||
|
||||
# Rebuild the program
|
||||
make
|
||||
|
||||
echo "($CONFIG_NUM/$TOTAL_CONFIGS): BK=$BK BM=$BM BN=$BN WM=$WM WN=$WN WN_ITER=$WN_ITER TM=$TM TN=$TN NUM_THREADS=$NUM_THREADS" |& tee -a $OUTPUT
|
||||
# Run the benchmark and get the result
|
||||
# Kill the program after 4 seconds if it doesn't finish
|
||||
timeout -v 8 ./sgemm 10 | tee -a $OUTPUT
|
||||
done
|
||||
done
|
||||
done
|
||||
done
|
||||
done
|
||||
done
|
||||
done
|
||||
done
|
||||
done
|
||||
115
upstream_ref/sgemm_edtallison/scripts/kernel_11_autotuner.sh
Executable file
115
upstream_ref/sgemm_edtallison/scripts/kernel_11_autotuner.sh
Executable file
@@ -0,0 +1,115 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -u
|
||||
|
||||
# Define the range of values for each parameter
|
||||
BK_VALUES=(8 16 32 64)
|
||||
BM_VALUES=(64 128 256)
|
||||
BN_VALUES=(64 128 256)
|
||||
WM_VALUES=(32 64 128 256)
|
||||
WN_VALUES=(32 64 128 256)
|
||||
WNITER_VALUES=(1 2 4 8)
|
||||
TM_VALUES=(4 8 16 32)
|
||||
TN_VALUES=(4 8 16 32)
|
||||
NUM_THREADS_VALUES=(128 256)
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
cd "../build"
|
||||
|
||||
RUNNER="../src/runner.cu"
|
||||
OUTPUT="../benchmark_results/kernel_11_autotune_results.txt"
|
||||
|
||||
# Clear the output file
|
||||
echo "" > $OUTPUT
|
||||
|
||||
# Set GPU to use
|
||||
export DEVICE="0"
|
||||
WARPSIZE=32
|
||||
|
||||
|
||||
TOTAL_CONFIGS="$(( ${#BK_VALUES[@]} * ${#BM_VALUES[@]} * ${#BN_VALUES[@]} * ${#WM_VALUES[@]} * ${#WN_VALUES[@]} * ${#WNITER_VALUES[@]} * ${#TM_VALUES[@]} * ${#TN_VALUES[@]} * ${#NUM_THREADS_VALUES[@]} ))"
|
||||
CONFIG_NUM=0
|
||||
|
||||
# Loop through all combinations of parameters
|
||||
for BK in "${BK_VALUES[@]}"; do
|
||||
for BM in "${BM_VALUES[@]}"; do
|
||||
for BN in "${BN_VALUES[@]}"; do
|
||||
for WM in "${WM_VALUES[@]}"; do
|
||||
for WN in "${WN_VALUES[@]}"; do
|
||||
for WN_ITER in "${WNITER_VALUES[@]}"; do
|
||||
for TM in "${TM_VALUES[@]}"; do
|
||||
for TN in "${TN_VALUES[@]}"; do
|
||||
for NUM_THREADS in "${NUM_THREADS_VALUES[@]}"; do
|
||||
echo ""
|
||||
CONFIG_NUM=$(( CONFIG_NUM + 1 ))
|
||||
# skip configurations that don't fullfil preconditions
|
||||
NUM_WARPS=$(( NUM_THREADS / 32 ))
|
||||
if ! (( BN % WN == 0 && BM % WM == 0 )); then
|
||||
echo "Error: BN % WN must be 0 and BM % WM must be 0."
|
||||
continue
|
||||
fi
|
||||
if ! (( (BN / WN) * (BM / WM) == NUM_WARPS )); then
|
||||
echo "Error: (BN / WN) * (BM / WM) must be equal to NUM_WARPS."
|
||||
continue
|
||||
fi
|
||||
if ! (( (WM * WN) % (WARPSIZE * TM * TN * WN_ITER) == 0 )); then
|
||||
echo "Error: (WM * WN) % (WARPSIZE * TM * TN * WN_ITER) must be 0."
|
||||
continue
|
||||
fi
|
||||
WM_ITER=$(( (WM * WN) / (WARPSIZE * TM * TN * WN_ITER) ))
|
||||
if ! (( WM % WM_ITER == 0 && WN % WN_ITER == 0 )); then
|
||||
echo "Error: WM % WM_ITER must be 0 and WN % WN_ITER must be 0."
|
||||
continue
|
||||
fi
|
||||
if ! (( (NUM_THREADS * 4) % BK == 0 )); then
|
||||
echo "Error: (NUM_THREADS * 4) % BK must be 0."
|
||||
continue
|
||||
fi
|
||||
if ! (( (NUM_THREADS * 4) % BN == 0 )); then
|
||||
echo "Error: (NUM_THREADS * 4) % BN must be 0."
|
||||
continue
|
||||
fi
|
||||
if ! (( BN % (16 * TN) == 0 )); then
|
||||
echo "Error: BN must be a multiple of 16 * TN."
|
||||
continue
|
||||
fi
|
||||
if ! (( BM % (16 * TM) == 0 )); then
|
||||
echo "Error: BM must be a multiple of 16 * TM."
|
||||
continue
|
||||
fi
|
||||
if ! (( (BM * BK) % (4 * NUM_THREADS) == 0 )); then
|
||||
echo "Error: (BM * BK) % (4 * NUM_THREADS) must be 0."
|
||||
continue
|
||||
fi
|
||||
if ! (( (BN * BK) % (4 * NUM_THREADS) == 0 )); then
|
||||
echo "Error: (BN * BK) % (4 * NUM_THREADS) must be 0."
|
||||
continue
|
||||
fi
|
||||
|
||||
# Update the parameters in the source code
|
||||
sed -i "s/const uint K11_NUM_THREADS = .*/const uint K11_NUM_THREADS = $NUM_THREADS;/" $RUNNER
|
||||
sed -i "s/const uint K11_BN = .*/const uint K11_BN = $BN;/" $RUNNER
|
||||
sed -i "s/const uint K11_BM = .*/const uint K11_BM = $BM;/" $RUNNER
|
||||
sed -i "s/const uint K11_BK = .*/const uint K11_BK = $BK;/" $RUNNER
|
||||
sed -i "s/const uint K11_WM = .*/const uint K11_WM = $WM;/" $RUNNER
|
||||
sed -i "s/const uint K11_WN = .*/const uint K11_WN = $WN;/" $RUNNER
|
||||
sed -i "s/const uint K11_WNITER = .*/const uint K11_WNITER = $WN_ITER;/" $RUNNER
|
||||
sed -i "s/const uint K11_TM = .*/const uint K11_TM = $TM;/" $RUNNER
|
||||
sed -i "s/const uint K11_TN = .*/const uint K11_TN = $TN;/" $RUNNER
|
||||
|
||||
# Rebuild the program
|
||||
make
|
||||
|
||||
echo "($CONFIG_NUM/$TOTAL_CONFIGS): BK=$BK BM=$BM BN=$BN WM=$WM WN=$WN WN_ITER=$WN_ITER TM=$TM TN=$TN NUM_THREADS=$NUM_THREADS" |& tee -a $OUTPUT
|
||||
# Run the benchmark and get the result
|
||||
# Kill the program after 8 seconds if it doesn't finish
|
||||
timeout -v 8 ./sgemm 11 | tee -a $OUTPUT
|
||||
done
|
||||
done
|
||||
done
|
||||
done
|
||||
done
|
||||
done
|
||||
done
|
||||
done
|
||||
done
|
||||
86
upstream_ref/sgemm_edtallison/scripts/kernel_9_autotuner.sh
Executable file
86
upstream_ref/sgemm_edtallison/scripts/kernel_9_autotuner.sh
Executable file
@@ -0,0 +1,86 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -u
|
||||
|
||||
# Define the range of values for each parameter
|
||||
BK_VALUES=(8 16 32 64)
|
||||
TM_VALUES=(4 8 16 32)
|
||||
TN_VALUES=(4 8 16 32)
|
||||
BM_VALUES=(64 128 256)
|
||||
BN_VALUES=(64 128 256)
|
||||
NUM_THREADS_VALUES=(256)
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
cd "../build"
|
||||
|
||||
RUNNER="../src/runner.cu"
|
||||
KERNEL="../src/kernels/9_kernel_autotuned.cuh"
|
||||
OUTPUT="../benchmark_results/kernel_9_autotune_results.txt"
|
||||
|
||||
# Clear the output file
|
||||
echo "" > $OUTPUT
|
||||
|
||||
# Set GPU to use
|
||||
export DEVICE="2"
|
||||
|
||||
TOTAL_CONFIGS="$(( ${#NUM_THREADS_VALUES[@]} * ${#BK_VALUES[@]} * ${#TM_VALUES[@]} * ${#TN_VALUES[@]} * ${#BM_VALUES[@]} * ${#BN_VALUES[@]} ))"
|
||||
CONFIG_NUM=0
|
||||
|
||||
# Loop through all combinations of parameters
|
||||
for bk in ${BK_VALUES[@]}; do
|
||||
for tm in ${TM_VALUES[@]}; do
|
||||
for tn in ${TN_VALUES[@]}; do
|
||||
for bm in ${BM_VALUES[@]}; do
|
||||
for bn in ${BN_VALUES[@]}; do
|
||||
for nt in ${NUM_THREADS_VALUES[@]}; do
|
||||
echo ""
|
||||
CONFIG_NUM=$(( $CONFIG_NUM + 1 ))
|
||||
|
||||
# skip configurations that don't fullfil preconditions
|
||||
config="BK=$bk TM=$tm TN=$tn BM=$bm BN=$bn NT=$nt"
|
||||
if [[ $(( ($nt * 4) % bk )) -ne 0 ]]; then
|
||||
echo "VECTORIZE: Skipping $config because (NUM_THREADS * 4) % BK = $(( ($nt * 4) % bk )) != 0))"
|
||||
continue
|
||||
fi
|
||||
if [[ $(( ($nt * 4) % bn )) -ne 0 ]]; then
|
||||
echo "VECTORIZE: Skipping $config because (NUM_THREADS * 4) % BN = $(( ($nt * 4) % bn )) != 0))"
|
||||
continue
|
||||
fi
|
||||
if [[ $(( $bn % (16 * $tn ) )) -ne 0 ]]; then
|
||||
echo "QUANTIZATION: Skipping $config because BN % (16 * TN) = $(( $bn % (16 * $tn ) )) != 0))"
|
||||
continue
|
||||
fi
|
||||
if [[ $(( $bm % (16 * $tm ) )) -ne 0 ]]; then
|
||||
echo "QUANTIZATION: Skipping $config because BM % (16 * TM) = $(( $bm % (16 * $tm ) )) != 0))"
|
||||
continue
|
||||
fi
|
||||
if [[ $(( ($bm * $bk) % ( 4 * $nt ) )) -ne 0 ]]; then
|
||||
echo "VECTORIZE: Skipping $config because (BM * BK) % (4 * NUM_THREADS) = $(( ($bm * $bk) % ( 4 * 256 ) )) != 0))"
|
||||
continue
|
||||
fi
|
||||
if [[ $(( ($bn * $bk) % ( 4 * $nt ) )) -ne 0 ]]; then
|
||||
echo "VECTORIZE: Skipping $config because (BN * BK) % (4 * NUM_THREADS) = $(( ($bn * $bk) % ( 4 * 256 ) )) != 0))"
|
||||
continue
|
||||
fi
|
||||
|
||||
# Update the parameters in the source code
|
||||
sed -i "s/const uint K9_BK = .*/const uint K9_BK = $bk;/" $RUNNER
|
||||
sed -i "s/const uint K9_TM = .*/const uint K9_TM = $tm;/" $RUNNER
|
||||
sed -i "s/const uint K9_TN = .*/const uint K9_TN = $tn;/" $RUNNER
|
||||
sed -i "s/const uint K9_BM = .*/const uint K9_BM = $bm;/" $RUNNER
|
||||
sed -i "s/const uint K9_BN = .*/const uint K9_BN = $bn;/" $RUNNER
|
||||
sed -i "s/const int K9_NUM_THREADS = .*/const int K9_NUM_THREADS = $nt;/" $KERNEL
|
||||
|
||||
# Rebuild the program
|
||||
make
|
||||
|
||||
echo "($CONFIG_NUM/$TOTAL_CONFIGS): BK=$bk TM=$tm TN=$tn BM=$bm BN=$bn NUM_THREADS=$nt" |& tee -a $OUTPUT
|
||||
# Run the benchmark and get the result
|
||||
# Kill the program after 4 seconds if it doesn't finish
|
||||
timeout -v 4 ./sgemm 9 | tee -a $OUTPUT
|
||||
done
|
||||
done
|
||||
done
|
||||
done
|
||||
done
|
||||
done
|
||||
Reference in New Issue
Block a user