{
  "id": "cuda/cublas-gemm-invalid-lda",
  "signature": "RuntimeError: CUBLAS_STATUS_INVALID_VALUE when calling cublasSgemmStridedBatched with lda=0",
  "signature_zh": "RuntimeError: 调用 cublasSgemmStridedBatched 时出现 CUBLAS_STATUS_INVALID_VALUE，lda=0",
  "regex": "CUBLAS_STATUS_INVALID_VALUE.*cublas[Ss]?[Dd]?[Cc]?[Zz]?gemm.*ld[a-z]=0",
  "domain": "cuda",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "cuBLAS GEMM or batched GEMM routines require leading dimensions (lda, ldb, ldc) to be non-zero and at least as large as the matrix width or height; a zero leading dimension causes an invalid value error.",
  "root_cause_type": "generic",
  "root_cause_zh": "cuBLAS GEMM 或批处理 GEMM 例程要求前导维度（lda、ldb、ldc）非零且至少与矩阵宽度或高度相同；零前导维度会导致无效值错误。",
  "versions": [
    {
      "version": "CUDA 11.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "CUDA 12.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "cuBLAS 11.11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "cuBLAS 12.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "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.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "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.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "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.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "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;",
      "success_rate": 0.95,
      "how": "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;",
      "condition": "",
      "sources": []
    },
    {
      "action": "Add a debug assertion before the cuBLAS call to check that leading dimensions are positive and valid. Example: assert(lda > 0 && lda >= rows);",
      "success_rate": 0.85,
      "how": "Add a debug assertion before the cuBLAS call to check that leading dimensions are positive and valid. Example: assert(lda > 0 && lda >= rows);",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "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;",
    "Add a debug assertion before the cuBLAS call to check that leading dimensions are positive and valid. Example: assert(lda > 0 && lda >= rows);"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.nvidia.com/cuda/cublas/index.html#cublas-t-routine",
  "official_doc_section": null,
  "error_code": "CUBLAS_STATUS_INVALID_VALUE (1)",
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-06-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}