From 00a05cf70fcc573c34662188465ea5729baf845d Mon Sep 17 00:00:00 2001 From: Joydeep Biswas Date: Tue, 30 Aug 2022 10:05:30 -0500 Subject: [PATCH] CUDA SDK Version-based SpMV Selection * The algorithm enum value for SpMV is now selected based on the version of the CUDA runtime that Ceres is compiled against. Change-Id: I2e0e39f1cbdb8ac26d2a9d45f4ebfc09b96d872b --- internal/ceres/cuda_sparse_matrix.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/internal/ceres/cuda_sparse_matrix.cc b/internal/ceres/cuda_sparse_matrix.cc index 1d8d0b023..a3ed0196e 100644 --- a/internal/ceres/cuda_sparse_matrix.cc +++ b/internal/ceres/cuda_sparse_matrix.cc @@ -54,6 +54,7 @@ #include "ceres/cuda_buffer.h" #include "ceres/cuda_kernels.h" #include "ceres/cuda_vector.h" +#include "cuda_runtime_api.h" #include "cusparse.h" namespace ceres::internal { @@ -105,6 +106,14 @@ void CudaSparseMatrix::SpMv(cusparseOperation_t op, const double alpha = 1.0; const double beta = 1.0; + // Starting in CUDA 11.2.1, CUSPARSE_MV_ALG_DEFAULT was deprecated in favor of + // CUSPARSE_SPMV_ALG_DEFAULT. +#if CUDART_VERSION >= 11021 + const auto algorithm = CUSPARSE_SPMV_ALG_DEFAULT; +#else // CUDART_VERSION >= 11021 + const auto algorithm = CUSPARSE_MV_ALG_DEFAULT; +#endif // CUDART_VERSION >= 11021 + CHECK_EQ(cusparseSpMV_bufferSize(context_->cusparse_handle_, op, &alpha, @@ -113,7 +122,7 @@ void CudaSparseMatrix::SpMv(cusparseOperation_t op, &beta, y->descr(), CUDA_R_64F, - CUSPARSE_SPMV_ALG_DEFAULT, + algorithm, &buffer_size), CUSPARSE_STATUS_SUCCESS); spmv_buffer_.Reserve(buffer_size); @@ -125,7 +134,7 @@ void CudaSparseMatrix::SpMv(cusparseOperation_t op, &beta, y->descr(), CUDA_R_64F, - CUSPARSE_SPMV_ALG_DEFAULT, + algorithm, spmv_buffer_.data()), CUSPARSE_STATUS_SUCCESS); }