{
  "id": "cuda/cublas-gemm-batched-wrong-rank",
  "signature": "RuntimeError: CUBLAS_STATUS_INVALID_VALUE when calling cublasGemmStridedBatchedEx with batch_count > 0 but A/B/C matrices have incompatible dimensions",
  "signature_zh": "运行时错误：调用 cublasGemmStridedBatchedEx 时 CUBLAS_STATUS_INVALID_VALUE，batch_count > 0 但 A/B/C 矩阵维度不兼容",
  "regex": "CUBLAS_STATUS_INVALID_VALUE when calling cublasGemmStridedBatchedEx",
  "domain": "cuda",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "cuBLAS batched GEMM requires that the leading dimensions (lda, ldb, ldc) and strides of matrices A, B, and C are consistent with the matrix dimensions and batch count; mismatched sizes cause an invalid value error.",
  "root_cause_type": "generic",
  "root_cause_zh": "cuBLAS 批量 GEMM 要求矩阵 A、B 和 C 的前导维度（lda、ldb、ldc）和步幅与矩阵维度和批次数一致；大小不匹配会导致无效值错误。",
  "versions": [
    {
      "version": "CUDA 11.7",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "CUDA 12.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "cuBLAS 11.10",
      "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": "Transposition changes the memory layout and may cause silent data corruption; the correct fix is to compute proper strides and leading dimensions.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This bypasses the error but loses the performance benefit of batching; the underlying dimension issue remains for actual batched use.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Verify that lda >= m, ldb >= k, ldc >= m, and that strideA >= m*k, strideB >= k*n, strideC >= m*n for each batch. Adjust matrix allocation accordingly.",
      "success_rate": 0.85,
      "how": "Verify that lda >= m, ldb >= k, ldc >= m, and that strideA >= m*k, strideB >= k*n, strideC >= m*n for each batch. Adjust matrix allocation accordingly.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use PyTorch's `torch.bmm` or `torch.matmul` with batched tensors instead of raw cuBLAS calls, as these handle dimension validation internally.",
      "success_rate": 0.9,
      "how": "Use PyTorch's `torch.bmm` or `torch.matmul` with batched tensors instead of raw cuBLAS calls, as these handle dimension validation internally.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Verify that lda >= m, ldb >= k, ldc >= m, and that strideA >= m*k, strideB >= k*n, strideC >= m*n for each batch. Adjust matrix allocation accordingly.",
    "Use PyTorch's `torch.bmm` or `torch.matmul` with batched tensors instead of raw cuBLAS calls, as these handle dimension validation internally."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.nvidia.com/cuda/cublas/index.html#cublas-gemm-strided-batched-ex",
  "official_doc_section": null,
  "error_code": "CUBLAS_STATUS_INVALID_VALUE",
  "verification_tier": "ai_generated",
  "confidence": 0.82,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2023-11-12",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}