Sample wrapper running through multiple algo and config attributes combination for single precision gemm using cublasLt low-level API
| 134 | // Sample wrapper running through multiple algo and config attributes |
| 135 | // combination for single precision gemm using cublasLt low-level API |
| 136 | void LtGemmSearch(cublasLtHandle_t ltHandle, cublasOperation_t transa, cublasOperation_t transb, int32_t const& m, |
| 137 | int32_t const& n, int32_t const& k, void const* alpha, // host pointer |
| 138 | void const* A, int32_t const& lda, void const* B, int32_t const& ldb, void const* beta, // host pointer |
| 139 | void* C, int32_t const& ldc, void* workSpace, size_t workSpaceSize, |
| 140 | #if CUBLAS_VER_MAJOR < 11 |
| 141 | cudaDataType_t computeType, |
| 142 | #else |
| 143 | cublasComputeType_t computeType, |
| 144 | #endif |
| 145 | cudaDataType_t scaleType, cudaDataType_t Atype, cudaDataType_t Btype, cudaDataType_t Ctype, |
| 146 | std::vector<customMatmulPerf_t>& perfResults) |
| 147 | { |
| 148 | |
| 149 | cublasStatus_t status = CUBLAS_STATUS_SUCCESS; |
| 150 | |
| 151 | cublasLtMatmulDesc_t operationDesc = nullptr; |
| 152 | cublasLtMatrixLayout_t Adesc = nullptr; |
| 153 | cublasLtMatrixLayout_t Bdesc = nullptr; |
| 154 | cublasLtMatrixLayout_t Cdesc = nullptr; |
| 155 | cublasLtMatmulPreference_t preference = nullptr; |
| 156 | |
| 157 | cudaEvent_t startEvent = nullptr; |
| 158 | cudaEvent_t stopEvent = nullptr; |
| 159 | cudaStream_t stream = nullptr; |
| 160 | |
| 161 | // SplitK value that we are going to try when SplitK is supported for a given algo. |
| 162 | int32_t const splitKSequenceA[] = {2, 3, 4, 5, 6, 8, 12, 16, 32}; |
| 163 | |
| 164 | // Let try a fixed number of combinations |
| 165 | int32_t algoCount = 0; |
| 166 | int32_t nbAlgoIds = 0; |
| 167 | int32_t algoIdA[kNB_ALGO_IDS]; |
| 168 | |
| 169 | PLUGIN_CUBLASASSERT(cublasLtMatmulPreferenceCreate(&preference)); |
| 170 | PLUGIN_CUBLASASSERT(cublasLtMatmulPreferenceSetAttribute( |
| 171 | preference, CUBLASLT_MATMUL_PREF_MAX_WORKSPACE_BYTES, &workSpaceSize, sizeof(workSpaceSize))); |
| 172 | |
| 173 | uint64_t const numericImplPrefer |
| 174 | = Ctype == CUDA_R_16F ? CUBLASLT_NUMERICAL_IMPL_FLAGS_HMMA : CUBLASLT_NUMERICAL_IMPL_FLAGS_FMA; |
| 175 | PLUGIN_CUBLASASSERT(cublasLtMatmulPreferenceSetAttribute( |
| 176 | preference, CUBLASLT_MATMUL_PREF_IMPL_MASK, &numericImplPrefer, sizeof(numericImplPrefer))); |
| 177 | |
| 178 | // Create operation descriptor; see cublasLtMatmulDescAttributes_t for details |
| 179 | // about defaults; here we just need to set the transforms for A and B |
| 180 | #if CUBLAS_VER_MAJOR < 11 |
| 181 | PLUGIN_CUBLASASSERT(cublasLtMatmulDescCreate(&operationDesc, computeType)); |
| 182 | #else |
| 183 | PLUGIN_CUBLASASSERT(cublasLtMatmulDescCreate(&operationDesc, computeType, scaleType)); |
| 184 | #endif |
| 185 | PLUGIN_CUBLASASSERT( |
| 186 | cublasLtMatmulDescSetAttribute(operationDesc, CUBLASLT_MATMUL_DESC_TRANSA, &transa, sizeof(transa))); |
| 187 | PLUGIN_CUBLASASSERT( |
| 188 | cublasLtMatmulDescSetAttribute(operationDesc, CUBLASLT_MATMUL_DESC_TRANSB, &transb, sizeof(transa))); |
| 189 | |
| 190 | // Create matrix descriptors. We are good with the details here so no need to |
| 191 | // set any extra attributes |
| 192 | PLUGIN_CUBLASASSERT( |
| 193 | cublasLtMatrixLayoutCreate(&Adesc, Atype, transa == CUBLAS_OP_N ? m : k, transa == CUBLAS_OP_N ? k : m, lda)); |
nothing calls this directly
no test coverage detected