[code question] gemm plugin
https://github.com/NVIDIA/TensorRT-LLM/blob/v0.7.0/cpp/tensorrt_llm/plugins/gemmPlugin/gemmPlugin.cpp#L59
The params order of runGemm() is const void* act, const void* weight.
void runGemm(const int M, const int N, const int K, const bool transA, const bool transB, const nvinfer1::DataType type,
const CublasGemmWrapperPtr& cublasWrapperPtr, const void* act, const void* weight, void* output,
const std::optional<cublasLtMatmulHeuristicResult_t>& heuristic, void* workspace, cudaStream_t stream)
Why is the order changed when calling the cublas gemm function?
cublasWrapperPtr->Gemm(transa, transb, m, n, k, weight, lda, act, ldb, output, ldc, heuristic);
ccc
After reading some documents, I found that this issue may be related to row major or column major concept.
The model weight is column major and the act is row major. Is that right?
Indeed, cuBLAS uses the BLAS convention that treats matrices are column-major ; including the output matrix. In LLMs, where activations tensors are row-major ; each row is a "token" and the columns are contiguous in memory (hidden-dimension), we need to ask cuBLAS to compute (AB)^T = B^T A^T. That's for this reason that we change the order of the arguments.