[QST]How to optimize the tensorrt-llm's mixed gemm
What is your question? Recently ,i used the tensorrt-llm's example to run the qwen 1.5-2.5B inference by A100 GPU.According to ncu's analysis report.Some gemm can be optimised. In that report said that the grid for this launch is configured to execute only 32 blocks, which is less than the GPU's 108 multiprocessors. This can underutilize some multiprocessors. I have tried to use smaller threadblock shape,but it had no effect.
For example tensorrt-llm used threadblock shape and warp shape is <16,128,64> <16,32,64> ,and i tried to use threadblock shape and warp shape are <8,128,64> <8,64,64>.
Working directory/tensorrt_llm/examples/models/core/qwen .
1、Download the Qwen2.5-1.5B(-Instruct).
2、transform the data:python: convert_checkpoint.py --model_dir ./Qwen2.5-1.5B-Instruct --output_dir ./output_dir --dtype float16 --use_weight_only --weight_only_precision int8
3、compile:trtllm-build --checkpoint_dir ./output_dir --output_dir ./1-gpu --gemm_plugin float16 > trt-build.txt.
4、python3 ../../../run.py --input_text "熵"
--max_output_len=10
--tokenizer_dir Qwen2.5-1.5B-Instruct
--engine_dir=./1-gpu/
In fpA_intB_gemm_template.h file,i added some code to print kernel's run time and this gemm's shape.
In that way ,i got ncu's report: ncu -o profile --target-processes all -f python3 ../../../run.py --input_text "熵" --max_output_len=1 --tokenizer_dir ./tmp/Qwen/Qwen2.5-1.5B-Instruct/ --engine_dir=./tmp/qwen/Qwen2.5-1.5B-Instruct/trt_engines/w8a8/1-gpu/ --cuda_graph_mode --no_prompt_template 2>&1 | tee log.txt mv profile.ncu-rep qwen2.5-1.5B-16b-w8a8.ncu-rep ncu --import qwen2.5-1.5B-16b-w8a8.ncu-rep > ncu-qwen2.5-1.5B-16b-w8a8.txt
These are som ncu report's message: void cutlass::Kernel<cutlass::GemmFpAIntB<cutlass::DqMmaMultistage<cutlass::GemmShape<16, 128, 64>, cutlass::PredicatedTileAccessIterator<cutlass::MatrixShape<16, 64>, cutlass::half_t, cutlass::RowMajor, 1, cutlass::PitchLinearWarpRakedThreadMap<cutlass::PitchLinearShape<64, 16>, 128, cutlass::PitchLinearShape<8, 4>, 8>, cutlass::Array<cutlass::half_t, 8, 0>, 0, cutlass::NoPermute>, cutlass::RegularTileAccessIterator<cutlass::MatrixShape<16, 64>, cutlass::half_t, cutlass::RowMajorTensorOpMultiplicandCrosswise<16, 64>, 0, cutlass::PitchLinearWarpRakedThreadMap<cutlass::PitchLinearShape<64, 16>, 128, cutlass::PitchLinearShape<8, 4>, 8>, 16>, 1, cutlass::PredicatedTileAccessIterator<cutlass::MatrixShape<128, 64>, unsigned char, cutlass::ColumnMajor, 0, cutlass::PitchLinearWarpRakedThreadMap<cutlass::PitchLinearShape<128, 64>, 128, cutlass::PitchLinearShape<8, 4>, 16>, cutlass::Array<unsigned char, 16, 0>, 0, cutlass::NoPermute>, cutlass::RegularTileAccessIterator<cutlass::MatrixShape<64, 128>, unsigned char, cutlass::ColumnMajorTensorOpMultiplicandCrosswise<8, 64>, 1, cutlass::PitchLinearWarpRakedThreadMap<cutlass::PitchLinearShape<64, 128>, 128, cutlass::PitchLinearShape<4, 8>, 16>, 16>, 1, cutlass::PredicatedTileIterator<cutlass::MatrixShape<1, 128>, cutlass::half_t, cutlass::RowMajor, 0, cutlass::PitchLinearStripminedThreadMap<cutlass::PitchLinearShape<128, 1>, 16, 8>, 8, 0, cutlass::NoPermute>, cutlass::PredicatedTileIterator<cutlass::MatrixShape<1, 128>, cutlass::half_t, cutlass::RowMajor, 0, cutlass::PitchLinearStripminedThreadMap<cutlass::PitchLinearShape<128, 1>, 16, 8>, 8, 0, cutlass::NoPermute>, float, cutlass::RowMajor, cutlass::MmaPolicy<cutlass::MmaTensorOpComputeBWithF16<cutlass::GemmShape<16, 32, 64>, cutlass::half_t, cutlass::RowMajorTensorOpMultiplicandCrosswise<16, 64>, unsigned char, cutlass::ColumnMajorTensorOpMultiplicandCrosswise<8, 64>, float, cutlass::RowMajor, cutlass::MmaTensorOpPolicy<cutlass::Mma<cutlass::GemmShape<16, 8, 16>, 32, cutlass::half_t, cutlass::RowMajor, cutlass::half_t, cutlass::ColumnMajor, float, cutlass::RowMajor, cutlass::OpMultiplyAdd>, cutlass::MatrixShape<1, 1>>, cutlass::GemmShape<16, 8, 16>, 1, 0, bool>, cutlass::MatrixShape<0, 0>, cutlass::MatrixShape<0, 0>, 1>, 3, cutlass::FastInterleavedAndBiasedNumericArrayConverter<cutlass::half_t, unsigned char, 16>, 1, 0, void>, cutlass::Epilogue<cutlass::GemmShape<16, 128, 64>, cutlass::MmaTensorOpComputeBWithF16<cutlass::GemmShape<16, 32, 64>, cutlass::half_t, cutlass::RowMajorTensorOpMultiplicandCrosswise<16, 64>, unsigned char, cutlass::ColumnMajorTensorOpMultiplicandCrosswise<8, 64>, float, cutlass::RowMajor, cutlass::MmaTensorOpPolicy<cutlass::Mma<cutlass::GemmShape<16, 8, 16>, 32, cutlass::half_t, cutlass::RowMajor, cutlass::half_t, cutlass::ColumnMajor, float, cutlass::RowMajor, cutlass::OpMultiplyAdd>, cutlass::MatrixShape<1, 1>>, cutlass::GemmShape<16, 8, 16>, 1, 0, bool>, 1, cutlass::PredicatedTileIterator<cutlass::OutputTileOptimalThreadMap<cutlass::OutputTileShape<128, 8, 1, 1, 1>, cutlass::OutputTileShape<1, 2, 1, 1, 2>, 128, 8, 16>, cutlass::half_t, 0, cutlass::NoPermute, 0>, cutlass::FragmentIteratorTensorOp<cutlass::GemmShape<16, 32, 64>, cutlass::GemmShape<16, 8, 16>, float, cutlass::Array<float, 4, 1>, cutlass::RowMajor>, cutlass::TileIteratorTensorOpMixed<cutlass::GemmShape<16, 32, 64>, cutlass::GemmShape<16, 8, 16>, float, 32, 16, 8, 8, 0>, cutlass::SharedLoadIteratorMixed<cutlass::OutputTileOptimalThreadMap<cutlass::OutputTileShape<128, 8, 1, 1, 1>, cutlass::OutputTileShape<1, 2, 1, 1, 2>, 128, 8, 16>::CompactedThreadMap, float, 32, 16, 8, 8, 0>, cutlass::LinearCombination<cutlass::half_t, 8, float, float, 1, 2, cutlass::half_t>, cutlass::MatrixShape<0, 8>, 2, 1>, cutlass::GemmIdentityThreadblockSwizzle<8>, cutlass::Sm80, 1>>(T1::Params) (16, 2, 1)x(128, 1, 1), Context 1, Stream 13, Device 0, CC 8.0 Section: GPU Speed Of Light Throughput ----------------------- ----------- ------------ Metric Name Metric Unit Metric Value ----------------------- ----------- ------------ DRAM Frequency Ghz 1.21 SM Frequency Mhz 763.58 Elapsed Cycles cycle 18,650 Memory Throughput % 8.62 DRAM Throughput % 8.62 Duration us 24.42 L1/TEX Cache Throughput % 27.66 L2 Cache Throughput % 13.52 SM Active Cycles cycle 4,748.06 Compute (SM) Throughput % 8.79 ----------------------- ----------- ------------
OPT This kernel grid is too small to fill the available resources on this device, resulting in only 0.1 full
waves across all SMs. Look at Launch Statistics for more details.
Section: Launch Statistics
-------------------------------- --------------- ---------------
Metric Name Metric Unit Metric Value
-------------------------------- --------------- ---------------
Block Size 128
Function Cache Configuration CachePreferNone
Grid Size 32
Registers Per Thread register/thread 68
Shared Memory Configuration Size Kbyte 167.94
Driver Shared Memory Per Block Kbyte/block 1.02
Dynamic Shared Memory Per Block Kbyte/block 30.98
Static Shared Memory Per Block byte/block 0
# SMs SM 108
Stack Size 1,024
Threads thread 4,096
# TPCs 54
Enabled TPC IDs all
Uses Green Context 0
Waves Per SM 0.06
-------------------------------- --------------- ---------------
**OPT Est. Speedup: 70.37%
**The grid for this launch is configured to execute only 32 blocks, which is less than the GPU's 108
multiprocessors. This can underutilize some multiprocessors. If you do not intend to execute this kernel
concurrently with other workloads, consider reducing the block size to have at least one block per
multiprocessor or increase the size of the grid to fully utilize the available hardware resource**s**. See the
Hardware Model (https://docs.nvidia.com/nsight-compute/ProfilingGuide/index.html#metrics-hw-model)
description for more details on launch configurations.
Section: Occupancy
------------------------------- ----------- ------------
Metric Name Metric Unit Metric Value
------------------------------- ----------- ------------
Block Limit SM block 32
Block Limit Registers block 7
Block Limit Shared Mem block 5
Block Limit Warps block 16
Theoretical Active Warps per SM warp 20
Theoretical Occupancy % 31.25
Achieved Occupancy % 5.73
Achieved Active Warps Per SM warp 3.67
------------------------------- ----------- ------------
OPT Est. Local Speedup: 81.66%
The difference between calculated theoretical (31.2%) and measured achieved occupancy (5.7%) can be the
result of warp scheduling overheads or workload imbalances during the kernel execution. Load imbalances can
occur between warps within a block as well as across blocks of the same kernel. See the CUDA Best Practices
Guide (https://docs.nvidia.com/cuda/cuda-c-best-practices-guide/index.html#occupancy) for more details on
optimizing occupancy.
----- --------------------------------------------------------------------------------------------------------------
OPT Est. Local Speedup: 68.75%
The 5.00 theoretical warps per scheduler this kernel can issue according to its occupancy are below the
hardware maximum of 16. This kernel's theoretical occupancy (31.2%) is limited by the required amount of
shared memory.
Section: GPU and Memory Workload Distribution
-------------------------- ----------- ------------
Metric Name Metric Unit Metric Value
-------------------------- ----------- ------------
Average DRAM Active Cycles cycle 2,550.20
Total DRAM Elapsed Cycles cycle 1,183,232
Average L1 Active Cycles cycle 4,748.06
Total L1 Elapsed Cycles cycle 1,883,824
Average L2 Active Cycles cycle 13,081.06
Total L2 Elapsed Cycles cycle 1,491,680
Average SM Active Cycles cycle 4,748.06
Total SM Elapsed Cycles cycle 1,883,824
Average SMSP Active Cycles cycle 4,323.94
Total SMSP Elapsed Cycles cycle 7,535,296
-------------------------- ----------- ------------
OPT Est. Speedup: 19.43%
One or more SMs have a much lower number of active cycles than the average number of active cycles. Maximum
instance value is 71.37% above the average, while the minimum instance value is 100.00% below the average.
----- --------------------------------------------------------------------------------------------------------------
OPT Est. Speedup: 17.79%
One or more SMSPs have a much lower number of active cycles than the average number of active cycles. Maximum
instance value is 71.78% above the average, while the minimum instance value is 100.00% below the average.
----- --------------------------------------------------------------------------------------------------------------
OPT Est. Speedup: 19.43%
One or more L1 Slices have a much lower number of active cycles than the average number of active cycles.
Maximum instance value is 71.37% above the average, while the minimum instance value is 100.00% below the
average.
I want to know how to use these message to optimise my gemm!
I want to know that how can i use the message provided above!
you can use splitk or streamk to saturate gpu if your problem size k is big and you have idle sm. basically, these two methods put more threadblocks on the k dimension
This issue has been labeled inactive-30d due to no recent activity in the past 30 days. Please close this issue if no further response or action is needed. Otherwise, please respond with a comment indicating any updates or changes to the original issue and/or confirm this issue still needs to be addressed. This issue will be labeled inactive-90d if there is no activity in the next 60 days.
This issue has been labeled inactive-90d due to no recent activity in the past 90 days. Please close this issue if no further response or action is needed. Otherwise, please respond with a comment indicating any updates or changes to the original issue and/or confirm this issue still needs to be addressed.