From d98ff432b98a4d7bea770c0cc221d8a0dab2e4a9 Mon Sep 17 00:00:00 2001 From: Haoyu Zhang Date: Fri, 29 Aug 2025 08:18:35 -0700 Subject: [PATCH] Fix FAISS build with ROCm7 (#4567) Summary: Pull Request resolved: https://github.com/facebookresearch/faiss/pull/4567 D80101131 enabled FAISS library to build with AMD GPUs. However, certain libraries are written using previous version of ROCm / hipBLAS libraries and fails to build with ROCm7 (hipBLAS 3). This library is a dependency of MVAI (minimal_viable_ai) so the build is currently broken for MVAI package with ROCm7. New hipBLAS has API renamed that landed with ROCm 7 (hipBLAS 3.x). Specifically, `hipblasDatatype_t` was removed and replaced by two separate types: - `hipDataType` for A/B/C/scale datatypes - `hipblasComputeType_t` for the GEMM compute type To make sure it build with both old and new versions, we need to add additional compile-time check to pick the right APIs. Reviewed By: leitian Differential Revision: D81293871 fbshipit-source-id: 755758ef485a74b35651412c5dbd3bc728145a07 --- faiss/gpu/utils/MatrixMult-inl.cuh | 31 +++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/faiss/gpu/utils/MatrixMult-inl.cuh b/faiss/gpu/utils/MatrixMult-inl.cuh index b28ea56da..a0ef20f6c 100644 --- a/faiss/gpu/utils/MatrixMult-inl.cuh +++ b/faiss/gpu/utils/MatrixMult-inl.cuh @@ -22,19 +22,26 @@ struct GetCudaType; #ifdef USE_AMD_ROCM +#if ((hipblasVersionMajor == 2 && defined(HIPBLAS_V2)) || \ + hipblasVersionMajor >= 3) +using hipDataTypeCompat = hipDataType; +#else +using hipDataTypeCompat = hipblasDatatype_t; +#endif + template <> struct GetCudaType { - static constexpr hipblasDatatype_t Type = HIPBLAS_R_32F; + static constexpr hipDataTypeCompat Type = HIPBLAS_R_32F; }; template <> struct GetCudaType { - static constexpr hipblasDatatype_t Type = HIPBLAS_R_16F; + static constexpr hipDataTypeCompat Type = HIPBLAS_R_16F; }; template <> struct GetCudaType<__hip_bfloat16> { - static constexpr hipblasDatatype_t Type = HIPBLAS_R_16B; + static constexpr hipDataTypeCompat Type = HIPBLAS_R_16B; }; #else @@ -76,6 +83,13 @@ cublasStatus_t rawGemm( auto cBT = GetCudaType::Type; #ifdef USE_AMD_ROCM +#if ((hipblasVersionMajor == 2 && defined(HIPBLAS_V2)) || \ + hipblasVersionMajor >= 3) + auto computeType = HIPBLAS_COMPUTE_32F; +#else + auto computeType = HIPBLAS_R_32F; +#endif + return hipblasGemmEx( handle, transa, @@ -94,7 +108,7 @@ cublasStatus_t rawGemm( C, HIPBLAS_R_32F, ldc, - HIPBLAS_R_32F, + computeType, HIPBLAS_GEMM_DEFAULT); #else @@ -177,6 +191,13 @@ cublasStatus_t rawBatchGemm( // Always accumulate in f32 #ifdef USE_AMD_ROCM +#if ((hipblasVersionMajor == 2 && defined(HIPBLAS_V2)) || \ + hipblasVersionMajor >= 3) + auto computeType = HIPBLAS_COMPUTE_32F; +#else + auto computeType = HIPBLAS_R_32F; +#endif + return hipblasGemmStridedBatchedEx( handle, transa, @@ -199,7 +220,7 @@ cublasStatus_t rawBatchGemm( ldc, strideC, batchCount, - HIPBLAS_R_32F, + computeType, HIPBLAS_GEMM_DEFAULT); #else return cublasGemmStridedBatchedEx(