Skip to content

perf(gemm): route all bf16 shapes through cublasLt on Kunlun, eliminting costly f32 fallback - #1552

Merged
wooway777 merged 1 commit into
InfiniTensor:mainfrom
rubik-hua:kunlun-gemm
Sep 8, 2026
Merged

wooway777 merged 1 commit into
InfiniTensor:mainfrom
rubik-hua:kunlun-gemm

Conversation

@rubik-hua

Copy link
Copy Markdown

Eliminate the f32-cast fallback for large skinny bf16 GEMMs (batch-1
decode with is_transed, n==1, m>2048). cublasLt (xblas) handles every
bf16 shape correctly; the previous f32 path re-cast the entire weight
matrix on every token, costing 16–200 ms per projection/lm_head call
and making 0.6B-class inference ~80× slower than expected.

fix(random_sample): eliminate race conditions in top-k/top-1 kernels on Kunlun

Add missing cluster-level barriers (sync_cluster() / mfence()) in
TopOneKernel and TopkKernel. Without them, thread 0 could read
stale workspace values while other cores were still writing, causing
non-deterministic wrong-token selection that manifested as garbled text
during greedy decode and top-k sampling.

昆仑上优化前1054秒,优化后10秒以内

cc870cf9fd4f80629bff071c57f38c9f

优化后
69482e5ee499d10ef61d2e587aff6c0a

image image

test_perf测试

优化前性能:
image
image

优化后性能:
image

后续应该仍然有优化空间,profiling看到有蛮多同步操作,后续优化再提PR吧
image

…ting costly f32 fallback

  Eliminate the f32-cast fallback for large skinny bf16 GEMMs (batch-1
  decode with is_transed, n==1, m>2048).  cublasLt (xblas) handles every
  bf16 shape correctly; the previous f32 path re-cast the entire weight
  matrix on every token, costing 16–200 ms per projection/lm_head call
  and making 0.6B-class inference ~80× slower than expected.

  fix(random_sample): eliminate race conditions in top-k/top-1 kernels on Kunlun

  Add missing cluster-level barriers (`sync_cluster()` / `mfence()`) in
  `TopOneKernel` and `TopkKernel`.  Without them, thread 0 could read
  stale workspace values while other cores were still writing, causing
  non-deterministic wrong-token selection that manifested as garbled text
  during greedy decode and top-k sampling.
@rubik-hua
rubik-hua requested a review from a team September 7, 2026 03:10
@wooway777
wooway777 merged commit d21bdc0 into InfiniTensor:main Sep 8, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants