Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARSE] Add support for cuSPARSE backend #527

Merged
merged 44 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
fac276d
[SPARSE] Add support for cuSPARSE backend
Rbiessy Sep 6, 2024
3d02b34
Remove previous compile time example
Rbiessy Sep 10, 2024
1122221
Update compile time example description
Rbiessy Sep 10, 2024
f42eab5
Remove unused mkl_helper file
Rbiessy Sep 10, 2024
8584899
Update README with cuSPARSE
Rbiessy Sep 10, 2024
7aa5177
Fix typos and rewording
Rbiessy Sep 11, 2024
70cdbe0
Rework test accuracy for spsv
Rbiessy Sep 12, 2024
8173331
Remove get_mem for USM
Rbiessy Sep 12, 2024
9c16425
Map statuses CUSPARSE_STATUS_NOT_INITIALIZED and CUSPARSE_STATUS_MATR…
Rbiessy Sep 13, 2024
36599a9
Reword comment
Rbiessy Sep 13, 2024
3b29e32
Reword comment
Rbiessy Sep 20, 2024
84565a9
Remove redundant namespace
Rbiessy Sep 20, 2024
44dc73d
Remove redundant namespace in MKL backends
Rbiessy Sep 20, 2024
050f22a
Add comments on the assumption made for buffers
Rbiessy Sep 23, 2024
77d19e8
Throw unimplemented for some cases with csr_alg3
Rbiessy Sep 23, 2024
d23b24d
Introduce sorted_by_rows property
Rbiessy Sep 23, 2024
4db2187
Avoid placeholder accessor
Rbiessy Sep 24, 2024
f73fd0b
Remove description from algorithms tables
Rbiessy Sep 26, 2024
18156e5
Use COO sorted_by_rows in example
Rbiessy Sep 26, 2024
5addc14
Document missing feature
Rbiessy Sep 30, 2024
6946d64
Remove workaround for alpha and beta spmv
Rbiessy Sep 30, 2024
8e77ead
Reword comment on empty accessors
Rbiessy Sep 30, 2024
325f794
Fix function name in exceptions
Rbiessy Sep 30, 2024
9bc77d1
Throw unimplemented for spsv using no_optimize_alg
Rbiessy Sep 30, 2024
710b80b
Fix documentation typo
Rbiessy Sep 30, 2024
00e5ced
an -> a
Rbiessy Sep 30, 2024
342380e
Revert throwing unsupported for spsv + no_optimize_alg
Rbiessy Sep 30, 2024
96b38fd
Fix documentation enums
Rbiessy Oct 1, 2024
c5ba2c4
Do not retrieve global handle for set_*_data functions using buffer API
Rbiessy Sep 13, 2024
1f5c80c
Remove host_task for set_*_data functions using USM API
Rbiessy Sep 13, 2024
58f08c9
Cache CUstream and cusparseHandle_t in operation descriptor
Rbiessy Oct 22, 2024
c0eae1e
Ensure descriptor is kept alive long enough when buffers are used
Rbiessy Oct 24, 2024
2149e39
USM tests using reset_data wait before updating device values
Rbiessy Oct 24, 2024
bad6bfb
Force inputs to be copied on device before the optimize step
Rbiessy Jul 29, 2024
6318d53
Disable specific case of spmm with csr_alg3 failing
Rbiessy Oct 24, 2024
956ae49
Disable enqueue_native_command extension for out-of-order queues
Rbiessy Oct 24, 2024
43428ca
Test in-order queues
Rbiessy Oct 25, 2024
790d018
clang-format-19.1
Rbiessy Oct 25, 2024
ae5e387
Merge branch 'develop' into romain/cusparse
Rbiessy Oct 25, 2024
97eef5c
Move more functions to the detail namespace
Rbiessy Oct 25, 2024
2888232
Fix CT example return value and expected result
Rbiessy Oct 25, 2024
b4f553c
Update example README output
Rbiessy Oct 25, 2024
a2177f7
clang-format
Rbiessy Oct 25, 2024
eef836a
Rename variables that are not placeholder anymore
Rbiessy Oct 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ option(ENABLE_CUFFT_BACKEND "Enable the cuFFT backend for the DFT interface" OFF
option(ENABLE_ROCFFT_BACKEND "Enable the rocFFT backend for the DFT interface" OFF)
option(ENABLE_PORTFFT_BACKEND "Enable the portFFT DFT backend for the DFT interface. Cannot be used with other DFT backends." OFF)

# sparse
option(ENABLE_CUSPARSE_BACKEND "Enable the cuSPARSE backend for the SPARSE_BLAS interface" OFF)

set(ONEMKL_SYCL_IMPLEMENTATION "dpc++" CACHE STRING "Name of the SYCL compiler")
set(HIP_TARGETS "" CACHE STRING "Target HIP architectures")

Expand Down Expand Up @@ -102,7 +105,8 @@ if(ENABLE_MKLGPU_BACKEND
list(APPEND DOMAINS_LIST "dft")
endif()
if(ENABLE_MKLCPU_BACKEND
OR ENABLE_MKLGPU_BACKEND)
OR ENABLE_MKLGPU_BACKEND
OR ENABLE_CUSPARSE_BACKEND)
list(APPEND DOMAINS_LIST "sparse_blas")
endif()

Expand All @@ -129,7 +133,7 @@ if(CMAKE_CXX_COMPILER OR NOT ONEMKL_SYCL_IMPLEMENTATION STREQUAL "dpc++")
string(REPLACE "\\" "/" CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER})
endif()
else()
if(ENABLE_CUBLAS_BACKEND OR ENABLE_CURAND_BACKEND OR ENABLE_CUSOLVER_BACKEND OR ENABLE_CUFFT_BACKEND
if(ENABLE_CUBLAS_BACKEND OR ENABLE_CURAND_BACKEND OR ENABLE_CUSOLVER_BACKEND OR ENABLE_CUFFT_BACKEND OR ENABLE_CUSPARSE_BACKEND
OR ENABLE_ROCBLAS_BACKEND OR ENABLE_ROCRAND_BACKEND OR ENABLE_ROCSOLVER_BACKEND OR ENABLE_ROCFFT_BACKEND)
set(CMAKE_CXX_COMPILER "clang++")
elseif(ENABLE_MKLGPU_BACKEND)
Expand Down
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ oneMKL is part of the [UXL Foundation](http://www.uxlfoundation.org).
</thead>
<tbody>
<tr>
<td rowspan=12 align="center">oneMKL interface</td>
<td rowspan=12 align="center">oneMKL selector</td>
<td rowspan=13 align="center">oneMKL interface</td>
<td rowspan=13 align="center">oneMKL selector</td>
<td align="center"><a href="https://software.intel.com/en-us/oneapi/onemkl">Intel(R) oneAPI Math Kernel Library (oneMKL)</a></td>
<td align="center">x86 CPU, Intel GPU</td>
</tr>
Expand All @@ -28,10 +28,10 @@ oneMKL is part of the [UXL Foundation](http://www.uxlfoundation.org).
<td align="center"><a href="https://developer.nvidia.com/cublas"> NVIDIA cuBLAS</a></td>
<td align="center">NVIDIA GPU</td>
</tr>
<tr>
<tr>
<td align="center"><a href="https://developer.nvidia.com/cusolver"> NVIDIA cuSOLVER</a></td>
<td align="center">NVIDIA GPU</td>
</tr>
</tr>
<tr>
<td align="center"><a href="https://developer.nvidia.com/curand"> NVIDIA cuRAND</a></td>
<td align="center">NVIDIA GPU</td>
Expand All @@ -40,6 +40,10 @@ oneMKL is part of the [UXL Foundation](http://www.uxlfoundation.org).
<td align="center"><a href="https://developer.nvidia.com/cufft"> NVIDIA cuFFT</a></td>
<td align="center">NVIDIA GPU</td>
</tr>
<tr>
<td align="center"><a href="https://developer.nvidia.com/cusparse"> NVIDIA cuSPARSE</a></td>
<td align="center">NVIDIA GPU</td>
</tr>
<tr>
<td align="center"><a href="https://ww.netlib.org"> NETLIB LAPACK</a> </td>
<td align="center">x86 CPU</td>
Expand Down Expand Up @@ -329,7 +333,7 @@ Supported compilers include:
<td align="center">Dynamic, Static</td>
</tr>
<tr>
<td rowspan=2 align="center">SPARSE_BLAS</td>
<td rowspan=3 align="center">SPARSE_BLAS</td>
<td align="center">x86 CPU</td>
<td align="center">Intel(R) oneMKL</td>
<td align="center">Intel DPC++</td>
Expand All @@ -341,6 +345,12 @@ Supported compilers include:
<td align="center">Intel DPC++</td>
<td align="center">Dynamic, Static</td>
</tr>
<tr>
<td align="center">NVIDIA GPU</td>
<td align="center">NVIDIA cuSPARSE</td>
<td align="center">Open DPC++</td>
<td align="center">Dynamic, Static</td>
</tr>
</tbody>
</table>

Expand Down
4 changes: 2 additions & 2 deletions cmake/FindCompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if(is_dpcpp)
# Check if the Nvidia target is supported. PortFFT uses this for choosing default configuration.
check_cxx_compiler_flag("-fsycl -fsycl-targets=nvptx64-nvidia-cuda" dpcpp_supports_nvptx64)

if(ENABLE_CURAND_BACKEND OR ENABLE_CUSOLVER_BACKEND)
if(ENABLE_CURAND_BACKEND OR ENABLE_CUSOLVER_BACKEND OR ENABLE_CUSPARSE_BACKEND)
list(APPEND UNIX_INTERFACE_COMPILE_OPTIONS
-fsycl-targets=nvptx64-nvidia-cuda -fsycl-unnamed-lambda)
list(APPEND UNIX_INTERFACE_LINK_OPTIONS
Expand All @@ -51,7 +51,7 @@ if(is_dpcpp)
-fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend
--offload-arch=${HIP_TARGETS})
endif()
if(ENABLE_CURAND_BACKEND OR ENABLE_CUSOLVER_BACKEND OR ENABLE_ROCBLAS_BACKEND
if(ENABLE_CURAND_BACKEND OR ENABLE_CUSOLVER_BACKEND OR ENABLE_CUSPARSE_BACKEND OR ENABLE_ROCBLAS_BACKEND
OR ENABLE_ROCRAND_BACKEND OR ENABLE_ROCSOLVER_BACKEND)
set_target_properties(ONEMKL::SYCL::SYCL PROPERTIES
INTERFACE_COMPILE_OPTIONS "${UNIX_INTERFACE_COMPILE_OPTIONS}"
Expand Down
8 changes: 6 additions & 2 deletions docs/building_the_project_with_dpcpp.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ The most important supported build options are:
* - ENABLE_CURAND_BACKEND
- True, False
- False
* - ENABLE_CUSPARSE_BACKEND
- True, False
- False
* - ENABLE_NETLIB_BACKEND
- True, False
- False
Expand Down Expand Up @@ -183,8 +186,8 @@ Building for CUDA
^^^^^^^^^^^^^^^^^

The CUDA backends can be enabled with ``ENABLE_CUBLAS_BACKEND``,
``ENABLE_CUFFT_BACKEND``, ``ENABLE_CURAND_BACKEND``, and
``ENABLE_CUSOLVER_BACKEND``.
``ENABLE_CUFFT_BACKEND``, ``ENABLE_CURAND_BACKEND``,
``ENABLE_CUSOLVER_BACKEND``, and ``ENABLE_CUSPARSE_BACKEND``.

No additional parameters are required for using CUDA libraries. In most cases,
the CUDA libraries should be found automatically by CMake.
Expand Down Expand Up @@ -371,6 +374,7 @@ disabled using the Ninja build system:
-DENABLE_CUBLAS_BACKEND=True \
-DENABLE_CUSOLVER_BACKEND=True \
-DENABLE_CURAND_BACKEND=True \
-DENABLE_CUSPARSE_BACKEND=True \
-DBUILD_FUNCTIONAL_TESTS=False

``$ONEMKL_DIR`` points at the oneMKL source directly. The x86 CPU (``MKLCPU``)
Expand Down
139 changes: 134 additions & 5 deletions docs/domains/sparse_linear_algebra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,150 @@ Currently known limitations:
- ``oneapi::mkl::sparse::set_csr_data`` and
``oneapi::mkl::sparse::set_coo_data`` functions cannot be used on a handle
that has already been used for an operation or its optimize function. Doing so
will throw an ``oneapi::mkl::unimplemented`` exception.
will throw a ``oneapi::mkl::unimplemented`` exception.
- Using ``spsv`` with the ``oneapi::mkl::sparse::spsv_alg::no_optimize_alg`` and
a sparse matrix that does not have the
``oneapi::mkl::sparse::matrix_property::sorted`` property will throw an
``oneapi::mkl::sparse::matrix_property::sorted`` property will throw a
``oneapi::mkl::unimplemented`` exception.
- Using ``spmm`` on Intel GPU with a sparse matrix that is
``oneapi::mkl::transpose::conjtrans`` and has the
``oneapi::mkl::sparse::matrix_property::symmetric`` property will throw an
``oneapi::mkl::sparse::matrix_property::symmetric`` property will throw a
``oneapi::mkl::unimplemented`` exception.
- Using ``spmv`` with a sparse matrix that is
``oneapi::mkl::transpose::conjtrans`` with a ``type_view``
``matrix_descr::symmetric`` or ``matrix_descr::hermitian`` will throw an
``matrix_descr::symmetric`` or ``matrix_descr::hermitian`` will throw a
``oneapi::mkl::unimplemented`` exception.
- Using ``spsv`` on Intel GPU with a sparse matrix that is
``oneapi::mkl::transpose::conjtrans`` and will throw an
``oneapi::mkl::transpose::conjtrans`` and will throw a
``oneapi::mkl::unimplemented`` exception.
- Scalar parameters ``alpha`` and ``beta`` should be host pointers to prevent
synchronizations and copies to the host.


cuSPARSE backend
----------------

Currently known limitations:

- The COO format requires the indices to be sorted by row. See the `cuSPARSE
documentation
<https://docs.nvidia.com/cuda/cusparse/index.html#coordinate-coo>`_. Sparse
operations using matrices with the COO format without the property
``matrix_property::sorted_by_rows`` or ``matrix_property::sorted`` will throw
a ``oneapi::mkl::unimplemented`` exception.
- Using ``spmm`` with the algorithm ``spmm_alg::csr_alg3`` and an ``opA`` other
than ``transpose::nontrans`` or an ``opB`` ``transpose::conjtrans`` will throw
a ``oneapi::mkl::unimplemented`` exception.
- Using ``spmm`` with the algorithm ``spmm_alg::csr_alg3``,
``opB=transpose::trans`` and real fp64 precision will throw a
``oneapi::mkl::unimplemented`` exception. This configuration can fail as of
CUDA 12.6.2, see the related issue
`here<https://forums.developer.nvidia.com/t/cusparse-spmm-sample-failing-with-misaligned-address/311022>`_.
- Using ``spmv`` with a ``type_view`` other than ``matrix_descr::general`` will
throw a ``oneapi::mkl::unimplemented`` exception.
- Using ``spsv`` with the algorithm ``spsv_alg::no_optimize_alg`` may still
perform some mandatory preprocessing.
- oneMKL Interface does not provide a way to use non-default algorithms without
calling preprocess functions such as ``cusparseSpMM_preprocess`` or
``cusparseSpMV_preprocess``. Feel free to create an issue if this is needed.


Operation algorithms mapping
----------------------------

The following tables describe how a oneMKL SYCL Interface algorithm maps to the
backend's algorithms. Refer to the backend's documentation for a more detailed
explanation of the algorithms.

Backends with no equivalent algorithms will fallback to the backend's default
behavior.
gajanan-choudhary marked this conversation as resolved.
Show resolved Hide resolved


spmm
^^^^

.. list-table::
:header-rows: 1
:widths: 10 30 45

* - ``spmm_alg`` value
- MKLCPU/MKLGPU
- cuSPARSE
* - ``default_alg``
- none
- ``CUSPARSE_SPMM_ALG_DEFAULT``
* - ``no_optimize_alg``
- none
- ``CUSPARSE_SPMM_ALG_DEFAULT``
* - ``coo_alg1``
- none
- ``CUSPARSE_SPMM_COO_ALG1``
* - ``coo_alg2``
- none
- ``CUSPARSE_SPMM_COO_ALG2``
* - ``coo_alg3``
- none
- ``CUSPARSE_SPMM_COO_ALG3``
* - ``coo_alg4``
- none
- ``CUSPARSE_SPMM_COO_ALG4``
* - ``csr_alg1``
- none
- ``CUSPARSE_SPMM_CSR_ALG1``
* - ``csr_alg2``
- none
- ``CUSPARSE_SPMM_CSR_ALG2``
* - ``csr_alg3``
- none
- ``CUSPARSE_SPMM_CSR_ALG3``


spmv
^^^^

.. list-table::
:header-rows: 1
:widths: 10 30 45

* - ``spmv_alg`` value
- MKLCPU/MKLGPU
- cuSPARSE
* - ``default_alg``
- none
- ``CUSPARSE_SPMV_ALG_DEFAULT``
* - ``no_optimize_alg``
- none
- ``CUSPARSE_SPMV_ALG_DEFAULT``
* - ``coo_alg1``
- none
- ``CUSPARSE_SPMV_COO_ALG1``
* - ``coo_alg2``
- none
- ``CUSPARSE_SPMV_COO_ALG2``
* - ``csr_alg1``
- none
- ``CUSPARSE_SPMV_CSR_ALG1``
* - ``csr_alg2``
- none
- ``CUSPARSE_SPMV_CSR_ALG2``
* - ``csr_alg3``
- none
- ``CUSPARSE_SPMV_ALG_DEFAULT``


spsv
^^^^

.. list-table::
:header-rows: 1
:widths: 10 30 45

* - ``spsv_alg`` value
- MKLCPU/MKLGPU
- cuSPARSE
* - ``default_alg``
- none
- ``CUSPARSE_SPSV_ALG_DEFAULT``
* - ``no_optimize_alg``
- none
- ``CUSPARSE_SPSV_ALG_DEFAULT``
Loading