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

[oneMKL][spblas] Update sparse blas API #522

Merged
merged 53 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
8b413e1
[oneMKL][spblas] Update sparse blas API
Rbiessy Feb 21, 2024
3e5c258
Reword high level sparse_blas domain page
Rbiessy Mar 5, 2024
0b92a22
Fix set_dense_vector_data alignment
Rbiessy Mar 5, 2024
ce62ad3
Rename template types to dataType and indexType
Rbiessy Mar 7, 2024
52a3a6e
Add comma
Rbiessy Mar 11, 2024
c272e3f
Capitalize acronym
Rbiessy Mar 11, 2024
e6811a4
Remove /
Rbiessy Mar 11, 2024
96bee85
Clarify non-zero entries
Rbiessy Mar 11, 2024
2545e7b
Add requirements on workspace alignment
Rbiessy Mar 11, 2024
6db7514
Clarify alpha and beta type
Rbiessy Mar 11, 2024
fda672d
Do not italicise T and H
Rbiessy Mar 11, 2024
2b00cf5
Reword and format spsv description
Rbiessy Mar 11, 2024
c863160
Reorder operations alphabetically
Rbiessy Mar 11, 2024
8a8f675
Replace occurences of sparse_matrix_handle_t with matrix_handle_t
Rbiessy Mar 12, 2024
13825be
Reword sparse_linear_algebra paragraph
Rbiessy Mar 12, 2024
c61ff7e
Avoid variable names in high level create_* functions description
Rbiessy Mar 12, 2024
13dd2e5
Clarify that container sizes are minimum sizes
Rbiessy Mar 12, 2024
ad83d1c
Clarify requirements on the COO and CSR sizes
Rbiessy Mar 13, 2024
b7037b5
Document that using smaller USM pointer is undefined behavior
Rbiessy Mar 13, 2024
4db05aa
Remove onemkl_exception_device_bad_alloc from create_* and set_*_data…
Rbiessy Mar 13, 2024
90c4cec
Fix matrix_view todo
Rbiessy Mar 14, 2024
0942926
Fix diagonal property description
Rbiessy Mar 14, 2024
dd541fe
Use bitmask for matrix properties
Rbiessy Mar 14, 2024
4b66461
Keep sparse_linear_algebra vague
Rbiessy Mar 21, 2024
81b8be5
Restrict workspace from being sub-buffers
Rbiessy Mar 22, 2024
652bfe7
Add no_optimize_alg and remove algorithms tables
Rbiessy Apr 4, 2024
c22684f
Remove trailing commas
Rbiessy Apr 4, 2024
02013d5
Make destroy and release functions aynchronous
Rbiessy Apr 5, 2024
b4c2a46
Update sorted description
Rbiessy Apr 5, 2024
0f7c767
Remove restriction on create_*_matrix to support multiple calls with …
Rbiessy Apr 5, 2024
15139cc
Make uplo_view description match with diag_view
Rbiessy Apr 5, 2024
7c34155
Rephrase operation descriptions
Rbiessy Apr 5, 2024
3ab3c5e
Clarifications on workspace
Rbiessy Apr 6, 2024
1cbd268
Clarify temp_buffer_size is the minimum workspace size
Rbiessy Apr 6, 2024
d0393b1
Minor fixes and rewording
Rbiessy Apr 6, 2024
4128a65
Rename create_* and destroy_* functions to init_* and release_*
Rbiessy Apr 6, 2024
ed39695
More rewording regarding nnz
Rbiessy Apr 6, 2024
32e43ff
Make alpha and beta const
Rbiessy Apr 6, 2024
15ec0e5
Clarify that optimize functions can reset the descriptor's data
Rbiessy Apr 7, 2024
16ed109
Remove references from buffers
Rbiessy Apr 11, 2024
9a422f6
Merge branch 'main' into romain/sparse_api
Rbiessy Apr 18, 2024
1060c7a
Clarify container types must be consistent
Rbiessy Apr 26, 2024
51e4068
Clarify restrictions to reset handles' data
Rbiessy May 2, 2024
ebc779c
Add comment on COO performance
Rbiessy May 3, 2024
7247b6d
Clarify matrix_properties are hints
Rbiessy May 3, 2024
38dbaef
Fix typos
Rbiessy May 3, 2024
ac1b223
Add note on operations' descriptor
Rbiessy May 3, 2024
1292ad6
Revert to set_matrix_property
Rbiessy May 6, 2024
e279fa3
Specify that dependencies and events may be unused for buffers
Rbiessy May 6, 2024
669a4e7
Clarify sorted property for COO format
Rbiessy May 7, 2024
8f94f4d
Add more notes on the purpose of the operation descriptors
Rbiessy May 7, 2024
1c236f7
Disallow changing sparse matrices before calling gemm or gemv
Rbiessy May 7, 2024
62bbc6e
Fix warning
Rbiessy May 7, 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
40 changes: 17 additions & 23 deletions source/elements/oneMKL/source/domains/sparse_linear_algebra.inc.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. SPDX-FileCopyrightText: 2019-2020 Intel Corporation
.. SPDX-FileCopyrightText: 2024 Intel Corporation
..
.. SPDX-License-Identifier: CC-BY-4.0

Expand All @@ -9,29 +9,23 @@ Sparse Linear Algebra

.. container::


The oneAPI Math Kernel Library provides a Data Parallel C++ interface
to some of the Sparse Linear Algebra routines.

:ref:`onemkl_spblas` provides basic operations on sparse vectors and matrices, and
separates them into two stages: analysis
(also called inspector stage or optimize stage) and execution. For a given matrix,
the analysis would typically be called one time and the execution may be called
multiple times. During the analysis stage, the API inspects the matrix properties
including size, sparsity pattern and available parallelism and can apply matrix
format or structure changes to enable a more optimized algorithm.
In the execution stage, multiple routine calls can take advantage of the analysis
stage data in order to improve performance.


In order to save information in between calls to Sparse BLAS computation routines,
the :ref:`onemkl_sparse_matrix_handle_t` type is introduced, that is essentially
an opaque pointer, used to store data related to initial sparse matrix
and data obtained during analysis stage.

The oneAPI Math Kernel Library provides a C++ interface to some Sparse Linear
Algebra routines using SYCL.

Rbiessy marked this conversation as resolved.
Show resolved Hide resolved
:ref:`onemkl_spblas` provides basic operations on sparse vectors and
matrices. Most operations are split into three stages: query of the external
workspace size, optimization stage and execution. For a given configuration,
the first two stages would typically be called once for a set of input
arguments and the execution stage may be called multiple times. During the
Rbiessy marked this conversation as resolved.
Show resolved Hide resolved
optimization stage, the API may inspect the matrix properties including size,
sparsity pattern and available parallelism, and may apply matrix format or
structure changes to enable a more optimized algorithm. User-provided matrix
data remain unmodified if such optimizations are made. In the execution
stage, multiple routine calls can take advantage of the optimization stage
data in order to improve performance.

.. toctree::
:hidden:
:hidden:

spblas/spblas.rst
spblas/spblas.rst

Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
.. SPDX-FileCopyrightText: 2024 Intel Corporation
..
.. SPDX-License-Identifier: CC-BY-4.0

.. _onemkl_sparse_create_coo_matrix:

create_coo_matrix
=================

Initializes a ``matrix_handle_t`` object with the provided COO data.

.. rubric:: Description and Assumptions

The ``oneapi::mkl::sparse::create_coo_matrix`` function initializes the
``matrix_handle_t`` object with the provided data.

In the case of buffers, the reference count of the provided buffer is
incremented which extends the lifetime of the underlying buffer until the sparse
matrix handle is destroyed with ``destroy_sparse_matrix`` or the data is reset
with ``set_coo_matrix_data``.

In the case of USM, the object does not take ownership of the data.

The ``oneapi::mkl::sparse::create_coo_matrix`` function defined below takes in
the number of non-zero elements in the sparse matrix as an argument. However, in
certain math operations where the output is a sparse matrix, e.g., sparse matrix
addition (sparse matrix + sparse matrix = sparse matrix), and multiplication of
two sparse matrices, the number of non-zero elements in the output sparse matrix
is not known in advance and must be calculated as part of the operation API.
Rbiessy marked this conversation as resolved.
Show resolved Hide resolved
Such APIs are currently not a part of the current oneMKL Specification, but will
Rbiessy marked this conversation as resolved.
Show resolved Hide resolved
be added in the future. Therefore, it is important for the ``create_coo_matrix``
API to be able to handle multiple calls to build the sparse matrix as function
arguments become known and arrays are allocated with the correct sizes. In
particular, the ``create_coo_matrix`` API must handle the case where the number
of non-zero elements in the matrix are unknown and the matrix arrays are
``nullptr`` or zero-sized ``sycl::buffer`` objects as applicable. This behavior
is currently left to be implementation-defined, but may be clarified in the
oneMKL Specification in the future.

See :ref:`onemkl_sparse_matrix_handle`.

.. _onemkl_sparse_create_coo_matrix_buffer:

create_coo_matrix (Buffer version)
----------------------------------

.. rubric:: Syntax

.. code-block:: cpp

namespace oneapi::mkl::sparse {

template <typename dataType, typename indexType>
void create_coo_matrix (sycl::queue &queue,
Rbiessy marked this conversation as resolved.
Show resolved Hide resolved
oneapi::mkl::sparse::matrix_handle_t *p_smhandle,
std::int64_t num_rows,
std::int64_t num_cols,
std::int64_t nnz,
index_base index,
sycl::buffer<indexType, 1> &row_ind,
sycl::buffer<indexType, 1> &col_ind,
sycl::buffer<dataType, 1> &val);

}

.. container:: section

.. rubric:: Template parameters

dataType
See :ref:`supported template types<onemkl_sparse_supported_types>`.

indexType
See :ref:`supported template types<onemkl_sparse_supported_types>`.

.. container:: section

.. rubric:: Input parameters

queue
The SYCL command queue which will be used for SYCL kernels execution.

p_smhandle
The address of the ``p_smhandle`` object to be initialized. Must only be
called on an uninitialized ``matrix_handle_t`` object.
gajanan-choudhary marked this conversation as resolved.
Show resolved Hide resolved

num_rows
Number of rows of the provided data ``val``. Must be at least 0.
Rbiessy marked this conversation as resolved.
Show resolved Hide resolved

num_cols
Number of columns of the provided data ``val``. Must be at least 0.

nnz
Number of non-zero entries in the matrix (which may include explicit
zeros). Must be at least 0.
Rbiessy marked this conversation as resolved.
Show resolved Hide resolved

index
Indicates how input arrays are indexed. The possible options are described
in :ref:`onemkl_enum_index_base` enum class.

row_ind
Buffer of length at least ``nnz`` containing the row indices in
``index``-based numbering. Refer to :ref:`onemkl_sparse_coo` format for
detailed description of ``row_ind``.

col_ind
Buffer of length at least ``nnz`` containing the column indices in
``index``-based numbering. Refer to :ref:`onemkl_sparse_coo` format for
detailed description of ``col_ind``.

val
Buffer of length at least ``nnz`` containing non-zero elements (and
possibly explicit zeros) of the input matrix. Refer to
:ref:`onemkl_sparse_coo` format for detailed description of ``val``.

.. container:: section

.. rubric:: Output parameters

p_smhandle
On return, the address is updated to point to a newly allocated and
initialized ``matrix_handle_t`` object that can be filled and used to
perform sparse BLAS operations.

.. container:: section

.. rubric:: Notes

- The parameters ``num_rows``, ``num_cols`` and ``nnz`` may be zero if and
only if ``row_ind``, ``col_ind`` and ``val`` are zero-sized, otherwise they
must be strictly greater than zero.

.. container:: section

.. rubric:: Throws

This function shall throw the following exceptions if the associated
condition is detected. An implementation may throw additional
implementation-specific exception(s) in case of error conditions not covered
here.

| :ref:`oneapi::mkl::host_bad_alloc<onemkl_exception_host_bad_alloc>`
| :ref:`oneapi::mkl::invalid_argument<onemkl_exception_invalid_argument>`
| :ref:`oneapi::mkl::unimplemented<onemkl_exception_unimplemented>`
| :ref:`oneapi::mkl::unsupported_device<onemkl_exception_unsupported_device>`

.. _onemkl_sparse_create_coo_matrix_usm:

create_coo_matrix (USM version)
-------------------------------

.. rubric:: Syntax

.. code-block:: cpp

namespace oneapi::mkl::sparse {

template <typename dataType, typename indexType>
void create_coo_matrix (sycl::queue &queue,
oneapi::mkl::sparse::matrix_handle_t *p_smhandle,
std::int64_t num_rows,
std::int64_t num_cols,
std::int64_t nnz,
index_base index,
indexType *row_ind,
indexType *col_ind,
dataType *val);

}

.. container:: section

.. rubric:: Template parameters

dataType
See :ref:`supported template types<onemkl_sparse_supported_types>`.

indexType
See :ref:`supported template types<onemkl_sparse_supported_types>`.

.. container:: section

.. rubric:: Input parameters

queue
The SYCL command queue which will be used for SYCL kernels execution.

p_smhandle
The address of the ``p_smhandle`` object to be initialized. Must only be
called on an uninitialized ``matrix_handle_t`` object.

num_rows
Number of rows of the provided data ``val``. Must be at least 0.

num_cols
Number of columns of the provided data ``val``. Must be at least 0.

nnz
Number of non-zero entries in the matrix (which may include explicit
zeros). Must be at least 0.

index
Indicates how input arrays are indexed. The possible options are described
in :ref:`onemkl_enum_index_base` enum class.

row_ind
USM pointer of length at least ``nnz`` containing the row indices in
``index``-based numbering. Refer to :ref:`onemkl_sparse_coo` format for
detailed description of ``row_ind``. The data must be accessible on the
device.

col_ind
USM pointer of length at least ``nnz`` containing the column indices in
``index``-based numbering. Refer to :ref:`onemkl_sparse_coo` format for
detailed description of ``col_ind``. The data must be accessible on the
device.

val
USM pointer of length at least ``nnz`` containing non-zero elements (and
possibly explicit zeros) of the input matrix. Refer to
:ref:`onemkl_sparse_coo` format for detailed description of ``val``. The
data must be accessible on the device. Using a USM pointer with a smaller
allocated memory size is undefined behavior.

.. container:: section

.. rubric:: Output parameters

p_smhandle
On return, the address is updated to point to a newly allocated and
initialized ``matrix_handle_t`` object that can be filled and used to
perform sparse BLAS operations.

.. container:: section

.. rubric:: Notes

- The parameters ``num_rows``, ``num_cols`` and ``nnz`` may be zero if and
only if ``row_ind``, ``col_ind`` and ``val`` are null pointers, otherwise
they must be strictly greater than zero.

.. container:: section

.. rubric:: Throws

This function shall throw the following exceptions if the associated
condition is detected. An implementation may throw additional
implementation-specific exception(s) in case of error conditions not covered
here.

| :ref:`oneapi::mkl::host_bad_alloc<onemkl_exception_host_bad_alloc>`
| :ref:`oneapi::mkl::invalid_argument<onemkl_exception_invalid_argument>`
| :ref:`oneapi::mkl::unimplemented<onemkl_exception_unimplemented>`
| :ref:`oneapi::mkl::unsupported_device<onemkl_exception_unsupported_device>`

**Parent topic:** :ref:`onemkl_sparse_data_handles`
Loading
Loading