|
| 1 | +From 0000000000000000000000000000000000000002 Mon Sep 17 00:00:00 2001 |
| 2 | +From: RISE Project CI <ci@riseproject.dev> |
| 3 | +Date: Sun, 20 Sep 2026 00:00:00 +0000 |
| 4 | +Subject: [PATCH] [CPU] Probe the torch wheel's OpenBLAS for sbgemm_ |
| 5 | + |
| 6 | +cpu_extension.cmake decides whether to compile the OpenBLAS bf16 GEMM path |
| 7 | +by globbing the installed torch wheel for libopenblas*.so*, and defines |
| 8 | +VLLM_HAS_OPENBLAS when the glob hits. Presence of the library is not the |
| 9 | +same thing as presence of the symbol: blas_gemm() in |
| 10 | +csrc/cpu/sgl-kernels/blas_gemm.h calls sbgemm_, and OpenBLAS only builds |
| 11 | +sbgemm_ for the architectures it has BFLOAT16 kernels for (x86_64 |
| 12 | +Cooper Lake and later, ARM64 Neoverse, POWER10, z14 and later). RISC-V is |
| 13 | +not one of them. |
| 14 | + |
| 15 | +The miss cannot be caught at link time, because the comment right above |
| 16 | +the glob is accurate - _C deliberately does not link OpenBLAS and expects |
| 17 | +libtorch.so to have loaded it RTLD_GLOBAL - so a shared object with an |
| 18 | +unresolved sbgemm_ links happily and the build succeeds. It fails on the |
| 19 | +first "import vllm._C" instead: |
| 20 | + |
| 21 | + ImportError: .../vllm/_C.abi3.so: undefined symbol: sbgemm_ |
| 22 | + |
| 23 | +blas_gemm.h already carries the right fallback for this case: its #else |
| 24 | +branch dispatches through at::native::cpublas::gemm_no_downcast_stub, |
| 25 | +which libtorch_cpu.so exports on every architecture. So ask the library |
| 26 | +whether it actually provides sbgemm_ and take that fallback when it does |
| 27 | +not, rather than assuming every non-x86 torch wheel ships a bf16-capable |
| 28 | +OpenBLAS. When the probe itself cannot run the previous behaviour is kept, |
| 29 | +so no platform that works today changes. |
| 30 | + |
| 31 | +Upstream-Status: To upstream [Architecture-agnostic: the probe is a no-op wherever OpenBLAS does export sbgemm_, and it fixes any platform whose torch wheel ships an OpenBLAS built without BUILD_BFLOAT16, riscv64 being the one this repo builds for] |
| 32 | + |
| 33 | +Signed-off-by: RISE Project CI <ci@riseproject.dev> |
| 34 | +--- |
| 35 | + cmake/cpu_extension.cmake | 20 ++++++++++++++++++-- |
| 36 | + 1 file changed, 18 insertions(+), 2 deletions(-) |
| 37 | + |
| 38 | +diff --git a/cmake/cpu_extension.cmake b/cmake/cpu_extension.cmake |
| 39 | +index 92c3daa..a7a229c 100644 |
| 40 | +--- a/cmake/cpu_extension.cmake |
| 41 | ++++ b/cmake/cpu_extension.cmake |
| 42 | +@@ -430,8 +430,24 @@ if (NOT ENABLE_X86_ISA) |
| 43 | + "${TORCH_INSTALL_PREFIX}/lib/libopenblas*.so*") |
| 44 | + # Note: we don't link openblas directly to _C extension, as it's available through libtorch.so |
| 45 | + if (_VLLM_TORCH_OPENBLAS_LIBS) |
| 46 | +- list(GET _VLLM_TORCH_OPENBLAS_LIBS 0 VLLM_OPENBLAS_LIB) |
| 47 | +- message(STATUS "CPU OpenBLAS library: ${VLLM_OPENBLAS_LIB}") |
| 48 | ++ list(GET _VLLM_TORCH_OPENBLAS_LIBS 0 _VLLM_TORCH_OPENBLAS_LIB) |
| 49 | ++ # blas_gemm() calls OpenBLAS' bf16 GEMM, which OpenBLAS only builds for |
| 50 | ++ # the architectures it has BFLOAT16 kernels for. Elsewhere the library is |
| 51 | ++ # present but sbgemm_ is not, and since _C resolves it through |
| 52 | ++ # libtorch.so instead of linking OpenBLAS itself, the miss is not |
| 53 | ++ # reported until the extension is imported. Probe for the symbol and keep |
| 54 | ++ # the PyTorch reference BLAS path when it is absent. |
| 55 | ++ execute_process( |
| 56 | ++ COMMAND ${CMAKE_NM} --dynamic --defined-only "${_VLLM_TORCH_OPENBLAS_LIB}" |
| 57 | ++ OUTPUT_VARIABLE _VLLM_TORCH_OPENBLAS_SYMBOLS |
| 58 | ++ ERROR_QUIET) |
| 59 | ++ if (_VLLM_TORCH_OPENBLAS_SYMBOLS STREQUAL "" OR |
| 60 | ++ _VLLM_TORCH_OPENBLAS_SYMBOLS MATCHES "[ \t]sbgemm_[\r\n]") |
| 61 | ++ set(VLLM_OPENBLAS_LIB "${_VLLM_TORCH_OPENBLAS_LIB}") |
| 62 | ++ message(STATUS "CPU OpenBLAS library: ${VLLM_OPENBLAS_LIB}") |
| 63 | ++ else() |
| 64 | ++ message(STATUS "CPU OpenBLAS library ${_VLLM_TORCH_OPENBLAS_LIB} provides no sbgemm_, using the PyTorch reference BLAS path") |
| 65 | ++ endif() |
| 66 | + endif() |
| 67 | + endif() |
| 68 | + |
| 69 | +-- |
| 70 | +2.51.0 |
0 commit comments