Skip to content

RuntimeError: cuBLAS error code=15 in fp8_nn_dev (sm_89) #21

Closed

Description

@wangerforcs

Error

RuntimeError: cuBLAS error at /pub/data/wangzb/FlashRT/csrc/gemm/gemm_runner.cu:125 code=15

CUBLAS_STATUS_NOT_SUPPORTED (code=15) when calling fp8_nn_dev on NVIDIA L40 (sm_89 Ada Lovelace).

Environment

  • GPU: NVIDIA L40 (sm_89)
  • CUDA: 12.9
  • Code path: gemm_runner.cu → fp8_nn_dev → cublasLtMatmul

Observation

In gemm_runner.cu there are several FP8 GEMM functions:

Function Used ? TRANSB
fp8_gemm No CUBLAS_OP_T
fp8_run No CUBLAS_OP_T
fp8_run_dev No CUBLAS_OP_T
fp8_nn_dev Yes (via pipeline_rtx.py) CUBLAS_OP_N

The three unused functions all set TRANSB = CUBLAS_OP_T, but the production path fp8_nn_dev uses CUBLAS_OP_N.

Meanwhile, the BF16_NN branch uses the same cuBLAS descriptor layout (CUBLAS_OP_N + row-major B(K, N)) and works without issues.

My Understanding

In pi05_rtx.py → convert_pi05_safetensors, all linear layer weights are transposed before storage ((N, K) → .t() → (K, N)). So weights are stored as row-major (K, N) on GPU.

cuBLAS assumes column-major. The three unused FP8 functions use CUBLAS_OP_T to account for this transposed layout, while fp8_nn_dev does not.

Since BF16_NN (same layout, no CUBLAS_OP_T) works fine, I suspect the code=15 may be caused by FP8 Tensor Cores having stricter requirements for matrix layout contiguity compared to BF16.

Could you help clarify what's causing this discrepancy? Is the TRANSB difference between fp8_nn_dev and the unused functions intentional, or is there a layout issue on sm_89 that needs to be addressed?

Activity

  1. LiangSu8899 commented on May 11, 2026

    @LiangSu8899
    Member

    Thanks for the detailed report and analysis.

    Your understanding of the stored weight layout is correct: in the Pi0.5 RTX path,
    linear weights are converted from the original HF layout (N, K) into row-major
    (K, N) before being stored on GPU.

    The TRANSB difference is intentional, though. The older fp8_gemm,
    fp8_run, and fp8_run_dev helpers use a different/legacy operand convention,
    where the weight is treated as (N, K) and the GEMM computes A @ B^T, so those
    paths set TRANSB = CUBLAS_OP_T.

    The production fp8_nn_dev path is the no-transpose path:

    A(M, K) @ B(K, N) -> D(M, N)

    so TRANSB = CUBLAS_OP_N matches the current stored (K, N) weight layout.
    Changing fp8_nn_dev to TRANSB = CUBLAS_OP_T would not be correct for the
    current Pi0.5 RTX weights.

    The L40 failure is more likely caused by cuBLASLt FP8 algorithm/layout support on
    Ada sm_89, rather than by a simple missing transpose. BF16 GEMM is more
    permissive here, while FP8 Tensor Core kernels can reject descriptor/layout
    combinations that work for BF16, and may also behave differently from the
    Blackwell sm_120 path.

    There is already another FP8 GEMM path in the core library,
    fp8_gemm_descale_fp16 / fp8_gemm_descale_bf16out, which uses the
    cuBLASLt operand-swap/column-major convention and is intended to work on SM89+.
    So the likely fix is not to rewrite the FP8 kernel or flip TRANSB in
    fp8_nn_dev, but to route the Pi0.5 RTX sm_89 pipeline through that existing
    SM89-compatible FP8 path.

    Separately, another tester is helping validate the SM89
    FP8 pipeline locally, and I should be able to update this soon with the proper
    SM89 FP8 routing once that test is confirmed.

  2. wangerforcs commented on May 11, 2026

    @wangerforcs
    ContributorAuthor

    Thanks for the clarification. I also tested fp8_gemm_descale_bf16out on SM89 following your suggestion.

    The results are as follows:

    [fp8_gemm_descale_bf16out] Heuristic FAILED for [64,64,32]
    tensor([ 9.9945e-04, -7.3242e-03, -3.6316e-03, -1.2939e-02, -6.5918e-03,
            -1.3733e-03,  3.3379e-05, -6.1340e-03,  4.5776e-05, -7.6294e-03],
           device='cuda:0', dtype=torch.bfloat16)
    tensor([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], device='cuda:0',
           dtype=torch.bfloat16)
    Max diff:  0.021606
    Mean diff: 0.004419
    Cos sim:   0.000000
    

    For reference, I compared against a standard BF16 torch.matmul result.

    It seems that due to the heuristic failure, the kernel does not produce valid FP8 GEMM results (likely skipping the actual computation path), which leads to all-zero outputs.

    I’m not sure whether this is related to my specific device setup (NVIDIA L40 / SM89) or if it indicates an issue in the current implementation or unsupported path in the FP8 routing.

    import torch
    import flash_rt.flash_rt_kernels as fvk
    
    torch.manual_seed(42)
    
    M, N, K = 64, 64, 32
    
    A = torch.randn(M, K, device="cuda", dtype=torch.bfloat16) / K
    B = torch.randn(K, N, device="cuda", dtype=torch.bfloat16) / K
    
    A_fp8 = A.to(torch.float8_e4m3fn) 
    B_fp8 = B.to(torch.float8_e4m3fn)
    
    D_cublas = torch.empty(M, N, device="cuda", dtype=torch.bfloat16)
    scale_a = torch.ones(1, device="cuda", dtype=torch.float32)
    scale_b = torch.ones(1, device="cuda", dtype=torch.float32)
    stream = torch.cuda.current_stream().cuda_stream
    
    fvk.fp8_gemm_descale_bf16out(
        A_fp8.data_ptr(), B_fp8.data_ptr(), D_cublas.data_ptr(),
        M, N, K,
        scale_a.data_ptr(), scale_b.data_ptr(),
        stream
    )
    torch.cuda.synchronize()
    
    A_ref = A.to(torch.bfloat16)
    B_ref = B.to(torch.bfloat16)
    
    D_ref = torch.matmul(A_ref, B_ref)
    
    diff = torch.abs(D_cublas.float() - D_ref.float())
    print(D_ref[0][:10])
    print(D_cublas[0][:10])
    cos_sim = torch.nn.functional.cosine_similarity(
        D_cublas.flatten().float(), D_ref.flatten().float(), dim=0
    ).item()
    
    print(f"Max diff:  {diff.max().item():.6f}")
    print(f"Mean diff: {diff.mean().item():.6f}")
    print(f"Cos sim:   {cos_sim:.6f}")
  3. LiangSu8899 commented on May 11, 2026

    @LiangSu8899
    Member

    Thanks for the detailed test. I think there are two separate issues here.

    First, the TRANSB difference is intentional. The legacy helpers and the current production path use different operand conventions.

    The older fp8_gemm / fp8_run / fp8_run_dev helpers treat the weight as [N, K] and compute:

    A[M, K] @ B[N, K]^T -> D[M, N]
    

    so those paths use TRANSB = CUBLAS_OP_T.

    The production fp8_nn_dev path treats the weight as already stored in row-major [K, N] and computes:

    A[M, K] @ B[K, N] -> D[M, N]
    

    so TRANSB = CUBLAS_OP_N is correct for the current Pi0.5 RTX weights. Flipping fp8_nn_dev to TRANSB=T would make the math/layout wrong.

    The BF16_NN path working with the same [K, N] logical layout is a good sanity check that the layout convention is not simply transposed incorrectly. It does not imply the same descriptor combination must be supported for FP8. The failure is more likely that cuBLASLt on L40 / sm_89 does not support this particular FP8 descriptor/layout/output combination, while BF16 is more permissive.

    Second, your fp8_gemm_descale_bf16out test exposed a real implementation issue. If cuBLASLt returns no heuristic, that helper currently only prints a warning and continues, instead of returning an error or throwing. In that case the output should be treated as undefined. The all-zero output is not a valid FP8 GEMM result.

    So the summary is:

    • The TRANSB reasoning is a misunderstanding of the two different operand conventions.
    • The L40 failure is real, but it is an SM89 FP8 cuBLASLt support/routing issue, not a missing transpose.
    • fp8_gemm_descale_bf16out also needs better failure handling before it can be used as a reliable fallback.

    Suggested next steps:

    1. Do not change fp8_nn_dev to TRANSB=T.
    2. Add hard error handling to the descale FP8 helpers, especially fp8_gemm_descale_bf16out, when heuristic returns no algorithm or cublasLtMatmul fails.
    3. Build a small SM89 probe matrix for:
      • fp8_nn_dev
      • fp8_gemm_descale_fp16
      • fp8_gemm_descale_bf16out
      • relevant Pi0.5 shapes, not only [64,64,32]
    4. Route SM89 separately only after a path is confirmed to produce valid numerical output.

    And I will also fix the silent-failure behavior. In particular, the descale FP8 helpers should not continue after cuBLASLt returns no heuristic or after cublasLtMatmul returns a non-success status. I will update these paths to raise a clear runtime error instead of leaving the output undefined. That will not make the SM89 path supported by itself, but it will prevent invalid all-zero outputs from being mistaken for valid GEMM results.

    Thx!!

  4. self-assigned this
    on May 11, 2026
  5. linked a pull request that will close this issueFail fast on unsupported FP8 descale GEMMs #22on May 11, 2026
  6. wangerforcs commented on May 12, 2026

    @wangerforcs
    ContributorAuthor

    The current implementation of fp8_gemm_descale_bf16out sets both TRANSA and TRANSB to opN, resulting in an NN layout for FP8 GEMM. However, according to cuBLASLt documentation and runtime behavior, FP8 GEMM only supports TN layout, and NN configuration leads to CUBLAS_STATUS_NOT_SUPPORTED during heuristic selection.

    Image

    This causes runtime failure in cublasLtMatmulAlgoGetHeuristic using CUBLASLT_LOG_LEVEL=5.

    [cublasLt][234782][Error][cublasLtMatmulAlgoGetHeuristic] FP8 matrix multiplications support only TN input layout. Got NN

    So it looks like this is not an issue with my environment or configuration, but rather a problem in the code, right?

    Scripts below seem correct.

    // fp8_nn_dev
        if (type == FP8_NN_DEV) {    
            CUBLAS_CHECK(cublasLtMatmulDescCreate(&entry.matmul_desc, CUBLAS_COMPUTE_32F, CUDA_R_32F));
            CUBLAS_CHECK(cublasLtMatmulDescSetAttribute(entry.matmul_desc, CUBLASLT_MATMUL_DESC_TRANSA, &op_N, sizeof(op_N)));
            CUBLAS_CHECK(cublasLtMatmulDescSetAttribute(entry.matmul_desc, CUBLASLT_MATMUL_DESC_TRANSB, &op_T, sizeof(op_T)));
            CUBLAS_CHECK(cublasLtMatrixLayoutCreate(&entry.A_desc, CUDA_R_8F_E4M3, M, K, K));
            CUBLAS_CHECK(cublasLtMatrixLayoutSetAttribute(entry.A_desc, CUBLASLT_MATRIX_LAYOUT_ORDER, &row_order, sizeof(row_order)));
            CUBLAS_CHECK(cublasLtMatrixLayoutCreate(&entry.B_desc, CUDA_R_8F_E4M3, N, K, K));
            CUBLAS_CHECK(cublasLtMatrixLayoutSetAttribute(entry.B_desc, CUBLASLT_MATRIX_LAYOUT_ORDER, &row_order, sizeof(row_order)));
            CUBLAS_CHECK(cublasLtMatrixLayoutCreate(&entry.D_desc, CUDA_R_16BF, M, N, N));
            CUBLAS_CHECK(cublasLtMatrixLayoutSetAttribute(entry.D_desc, CUBLASLT_MATRIX_LAYOUT_ORDER, &row_order, sizeof(row_order)));
        } 
    #test script
    import torch
    import flash_rt.flash_rt_kernels as fvk
    
    torch.manual_seed(42)
    
    M, N, K = 64, 128, 32
    
    A = torch.randn(M, K, device="cuda", dtype=torch.bfloat16) / (K ** 0.5)
    B = torch.randn(K, N, device="cuda", dtype=torch.bfloat16) / (K ** 0.5)
    
    A_fp8 = A.contiguous().to(torch.float8_e4m3fn) 
    B_fp8 = B.t().contiguous().to(torch.float8_e4m3fn)
    
    D_cublas = torch.empty(M, N, device="cuda", dtype=torch.bfloat16)
    scale_a = torch.ones(1, device="cuda", dtype=torch.float32)
    scale_b = torch.ones(1, device="cuda", dtype=torch.float32)
    stream = torch.cuda.current_stream().cuda_stream
    
    gemm = fvk.GemmRunner()
    gemm.fp8_nn_dev(
        A_fp8.data_ptr(), B_fp8.data_ptr(), D_cublas.data_ptr(),
        M, N, K,
        scale_a.data_ptr(), scale_b.data_ptr(),
        stream
    )
    torch.cuda.synchronize()
    
    A_ref = A.to(torch.bfloat16)
    B_ref = B.to(torch.bfloat16)
    
    D_ref = torch.matmul(A_ref, B_ref)
    
    diff = torch.abs(D_cublas.float() - D_ref.float())
    cos_sim = torch.nn.functional.cosine_similarity(
        D_cublas.flatten().float(), D_ref.flatten().float(), dim=0
    ).item()
    
    print(f"Max diff:  {diff.max().item():.6f}")
    print(f"Mean diff: {diff.mean().item():.6f}")
    print(f"Cos sim:   {cos_sim:.6f}")
  7. LiangSu8899 commented on May 12, 2026

    @LiangSu8899
    Member

    Thanks again for digging into this and for pointing out the cuBLASLt FP8 layout requirement.

    I pushed a tentative SM89 fix to this branch:

    Add-SM89-compatible-FP8-GEMM-layout

    The change keeps the existing SM120 path unchanged, and adds a separate SM89 FP8 GEMM route. For SM89, Pi0.5 now stores FP8 weights as [N, K] and dispatches through a new fp8_nt_dev path, so the GEMM is computed as:

    A[M, K] @ B[N, K]^T -> D[M, N]

    This matches the FP8 TN-style layout requirement from cuBLASLt, while avoiding changing the existing fp8_nn_dev path used by the current Blackwell route.

    Your test worked because it manually prepared B as B.t().contiguous(), which effectively matched the [N, K] weight layout expected by the transpose-B FP8 path. The previous production path still used the [K, N] no-transpose layout, which cuBLASLt rejects for FP8 on SM89.

    Could you try this branch on your L40 setup and check whether Pi0.5 FP8 now runs correctly?
    https://github.com/LiangSu8899/FlashRT/tree/Add-SM89-compatible-FP8-GEMM-layout

  8. wangerforcs commented on May 13, 2026

    @wangerforcs
    ContributorAuthor

    Thanks for the clarification and for pushing the SM89 fix.

    I’ve tested the updated branch. The FP8 pipeline now runs correctly and the numerical results are also reasonable. Compared to BF16 reference outputs, the FP8 inference results are very close, with only minor deviations expected from FP8 quantization.

    Thanks again for your help and the quick turnaround on this fix.

    Update benchmark result on L40(2 views using FP8). Pretty good.

    Benchmark (20 iter, warmup=500):
      P50: 26.6 ms (38 Hz)
      min: 26.2, mean: 26.7, max: 27.3 ms
    ============================================================
    RESULTS: libero_spatial (server)
    ============================================================
      Task  0: 50/50 = 100.0%  pick up the black bowl between the plate and the ramekin and place it on the plate
      Task  1: 50/50 = 100.0%  pick up the black bowl next to the ramekin and place it on the plate
      Task  2: 50/50 = 100.0%  pick up the black bowl from table center and place it on the plate
      Task  3: 49/50 = 98.0%  pick up the black bowl on the cookie box and place it on the plate
      Task  4: 49/50 = 98.0%  pick up the black bowl in the top drawer of the wooden cabinet and place it on the plate
      Task  5: 45/50 = 90.0%  pick up the black bowl on the ramekin and place it on the plate
      Task  6: 50/50 = 100.0%  pick up the black bowl next to the cookie box and place it on the plate
      Task  7: 50/50 = 100.0%  pick up the black bowl on the stove and place it on the plate
      Task  8: 50/50 = 100.0%  pick up the black bowl next to the plate and place it on the plate
      Task  9: 49/50 = 98.0%  pick up the black bowl on the wooden cabinet and place it on the plate
    ============================================================
      Overall: 492/500 = 98.4%
    ============================================================
  9. linked a pull request that will close this issueAdd SM89 FP8 GEMM layout path #26on May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions