# RuntimeError: 调用 cublasSgemmStridedBatched 时出现 CUBLAS_STATUS_INVALID_VALUE，lda=0

- **ID:** `cuda/cublas-gemm-invalid-lda`
- **领域:** cuda
- **类别:** runtime_error
- **错误码:** `CUBLAS_STATUS_INVALID_VALUE (1)`
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

cuBLAS GEMM 或批处理 GEMM 例程要求前导维度（lda、ldb、ldc）非零且至少与矩阵宽度或高度相同；零前导维度会导致无效值错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| CUDA 11.8 | active | — | — |
| CUDA 12.1 | active | — | — |
| cuBLAS 11.11 | active | — | — |
| cuBLAS 12.0 | active | — | — |

## 解决方案

1. ```
   Ensure lda, ldb, and ldc are at least 1 and >= number of rows (for column-major) or columns (for row-major). Example fix: if (lda == 0) lda = matrix_width;
   ```
2. ```
   Add a debug assertion before the cuBLAS call to check that leading dimensions are positive and valid. Example: assert(lda > 0 && lda >= rows);
   ```

## 无效尝试

- **** — Increasing batch size or matrix dimensions does not fix a zero leading dimension; the error persists because the root cause is a programming mistake, not resource limits. (95% 失败率)
- **** — Switching to a different cuBLAS routine (e.g., from gemmStridedBatched to gemm) only masks the symptom; the caller still passes lda=0, which may crash later or produce wrong results. (90% 失败率)
- **** — Setting lda to a negative value (e.g., -1) causes a different error (CUBLAS_STATUS_NOT_INITIALIZED or segfault) but does not resolve the zero-layout issue. (85% 失败率)
